Skip to content

Commit

Permalink
Merge pull request #125 from zekh167/bladder_marker
Browse files Browse the repository at this point in the history
Added four fiducial points.
  • Loading branch information
rchristie authored May 11, 2021
2 parents 5532f96 + fccc9fd commit e4ce4f1
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 52 deletions.
7 changes: 6 additions & 1 deletion src/scaffoldmaker/annotation/bladder_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
("ventral part of serosa of urethra", "ILX:0739306"),
("ventral part of serosa of urinary bladder", "ILX:0739249"),
("ventral part of bladder", "None"),
("ventral part of urethra", "ILX:0739259")
("ventral part of urethra", "ILX:0739259"),
("apex of urinary bladder", "ILX:0774405"),
("left ureter junction with bladder", "None"),
("right ureter junction with bladder", "None"),
("urethra junction with bladder dorsal", "None"),
("urethra junction with bladder ventral", "None")
]

def get_bladder_term(name : str):
Expand Down
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
134 changes: 85 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,49 @@ 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
apexGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("apex of urinary bladder"))
leftUreterGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("left ureter junction with bladder"))
rightUreterGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("right ureter junction with bladder"))
dorsalUrethraGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("urethra junction with bladder dorsal"))
ventralUrethraGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("urethra junction with bladder ventral"))

idx1 = 1
xi1 = [0.0, 0.0, 0.0]
markerList = []
markerList.append({"group": apexGroup, "elementId": idx1, "xi": xi1})
if includeUreter:
idx2 = elementsCountAlong * elementsCountAround + elementsCountAroundUreter
xi2 = [0.0, 1.0, 0.0]
markerList.append({"group": leftUreterGroup, "elementId": idx2, "xi": xi2})
idx3 = elementsCountAlong * elementsCountAround + 2 * elementsCountAroundUreter
xi3 = [0.0, 1.0, 0.0]
markerList.append({"group": rightUreterGroup, "elementId": idx3, "xi": xi3})
else:
idx2 = ureterElementPositionDown * elementsCountAround * elementsCountThroughWall + ureterElementPositionAround + 1
xi2 = [ureter1Position.xi1, ureter1Position.xi2, 0.0]
markerList.append({"group": leftUreterGroup, "elementId": idx2, "xi": xi2})
idx3 = ureterElementPositionDown * elementsCountAround * elementsCountThroughWall + elementsCountAround - ureterElementPositionAround
xi3 = [1 - ureter1Position.xi1, ureter1Position.xi2, 0.0]
markerList.append({"group": rightUreterGroup, "elementId": idx3, "xi": xi3})
idx4 = (elementsCountAlongBladder - 1) * elementsCountAround * elementsCountThroughWall + elementsCountAround // 2
xi4 = [1.0, 1.0, 0.0]
markerList.append({"group": dorsalUrethraGroup, "elementId": idx4, "xi": xi4})
idx5 = (elementsCountAlongBladder - 1) * elementsCountAround * elementsCountThroughWall + 1
xi5 = [0.0, 1.0, 0.0]
markerList.append({"group": ventralUrethraGroup, "elementId": idx5, "xi": xi5})

nodeIdentifier = nextNodeIdentifier + elementsCountAroundUreter * 4 * 2 + elementsCountAroundUreter * 2 * 2 * elementsCountUreterRadial
bladderNodesetGroup = bladderGroup.getNodesetGroup(nodes)
for marker in markerList:
annotationGroup = marker["group"]
markerPoint = markerPoints.createNode(nodeIdentifier, markerTemplateInternal)
cache.setNode(markerPoint)
markerLocation.assignMeshLocation(cache, mesh.findElementByIdentifier(marker["elementId"]), marker["xi"])
markerName.assignString(cache, annotationGroup.getName())
annotationGroup.getNodesetGroup(nodes).addNode(markerPoint)
bladderNodesetGroup.addNode(markerPoint)
nodeIdentifier += 1

fm.endChange()
return annotationGroups
Expand Down

0 comments on commit e4ce4f1

Please sign in to comment.