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
122 changes: 73 additions & 49 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 @@ -812,14 +813,37 @@ def generateBaseMesh(cls, region, options):
d2Final, nextNodeIdentifier, nextElementIdentifier, elementsCountUreterRadial,
ureterMeshGroup, bladderMeshGroup)

# Apex annotation point
nodeIdentifier = nextNodeIdentifier
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])
# Define markers for apex, ureter and urethra junctions with bladder
idx1 = 1
xi1 = [0.0, 0.0, 0.0]
if includeUreter:
idx2 = elementsCountAlong * elementsCountAround + elementsCountAroundUreter
idx3 = elementsCountAlong * elementsCountAround + 2 * elementsCountAroundUreter
xi2 = [0.0, 1.0, 0.0]
xi3 = [0.0, 1.0, 0.0]
else:
idx2 = ureterElementPositionDown * elementsCountAround * elementsCountThroughWall + ureterElementPositionAround + 1
idx3 = ureterElementPositionDown * elementsCountAround * elementsCountThroughWall + elementsCountAround - ureterElementPositionAround
xi2 = [ureter1Position.xi1, ureter1Position.xi2, 0.0]
xi3 = [1 - ureter1Position.xi1, ureter1Position.xi2, 0.0]
idx4 = (elementsCountAlongBladder - 1) * elementsCountAround * elementsCountThroughWall + elementsCountAround // 2
xi4 = [1.0, 1.0, 0.0]
idx5 = (elementsCountAlongBladder - 1) * elementsCountAround * elementsCountThroughWall + 1
xi5 = [0.0, 1.0, 0.0]

element_id = [idx1, idx2, idx3, idx4, idx5]
xi = [xi1, xi2, xi3, xi4, xi5]
marker_dic = {"name": ["Apex of urinary bladder", " left ureter junction with bladder", "right ureter junction with bladder",
"urethra junction with bladder dorsal", "urethra junction with bladder ventral"], "element_id": element_id, "xi": xi}
Copy link
Member

Choose a reason for hiding this comment

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

Better, but I suggest you rearrange all the above code to get the names at the top and assign them to variables e.g.

apexMarkerName = "apex of urinary bladder"
leftUreterMarkerName = "left ureter junction with bladder"
rightUreterMarkerName = "right ureter junction with bladder"
dorsalUrethraMarkerName = "urethra junction with bladder dorsal"
ventralUrethraMarkerName = "urethra junction with bladder ventral"

Then you can go through all your code cases and add markers to the following list:

markers = []
markers.append({ "name" : apexMarkerName, "element" : element, "xi" : xi })
if includeUreter:
    ...
    markers.append({ "name" : leftUreterMarkerName , "element" : element, "xi" : xi })
    ...
else:
    ...

At the end you can do a for loop over the markers and add them all.

The benefit is that you have the text names written once, the language will catch you if you put an incorrect variable name in for the marker, and each record of a marker point keeps name, element and xi together. All helpful for maintenance.

Also note that you had some capitals and leading whitespace in the names in your array...


nodeIdentifier = nextNodeIdentifier + elementsCountAroundUreter * 4 * 2 + elementsCountAroundUreter * 2 * 2 * elementsCountUreterRadial
for n in range(len(marker_dic["name"])):
element1 = mesh.findElementByIdentifier(marker_dic["element_id"][n])
markerPoint = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerPoint)
markerName.assignString(cache, (marker_dic["name"][n]))
markerLocation.assignMeshLocation(cache, element1, marker_dic["xi"][n])
nodeIdentifier += 1

fm.endChange()
return annotationGroups
Expand Down