Skip to content

Commit

Permalink
Improve wholebody2 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rchristie committed Sep 6, 2024
1 parent eb4294e commit 06d7c33
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
89 changes: 49 additions & 40 deletions src/scaffoldmaker/meshtypes/meshtype_3d_wholebody2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, \
getAnnotationGroupForTerm
from scaffoldmaker.annotation.body_terms import get_body_term
from scaffoldmaker.utils.tubenetworkmesh import TubeNetworkMeshBuilder, TubeNetworkMeshGenerateData
from scaffoldmaker.utils.tubenetworkmesh import (
calculateElementsCountAcrossMinor, TubeNetworkMeshBuilder, TubeNetworkMeshGenerateData)
from scaffoldmaker.utils.zinc_utils import exnode_string_from_nodeset_field_parameters
from cmlibs.zinc.node import Node

Expand Down Expand Up @@ -229,34 +230,25 @@ def getDefaultOptions(cls, parameterSetName="Default"):
"Target element density along longest segment": 5.0,
"Show trim surfaces": False,
"Use Core": True,
"Number of elements across head core major": 6,
"Number of elements across torso core major": 6,
"Number of elements across arm core major": 4,
"Number of elements across leg core major": 4,
"Number of elements across core box minor": 2,
"Number of elements across core transition": 1
}

if "Human 2 Medium" in parameterSetName:
options["Number of elements around head"] = 16
options["Number of elements around torso"] = 16
options["Number of elements around arm"] = 12
options["Number of elements around arm"] = 8
options["Number of elements around leg"] = 12

options["Number of elements across head core major"] = 8
options["Number of elements across torso core major"] = 8
options["Number of elements across arm core major"] = 6
options["Number of elements across leg core major"] = 6

options["Target element density along longest segment"] = 8.0
options["Number of elements across core box minor"] = 2
elif "Human 2 Fine" in parameterSetName:
options["Number of elements around head"] = 24
options["Number of elements around torso"] = 24
options["Number of elements around arm"] = 20
options["Number of elements around leg"] = 20

options["Number of elements across head core major"] = 10
options["Number of elements across torso core major"] = 10
options["Number of elements across arm core major"] = 8
options["Number of elements across leg core major"] = 8
options["Number of elements around arm"] = 12
options["Number of elements around leg"] = 16
options["Number of elements through wall"] = 2
options["Target element density along longest segment"] = 10.0
options["Number of elements across core box minor"] = 4

return options

Expand All @@ -272,10 +264,8 @@ def getOrderedOptionNames(cls):
"Target element density along longest segment",
"Show trim surfaces",
"Use Core",
"Number of elements across head core major",
"Number of elements across torso core major",
"Number of elements across arm core major",
"Number of elements across leg core major"]
"Number of elements across core box minor",
"Number of elements across core transition"]
return optionNames

@classmethod
Expand Down Expand Up @@ -311,8 +301,10 @@ def getOptionScaffoldPackage(cls, optionName, scaffoldType, parameterSetName=Non

@classmethod
def checkOptions(cls, options):
dependentChanges = False
if not options["Network layout"].getScaffoldType() in cls.getOptionValidScaffoldTypes("Network layout"):
options["Network layout"] = cls.getOptionScaffoldPackage('Network layout', MeshType_1d_network_layout1)
minElementsCountAround = None
for key in [
"Number of elements around head",
"Number of elements around torso",
Expand All @@ -321,23 +313,36 @@ def checkOptions(cls, options):
]:
if options[key] < 8:
options[key] = 8

for key in [
"Number of elements across head core major",
"Number of elements across torso core major",
"Number of elements across arm core major",
"Number of elements across leg core major"
]:
if options[key] < 4:
options[key] = 4
elif options[key] % 4:
options[key] += 4 - (options[key] % 4)
if (minElementsCountAround is None) or (options[key] < minElementsCountAround):
minElementsCountAround = options[key]

if options["Number of elements through wall"] < 0:
options["Number of elements through wall"] = 1

if options["Target element density along longest segment"] < 1.0:
options["Target element density along longest segment"] = 1.0

dependentChanges = False
if options["Number of elements across core transition"] < 1:
options["Number of elements across core transition"] = 1

elementsCountCoreTransition = options['Number of elements across core transition']
maxElementsCountCoreBoxMinor = calculateElementsCountAcrossMinor(
minElementsCountAround, elementsCountCoreTransition, 2 + 2 * elementsCountCoreTransition) \
- 2 * elementsCountCoreTransition

for key in [
"Number of elements across core box minor"
]:
if options[key] < 2:
options[key] = 2
elif options[key] > maxElementsCountCoreBoxMinor:
options[key] = maxElementsCountCoreBoxMinor
dependentChanges = True
elif options[key] % 2:
options[key] += options[key] % 2

return dependentChanges

@classmethod
Expand All @@ -348,26 +353,30 @@ def generateBaseMesh(cls, region, options):
:param options: Dict containing options. See getDefaultOptions().
:return: list of AnnotationGroup, None
"""
parameterSetName = options['Base parameter set']
isHuman = parameterSetName in ["Default", "Human 1", "Human 2 Coarse", "Human 2 Medium", "Human 2 Fine"]
# parameterSetName = options['Base parameter set']
# isHuman = parameterSetName in ["Default", "Human 1", "Human 2 Coarse", "Human 2 Medium", "Human 2 Fine"]

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()

elementsCountCoreBoxMinor = options["Number of elements across core box minor"]
elementsCountCoreTransition = options['Number of elements across core transition']
elementsCountCoreMinor = elementsCountCoreBoxMinor + 2 * elementsCountCoreTransition
annotationElementsCountsAround = []
annotationElementsCountsAcross = []
for layoutAnnotationGroup in layoutAnnotationGroups:
elementsCountAround = 0
elementsCountAcrossMajor = 0
elementsCountCoreMajor = 0
name = layoutAnnotationGroup.getName()
if name in ["head", "torso", "arm", "leg"]:
elementsCountAround = options["Number of elements around " + name]
elementsCountAcrossMajor = options["Number of elements across " + name + " core major"]
elementsCountCoreMajor = calculateElementsCountAcrossMinor(
elementsCountAround, elementsCountCoreTransition, elementsCountCoreMinor)
annotationElementsCountsAround.append(elementsCountAround)
annotationElementsCountsAcross.append(elementsCountAcrossMajor)
annotationElementsCountsAcross.append(elementsCountCoreMajor)

isCore = options["Use Core"]

Expand All @@ -378,8 +387,8 @@ def generateBaseMesh(cls, region, options):
elementsCountThroughWall=options["Number of elements through wall"],
layoutAnnotationGroups=layoutAnnotationGroups,
annotationElementsCountsAround=annotationElementsCountsAround,
defaultElementsCountAcrossMajor=options['Number of elements across head core major'],
elementsCountTransition=options['Number of elements across core transition'],
defaultElementsCountAcrossMajor=annotationElementsCountsAcross[-1],
elementsCountTransition=elementsCountCoreTransition,
annotationElementsCountsAcrossMajor=annotationElementsCountsAcross,
isCore=isCore)

Expand Down
14 changes: 4 additions & 10 deletions tests/test_wholebody2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_wholebody2_core(self):
self.assertEqual(parameterSetNames, ["Default", "Human 1", "Human 2 Coarse", "Human 2 Medium",
"Human 2 Fine"])
options = scaffold.getDefaultOptions("Default")
self.assertEqual(15, len(options))
self.assertEqual(12, len(options))
self.assertEqual(12, options["Number of elements around head"])
self.assertEqual(12, options["Number of elements around torso"])
self.assertEqual(8, options["Number of elements around arm"])
Expand All @@ -36,10 +36,7 @@ def test_wholebody2_core(self):
self.assertEqual(5.0, options["Target element density along longest segment"])
self.assertEqual(False, options["Show trim surfaces"])
self.assertEqual(True, options["Use Core"])
self.assertEqual(6, options["Number of elements across head core major"])
self.assertEqual(6, options["Number of elements across torso core major"])
self.assertEqual(4, options["Number of elements across arm core major"])
self.assertEqual(4, options["Number of elements across leg core major"])
self.assertEqual(2, options["Number of elements across core box minor"])
self.assertEqual(1, options["Number of elements across core transition"])

context = Context("Test")
Expand Down Expand Up @@ -119,7 +116,7 @@ def test_wholebody2_tube(self):
self.assertEqual(parameterSetNames, ["Default", "Human 1", "Human 2 Coarse", "Human 2 Medium",
"Human 2 Fine"])
options = scaffold.getDefaultOptions("Default")
self.assertEqual(15, len(options))
self.assertEqual(12, len(options))
self.assertEqual(12, options["Number of elements around head"])
self.assertEqual(12, options["Number of elements around torso"])
self.assertEqual(8, options["Number of elements around arm"])
Expand All @@ -128,10 +125,7 @@ def test_wholebody2_tube(self):
self.assertEqual(5.0, options["Target element density along longest segment"])
self.assertEqual(False, options["Show trim surfaces"])
self.assertEqual(True, options["Use Core"])
self.assertEqual(6, options["Number of elements across head core major"])
self.assertEqual(6, options["Number of elements across torso core major"])
self.assertEqual(4, options["Number of elements across arm core major"])
self.assertEqual(4, options["Number of elements across leg core major"])
self.assertEqual(2, options["Number of elements across core box minor"])
self.assertEqual(1, options["Number of elements across core transition"])

options["Use Core"] = False
Expand Down

0 comments on commit 06d7c33

Please sign in to comment.