Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added four fiducial points. #125

Merged
merged 8 commits into from
May 11, 2021
Merged
4 changes: 2 additions & 2 deletions src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def generateBaseMesh(cls, region, options):
elementtemplate.defineField(coordinates, -1, eft)

neckGroup = AnnotationGroup(region, get_bladder_term("neck of urinary bladder"))
bodyGroup = AnnotationGroup(region, get_bladder_term("Dome of the Bladder"))
bodyGroup = AnnotationGroup(region, get_bladder_term("dome of the bladder"))
urinaryBladderGroup = AnnotationGroup(region, get_bladder_term("urinary bladder"))
annotationGroups = [neckGroup, bodyGroup, urinaryBladderGroup]

Expand Down Expand Up @@ -863,7 +863,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups):
# create 2d surface mesh groups
fm = region.getFieldmodule()
neckGroup = getAnnotationGroupForTerm(annotationGroups, get_bladder_term("neck of urinary bladder"))
bodyGroup = getAnnotationGroupForTerm(annotationGroups, get_bladder_term("Dome of the Bladder"))
bodyGroup = getAnnotationGroupForTerm(annotationGroups, get_bladder_term("dome of the bladder"))
urinaryBladderGroup = getAnnotationGroupForTerm(annotationGroups, get_bladder_term("urinary bladder"))
mesh2d = fm.findMeshByDimension(2)
is_exterior = fm.createFieldIsExterior()
Expand Down
139 changes: 97 additions & 42 deletions src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,52 +677,53 @@ def generateBaseMesh(cls, region, options):
outerNodes_d1.append(d1List[(2 * n2 + 1) * elementsCountAround + n1])
outerNodes_d2.append(d2List[(2 * n2 + 1) * elementsCountAround + n1])

elementsCount1 = elementsCountAround // 2
elementsCount2 = elementsCountAlongBladder
# Create trackSurface at the outer layer of the bladder for ureter 1
nodesOnTrackSurface_x = []
nodesOnTrackSurface_d1 = []
nodesOnTrackSurface_d2 = []
for n2 in range(elementsCountAlongBladder + 1):
for n1 in range(elementsCountAround // 2 + 1):
nodesOnTrackSurface_x.append(outerNodes_x[n2 * elementsCountAround + n1])
nodesOnTrackSurface_d1.append(outerNodes_d1[n2 * elementsCountAround + n1])
nodesOnTrackSurface_d2.append(outerNodes_d2[n2 * elementsCountAround + n1])
trackSurfaceUreter1 = TrackSurface(elementsCount1, elementsCount2, nodesOnTrackSurface_x,
nodesOnTrackSurface_d1, nodesOnTrackSurface_d2)

ureter1Position = trackSurfaceUreter1.createPositionProportion(ureterPositionAround, ureterPositionDown)
ureterElementPositionAround = ureter1Position.e1
ureterElementPositionDown = ureter1Position.e2
elementToDeleteStartIdx1 = elementsCountThroughWall * elementsCountAround * (ureterElementPositionDown - (0 if ureter1Position.xi2 > 0.5 else 1)) \
+ ureterElementPositionAround + (1 if ureter1Position.xi1 > 0.5 else 0)

elementIndex = elementToDeleteStartIdx1 - elementsCountAround * ureterElementPositionDown

# Create trackSurface at the outer layer of the bladder for ureter 2
nodesOnTrackSurface2_x = []
nodesOnTrackSurface2_d1 = []
nodesOnTrackSurface2_d2 = []
for n2 in range(elementsCountAlongBladder + 1):
for n1 in range(elementsCountAround // 2, elementsCountAround):
nodesOnTrackSurface2_x.append(outerNodes_x[n2 * elementsCountAround + n1])
nodesOnTrackSurface2_d1.append(outerNodes_d1[n2 * elementsCountAround + n1])
nodesOnTrackSurface2_d2.append(outerNodes_d2[n2 * elementsCountAround + n1])
nodesOnTrackSurface2_x.append(outerNodes_x[n2 * elementsCountAround])
nodesOnTrackSurface2_d1.append(outerNodes_d1[n2 * elementsCountAround])
nodesOnTrackSurface2_d2.append(outerNodes_d2[n2 * elementsCountAround])

trackSurfaceUreter2 = TrackSurface(elementsCount1, elementsCount2, nodesOnTrackSurface2_x,
nodesOnTrackSurface2_d1, nodesOnTrackSurface2_d2)
ureter2Position = TrackSurfacePosition(elementsCountAround // 2 - ureterElementPositionAround + (-1 if ureter1Position.xi1 > 0 else 0),
ureterElementPositionDown,
(1 - ureter1Position.xi1) if ureter1Position.xi1 > 0 else ureter1Position.xi1,
ureter1Position.xi2)

if includeUreter:
elementsCount1 = elementsCountAround // 2
elementsCount2 = elementsCountAlongBladder
# Create trackSurface at the outer layer of the bladder for ureter 1
nodesOnTrackSurface_x = []
nodesOnTrackSurface_d1 = []
nodesOnTrackSurface_d2 = []
for n2 in range(elementsCountAlongBladder + 1):
for n1 in range(elementsCountAround // 2 + 1):
nodesOnTrackSurface_x.append(outerNodes_x[n2 * elementsCountAround + n1])
nodesOnTrackSurface_d1.append(outerNodes_d1[n2 * elementsCountAround + n1])
nodesOnTrackSurface_d2.append(outerNodes_d2[n2 * elementsCountAround + n1])
trackSurfaceUreter1 = TrackSurface(elementsCount1, elementsCount2, nodesOnTrackSurface_x,
nodesOnTrackSurface_d1, nodesOnTrackSurface_d2)

ureter1Position = trackSurfaceUreter1.createPositionProportion(ureterPositionAround, ureterPositionDown)
ureterElementPositionAround = ureter1Position.e1
ureterElementPositionDown = ureter1Position.e2
elementToDeleteStartIdx1 = elementsCountThroughWall * elementsCountAround * (ureterElementPositionDown - (0 if ureter1Position.xi2 > 0.5 else 1)) \
+ ureterElementPositionAround + (1 if ureter1Position.xi1 > 0.5 else 0)

elementIndex = elementToDeleteStartIdx1 - elementsCountAround * ureterElementPositionDown
if ureterElementPositionAround > (elementsCountAround / 4):
elementsCountVentral1 = (elementsCountAround // 4)
else:
elementsCountVentral1 = elementIndex - 1

# Create trackSurface at the outer layer of the bladder for ureter 2
nodesOnTrackSurface2_x = []
nodesOnTrackSurface2_d1 = []
nodesOnTrackSurface2_d2 = []
for n2 in range(elementsCountAlongBladder + 1):
for n1 in range(elementsCountAround // 2, elementsCountAround):
nodesOnTrackSurface2_x.append(outerNodes_x[n2 * elementsCountAround + n1])
nodesOnTrackSurface2_d1.append(outerNodes_d1[n2 * elementsCountAround + n1])
nodesOnTrackSurface2_d2.append(outerNodes_d2[n2 * elementsCountAround + n1])
nodesOnTrackSurface2_x.append(outerNodes_x[n2 * elementsCountAround])
nodesOnTrackSurface2_d1.append(outerNodes_d1[n2 * elementsCountAround])
nodesOnTrackSurface2_d2.append(outerNodes_d2[n2 * elementsCountAround])

trackSurfaceUreter2 = TrackSurface(elementsCount1, elementsCount2, nodesOnTrackSurface2_x,
nodesOnTrackSurface2_d1, nodesOnTrackSurface2_d2)
ureter2Position = TrackSurfacePosition(elementsCountAround // 2 - ureterElementPositionAround + (-1 if ureter1Position.xi1 > 0 else 0),
ureterElementPositionDown,
(1 - ureter1Position.xi1) if ureter1Position.xi1 > 0 else ureter1Position.xi1,
ureter1Position.xi2)
else:
elementsCountVentral1 = elementsCountAround // 4

Expand Down Expand Up @@ -813,14 +814,68 @@ def generateBaseMesh(cls, region, options):
ureterMeshGroup, bladderMeshGroup)

# Apex annotation point
nodeIdentifier = nextNodeIdentifier
nodeIdentifier = nextNodeIdentifier + elementsCountAroundUreter * 4 * 2 + elementsCountAroundUreter * 2 * 2 * elementsCountUreterRadial
idx = 1
element1 = mesh.findElementByIdentifier(idx)
markerPoint = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerPoint)
markerName.assignString(cache, 'Apex of urinary bladder')
markerLocation.assignMeshLocation(cache, element1, [0.0, 0.0, 1.0])

# Markers for ureters
if includeUreter:
# Left ureter
nodeIdentifier += 1
idx1 = elementsCountAlong * elementsCountAround + elementsCountAroundUreter
element1 = mesh.findElementByIdentifier(idx1)
markerUreter1Point = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerUreter1Point)
markerName.assignString(cache, 'ureter junction of bladder trigone')
markerLocation.assignMeshLocation(cache, element1, [0.0, 1.0, 1.0])
# Right ureter
nodeIdentifier += 1
idx2 = elementsCountAlong * elementsCountAround + 2 * elementsCountAroundUreter
element2 = mesh.findElementByIdentifier(idx2)
markerUreter2Point = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerUreter2Point)
markerName.assignString(cache, 'ureter junction of bladder trigone')
markerLocation.assignMeshLocation(cache, element2, [0.0, 1.0, 1.0])
else:
# Left ureter
nodeIdentifier += 1
idx1 = ureterElementPositionDown * elementsCountAround + ureterElementPositionAround + 1
element1 = mesh.findElementByIdentifier(idx1)
markerUreter1Point = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerUreter1Point)
markerName.assignString(cache, 'ureter junction of bladder trigone')
markerLocation.assignMeshLocation(cache, element1, [ureter1Position.xi1, ureter1Position.xi2, 1.0])
# Right ureter
nodeIdentifier += 1
idx2 = ureterElementPositionDown * elementsCountAround + elementsCountAround - ureterElementPositionAround
element2 = mesh.findElementByIdentifier(idx2)
markerUreter2Point = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerUreter2Point)
markerName.assignString(cache, 'ureter junction of bladder trigone')
markerLocation.assignMeshLocation(cache, element2, [1-ureter1Position.xi1, ureter1Position.xi2, 1.0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having 4 sets of code to make equivalent points. Prone to maintenance problems.
Can you propose a way to store the points in a structure, e.g. a dict { "name" : "ureter...", "element_id" : idx1, "xi" : [ x, y, z ] }. Then make the 2 points in common code below. I like to see minimum code in special case clauses.
Need to qualify names with left/right.
Do you mean 'ureter junction with bladder trigone'? Is it necessary to specify trigone?


# Markers for urethra
# Dorsal
nodeIdentifier += 1
idx1 = (elementsCountAlongBladder - 1) * elementsCountAround + elementsCountAround // 2
element1 = mesh.findElementByIdentifier(idx1)
markerUreter1Point = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerUreter1Point)
markerName.assignString(cache, 'urethra junction with bladder dorsal')
markerLocation.assignMeshLocation(cache, element1, [1.0, 1.0, 1.0])
# Ventral
nodeIdentifier += 1
idx1 = (elementsCountAlongBladder - 1) * elementsCountAround + 1
element1 = mesh.findElementByIdentifier(idx1)
markerUreter1Point = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerUreter1Point)
markerName.assignString(cache, 'urethra junction with bladder ventral')
markerLocation.assignMeshLocation(cache, element1, [0.0, 1.0, 1.0])

fm.endChange()
return annotationGroups

Expand Down