Skip to content

Commit

Permalink
Improve network mesh generator argument order
Browse files Browse the repository at this point in the history
  • Loading branch information
rchristie committed Oct 21, 2024
1 parent 87738d2 commit cbbc0ef
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 221 deletions.
15 changes: 10 additions & 5 deletions src/scaffoldmaker/annotation/uterus_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
("dorsal cervix junction with vagina", "None"),
("dorsal top left horn", "None"),
("dorsal top right horn", "None"),
("dorsal uterus", "None"),
("external cervical os", "UBERON:0013760", "FMA:76836", "ILX:0736534"),
("fundus of uterus", "None"),
("internal cervical os", "UBERON:0013759", "FMA:17747", "ILX:0729495"),
Expand All @@ -18,6 +19,7 @@
("left transverse cervical ligament", "None"),
("left uterine horn", "UBERON:0009020"),
("left uterine tube", "UBERON:0001303", "FMA:18484", "ILX:0734218"),
("left uterus", "None"),
("lumen of body of uterus", "None"),
("lumen of fallopian tube", "None"),
("lumen of left horn", "None"),
Expand All @@ -33,6 +35,7 @@
("right transverse cervical ligament", "None"),
("right uterine horn", "UBERON:0009022"),
("right uterine tube", "UBERON:0001302", "FMA:18483", "ILX:0724908"),
("right uterus", "None"),
("serosa of body of uterus", "None"),
("serosa of left uterine tube", "None"),
("serosa of left horn", "None"),
Expand All @@ -41,7 +44,7 @@
("serosa of uterine cervix", "None"),
("serosa of uterus", "UBERON:0001297"),
("serosa of vagina", "None"),
("uterine cervix", "UBERON:0000002","FMA:17740", "ILX:0724162"),
("uterine cervix", "UBERON:0000002", "FMA:17740", "ILX:0724162"),
("uterine horn", "UBERON:000224"),
("uterine lumen", "UBERON:0013769"),
("uterine wall", "UBERON:0000459", "FMA:17560", "ILX:0735839"),
Expand All @@ -50,15 +53,17 @@
("vagina orifice", "UBERON:0012317", "FMA:19984", "ILX:0729556"),
("ventral cervix junction with vagina", "None"),
("ventral top left horn", "None"),
("ventral top right horn", "None")]
("ventral top right horn", "None"),
("ventral uterus", "None")]


def get_uterus_term(name: str):
"""
Find term by matching name to any identifier held for a term.
Raise exception if name not found.
:return ( preferred name, preferred id )
:return: ( preferred name, preferred id )
"""
for term in uterus_terms:
if name in term:
return (term[0], term[1])
raise NameError("Uterus annotation term '" + name + "' not found.")
return term[0], term[1]
raise NameError("Uterus annotation term '" + name + "' not found.")
10 changes: 5 additions & 5 deletions src/scaffoldmaker/meshtypes/meshtype_2d_tubenetwork1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def getDefaultOptions(cls, parameterSetName="Default"):
options["Target element density along longest segment"] = 12.0
return options

@staticmethod
def getOrderedOptionNames():
@classmethod
def getOrderedOptionNames(cls):
return [
"Network layout",
"Number of elements around",
Expand Down Expand Up @@ -119,11 +119,11 @@ def generateBaseMesh(cls, region, options):
tubeNetworkMeshBuilder = TubeNetworkMeshBuilder(
networkMesh,
targetElementDensityAlongLongestSegment=options["Target element density along longest segment"],
defaultElementsCountAround=options["Number of elements around"],
elementsCountThroughWall=1,
layoutAnnotationGroups=networkLayout.getAnnotationGroups(),
annotationElementsCountsAlong=options["Annotation numbers of elements along"],
annotationElementsCountsAround=options["Annotation numbers of elements around"])
defaultElementsCountAround=options["Number of elements around"],
annotationElementsCountsAround=options["Annotation numbers of elements around"],
elementsCountThroughShell=1)
tubeNetworkMeshBuilder.build()
generateData = TubeNetworkMeshGenerateData(
region, 2,
Expand Down
28 changes: 9 additions & 19 deletions src/scaffoldmaker/meshtypes/meshtype_3d_tubenetwork1.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def getDefaultOptions(cls, parameterSetName="Default"):
options["Target element density along longest segment"] = 12.0
return options

@staticmethod
def getOrderedOptionNames():
@classmethod
def getOrderedOptionNames(cls):
return [
"Network layout",
"Number of elements around",
Expand Down Expand Up @@ -212,31 +212,21 @@ def generateBaseMesh(cls, region, options):
layoutRegion = region.createRegion()
networkLayout = options["Network layout"]
networkLayout.generate(layoutRegion) # ask scaffold to generate to get user-edited parameters
layoutAnnotationGroups = networkLayout.getAnnotationGroups()
networkMesh = networkLayout.getConstructionObject()

defaultAroundCount = options["Number of elements around"]
coreTransitionCount = options["Number of elements across core transition"]
defaultCoreBoxMinorCount = options["Number of elements across core box minor"]
# implementation currently uses major count including transition
defaultCoreMajorCount = defaultAroundCount // 2 - defaultCoreBoxMinorCount + 2 * coreTransitionCount
annotationAroundCounts = options["Annotation numbers of elements around"]
annotationCoreBoxMinorCounts = options["Annotation numbers of elements across core box minor"]

tubeNetworkMeshBuilder = TubeNetworkMeshBuilder(
networkMesh,
targetElementDensityAlongLongestSegment=options["Target element density along longest segment"],
defaultElementsCountAround=defaultAroundCount,
elementsCountThroughWall=options["Number of elements through shell"],
layoutAnnotationGroups=layoutAnnotationGroups,
layoutAnnotationGroups=networkLayout.getAnnotationGroups(),
annotationElementsCountsAlong=options["Annotation numbers of elements along"],
annotationElementsCountsAround=annotationAroundCounts,
defaultElementsCountCoreBoxMinor=defaultCoreBoxMinorCount,
elementsCountTransition=coreTransitionCount,
annotationElementsCountsCoreBoxMinor=annotationCoreBoxMinorCounts,
defaultElementsCountAround=options["Number of elements around"],
annotationElementsCountsAround=options["Annotation numbers of elements around"],
elementsCountThroughShell=options["Number of elements through shell"],
isCore=options["Core"],
elementsCountTransition=options["Number of elements across core transition"],
defaultElementsCountCoreBoxMinor=options["Number of elements across core box minor"],
annotationElementsCountsCoreBoxMinor=options["Annotation numbers of elements across core box minor"],
useOuterTrimSurfaces=options["Use outer trim surfaces"])

tubeNetworkMeshBuilder.build()
generateData = TubeNetworkMeshGenerateData(
region, 3,
Expand Down
57 changes: 21 additions & 36 deletions src/scaffoldmaker/meshtypes/meshtype_3d_uterus2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,30 @@

class UterusTubeNetworkMeshGenerateData(TubeNetworkMeshGenerateData):

def __init__(self, region, meshDimension, isLinearThroughWall, isShowTrimSurfaces,
coordinateFieldName="coordinates", startNodeIdentifier=1, startElementIdentifier=1):
def __init__(self, region, meshDimension, coordinateFieldName="coordinates",
startNodeIdentifier=1, startElementIdentifier=1, isLinearThroughWall=False, isShowTrimSurfaces=False):
"""
:param isLinearThroughWall: Callers should only set if 3-D with no core.
:param isShowTrimSurfaces: Tells junction generateMesh to make 2-D trim surfaces.
"""
super(UterusTubeNetworkMeshGenerateData, self).__init__(
region, meshDimension, isLinearThroughWall, isShowTrimSurfaces,
coordinateFieldName, startNodeIdentifier, startElementIdentifier)
region, meshDimension, coordinateFieldName, startNodeIdentifier, startElementIdentifier,
isLinearThroughWall, isShowTrimSurfaces)
self._fundusGroup = self.getOrCreateAnnotationGroup(get_uterus_term("fundus of uterus"))
self._leftGroup = self.getOrCreateAnnotationGroup(("left uterus", "None"))
self._rightGroup = self.getOrCreateAnnotationGroup(("right uterus", "None"))
self._dorsalGroup = self.getOrCreateAnnotationGroup(("dorsal uterus", "None"))
self._ventralGroup = self.getOrCreateAnnotationGroup(("ventral uterus", "None"))
# force these annotation group names in base class
self._leftGroup = self.getOrCreateAnnotationGroup(get_uterus_term("left uterus"))
self._rightGroup = self.getOrCreateAnnotationGroup(get_uterus_term("right uterus"))
self._dorsalGroup = self.getOrCreateAnnotationGroup(get_uterus_term("dorsal uterus"))
self._ventralGroup = self.getOrCreateAnnotationGroup(get_uterus_term("ventral uterus"))

def getFundusMeshGroup(self):
return self._fundusGroup.getMeshGroup(self._mesh)

def getLeftMeshGroup(self):
return self._leftGroup.getMeshGroup(self._mesh)

def getRightMeshGroup(self):
return self._rightGroup.getMeshGroup(self._mesh)

def getDorsalMeshGroup(self):
return self._dorsalGroup.getMeshGroup(self._mesh)

def getVentralMeshGroup(self):
return self._ventralGroup.getMeshGroup(self._mesh)

class UterusTubeNetworkMeshBuilder(TubeNetworkMeshBuilder):

def __init__(self, networkMesh: NetworkMesh, targetElementDensityAlongLongestSegment: float,
defaultElementsCountAround: int, elementsCountThroughWall: int,
layoutAnnotationGroups: list = [], annotationElementsCountsAlong: list = [],
annotationElementsCountsAround: list = [], useOuterTrimSurfaces=True):
super(UterusTubeNetworkMeshBuilder, self).__init__(
networkMesh, targetElementDensityAlongLongestSegment, defaultElementsCountAround,
elementsCountThroughWall, layoutAnnotationGroups,
annotationElementsCountsAlong, annotationElementsCountsAround, useOuterTrimSurfaces=useOuterTrimSurfaces)
"""
Adds left, right, dorsal, ventral, fundus annotations.
Future: derive from BodyTubeNetworkMeshBuilder to get left/right/dorsal/ventral.
"""

def generateMesh(self, generateData):
super(UterusTubeNetworkMeshBuilder, self).generateMesh(generateData)
Expand Down Expand Up @@ -490,11 +474,12 @@ def generateBaseMesh(cls, region, options):
uterusTubeNetworkMeshBuilder = UterusTubeNetworkMeshBuilder(
networkMesh,
targetElementDensityAlongLongestSegment=options["Target element density along longest segment"],
defaultElementsCountAround=options['Number of elements around'],
elementsCountThroughWall=options["Number of elements through wall"],
layoutAnnotationGroups=layoutAnnotationGroups,
annotationElementsCountsAlong=annotationAlongCounts,
annotationElementsCountsAround=annotationElementsCountsAround)
defaultElementsCountAround=options['Number of elements around'],
annotationElementsCountsAround=annotationElementsCountsAround,
elementsCountThroughShell=options["Number of elements through wall"],
useOuterTrimSurfaces=True)
uterusTubeNetworkMeshBuilder.build()
generateData = UterusTubeNetworkMeshGenerateData(
region, 3,
Expand Down Expand Up @@ -633,10 +618,10 @@ def defineFaceAnnotations(cls, region, options, annotationGroups):
get_uterus_term("lumen of vagina"))
lumenOfVagina.getMeshGroup(mesh2d).addElementsConditional(is_vagina_inner)

leftGroup = getAnnotationGroupForTerm(annotationGroups, ("left uterus", "None"))
rightGroup = getAnnotationGroupForTerm(annotationGroups, ("right uterus", "None"))
dorsalGroup = getAnnotationGroupForTerm(annotationGroups, ("dorsal uterus", "None"))
ventralGroup = getAnnotationGroupForTerm(annotationGroups, ("ventral uterus", "None"))
leftGroup = getAnnotationGroupForTerm(annotationGroups, get_uterus_term("left uterus"))
rightGroup = getAnnotationGroupForTerm(annotationGroups, get_uterus_term("right uterus"))
dorsalGroup = getAnnotationGroupForTerm(annotationGroups, get_uterus_term("dorsal uterus"))
ventralGroup = getAnnotationGroupForTerm(annotationGroups, get_uterus_term("ventral uterus"))

if isHuman:
leftUterineTubeGroup = getAnnotationGroupForTerm(annotationGroups, get_uterus_term("left uterine tube"))
Expand Down
Loading

0 comments on commit cbbc0ef

Please sign in to comment.