diff --git a/setup.py b/setup.py index 1c6a24c2..aea72b65 100644 --- a/setup.py +++ b/setup.py @@ -25,9 +25,9 @@ def readfile(filename, split=False): # into the 'requirements.txt' file. requires = [ # minimal requirements listing - "cmlibs.maths", - "cmlibs.utils", - "cmlibs.zinc", + "cmlibs.maths >= 0.3", + "cmlibs.utils >= 0.6", + "cmlibs.zinc >= 4.0", "scipy", "numpy", ] @@ -35,7 +35,7 @@ def readfile(filename, split=False): setup( name="scaffoldmaker", - version="0.9.0", + version="0.10.0", description="Python client for generating anatomical scaffolds using Zinc", long_description="\n".join(readme) + source_license, long_description_content_type="text/x-rst", diff --git a/src/scaffoldmaker/annotation/annotationgroup.py b/src/scaffoldmaker/annotation/annotationgroup.py index e9280f3e..decc82fe 100644 --- a/src/scaffoldmaker/annotation/annotationgroup.py +++ b/src/scaffoldmaker/annotation/annotationgroup.py @@ -6,17 +6,17 @@ from cmlibs.utils.zinc.general import ChangeManager from cmlibs.utils.zinc.field import find_or_create_field_coordinates, find_or_create_field_group, \ find_or_create_field_stored_mesh_location, find_or_create_field_stored_string +from cmlibs.utils.zinc.finiteelement import get_highest_dimension_mesh, get_next_unused_node_identifier +from cmlibs.utils.zinc.group import group_get_highest_dimension, \ + identifier_ranges_from_string, identifier_ranges_to_string, \ + mesh_group_add_identifier_ranges, mesh_group_to_identifier_ranges, \ + nodeset_group_add_identifier_ranges, nodeset_group_to_identifier_ranges from cmlibs.zinc.element import Element, Mesh from cmlibs.zinc.field import Field, FieldFiniteElement, FieldGroup, FieldStoredMeshLocation, FieldStoredString, \ FieldFindMeshLocation from cmlibs.zinc.fieldcache import Fieldcache from cmlibs.zinc.fieldmodule import Fieldmodule -from cmlibs.zinc.node import Node from cmlibs.zinc.result import RESULT_OK -from scaffoldmaker.utils.zinc_utils import get_highest_dimension_mesh, get_next_unused_node_identifier, \ - group_get_highest_dimension, identifier_ranges_from_string, identifier_ranges_to_string, \ - mesh_group_add_identifier_ranges, mesh_group_to_identifier_ranges, \ - nodeset_group_add_identifier_ranges, nodeset_group_to_identifier_ranges class AnnotationGroup(object): @@ -75,7 +75,7 @@ def toDict(self): identifierRanges = [] if dimension > 0: mesh = fieldmodule.findMeshByDimension(dimension) - meshGroup = self._group.getFieldElementGroup(mesh).getMeshGroup() + meshGroup = self._group.getMeshGroup(mesh) if meshGroup.isValid(): identifierRanges = mesh_group_to_identifier_ranges(meshGroup) else: @@ -84,7 +84,7 @@ def toDict(self): identifierRanges = [[self._markerIdentifier, self._markerIdentifier]] else: nodes = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - nodesetGroup = self._group.getFieldNodeGroup(nodes).getNodesetGroup() + nodesetGroup = self._group.getNodesetGroup(nodes) if nodesetGroup.isValid(): identifierRanges = nodeset_group_to_identifier_ranges(nodesetGroup) dct = { @@ -438,18 +438,8 @@ def setName(self, name): fieldcache.setNode(markerNode) markerName.assignString(fieldcache, name) else: - with ChangeManager(fieldmodule): - if RESULT_OK != self._group.setName(name): - return False - # workaround for zinc issue: must rename subelement groups - for dimension in range(3, 0, -1): - mesh = fieldmodule.findMeshByDimension(dimension) - elementGroup = self._group.getFieldElementGroup(mesh) - if elementGroup.isValid(): - elementGroup.setName(name + '.' + mesh.getName()) - nodeGroup = self._group.getFieldNodeGroup(nodes) - if nodeGroup.isValid(): - nodeGroup.setName(name + '.' + nodes.getName()) + if RESULT_OK != self._group.setName(name): + return False self._name = name return True @@ -488,55 +478,37 @@ def getDimension(self): """ return group_get_highest_dimension(self._group) - def getFieldElementGroup(self, mesh): - """ - :param mesh: The Zinc mesh to manage a sub group of. - :return: The Zinc element group field for mesh in this AnnotationGroup. - """ - elementGroup = self._group.getFieldElementGroup(mesh) - if not elementGroup.isValid(): - elementGroup = self._group.createFieldElementGroup(mesh) - return elementGroup - - def getFieldNodeGroup(self, nodeset): - """ - :param nodeset: The Zinc nodeset to manage a sub group of. - :return: The Zinc node group field for nodeset in this AnnotationGroup. - """ - nodeGroup = self._group.getFieldNodeGroup(nodeset) - if not nodeGroup.isValid(): - nodeGroup = self._group.createFieldNodeGroup(nodeset) - return nodeGroup - def getMeshGroup(self, mesh): """ + Get or create mesh group. :param mesh: The Zinc mesh to manage a sub group of. :return: The Zinc meshGroup for adding elements of mesh in this AnnotationGroup. """ - return self.getFieldElementGroup(mesh).getMeshGroup() + return self._group.getOrCreateMeshGroup(mesh) def hasMeshGroup(self, mesh): """ :param mesh: The Zinc mesh to query a sub group of. :return: True if MeshGroup for mesh exists and is not empty, otherwise False. """ - elementGroup = self._group.getFieldElementGroup(mesh) - return elementGroup.isValid() and (elementGroup.getMeshGroup().getSize() > 0) + meshGroup = self._group.getMeshGroup(mesh) + return meshGroup.isValid() and (meshGroup.getSize() > 0) def getNodesetGroup(self, nodeset): """ + Get or create nodeset group. :param nodeset: The Zinc nodeset to manage a sub group of. :return: The Zinc nodesetGroup for adding nodes from nodeset in this AnnotationGroup. """ - return self.getFieldNodeGroup(nodeset).getNodesetGroup() + return self._group.getOrCreateNodesetGroup(nodeset) def hasNodesetGroup(self, nodeset): """ :param nodeset: The Zinc nodeset to query a sub group of. :return: True if NodesetGroup for nodeset exists and is not empty, otherwise False. """ - nodeGroup = self._group.getFieldNodeGroup(nodeset) - return nodeGroup.isValid() and (nodeGroup.getNodesetGroup().getSize() > 0) + nodesetGroup = self._group.getNodesetGroup(nodeset) + return nodesetGroup.isValid() and (nodesetGroup.getSize() > 0) def addSubelements(self): """ @@ -546,11 +518,10 @@ def addSubelements(self): fm = self._group.getFieldmodule() for dimension in range(1, 4): mesh = fm.findMeshByDimension(dimension) - elementGroup = self._group.getFieldElementGroup(mesh) - if elementGroup.isValid(): - meshGroup = elementGroup.getMeshGroup() + meshGroup = self._group.getMeshGroup(mesh) + if meshGroup.isValid(): #print('Mesh group:', self._name, ', size', meshGroup.getSize()) - meshGroup.addElementsConditional(elementGroup) # use FieldElementGroup as conditional field + meshGroup.addElementsConditional(self._group) # use whole group as conditional field def findAnnotationGroupByName(annotationGroups: list, name: str): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py index f60134bb..d61a40e5 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py @@ -872,11 +872,11 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) - is_body = bodyGroup.getFieldElementGroup(mesh2d) + is_body = bodyGroup.getGroup() is_body_serosa = fm.createFieldAnd(is_body, is_exterior_face_xi3_1) is_body_lumen = fm.createFieldAnd(is_body, is_exterior_face_xi3_0) - is_neck = neckGroup.getFieldElementGroup(mesh2d) + is_neck = neckGroup.getGroup() is_neck_serosa = fm.createFieldAnd(is_neck, is_exterior_face_xi3_1) is_neck_lumen = fm.createFieldAnd(is_neck, is_exterior_face_xi3_0) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py index b3cc8d97..f85bef85 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py @@ -7,7 +7,7 @@ import copy import math -from cmlibs.utils.zinc.field import findOrCreateFieldGroup, findOrCreateFieldNodeGroup, \ +from cmlibs.utils.zinc.field import findOrCreateFieldGroup, \ findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field @@ -632,7 +632,7 @@ def generateBaseMesh(cls, region, options): markerLocation = findOrCreateFieldStoredMeshLocation(fm, mesh, name="marker_location") nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerPoints = findOrCreateFieldNodeGroup(markerGroup, nodes).getNodesetGroup() + markerPoints = markerGroup.getOrCreateNodesetGroup(nodes) markerTemplateInternal = nodes.createNodetemplate() markerTemplateInternal.defineField(markerName) markerTemplateInternal.defineField(markerLocation) @@ -649,12 +649,12 @@ def generateBaseMesh(cls, region, options): tmpGroup = tmpFieldmodule.findFieldByName("urinary bladder").castGroup() cx_bladder, cd1_bladder, cd2_bladder, cd12_bladder = get_nodeset_path_field_parameters( - tmpGroup.getFieldNodeGroup(tmpNodes).getNodesetGroup(), tmpCoordinates, + tmpGroup.getNodesetGroup(tmpNodes), tmpCoordinates, [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2]) tmpGroup = tmpFieldmodule.findFieldByName("urethra").castGroup() cx_urethra, cd1_urethra, cd2_urethra, cd12_urethra = get_nodeset_path_field_parameters( - tmpGroup.getFieldNodeGroup(tmpNodes).getNodesetGroup(), tmpCoordinates, + tmpGroup.getNodesetGroup(tmpNodes), tmpCoordinates, [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2]) del tmpGroup @@ -1208,20 +1208,20 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) - is_body = bodyGroup.getFieldElementGroup(mesh2d) + is_body = bodyGroup.getGroup() is_body_serosa = fm.createFieldAnd(is_body, is_exterior_face_xi3_1) is_body_lumen = fm.createFieldAnd(is_body, is_exterior_face_xi3_0) - is_neck = neckGroup.getFieldElementGroup(mesh2d) + is_neck = neckGroup.getGroup() is_neck_serosa = fm.createFieldAnd(is_neck, is_exterior_face_xi3_1) is_neck_lumen = fm.createFieldAnd(is_neck, is_exterior_face_xi3_0) - is_urinaryBladder = urinaryBladderGroup.getFieldElementGroup(mesh2d) + is_urinaryBladder = urinaryBladderGroup.getGroup() is_urinaryBladder_serosa = fm.createFieldAnd(is_urinaryBladder, is_exterior_face_xi3_1) is_urinaryBladder_lumen = fm.createFieldAnd(is_urinaryBladder, is_exterior_face_xi3_0) - is_dorsal_bladder = bladderDorsalGroup.getFieldElementGroup(mesh2d) - is_ventral_bladder = bladderVentralGroup.getFieldElementGroup(mesh2d) + is_dorsal_bladder = bladderDorsalGroup.getGroup() + is_ventral_bladder = bladderVentralGroup.getGroup() serosaOfUrinaryBladder = \ findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("serosa of urinary bladder")) @@ -1324,12 +1324,12 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): get_bladder_term("ventral part of urethra")) urethraDorsalGroup = getAnnotationGroupForTerm(annotationGroups, get_bladder_term("dorsal part of urethra")) - is_urethra = urethraGroup.getFieldElementGroup(mesh2d) + is_urethra = urethraGroup.getGroup() is_urethra_serosa = fm.createFieldAnd(is_urethra, is_exterior_face_xi3_1) is_urethra_lumen = fm.createFieldAnd(is_urethra, is_exterior_face_xi3_0) - is_dorsal_urethra = urethraDorsalGroup.getFieldElementGroup(mesh2d) - is_ventral_urethra = urethraVentralGroup.getFieldElementGroup(mesh2d) + is_dorsal_urethra = urethraDorsalGroup.getGroup() + is_ventral_urethra = urethraVentralGroup.getGroup() serosaOfUrethra = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_bladder_term("serosa of urethra")) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py b/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py index 2c0c6c0a..ad2ea676 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py @@ -8,9 +8,7 @@ from cmlibs.zinc.element import Element from cmlibs.zinc.node import Node -from cmlibs.zinc.field import FieldFindMeshLocation -from cmlibs.utils.zinc.field import Field, findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, \ - findOrCreateFieldStoredString +from cmlibs.utils.zinc.field import Field, findOrCreateFieldCoordinates, findOrCreateFieldStoredString from cmlibs.utils.zinc.general import ChangeManager from cmlibs.utils.zinc.finiteelement import getMaximumNodeIdentifier from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm @@ -626,7 +624,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): groupNames = ['brainstem', 'midbrain', 'medulla oblongata', 'pons'] for groupName in groupNames: subGroup = AnnotationGroup(region, get_brainstem_term(groupName)) - issub = subGroup.getFieldElementGroup(mesh2d) + issub = subGroup.getGroup() is_subface_ext = fm.createFieldOr(fm.createFieldAnd(issub, is_exterior_face_xi1), fm.createFieldAnd(issub, is_exterior_face_xi3)) subFaceGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_brainstem_term(groupName + ' exterior')) subFaceGroup.getMeshGroup(mesh2d).addElementsConditional(is_subface_ext) @@ -636,7 +634,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): for groupName in groupNames: subGroupName = 'midbrain' if groupName == 'thalamus-brainstem interface' else 'medulla oblongata' subGroup = AnnotationGroup(region, get_brainstem_term(subGroupName)) - issub = subGroup.getFieldElementGroup(mesh2d) + issub = subGroup.getGroup() is_subface_ext = fm.createFieldAnd(issub, is_exterior_face_xi2) subFaceGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_brainstem_term(groupName)) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py index 43340af3..8ea87931 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py @@ -673,7 +673,7 @@ def generateBaseMesh(cls, region, options): for termName in colonTermsAlong: tmpGroup = tmpFieldmodule.findFieldByName(termName).castGroup() if termName else None - tmpNodeset = tmpGroup.getFieldNodeGroup(tmpNodes).getNodesetGroup() if tmpGroup else tmpNodes + tmpNodeset = tmpGroup.getNodesetGroup(tmpNodes) if tmpGroup else tmpNodes cxGroup, cd1Group, cd2Group, cd3Group, cd12Group, cd13Group = get_nodeset_path_field_parameters( tmpNodeset, tmpCoordinates, @@ -959,7 +959,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) - is_colon = colonGroup.getFieldElementGroup(mesh2d) + is_colon = colonGroup.getGroup() is_serosa = fm.createFieldAnd(is_colon, is_exterior_face_xi3_1) serosa = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_colon_term("serosa of colon")) serosa.getMeshGroup(mesh2d).addElementsConditional(is_serosa) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py index 50645d61..ccd27b9b 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py @@ -424,7 +424,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) - is_colon = colonGroup.getFieldElementGroup(mesh2d) + is_colon = colonGroup.getGroup() is_serosa = fm.createFieldAnd(is_colon, is_exterior_face_xi3_1) serosa = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_colon_term("serosa of colon")) serosa.getMeshGroup(mesh2d).addElementsConditional(is_serosa) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_esophagus1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_esophagus1.py index bdbcee3a..b187d359 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_esophagus1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_esophagus1.py @@ -7,7 +7,7 @@ import copy import math from cmlibs.utils.zinc.field import findOrCreateFieldGroup, findOrCreateFieldStoredString, \ - findOrCreateFieldStoredMeshLocation, findOrCreateFieldNodeGroup + findOrCreateFieldStoredMeshLocation from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field from cmlibs.zinc.node import Node @@ -214,7 +214,7 @@ def generateBaseMesh(cls, region, options): for termName in esophagusTermsAlong: tmpGroup = tmpFieldmodule.findFieldByName(termName).castGroup() if termName else None - tmpNodeset = tmpGroup.getFieldNodeGroup(tmpNodes).getNodesetGroup() if tmpGroup else tmpNodes + tmpNodeset = tmpGroup.getNodesetGroup(tmpNodes) if tmpGroup else tmpNodes cxGroup, cd1Group, cd2Group, cd3Group, cd12Group, cd13Group = get_nodeset_path_field_parameters( tmpNodeset, tmpCoordinates, @@ -457,7 +457,7 @@ def generateBaseMesh(cls, region, options): markerLocation = findOrCreateFieldStoredMeshLocation(fm, mesh, name="marker_location") nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerPoints = findOrCreateFieldNodeGroup(markerGroup, nodes).getNodesetGroup() + markerPoints = markerGroup.getOrCreateNodesetGroup(nodes) markerTemplateInternal = nodes.createNodetemplate() markerTemplateInternal.defineField(markerName) markerTemplateInternal.defineField(markerLocation) @@ -535,7 +535,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) - is_esophagus = esophagusGroup.getFieldElementGroup(mesh2d) + is_esophagus = esophagusGroup.getGroup() is_serosa = fm.createFieldAnd(is_esophagus, is_exterior_face_xi3_1) serosa = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_esophagus_term("serosa of esophagus")) serosa.getMeshGroup(mesh2d).addElementsConditional(is_serosa) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py index 4e53dd91..3db28e06 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py @@ -4,8 +4,7 @@ from __future__ import division -from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates from cmlibs.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field @@ -446,6 +445,6 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): epiGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("epicardium")) mesh2d = fm.findMeshByDimension(2) is_exterior_face_xi3_1 = fm.createFieldAnd(fm.createFieldIsExterior(), fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) - is_non_septal_fibrous_ring = fm.createFieldXor(lFibrousRingGroup.getFieldElementGroup(mesh2d), rFibrousRingGroup.getFieldElementGroup(mesh2d)) + is_non_septal_fibrous_ring = fm.createFieldXor(lFibrousRingGroup.getGroup(), rFibrousRingGroup.getGroup()) is_non_septal_fibrous_ring_epi = fm.createFieldAnd(is_non_septal_fibrous_ring, is_exterior_face_xi3_1) epiGroup.getMeshGroup(mesh2d).addElementsConditional(is_non_septal_fibrous_ring_epi) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py index 9cf4b6d0..4d653b0e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py @@ -10,7 +10,7 @@ from cmlibs.maths.vectorops import add, cross, dot, magnitude, mult, normalize, sub from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString + findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier from cmlibs.zinc.element import Element, Elementbasis from cmlibs.zinc.field import Field, FieldGroup @@ -3236,14 +3236,14 @@ def generateBaseMesh(cls, region, options): if defineEpicardiumLayer: # project epicardial points over atria to build fat pad epiGroup = fm.createFieldGroup() - epiMesh = epiGroup.createFieldElementGroup(mesh).getMeshGroup() - is_a = fm.createFieldOr(lamGroup.getFieldElementGroup(mesh), ramGroup.getFieldElementGroup(mesh)) - is_aa = fm.createFieldOr(laaGroup.getFieldElementGroup(mesh), raaGroup.getFieldElementGroup(mesh)) - is_not_epi = fm.createFieldNot(fm.createFieldOr(is_aa, aSeptumGroup.getFieldElementGroup(mesh))) + epiMesh = epiGroup.createMeshGroup(mesh) + is_a = fm.createFieldOr(lamGroup.getGroup(), ramGroup.getGroup()) + is_aa = fm.createFieldOr(laaGroup.getGroup(), raaGroup.getGroup()) + is_not_epi = fm.createFieldNot(fm.createFieldOr(is_aa, aSeptumGroup.getGroup())) is_a_epi = fm.createFieldAnd(is_a, is_not_epi) epiMesh.addElementsConditional(is_a_epi) # print("epiMesh.getSize()", epiMesh.getSize()) - epiNodes = epiGroup.createFieldNodeGroup(nodes).getNodesetGroup() + epiNodes = epiGroup.createNodesetGroup(nodes) # add nodes on xi3=1 of epiMesh to epiNodes epiElementIdentifiers = [] elementIterator = epiMesh.createElementiterator() @@ -3273,10 +3273,10 @@ def generateBaseMesh(cls, region, options): epiNode = nodeIterator.next() fpGroup = fm.createFieldGroup() fpGroup.setName("fp") - fpNodes = fpGroup.createFieldNodeGroup(nodes).getNodesetGroup() + fpNodes = fpGroup.createNodesetGroup(nodes) bridgeGroup = fm.createFieldGroup() bridgeGroup.setName("ia_bridge") - bridgeNodes = bridgeGroup.createFieldNodeGroup(nodes).getNodesetGroup() + bridgeNodes = bridgeGroup.createNodesetGroup(nodes) bridgeNodeTangents = {} # parameters for shifting centre of fatpad to spread elements around PV, VC inlets @@ -3487,10 +3487,10 @@ def refineMesh(cls, meshrefinement, options): sourceFm = meshrefinement._sourceFm annotationGroups = meshrefinement._sourceAnnotationGroups - laGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("left atrium myocardium")) - laElementGroupField = laGroup.getFieldElementGroup(meshrefinement._sourceMesh) - raGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("right atrium myocardium")) - raElementGroupField = raGroup.getFieldElementGroup(meshrefinement._sourceMesh) + # laGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("left atrium myocardium")) + # laElementGroupField = laGroup.getGroup() + # raGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("right atrium myocardium")) + # raElementGroupField = raGroup.getGroup() aSeptumGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("interatrial septum")) aSeptumMeshGroup = aSeptumGroup.getMeshGroup(meshrefinement._sourceMesh) epicardiumGroup = None @@ -3569,25 +3569,24 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) - is_lam = lamGroup.getFieldElementGroup(mesh2d) - is_ram = ramGroup.getFieldElementGroup(mesh2d) + is_lam = lamGroup.getGroup() + is_ram = ramGroup.getGroup() is_lam_endo = fm.createFieldAnd(is_lam, is_exterior_face_xi3_0) is_ram_endo = fm.createFieldOr(fm.createFieldAnd(fm.createFieldAnd(is_ram, is_exterior_face_xi3_0), fm.createFieldNot(is_lam_endo)), - fm.createFieldAnd(aSeptumGroup.getFieldElementGroup(mesh2d), + fm.createFieldAnd(aSeptumGroup.getGroup(), is_exterior_face_xi3_1)) - is_laa = laaGroup.getFieldElementGroup(mesh2d) - is_raa = raaGroup.getFieldElementGroup(mesh2d) + is_laa = laaGroup.getGroup() + is_raa = raaGroup.getGroup() is_laa_endo = fm.createFieldAnd(is_laa, is_exterior_face_xi3_0) is_raa_endo = fm.createFieldAnd(is_raa, is_exterior_face_xi3_0) - is_laa_epi = fm.createFieldAnd(laaGroup.getFieldElementGroup(mesh2d), is_exterior_face_xi3_1) - is_raa_epi = fm.createFieldAnd(raaGroup.getFieldElementGroup(mesh2d), is_exterior_face_xi3_1) - # is_myocardium = fm.createFieldOr(is_lam, is_ram) + is_laa_epi = fm.createFieldAnd(laaGroup.getGroup(), is_exterior_face_xi3_1) + is_raa_epi = fm.createFieldAnd(raaGroup.getGroup(), is_exterior_face_xi3_1) is_ext_xi3_1_and_not_septum = fm.createFieldAnd( - is_exterior_face_xi3_1, fm.createFieldNot(aSeptumGroup.getFieldElementGroup(mesh2d))) + is_exterior_face_xi3_1, fm.createFieldNot(aSeptumGroup.getGroup())) is_os_lam = fm.createFieldAnd(is_lam, is_ext_xi3_1_and_not_septum) is_os_ram = fm.createFieldAnd(is_ram, is_ext_xi3_1_and_not_septum) - is_epi = epiGroup.getFieldElementGroup(mesh2d) + is_epi = epiGroup.getGroup() # luminal surfaces of endocardium of left/right atrium lslaEndoGroup = findOrCreateAnnotationGroupForTerm( @@ -3599,10 +3598,10 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): # endocardium groups are defined identically to luminal surfaces at scaffold scale laEndoGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("left atrium endocardium")) - laEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lslaEndoGroup.getFieldElementGroup(mesh2d)) + laEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lslaEndoGroup.getGroup()) raEndoGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("right atrium endocardium")) - raEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lsraEndoGroup.getFieldElementGroup(mesh2d)) + raEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lsraEndoGroup.getGroup()) laaEndoGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("endocardium of left auricle")) @@ -3628,8 +3627,8 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): osramGroup.getMeshGroup(mesh2d).addElementsConditional(fm.createFieldAnd(is_ram, is_epi)) osmGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("outer surface of myocardium")) - osmGroup.getMeshGroup(mesh2d).addElementsConditional(oslamGroup.getFieldElementGroup(mesh2d)) - osmGroup.getMeshGroup(mesh2d).addElementsConditional(osramGroup.getFieldElementGroup(mesh2d)) + osmGroup.getMeshGroup(mesh2d).addElementsConditional(oslamGroup.getGroup()) + osmGroup.getMeshGroup(mesh2d).addElementsConditional(osramGroup.getGroup()) if defineEpicardiumLayer: # future: limit to atria once ventricles have epicardium layer is_os_epi = fm.createFieldAnd(is_epi, is_exterior_face_xi3_1) @@ -3639,16 +3638,16 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): # note: epiGroup only contains 3-D elements in this case else: # if no volumetric epicardium group, add outer surface of atrial myocardium - epiGroup.getMeshGroup(mesh2d).addElementsConditional(oslamGroup.getFieldElementGroup(mesh2d)) - epiGroup.getMeshGroup(mesh2d).addElementsConditional(osramGroup.getFieldElementGroup(mesh2d)) + epiGroup.getMeshGroup(mesh2d).addElementsConditional(oslamGroup.getGroup()) + epiGroup.getMeshGroup(mesh2d).addElementsConditional(osramGroup.getGroup()) lslpvGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("luminal surface of left pulmonary vein")) lsrpvGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("luminal surface of right pulmonary vein")) - is_lpv = lpvGroup.getFieldElementGroup(mesh2d) - is_mpv = mpvGroup.getFieldElementGroup(mesh2d) if mpvGroup else None - is_rpv = rpvGroup.getFieldElementGroup(mesh2d) + is_lpv = lpvGroup.getGroup() + is_mpv = mpvGroup.getGroup() if mpvGroup else None + is_rpv = rpvGroup.getGroup() lslpvGroup.getMeshGroup(mesh2d).addElementsConditional( fm.createFieldAnd(is_exterior_face_xi3_0, is_lpv)) if mpvGroup: @@ -3663,8 +3662,8 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): annotationGroups, region, get_heart_term("luminal surface of inferior vena cava")) lssvcGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("luminal surface of superior vena cava")) - is_ivc = ivcGroup.getFieldElementGroup(mesh2d) - is_svc = svcGroup.getFieldElementGroup(mesh2d) + is_ivc = ivcGroup.getGroup() + is_svc = svcGroup.getGroup() lsivcGroup.getMeshGroup(mesh2d).addElementsConditional( fm.createFieldAnd(is_exterior_face_xi3_0, is_ivc)) lssvcGroup.getMeshGroup(mesh2d).addElementsConditional( diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py index a187fe62..6b1edb96 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py @@ -345,7 +345,7 @@ def generateBaseMesh(cls, region, options): leftFibrousRingGroup = fm.findFieldByName('left fibrous ring').castGroup() mergeWithBase = False if leftFibrousRingGroup.isValid(): - leftFibrousRingMeshGroup = leftFibrousRingGroup.getFieldElementGroup(fm.findMeshByDimension(3)).getMeshGroup() + leftFibrousRingMeshGroup = leftFibrousRingGroup.getMeshGroup(fm.findMeshByDimension(3)) elementiter = leftFibrousRingMeshGroup.createElementiterator() element = elementiter.next() element = elementiter.next() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py index 5531da8e..ad870597 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py @@ -7,8 +7,7 @@ import math -from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates from cmlibs.zinc.element import Element, Elementbasis from cmlibs.zinc.field import Field from cmlibs.zinc.node import Node @@ -1228,15 +1227,14 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) - is_lvm = lvmGroup.getFieldElementGroup(mesh2d) - is_rvm = rvmGroup.getFieldElementGroup(mesh2d) + is_lvm = lvmGroup.getGroup() + is_rvm = rvmGroup.getGroup() is_lvm_endo = fm.createFieldAnd(is_lvm, is_exterior_face_xi3_0) is_rvm_endo = fm.createFieldOr(fm.createFieldAnd(fm.createFieldAnd(is_rvm, is_exterior_face_xi3_0), - fm.createFieldNot(is_lvm_endo)), - fm.createFieldAnd(vSeptumGroup.getFieldElementGroup(mesh2d), - is_exterior_face_xi3_1)) + fm.createFieldNot(is_lvm_endo)), + fm.createFieldAnd(vSeptumGroup.getGroup(), is_exterior_face_xi3_1)) is_ext_xi3_1_and_not_septum = fm.createFieldAnd( - is_exterior_face_xi3_1, fm.createFieldNot(vSeptumGroup.getFieldElementGroup(mesh2d))) + is_exterior_face_xi3_1, fm.createFieldNot(vSeptumGroup.getGroup())) is_os_lvm = fm.createFieldAnd(is_lvm, is_ext_xi3_1_and_not_septum) is_os_rvm = fm.createFieldAnd(is_rvm, is_ext_xi3_1_and_not_septum) @@ -1250,10 +1248,10 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): # endocardium groups are defined identically to luminal surfaces at scaffold scale lvEndoGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("endocardium of left ventricle")) - lvEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lslvEndoGroup.getFieldElementGroup(mesh2d)) + lvEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lslvEndoGroup.getGroup()) rvEndoGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("endocardium of right ventricle")) - rvEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lsrvEndoGroup.getFieldElementGroup(mesh2d)) + rvEndoGroup.getMeshGroup(mesh2d).addElementsConditional(lsrvEndoGroup.getGroup()) oslvmGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("outer surface of myocardium of left ventricle")) @@ -1263,11 +1261,11 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): osrvmGroup.getMeshGroup(mesh2d).addElementsConditional(is_os_rvm) osmGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_heart_term("outer surface of myocardium")) - osmGroup.getMeshGroup(mesh2d).addElementsConditional(oslvmGroup.getFieldElementGroup(mesh2d)) - osmGroup.getMeshGroup(mesh2d).addElementsConditional(osrvmGroup.getFieldElementGroup(mesh2d)) + osmGroup.getMeshGroup(mesh2d).addElementsConditional(oslvmGroup.getGroup()) + osmGroup.getMeshGroup(mesh2d).addElementsConditional(osrvmGroup.getGroup()) # if no volumetric epicardium group, add outer surface of myocardium epiGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_heart_term("epicardium")) - epiGroup.getMeshGroup(mesh2d).addElementsConditional(osmGroup.getFieldElementGroup(mesh2d)) + epiGroup.getMeshGroup(mesh2d).addElementsConditional(osmGroup.getGroup()) def getSeptumPoints(septumArcRadians, lvRadius, radialDisplacement, elementsCountAroundLVFreeWall, elementsCountAroundVSeptum, z, n3): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py index b990e5e0..d0177070 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py @@ -8,7 +8,7 @@ import math from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString + findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field @@ -351,7 +351,7 @@ def generateBaseMesh(cls, region, options): markerName = findOrCreateFieldStoredString(fieldmodule, name="marker_name") markerLocation = findOrCreateFieldStoredMeshLocation(fieldmodule, mesh, name="marker_location") - markerPoints = findOrCreateFieldNodeGroup(markerGroup, nodes).getNodesetGroup() + markerPoints = markerGroup.getOrCreateNodesetGroup(nodes) markerTemplateInternal = nodes.createNodetemplate() markerTemplateInternal.defineField(markerName) markerTemplateInternal.defineField(markerLocation) @@ -935,9 +935,13 @@ def generateBaseMesh(cls, region, options): elementIdentifier = max(1, getMaximumElementIdentifier(mesh) + 1) #print("LV elements") - elementIdentifier = lvShield.generateElements(fieldmodule, coordinates, elementIdentifier, [ heartMeshGroup, lvMeshGroup ]) + elementIdentifier = lvShield.generateElements(fieldmodule, coordinates, elementIdentifier, + meshGroupsElementsAlong=[1, 1], + meshGroups=[heartMeshGroup, lvMeshGroup]) #print("RV elements") - elementIdentifier = rvShield.generateElements(fieldmodule, coordinates, elementIdentifier, [ heartMeshGroup, rvMeshGroup ]) + elementIdentifier = rvShield.generateElements(fieldmodule, coordinates, elementIdentifier, + meshGroupsElementsAlong=[1, 1], + meshGroups=[heartMeshGroup, rvMeshGroup]) tricubichermite = eftfactory_tricubichermite(mesh, useCrossDerivatives) elementtemplate1 = mesh.createElementtemplate() @@ -1105,15 +1109,15 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) - is_lv = lvGroup.getFieldElementGroup(mesh2d) - is_rv = rvGroup.getFieldElementGroup(mesh2d) + is_lv = lvGroup.getGroup() + is_rv = rvGroup.getGroup() is_lv_endo = fm.createFieldAnd(is_lv, is_exterior_face_xi3_0) is_rv_endo = fm.createFieldOr(fm.createFieldAnd(fm.createFieldAnd(is_rv, is_exterior_face_xi3_0), fm.createFieldNot(is_lv_endo)), - fm.createFieldAnd(vSeptumGroup.getFieldElementGroup(mesh2d), is_exterior_face_xi3_1)) + fm.createFieldAnd(vSeptumGroup.getGroup(), is_exterior_face_xi3_1)) is_v_epi = fm.createFieldAnd(fm.createFieldOr(is_lv, is_rv), fm.createFieldAnd(is_exterior_face_xi3_1, - fm.createFieldNot(vSeptumGroup.getFieldElementGroup(mesh2d)))) + fm.createFieldNot(vSeptumGroup.getGroup()))) epiGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_heart_term("epicardium")) epiGroup.getMeshGroup(mesh2d).addElementsConditional(is_v_epi) lvEndoGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_heart_term("endocardium of left ventricle")) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py index 75479093..2488ff28 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py @@ -10,7 +10,7 @@ import math from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString + findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field, FieldGroup @@ -363,7 +363,7 @@ def generateBaseMesh(cls, region, options): fieldassignment = coordinates.createFieldassignment(newCoordinates) fieldassignment.setNodeset(nodes) # marker points are not rotated - fieldassignment.setConditionalField(fm.createFieldNot(markerGroup.getFieldNodeGroup(nodes))) + fieldassignment.setConditionalField(fm.createFieldNot(markerGroup)) fieldassignment.assign() # discover ventricles top LV inner, RV inner, V Outer nodes, coordinates and derivatives @@ -1439,18 +1439,18 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_face_xi2_1 = fm.createFieldIsOnFace(Element.FACE_TYPE_XI2_1) lvGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("left ventricle myocardium")) rvGroup = getAnnotationGroupForTerm(annotationGroups, get_heart_term("right ventricle myocardium")) - is_lv = lvGroup.getFieldElementGroup(mesh2d) - is_rv = rvGroup.getFieldElementGroup(mesh2d) - is_lvo = lvOutletGroup.getFieldElementGroup(mesh2d) - is_mac = mitralAorticCurtainGroup.getFieldElementGroup(mesh2d) + is_lv = lvGroup.getGroup() + is_rv = rvGroup.getGroup() + is_lvo = lvOutletGroup.getGroup() + is_mac = mitralAorticCurtainGroup.getGroup() is_lfr = fm.createFieldAnd( is_exterior, fm.createFieldOr( fm.createFieldAnd(fm.createFieldAnd(is_lv, fm.createFieldNot(is_lvo)), is_face_xi2_1), fm.createFieldAnd(is_mac, is_face_xi2_0))) lFibrousRingGroup.getMeshGroup(mesh2d).addElementsConditional(is_lfr) - is_ca = conusArteriosusGroup.getFieldElementGroup(mesh2d) - is_svc = supraventricularCrestGroup.getFieldElementGroup(mesh2d) + is_ca = conusArteriosusGroup.getGroup() + is_svc = supraventricularCrestGroup.getGroup() is_rfr = fm.createFieldAnd( is_exterior, fm.createFieldAnd( diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py index 0cfdf90f..cdda5e8c 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py @@ -3,7 +3,7 @@ ''' from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString + findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field from cmlibs.zinc.node import Node @@ -170,7 +170,7 @@ def generateBaseMesh(cls, region, options): markerLocation = findOrCreateFieldStoredMeshLocation(fm, mesh, name="marker_location") nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerPoints = findOrCreateFieldNodeGroup(markerGroup, nodes).getNodesetGroup() + markerPoints = markerGroup.getOrCreateNodesetGroup(nodes) markerTemplateInternal = nodes.createNodetemplate() markerTemplateInternal.defineField(markerName) markerTemplateInternal.defineField(markerLocation) @@ -1269,8 +1269,8 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): upperLeftGroup = getAnnotationGroupForTerm(annotationGroups, get_lung_term("upper lobe of left lung")) lowerLeftGroup = getAnnotationGroupForTerm(annotationGroups, get_lung_term("lower lobe of left lung")) - is_upperLeftGroup = upperLeftGroup.getFieldElementGroup(mesh2d) - is_lowerLeftGroup = lowerLeftGroup.getFieldElementGroup(mesh2d) + is_upperLeftGroup = upperLeftGroup.getGroup() + is_lowerLeftGroup = lowerLeftGroup.getGroup() is_obliqueLeftGroup = fm.createFieldAnd(is_upperLeftGroup, is_lowerLeftGroup) obliqueLeftGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_lung_term("oblique fissure of left lung")) @@ -1281,9 +1281,9 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): middleRightGroup = getAnnotationGroupForTerm(annotationGroups, get_lung_term("middle lobe of right lung")) lowerRightGroup = getAnnotationGroupForTerm(annotationGroups, get_lung_term("lower lobe of right lung")) - is_upperRightGroup = upperRightGroup.getFieldElementGroup(mesh2d) - is_middleRightGroup = middleRightGroup.getFieldElementGroup(mesh2d) - is_lowerRightGroup = lowerRightGroup.getFieldElementGroup(mesh2d) + is_upperRightGroup = upperRightGroup.getGroup() + is_middleRightGroup = middleRightGroup.getGroup() + is_lowerRightGroup = lowerRightGroup.getGroup() is_obliqueRightGroup = fm.createFieldAnd(fm.createFieldOr(is_middleRightGroup, is_upperRightGroup), is_lowerRightGroup) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_lung2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_lung2.py index fee7acc1..eee3b74d 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_lung2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_lung2.py @@ -1,42 +1,35 @@ -''' +""" Generates a 3D generic lung mesh. -''' +""" import copy import math -from scaffoldmaker.utils.interpolation import sampleCubicHermiteCurves, interpolateSampleCubicHermite, \ - smoothCubicHermiteDerivativesLine, interpolateSampleLinear -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm +from cmlibs.maths.vectorops import cross, dot, mult, normalize, sub +from cmlibs.utils.zinc.field import Field, findOrCreateFieldCoordinates +from cmlibs.zinc.element import Element +from cmlibs.zinc.node import Node +from scaffoldmaker.utils.interpolation import sampleCubicHermiteCurves, smoothCubicHermiteDerivativesLine +from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, \ + getAnnotationGroupForTerm from scaffoldmaker.annotation.lung_terms import get_lung_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, remapEftNodeValueLabelsVersion, setEftScaleFactorIds -from scaffoldmaker.utils.cylindermesh import createEllipsePerimeter +from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from cmlibs.utils.zinc.general import ChangeManager -from scaffoldmaker.utils.geometry import createEllipsoidPoints, getEllipseRadiansToX, getEllipseArcLength, \ - getApproximateEllipsePerimeter, sampleEllipsePoints, updateEllipseAngleByArcLength, getEllipsoidPlaneA, \ +from scaffoldmaker.utils.geometry import sampleEllipsePoints, getEllipsoidPlaneA, \ getEllipsoidPolarCoordinatesFromPosition, getEllipsoidPolarCoordinatesTangents from scaffoldmaker.utils.interpolation import computeCubicHermiteDerivativeScaling, interpolateCubicHermite, \ interpolateCubicHermiteDerivative from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils.vector import magnitude, setMagnitude, crossproduct3, normalise -from cmlibs.maths.vectorops import add, cross, dot, mult, normalize, sub +from scaffoldmaker.utils.vector import magnitude from scaffoldmaker.utils.zinc_utils import disconnectFieldMeshGroupBoundaryNodes -from cmlibs.utils.zinc.field import Field, findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString, createFieldEulerAnglesRotationMatrix -from cmlibs.utils.zinc.finiteelement import get_element_node_identifiers -from cmlibs.zinc.element import Element -from cmlibs.zinc.node import Node -class MeshType_3d_lung2(Scaffold_base): - ''' - Generic 3D lung scaffold. - ''' +class MeshType_3d_lung2(Scaffold_base): """ - Generates an ellipsoid with a tear-shaped base for the lung mathematically, - with x, y, z length and the position, angle of the oblique fissure. - Regions and markers of the lung are annotated. + Generic 3D lung scaffold. + Generates a half ellipsoid with a tear-shaped base for the lung mathematically, + with x, y, z length and the position, angle of the oblique fissure. + Regions and markers of the lung are annotated. """ materialOptions = { @@ -79,12 +72,12 @@ class MeshType_3d_lung2(Scaffold_base): 'Material Parameters': None } - @staticmethod - def getName(): + @classmethod + def getName(cls): return '3D Lung 2' - @staticmethod - def getParameterSetNames(): + @classmethod + def getParameterSetNames(cls): return [ 'Default', 'Human 1', @@ -224,8 +217,8 @@ def getDefaultOptions(cls, parameterSetName='Default'): return options - @staticmethod - def getOrderedOptionNames(): + @classmethod + def getOrderedOptionNames(cls): optionNames = [ 'Number of left lung lobes', 'Left-right lung spacing', @@ -268,9 +261,9 @@ def getOrderedOptionNames(): @classmethod def checkOptions(cls, options): - ''' + """ :return: True if dependent options changed, otherwise False. - ''' + """ dependentChanges = False if options['Refine number of elements'] < 1: options['Refine number of elements'] = 1 @@ -282,12 +275,12 @@ def checkOptions(cls, options): @classmethod def generateBaseMesh(cls, region, options): - ''' + """ Generate the base tricubic Hermite mesh. See also generateMesh(). :param region: Zinc region to define model in. Must be empty. :param options: Dict containing options. See getDefaultOptions(). :return: list of AnnotationGroup, None - ''' + """ # Generate two meshes: geometric[0] and lung[1] coordinates for coordinate in range(2): if coordinate == 0: @@ -410,18 +403,18 @@ def generateBaseMesh(cls, region, options): annotationGroups.append(rightLungAccessoryLobeGroup) rightLungAccessoryLobeNodesetGroup = rightLungAccessoryLobeGroup.getNodesetGroup(nodes) # Marker points - accessoryDorsalApexGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("dorsal apex of right lung accessory lobe")) - accessoryVentralApexGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("ventral apex of right lung accessory lobe")) - accessoryVentralLeftGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("left ventral base of right lung accessory lobe")) - accessoryVentralRightGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("right ventral base of right lung accessory lobe")) - accessoryDorsalLeftGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("left dorsal base of right lung accessory lobe")) - accessoryDorsalRightGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("right dorsal base of right lung accessory lobe")) + accessoryDorsalApexGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("dorsal apex of right lung accessory lobe")) + accessoryVentralApexGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("ventral apex of right lung accessory lobe")) + accessoryVentralLeftGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("left ventral base of right lung accessory lobe")) + accessoryVentralRightGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("right ventral base of right lung accessory lobe")) + accessoryDorsalLeftGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("left dorsal base of right lung accessory lobe")) + accessoryDorsalRightGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("right dorsal base of right lung accessory lobe")) # Nodeset group leftLungNodesetGroup = leftLungGroup.getNodesetGroup(nodes) @@ -431,32 +424,35 @@ def generateBaseMesh(cls, region, options): mediastinumRightNodesetGroup = mediastinumRightGroup.getNodesetGroup(nodes) # Arbitrary anatomical groups and nodesets for transformation - upperLeftDorsalLungGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, ["upper lobe of left lung dorsal", "None"]) + upperLeftDorsalLungGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, ["upper lobe of left lung dorsal", "None"]) upperLeftDorsalLungMeshGroup = upperLeftDorsalLungGroup.getMeshGroup(mesh) - upperRightDorsalLungGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, ["upper lobe of right lung dorsal", "None"]) + upperRightDorsalLungGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, ["upper lobe of right lung dorsal", "None"]) upperRightDorsalLungMeshGroup = upperRightDorsalLungGroup.getMeshGroup(mesh) - rightMedialLungGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, ["medial right lung", "None"]) - leftMedialLungGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, ["medial left lung", "None"]) + rightMedialLungGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, ["medial right lung", "None"]) + leftMedialLungGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, ["medial left lung", "None"]) rightMedialLungNodesetGroup = rightMedialLungGroup.getNodesetGroup(nodes) leftMedialLungNodesetGroup = leftMedialLungGroup.getNodesetGroup(nodes) # Marker points/groups - leftApexGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("apex of left lung")) - rightApexGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("apex of right lung")) - leftVentralGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("ventral base of left lung")) - rightVentralGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("ventral base of right lung")) - rightLateralGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term( - "laterodorsal tip of middle lobe of right lung")) - leftMedialGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("medial base of left lung")) - rightMedialGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_lung_term("medial base of right lung")) + leftApexGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("apex of left lung")) + rightApexGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("apex of right lung")) + leftVentralGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("ventral base of left lung")) + rightVentralGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("ventral base of right lung")) + rightLateralGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("laterodorsal tip of middle lobe of right lung")) + leftMedialGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("medial base of left lung")) + rightMedialGroup = findOrCreateAnnotationGroupForTerm( + annotationGroups, region, get_lung_term("medial base of right lung")) cache = fm.createFieldcache() @@ -509,7 +505,6 @@ def generateBaseMesh(cls, region, options): uElementsCount1, uElementsCount2, uElementsCount3, lowerRightNodeIds, upperRightNodeIds, nodeIdentifier) - if hasAccessoryLobe: # The number of the elements in the accessory lobe right lung accesssoryLobeElementsCount1 = 2 @@ -518,7 +513,8 @@ def generateBaseMesh(cls, region, options): accessoryLobeNodeIds = [] # Accessory lobe right lung nodes - nodeIdentifier = createAccessorylobeLungNodes(accessoryLobeBaseMidpointXY, cache, coordinates, nodes, nodetemplate, + nodeIdentifier = createAccessorylobeLungNodes( + accessoryLobeBaseMidpointXY, cache, coordinates, nodes, nodetemplate, rightLungAccessoryLobeNodesetGroup, lungNodesetGroup, accesssoryLobeElementsCount1, accesssoryLobeElementsCount2, accesssoryLobeElementsCount3, accessoryLobeLength, accessoryLobeDorsalWidth, accessoryLobeDorsalHeight, accessoryLobeVentralWidth, @@ -531,8 +527,8 @@ def generateBaseMesh(cls, region, options): if numberOfLeftLung == 2: # Left lung elements - elementIdentifier, leftUpperLobeElementID, leftLowerLobeElementID = \ - createLungElements(coordinates, eftfactory, eftRegular, elementtemplateRegular, + elementIdentifier, leftUpperLobeElementID, leftLowerLobeElementID = createLungElements( + coordinates, eftfactory, eftRegular, elementtemplateRegular, elementtemplateCustom, mesh, lungMeshGroup, leftLungMeshGroup, lowerLeftLungMeshGroup, None, upperLeftLungMeshGroup, mediastinumLeftGroupMeshGroup, upperLeftDorsalLungMeshGroup, @@ -540,18 +536,18 @@ def generateBaseMesh(cls, region, options): uElementsCount1, uElementsCount2, uElementsCount3, lowerLeftNodeIds, upperLeftNodeIds, elementIdentifier) else: - elementIdentifier, leftUpperLobeElementID, leftLowerLobeElementID = \ - createLungElements(coordinates, eftfactory, eftRegular, elementtemplateRegular, - elementtemplateCustom, mesh, lungMeshGroup, - leftLungMeshGroup, None, None, None, - mediastinumLeftGroupMeshGroup, None, - lElementsCount1, lElementsCount2, lElementsCount3, - uElementsCount1, uElementsCount2, uElementsCount3, - lowerLeftNodeIds, upperLeftNodeIds, elementIdentifier) + elementIdentifier, leftUpperLobeElementID, leftLowerLobeElementID = createLungElements( + coordinates, eftfactory, eftRegular, elementtemplateRegular, + elementtemplateCustom, mesh, lungMeshGroup, + leftLungMeshGroup, None, None, None, + mediastinumLeftGroupMeshGroup, None, + lElementsCount1, lElementsCount2, lElementsCount3, + uElementsCount1, uElementsCount2, uElementsCount3, + lowerLeftNodeIds, upperLeftNodeIds, elementIdentifier) # Right lung elements - elementIdentifier, rightUpperLobeElementID, rightLowerLobeElementID = \ - createLungElements(coordinates, eftfactory, eftRegular, elementtemplateRegular, + elementIdentifier, rightUpperLobeElementID, rightLowerLobeElementID = createLungElements( + coordinates, eftfactory, eftRegular, elementtemplateRegular, elementtemplateCustom, mesh, lungMeshGroup, rightLungMeshGroup, lowerRightLungMeshGroup, middleRightLungMeshGroup, upperRightLungMeshGroup, mediastinumRightGroupMeshGroup, upperRightDorsalLungMeshGroup, @@ -575,7 +571,7 @@ def generateBaseMesh(cls, region, options): sir_1 = region_1.createStreaminformationRegion() srm_1 = sir_1.createStreamresourceMemory() region_1.write(sir_1) - result, buffer = srm_1.getBuffer() + buffer = srm_1.getBuffer()[1] region = region_temp sir = region.createStreaminformationRegion() @@ -647,7 +643,7 @@ def generateBaseMesh(cls, region, options): lowerLeftElementCount = (lElementsCount1 * (lElementsCount2-1) * lElementsCount3 + lElementsCount1) idx = lowerLeftElementCount + (uElementsCount1 * uElementsCount2 * (uElementsCount3//2) + uElementsCount2) - markerList.append({ "group" : leftApexGroup, "elementId" : idx, "xi" : [0.0, 1.0, 1.0]}) + markerList.append({ "group" : leftApexGroup, "elementId": idx, "xi": [0.0, 1.0, 1.0]}) idx = lElementsCount1 * (lElementsCount2 // 2) markerList.append({"group": leftMedialGroup, "elementId": idx, "xi": [1.0, 1.0, 0.0]}) @@ -660,7 +656,7 @@ def generateBaseMesh(cls, region, options): lowerRightElementCount = lowerLeftElementCount idx = leftLungElementCount + lowerRightElementCount + \ - (uElementsCount1 * uElementsCount2 * (uElementsCount3//2) + uElementsCount2) + (uElementsCount1 * uElementsCount2 * (uElementsCount3//2) + uElementsCount2) markerList.append({"group": rightApexGroup, "elementId": idx, "xi": [0.0, 1.0, 1.0]}) idx = leftLungElementCount + lElementsCount1 + 1 @@ -679,7 +675,7 @@ def generateBaseMesh(cls, region, options): idx = rightLungElementCount + leftLungElementCount + idx_temp markerList.append({"group": accessoryDorsalApexGroup, "elementId": idx, "xi": [0.0, 0.0, 1.0]}) - idx_temp = accesssoryLobeElementsCount1 * accesssoryLobeElementsCount2 * (accesssoryLobeElementsCount3) + idx_temp = accesssoryLobeElementsCount1 * accesssoryLobeElementsCount2 * accesssoryLobeElementsCount3 idx = rightLungElementCount + leftLungElementCount + idx_temp markerList.append({"group": accessoryVentralApexGroup, "elementId": idx, "xi": [0.0, 1.0, 1.0]}) @@ -763,7 +759,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): mediastanumTerms = ["anterior mediastinum of left lung", "anterior mediastinum of right lung"] for mediastanumTerm in mediastanumTerms: mediastanumGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_lung_term(mediastanumTerm)) - is_anteriorBorderGroup = mediastanumGroup.getFieldElementGroup(mesh1d) + is_anteriorBorderGroup = mediastanumGroup.getGroup() is_mediastanumGroup_exterior = fm.createFieldAnd(is_anteriorBorderGroup, is_exterior) is_mediastanumGroup_exterior_xi1_0 = fm.createFieldAnd(is_mediastanumGroup_exterior, is_xi1_0) is_mediastanumGroup_exterior_xi1_01 = fm.createFieldAnd(is_mediastanumGroup_exterior_xi1_0, is_xi1_1) @@ -782,7 +778,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): arbTerms = ["upper lobe of left lung dorsal", "upper lobe of right lung dorsal"] for arbTerm in arbTerms: group = findOrCreateAnnotationGroupForTerm(annotationGroups, region, [arbTerm, "None"]) - group2d = group.getFieldElementGroup(mesh2d) + group2d = group.getGroup() group2d_exterier = fm.createFieldAnd(group2d, is_exterior) arbLobe_group.update({arbTerm: group}) arbLobe_2dgroup.update({arbTerm: group2d}) @@ -810,7 +806,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): continue group = getAnnotationGroupForTerm(annotationGroups, get_lung_term(term)) - group2d = group.getFieldElementGroup(mesh2d) + group2d = group.getGroup() group2d_exterior = fm.createFieldAnd(group2d, is_exterior) surfaceGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_lung_term(term + " surface")) @@ -883,7 +879,8 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): if not openFissures: fissureTerms = ["oblique fissure of right lung", "horizontal fissure of right lung"] - if numberOfLeftLung > 1: fissureTerms.append("oblique fissure of left lung") + if numberOfLeftLung > 1: + fissureTerms.append("oblique fissure of left lung") lobeFissureTerms = ["oblique fissure of lower lobe of left lung", "oblique fissure of upper lobe of left lung", "oblique fissure of lower lobe of right lung", @@ -895,10 +892,12 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): if (fissureTerm == "oblique fissure of left lung") and (numberOfLeftLung > 1): fissureGroup = fm.createFieldAnd(lobe["upper lobe of left lung"], lobe["lower lobe of left lung"]) elif fissureTerm == "oblique fissure of right lung": - fissureGroup = fm.createFieldAnd(fm.createFieldOr(lobe["middle lobe of right lung"], lobe["upper lobe of right lung"]), - lobe["lower lobe of right lung"]) + fissureGroup = fm.createFieldAnd( + fm.createFieldOr(lobe["middle lobe of right lung"], lobe["upper lobe of right lung"]), + lobe["lower lobe of right lung"]) elif fissureTerm == "horizontal fissure of right lung": - fissureGroup = fm.createFieldAnd(lobe["upper lobe of right lung"], lobe["middle lobe of right lung"]) + fissureGroup = fm.createFieldAnd( + lobe["upper lobe of right lung"], lobe["middle lobe of right lung"]) fissureSurfaceGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_lung_term(fissureTerm)) fissureSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(fissureGroup) @@ -916,37 +915,37 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): # add fissures to lobe surface groups if numberOfLeftLung > 1: - obliqueFissureOfLeftLungElementGroup = getAnnotationGroupForTerm( - annotationGroups, get_lung_term("oblique fissure of left lung")).getFieldElementGroup(mesh2d) + obliqueFissureOfLeftLungGroup = getAnnotationGroupForTerm( + annotationGroups, get_lung_term("oblique fissure of left lung")).getGroup() for lobeSurfaceTerm in ("lower lobe of left lung surface", "upper lobe of left lung surface"): lobeSurfaceGroup = getAnnotationGroupForTerm( annotationGroups, get_lung_term(lobeSurfaceTerm)) - lobeSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(obliqueFissureOfLeftLungElementGroup) - horizontalFissureOfRightLungElementGroup = getAnnotationGroupForTerm( + lobeSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(obliqueFissureOfLeftLungGroup) + horizontalFissureOfRightLungGroup = getAnnotationGroupForTerm( annotationGroups, - get_lung_term("horizontal fissure of right lung")).getFieldElementGroup(mesh2d) - obliqueFissureOfRightLungElementGroup = getAnnotationGroupForTerm( + get_lung_term("horizontal fissure of right lung")).getGroup() + obliqueFissureOfRightLungGroup = getAnnotationGroupForTerm( annotationGroups, - get_lung_term("oblique fissure of right lung")).getFieldElementGroup(mesh2d) - obliqueFissureOfMiddleLobeOfRightLungElementGroup = getAnnotationGroupForTerm( + get_lung_term("oblique fissure of right lung")).getGroup() + obliqueFissureOfMiddleLobeOfRightLungGroup = getAnnotationGroupForTerm( annotationGroups, - get_lung_term("oblique fissure of middle lobe of right lung")).getFieldElementGroup(mesh2d) - obliqueFissureOfUpperLobeOfRightLungElementGroup = getAnnotationGroupForTerm( + get_lung_term("oblique fissure of middle lobe of right lung")).getGroup() + obliqueFissureOfUpperLobeOfRightLungGroup = getAnnotationGroupForTerm( annotationGroups, - get_lung_term("oblique fissure of upper lobe of right lung")).getFieldElementGroup(mesh2d) + get_lung_term("oblique fissure of upper lobe of right lung")).getGroup() lobeSurfaceGroup = getAnnotationGroupForTerm( annotationGroups, get_lung_term("lower lobe of right lung surface")) - lobeSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(obliqueFissureOfRightLungElementGroup) + lobeSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(obliqueFissureOfRightLungGroup) lobeSurfaceGroup = getAnnotationGroupForTerm( annotationGroups, get_lung_term("middle lobe of right lung surface")) lobeSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional( - fm.createFieldOr(obliqueFissureOfMiddleLobeOfRightLungElementGroup, - horizontalFissureOfRightLungElementGroup)) + fm.createFieldOr(obliqueFissureOfMiddleLobeOfRightLungGroup, + horizontalFissureOfRightLungGroup)) lobeSurfaceGroup = getAnnotationGroupForTerm( annotationGroups, get_lung_term("upper lobe of right lung surface")) lobeSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional( - fm.createFieldOr(obliqueFissureOfUpperLobeOfRightLungElementGroup, - horizontalFissureOfRightLungElementGroup)) + fm.createFieldOr(obliqueFissureOfUpperLobeOfRightLungGroup, + horizontalFissureOfRightLungGroup)) if openFissures: if numberOfLeftLung > 1: @@ -977,8 +976,9 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): leftLungSurfaceGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_lung_term('left lung surface')) leftLungSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(lobe_exterior['left lung surface']) - obliqueLowerRight = fm.createFieldOr(fm.createFieldAnd(lobe_exterior['lower lobe of right lung surface'], is_xi2_1), - fm.createFieldAnd(lobe_exterior['lower lobe of right lung surface'], is_xi3_1)) + obliqueLowerRight = fm.createFieldOr( + fm.createFieldAnd(lobe_exterior['lower lobe of right lung surface'], is_xi2_1), + fm.createFieldAnd(lobe_exterior['lower lobe of right lung surface'], is_xi3_1)) obliqueMiddleRight = fm.createFieldAnd(lobe_exterior['middle lobe of right lung surface'], is_xi2_0) @@ -1000,7 +1000,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): rightLungSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(rightLungSurface) for term in ("lower lobe of right lung surface", "middle lobe of right lung surface", - "upper lobe of right lung surface"): + "upper lobe of right lung surface"): rightLungSurfaceGroup = findOrCreateAnnotationGroupForTerm( annotationGroups, region, get_lung_term(term)) rightLungSurfaceGroup.getMeshGroup(mesh2d).addElementsConditional(lobe_exterior[term]) @@ -1052,6 +1052,7 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, :param nodes: :param nodetemplate: :param mediastinumNodesetGroup: + :param medialLungNodesetGroup: :param lungSideNodesetGroup: :param lungNodesetGroup: :param lElementsCount1: @@ -1068,9 +1069,6 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, # Initialise parameters leftLung = 0 - d1 = [1.0, 0.0, 0.0] - d2 = [0.0, 1.0, 0.0] - d3 = [0.0, 0.0, 1.0] centre = [0.0, 0.0, 0.0] xAxis = [1.0, 0.0, 0.0] @@ -1104,7 +1102,7 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, lower_edge, lower_edge_d3 = sampleEllipsePoints( planeCentre, vec1, vec2, 0.0, -totalRadiansAround, lElementsCount3) - # oblique fissure - in 2 parts as horizontal fissure starts half way up it + # oblique fissure - in 2 parts as horizontal fissure starts halfway up it planeCentre, vec1, vec2 = getEllipsoidPlaneA(widthUnit, lengthUnit, heightUnit, obp, lower_edge[lElementsCount3]) dx = dot(sub(obp, planeCentre), normalize(vec1)) totalRadiansAround = math.acos(dx / magnitude(vec1)) @@ -1218,7 +1216,7 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, d1 = mult(d1, scale) d2 = mult(d2, scale) ix = interpolateCubicHermite(x1, d1, x2, d2, 0.5) - id = interpolateCubicHermiteDerivative(x1, d1, x2, d2, 0.5) + ixd = interpolateCubicHermiteDerivative(x1, d1, x2, d2, 0.5) # move sample point to be on ellipsoid surface and re-smooth derivatives to be tangential u, v = getEllipsoidPolarCoordinatesFromPosition(widthUnit, lengthUnit, heightUnit, ix) tip_x, tip_dx_du, tip_dx_dv = getEllipsoidPolarCoordinatesTangents(widthUnit, lengthUnit, heightUnit, u, v) @@ -1226,8 +1224,8 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, lower_row2[-2] = tip_x lower_row2[-1] = obl[-2] # subtract component of derivative in surface normal direction - snc = dot(id, tip_surface_normal) - lower_row2_d2[-2] = sub(id, mult(tip_surface_normal, snc)) + snc = dot(ixd, tip_surface_normal) + lower_row2_d2[-2] = sub(ixd, mult(tip_surface_normal, snc)) lower_row2_d2[-1] = upper_row2_d2[0] td2 = smoothCubicHermiteDerivativesLine(lower_row2[-3:], lower_row2_d2[-3:], fixAllDirections=True, fixStartDerivative=True, fixEndDerivative=True) @@ -1237,7 +1235,7 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, # td2 = smoothCubicHermiteDerivativesLine(lower_row2[-3:], td2, fixAllDirections=True, # fixStartDerivative=True, fixEndDerivative=True) lower_row2_d2[-2] = td2[1] - # lower_row2_d2[-2] = id # GRC temp + # lower_row2_d2[-2] = ixd # smooth along lowerObl through new point to get its d2 lowerObl[-2] = tip_x lowerObl[-1] = lower_row1[-2] @@ -1266,7 +1264,7 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, elif n3 == 3: x = obl tx.append(x[n2]) - td3 = [[0.0, 0.0, 0.0] for n3 in range(lElementsCount3 + 1)] + td3 = [[0.0, 0.0, 0.0] for _ in range(lElementsCount3 + 1)] fixEndDerivative = False if n2 == 1: td3[-1] = upper_col1_d3[0] @@ -1372,9 +1370,8 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, lungSideNodesetGroup.addNode(node) lungNodesetGroup.addNode(node) - - # smooth derivatives - upper lobe - upper_row4_d2 = [[-1.0, 0.0, 0.0]] + [[0.0, 0.0, 0.0] for i in range(len(upper_row4) - 2)] + [[1.0, 0.0, 0.0]] + # smooth derivatives - upper lobe + upper_row4_d2 = [[-1.0, 0.0, 0.0]] + [[0.0, 0.0, 0.0] for _ in range(len(upper_row4) - 2)] + [[1.0, 0.0, 0.0]] upper_row4_d2 = smoothCubicHermiteDerivativesLine(upper_row4, upper_row4_d2, fixStartDirection=True, fixEndDirection=True) # apex row @@ -1439,7 +1436,7 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, sx = upper_row3[n2 - 2] if n2 < 4: next_sxd2 = upper_row3[n2 - 1] - elif (n3 == 3): + elif n3 == 3: sx = upper_row4[n2] if n2 < 4: next_sxd2 = upper_row4[n2 + 1] @@ -1535,11 +1532,11 @@ def createLungNodes(spaceFromCentre, lengthUnit, widthUnit, heightUnit, def createLungElements(coordinates, eftfactory, eftRegular, elementtemplateRegular, elementtemplateCustom, mesh, - lungMeshGroup, lungSideMeshGroup, lowerLobeMeshGroup, middleLobeMeshGroup, - upperLobeMeshGroup, mediastinumMeshGroup, upperDorsalMeshGroup, - lElementsCount1, lElementsCount2, lElementsCount3, - uElementsCount1, uElementsCount2, uElementsCount3, - lowerNodeIds, upperNodeIds, elementIdentifier): + lungMeshGroup, lungSideMeshGroup, lowerLobeMeshGroup, middleLobeMeshGroup, + upperLobeMeshGroup, mediastinumMeshGroup, upperDorsalMeshGroup, + lElementsCount1, lElementsCount2, lElementsCount3, + uElementsCount1, uElementsCount2, uElementsCount3, + lowerNodeIds, upperNodeIds, elementIdentifier): """ :param lowerNodeIds: Indexing by [lElementsCount3 + 1][lElementsCount2 + 1][lElementsCount1 + 1] :param upperNodeIds: Indexing by [uElementsCount3 + 1][uElementsCount2 + 1][uElementsCount1 + 1] @@ -1800,10 +1797,11 @@ def createLungElements(coordinates, eftfactory, eftRegular, elementtemplateRegul return elementIdentifier, upperLobeElementID, lowerLobeElementID + def createAccessorylobeLungNodes(centre, cache, coordinates, nodes, nodetemplate, lungSideNodesetGroup, lungNodesetGroup, - elementsCount1, elementsCount2, elementsCount3, - length, dorsalWidth, dorsalHeight, ventralWidth, ventralHeight, - nodeIds, nodeIdentifier): + elementsCount1, elementsCount2, elementsCount3, + length, dorsalWidth, dorsalHeight, ventralWidth, ventralHeight, + nodeIds, nodeIdentifier): """ Create a 3D triangular mesh from getAccessorylobeLungNodes :parameter: elementsCount1 - x, elementsCount2 - y, elementsCount3 - z @@ -1867,7 +1865,7 @@ def createAccessorylobeLungNodes(centre, cache, coordinates, nodes, nodetemplate if n3 < elementsCount3: d1 = [px[n3][n1][n2][i] - px[n3][n1-1][n2][i] for i in range(3)] if n1 == elementsCount1 else \ - [px[n3][n1+1][n2][i] - px[n3][n1][n2][i] for i in range(3)] + [px[n3][n1+1][n2][i] - px[n3][n1][n2][i] for i in range(3)] d3 = [px[n3+1][1][n2][i] - px[n3][n1][n2][i] for i in range(3)] if n3 == 1 else \ [px[n3 + 1][n1][n2][i] - px[n3][n1][n2][i] for i in range(3)] else: @@ -1890,10 +1888,11 @@ def createAccessorylobeLungNodes(centre, cache, coordinates, nodes, nodetemplate return nodeIdentifier + def createAccessorylobeLungElements(coordinates, eftfactory, eftRegular, elementtemplateRegular, elementtemplateCustom, - mesh, lungMeshGroup, diaphragmaticLobeMeshGroup, - elementsCount1, elementsCount2, elementsCount3, - NodeIds, elementIdentifier): + mesh, lungMeshGroup, diaphragmaticLobeMeshGroup, + elementsCount1, elementsCount2, elementsCount3, + NodeIds, elementIdentifier): """ Create a 3D triangular mesh from getAccessorylobeLungNodes :parameter: elementsCount1 - x, elementsCount2 - y, elementsCount3 - z @@ -1957,6 +1956,7 @@ def createAccessorylobeLungElements(coordinates, eftfactory, eftRegular, element return elementIdentifier + def concavingDiaphragmaticSurface(diaphragmCurvatureX, diaphragmCurvatureY, fm, coordinates, diaphragmCentreX, diaphragmCentreY, lungNodesetGroup): """ @@ -1997,13 +1997,13 @@ def concavingDiaphragmaticSurface(diaphragmCurvatureX, diaphragmCurvatureY, fm, kappa_x = fm.createFieldConstant([diaphragmCurvatureX, 0.0, 0.0]) r_x = fm.createFieldConstant([1/diaphragmCurvatureX, 0.0, 0.0]) s_x = fm.createFieldMultiply(offset_coordinates, only_x) - z_x = fm.createFieldMultiply(coordinates, only_z) - z_x = fm.createFieldComponent(z_x, [3, 1, 1]) - s_zx = r_x # if no bulge s_zx = r_x + # z_x = fm.createFieldMultiply(coordinates, only_z) + # z_x = fm.createFieldComponent(z_x, [3, 1, 1]) + s_zx = r_x # if no bulge s_zx = r_x theta_x = fm.createFieldMultiply(kappa_x, s_x) x_new = fm.createFieldMultiply(s_zx, fm.createFieldSin(theta_x)) delta_zx = fm.createFieldMultiply(s_zx, fm.createFieldSubtract(fm.createFieldCos(theta_x), - fm.createFieldConstant([1.0, 0.0, 0.0]))) + fm.createFieldConstant([1.0, 0.0, 0.0]))) delta_zx = fm.createFieldComponent(delta_zx, [3, 3, 1]) # y-coordinates @@ -2011,8 +2011,8 @@ def concavingDiaphragmaticSurface(diaphragmCurvatureX, diaphragmCurvatureY, fm, kappa_y = fm.createFieldConstant([0.0, diaphragmCurvatureY, 0.0]) r_y = fm.createFieldConstant([0.0, 1/diaphragmCurvatureY, 0.0]) s_y = fm.createFieldMultiply(offset_coordinates, only_y) - z_y = fm.createFieldMultiply(coordinates, only_z) - z_y = fm.createFieldComponent(z_y, [1, 3, 1]) + # z_y = fm.createFieldMultiply(coordinates, only_z) + # z_y = fm.createFieldComponent(z_y, [1, 3, 1]) s_zy = r_y # if no bulge s_zx = r_y theta_y = fm.createFieldMultiply(kappa_y, s_y) y_new = fm.createFieldMultiply(s_zy, fm.createFieldSin(theta_y)) @@ -2104,6 +2104,7 @@ def sharpeningRidge(sharpeningFactor, fm, coordinates, lungNodesetGroup, spaceFr fieldassignment.setNodeset(lungNodesetGroup) fieldassignment.assign() + def tiltLungs(tiltApex_xAxis, tiltApex_yAxis, tiltDiap_yAxis, tiltDiap_xAxis, fm, coordinates, lungNodesetGroup): """ :param tiltDegree: [tilted degree for apex, for diaphragm] @@ -2125,6 +2126,7 @@ def tiltLungs(tiltApex_xAxis, tiltApex_yAxis, tiltDiap_yAxis, tiltDiap_xAxis, fm fieldassignment.setNodeset(lungNodesetGroup) fieldassignment.assign() + def rotateLungs(rotateZ, fm, coordinates, lungNodesetGroup, spaceFromCentre): """ Rotate a specific lung at the center of the elements about z-axis @@ -2147,7 +2149,7 @@ def rotateLungs(rotateZ, fm, coordinates, lungNodesetGroup, spaceFromCentre): origin = fm.createFieldAdd(coordinates, offset) if rotateZ != 0.0: - rotateZ = -rotateZ / 180 * math.pi # negative value due to right handed rule + rotateZ = -rotateZ / 180 * math.pi # negative value due to right handed rule rotateZMatrix = fm.createFieldConstant([math.cos(rotateZ), math.sin(rotateZ), 0.0, -math.sin(rotateZ), math.cos(rotateZ), 0.0, 0.0, 0.0, 1.0]) newCoordinates = fm.createFieldMatrixMultiply(3, rotateZMatrix, origin) translate_coordinates = fm.createFieldSubtract(newCoordinates, offset) @@ -2155,12 +2157,12 @@ def rotateLungs(rotateZ, fm, coordinates, lungNodesetGroup, spaceFromCentre): fieldassignment.setNodeset(lungNodesetGroup) fieldassignment.assign() + def medialProtrusion(protrusion_factor, fm, coordinates, medialLungNodesetGroup, spaceFromCentre, width, length, height): """ :param tiltDegree: [tilted degree for apex, for diaphragm] :param fm: :param coordinates: - :param nodes: :return: transformed lungs """ # FieldConstant - Matrix = [ x1, x4, x7, @@ -2187,19 +2189,19 @@ def medialProtrusion(protrusion_factor, fm, coordinates, medialLungNodesetGroup, absXcoor = fm.createFieldAbs(Xcoor) constant = fm.createFieldConstant([0.0, rateOfChangeY, 0.0]) - scaleFunction = fm.createFieldMultiply(constant, squaredOrigin) # [0.0, k1y^2, 0.0] - squaredY = fm.createFieldComponent(scaleFunction, [2, 1, 1]) # [k1y^2, 0.0, 0.0] - squaredY_Z = fm.createFieldMultiply(absZcoor, squaredY) # [(k1)(y^2)(|z|), 0.0, 0.0] - squaredY_XZ = fm.createFieldMultiply(absXcoor, squaredY_Z) # [(k1)(y^2)(|z|), 0.0, 0.0] - squaredYOne = fm.createFieldAdd(squaredY_XZ, scale_y) # [k1|x||z|y^2 + peak, 1.0, 1.0] - recipFunction = fm.createFieldDivide(scale, squaredYOne) # 1/[k1|x||z|y^2 + peak], 0.0/1.0, 0.0/1.0] + scaleFunction = fm.createFieldMultiply(constant, squaredOrigin) # [0.0, k1y^2, 0.0] + squaredY = fm.createFieldComponent(scaleFunction, [2, 1, 1]) # [k1y^2, 0.0, 0.0] + squaredY_Z = fm.createFieldMultiply(absZcoor, squaredY) # [(k1)(y^2)(|z|), 0.0, 0.0] + squaredY_XZ = fm.createFieldMultiply(absXcoor, squaredY_Z) # [(k1)(y^2)(|z|), 0.0, 0.0] + squaredYOne = fm.createFieldAdd(squaredY_XZ, scale_y) # [k1|x||z|y^2 + peak, 1.0, 1.0] + recipFunction = fm.createFieldDivide(scale, squaredYOne) # 1/[k1|x||z|y^2 + peak], 0.0/1.0, 0.0/1.0] constant_1 = fm.createFieldConstant([0.0, 1.0, 1.0]) - yFunction = fm.createFieldAdd(recipFunction, constant_1) # 1/[k1y^2 + peak], 1.0, 1.0] + yFunction = fm.createFieldAdd(recipFunction, constant_1) # 1/[k1y^2 + peak], 1.0, 1.0] constant = fm.createFieldConstant([0.0, 0.0, rateOfChangeZ]) - scaleFunction = fm.createFieldMultiply(constant, squaredOrigin) # [0.0, 0.0, k2z^2] + scaleFunction = fm.createFieldMultiply(constant, squaredOrigin) # [0.0, 0.0, k2z^2] squaredZ = fm.createFieldComponent(scaleFunction, [3, 1, 1]) - squaredZOne = fm.createFieldAdd(squaredZ, scale_z) # [k2z^2 + peak, 1.0, 1.0] + squaredZOne = fm.createFieldAdd(squaredZ, scale_z) # [k2z^2 + peak, 1.0, 1.0] transformation_matrix = fm.createFieldMultiply(yFunction, squaredZOne) taper_coordinates = fm.createFieldMultiply(origin, transformation_matrix) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py index da0ba0c6..767c5f6c 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py @@ -1031,7 +1031,7 @@ def generateBaseMesh(cls, region, options): for termName in smallIntestineTermsAlong: tmpGroup = tmpFieldmodule.findFieldByName(termName).castGroup() if termName else None - tmpNodeset = tmpGroup.getFieldNodeGroup(tmpNodes).getNodesetGroup() if tmpGroup else tmpNodes + tmpNodeset = tmpGroup.getNodesetGroup(tmpNodes) if tmpGroup else tmpNodes cxGroup, cd1Group, cd2Group, cd3Group, cd12Group, cd13Group = get_nodeset_path_field_parameters( tmpNodeset, tmpCoordinates, @@ -1276,7 +1276,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): is_exterior = fm.createFieldIsExterior() is_exterior_face_xi3_1 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_1)) is_exterior_face_xi3_0 = fm.createFieldAnd(is_exterior, fm.createFieldIsOnFace(Element.FACE_TYPE_XI3_0)) - is_smallIntestine = smallIntestineGroup.getFieldElementGroup(mesh2d) + is_smallIntestine = smallIntestineGroup.getGroup() is_serosa = fm.createFieldAnd(is_smallIntestine, is_exterior_face_xi3_1) serosa = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_smallintestine_term("serosa of small intestine")) @@ -1285,7 +1285,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): duodenumGroup = getAnnotationGroupForTerm(annotationGroups, get_smallintestine_term("duodenum")) duodenumSerosa = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_smallintestine_term("serosa of duodenum")) - is_duodenum = duodenumGroup.getFieldElementGroup(mesh2d) + is_duodenum = duodenumGroup.getGroup() is_duodenumSerosa = fm.createFieldAnd(is_duodenum, is_exterior_face_xi3_1) duodenumSerosa.getMeshGroup(mesh2d).addElementsConditional(is_duodenumSerosa) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py index 201b8e73..14b9d107 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py @@ -6,8 +6,8 @@ import math -from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, \ - findOrCreateFieldStoredString +from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ + findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field from cmlibs.zinc.node import Node @@ -249,7 +249,7 @@ def generateBaseMesh(cls, region, options): markerName = findOrCreateFieldStoredString(fm, name="marker_name") markerLocation = findOrCreateFieldStoredMeshLocation(fm, mesh, name="marker_location") - markerPoints = findOrCreateFieldNodeGroup(markerGroup, nodes).getNodesetGroup() + markerPoints = markerGroup.getOrCreateNodesetGroup(nodes) markerTemplateInternal = nodes.createNodetemplate() markerTemplateInternal.defineField(markerName) markerTemplateInternal.defineField(markerLocation) @@ -584,7 +584,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): armTerms, faceTerms = getAutomaticArmFaceTerms(armCount) armGroups = [getAnnotationGroupForTerm(annotationGroups, armTerm) for armTerm in armTerms] - isArm =[armGroup.getFieldElementGroup(mesh2d) for armGroup in armGroups] + isArm =[armGroup.getGroup() for armGroup in armGroups] for arm in range(armCount): is_face = fm.createFieldOr( fm.createFieldAnd(isArm[arm - 1], is_exterior_face_xi2_1), diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py index d80c1a90..900c2394 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py @@ -1190,7 +1190,7 @@ def __init__(self, region, centralPath, stomachTermsAlong=[None]): for termName in stomachTermsAlong: tmpGroup = tmpFieldmodule.findFieldByName(termName).castGroup() if termName else None - tmpNodeset = tmpGroup.getFieldNodeGroup(tmpNodes).getNodesetGroup() if tmpGroup else tmpNodes + tmpNodeset = tmpGroup.getNodesetGroup(tmpNodes) if tmpGroup else tmpNodes cxGroup, cd1Group, cd2Group, cd3Group, cd12Group, cd13Group = get_nodeset_path_field_parameters( tmpNodeset, tmpCoordinates, diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py index ad49f925..71165cf3 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py @@ -7,9 +7,8 @@ import copy -from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldStoredString, findOrCreateFieldStoredMeshLocation, findOrCreateFieldNodeGroup -from cmlibs.utils.zinc.finiteelement import getMaximumNodeIdentifier, get_element_node_identifiers +from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates +from cmlibs.utils.zinc.finiteelement import get_element_node_identifiers from cmlibs.utils.zinc.general import ChangeManager from cmlibs.zinc.element import Element from cmlibs.zinc.field import Field @@ -18,7 +17,6 @@ from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm from scaffoldmaker.annotation.annotationgroup import getAnnotationGroupForTerm from scaffoldmaker.annotation.body_terms import get_body_term -from scaffoldmaker.annotation.nerve_terms import get_nerve_term from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1 from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage diff --git a/src/scaffoldmaker/meshtypes/scaffold_base.py b/src/scaffoldmaker/meshtypes/scaffold_base.py index ed5698f0..4946def6 100644 --- a/src/scaffoldmaker/meshtypes/scaffold_base.py +++ b/src/scaffoldmaker/meshtypes/scaffold_base.py @@ -5,12 +5,12 @@ import copy from cmlibs.utils.zinc.general import ChangeManager +from cmlibs.utils.zinc.scene import scene_get_selection_group from cmlibs.zinc.field import Field from scaffoldmaker.utils.derivativemoothing import DerivativeSmoothing from scaffoldmaker.utils.interpolation import DerivativeScalingMode from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils.zinc_utils import get_nodeset_field_parameters, print_node_field_parameters, \ - region_get_selection_group +from scaffoldmaker.utils.zinc_utils import get_nodeset_field_parameters, print_node_field_parameters class Scaffold_base: @@ -169,9 +169,9 @@ def printNodeFieldParameters(cls, region, options, functionOptions, editGroupNam ''' fieldmodule = region.getFieldmodule() nodeset = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - selectionGroup = region_get_selection_group(region) + selectionGroup = scene_get_selection_group(region.getScene(), inherit_root_region=region.getRoot()) if selectionGroup: - nodeset = selectionGroup.getFieldNodeGroup(nodeset).getNodesetGroup() + nodeset = selectionGroup.getNodesetGroup(nodeset) if not nodeset.isValid(): print('Print node field parameters: No nodes selected') return False, False @@ -185,7 +185,7 @@ def printNodeFieldParameters(cls, region, options, functionOptions, editGroupNam def smoothDerivatives(cls, region, options, functionOptions, editGroupName): fieldmodule = region.getFieldmodule() coordinatesField = fieldmodule.findFieldByName('coordinates').castFiniteElement() - selectionGroup = region_get_selection_group(region) + selectionGroup = scene_get_selection_group(region.getScene(), inherit_root_region=region.getRoot()) groupName = selectionGroup.getName() if selectionGroup else None updateDirections = functionOptions['Update directions'] scalingMode = DerivativeScalingMode.ARITHMETIC_MEAN if functionOptions['Scaling mode']['Arithmetic mean'] else DerivativeScalingMode.HARMONIC_MEAN diff --git a/src/scaffoldmaker/scaffoldpackage.py b/src/scaffoldmaker/scaffoldpackage.py index ec727ab4..0715f4ee 100644 --- a/src/scaffoldmaker/scaffoldpackage.py +++ b/src/scaffoldmaker/scaffoldpackage.py @@ -8,14 +8,13 @@ from cmlibs.maths.vectorops import euler_to_rotation_matrix from cmlibs.utils.zinc.field import createFieldEulerAnglesRotationMatrix -from cmlibs.utils.zinc.finiteelement import get_maximum_node_identifier +from cmlibs.utils.zinc.finiteelement import get_highest_dimension_mesh, get_maximum_node_identifier from cmlibs.utils.zinc.general import ChangeManager from cmlibs.zinc.field import Field, FieldGroup from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName, \ getAnnotationMarkerLocationField # , getAnnotationMarkerNameField from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils import vector -from scaffoldmaker.utils.zinc_utils import get_highest_dimension_mesh class ScaffoldPackage: @@ -295,8 +294,7 @@ def deleteElementsInRanges(self, region, deleteElementRanges): # put the elements in a group and use subelement handling to get nodes in use by it destroyGroup = fm.createFieldGroup() destroyGroup.setSubelementHandlingMode(FieldGroup.SUBELEMENT_HANDLING_MODE_FULL) - destroyElementGroup = destroyGroup.createFieldElementGroup(mesh) - destroyMesh = destroyElementGroup.getMeshGroup() + destroyMesh = destroyGroup.createMeshGroup(mesh) elementIter = mesh.createElementiterator() element = elementIter.next() while element.isValid(): @@ -309,11 +307,10 @@ def deleteElementsInRanges(self, region, deleteElementRanges): # print("Deleting", destroyMesh.getSize(), "element(s)") if destroyMesh.getSize() > 0: fieldcache = fm.createFieldcache() - destroyNodeGroup = destroyGroup.getFieldNodeGroup(nodes) - destroyNodes = destroyNodeGroup.getNodesetGroup() + destroyNodes = destroyGroup.getNodesetGroup(nodes) markerGroup = fm.findFieldByName("marker").castGroup() if markerGroup.isValid(): - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) markerLocation = getAnnotationMarkerLocationField(fm, mesh) if markerNodes.isValid() and markerLocation.isValid(): @@ -333,7 +330,7 @@ def deleteElementsInRanges(self, region, deleteElementRanges): del fieldcache # must destroy elements first as Zinc won't destroy nodes that are in use - mesh.destroyElementsConditional(destroyElementGroup) + mesh.destroyElementsConditional(destroyGroup) annotationGroups = self._autoAnnotationGroups + self._userAnnotationGroups # attempt to re-find locations of to-be-destroyed marker points with material coordinates: @@ -358,13 +355,11 @@ def deleteElementsInRanges(self, region, deleteElementRanges): else: self._userAnnotationGroups.remove(annotationGroup) - nodes.destroyNodesConditional(destroyNodeGroup) + nodes.destroyNodesConditional(destroyGroup) # clean up group so no external code hears is notified of its existence del destroyNodes - del destroyNodeGroup del destroyMesh - del destroyElementGroup del destroyGroup def getNextNodeIdentifier(self): diff --git a/src/scaffoldmaker/utils/derivativemoothing.py b/src/scaffoldmaker/utils/derivativemoothing.py index e615ece6..c93b7b9a 100644 --- a/src/scaffoldmaker/utils/derivativemoothing.py +++ b/src/scaffoldmaker/utils/derivativemoothing.py @@ -118,10 +118,7 @@ def __init__(self, region, field, selectionGroupName=None, scalingMode=Derivativ # edited nodes are added to the edit nodeset group, if group is supplied if editGroupName: editGroup = findOrCreateFieldGroup(self._fieldmodule, editGroupName, managed=True) - editNodeGroup = editGroup.getFieldNodeGroup(self._nodes) - if not editNodeGroup.isValid(): - editNodeGroup = editGroup.createFieldNodeGroup(self._nodes) - self._editNodesetGroup = editNodeGroup.getNodesetGroup() + self._editNodesetGroup = editGroup.getOrCreateNodesetGroup(self._nodes) else: self._editNodesetGroup = None # edges define curves with 4 expressions for x1, d1, x2, d2, followed by the arcLength @@ -136,7 +133,7 @@ def __init__(self, region, field, selectionGroupName=None, scalingMode=Derivativ if not self._selectionGroup.isValid(): print('DerivativeSmoothing: Selection group not found') return - self._selectionNodes = self._selectionGroup.getFieldNodeGroup(self._nodes).getNodesetGroup() + self._selectionNodes = self._selectionGroup.getNodesetGroup(self._nodes) if (not self._selectionNodes.isValid()) or (self._selectionNodes.getSize() == 0): print('DerivativeSmoothing: No nodes selected for smoothing') return diff --git a/src/scaffoldmaker/utils/exportvtk.py b/src/scaffoldmaker/utils/exportvtk.py index 7c1bf934..bd29c6b4 100644 --- a/src/scaffoldmaker/utils/exportvtk.py +++ b/src/scaffoldmaker/utils/exportvtk.py @@ -39,9 +39,7 @@ def __init__(self, region, description, annotationGroups = None): markerGroup = self._fieldmodule.findFieldByName("marker") if markerGroup.isValid(): markerGroup = markerGroup.castGroup() - markerNodeGroup = markerGroup.getFieldNodeGroup(self._nodes) - if markerNodeGroup.isValid(): - self._markerNodes = markerNodeGroup.getNodesetGroup() + self._markerNodes = markerGroup.getNodesetGroup(self._nodes) def _write(self, outstream): if version_info.major > 2: diff --git a/src/scaffoldmaker/utils/meshrefinement.py b/src/scaffoldmaker/utils/meshrefinement.py index ff3b04f5..c96994be 100644 --- a/src/scaffoldmaker/utils/meshrefinement.py +++ b/src/scaffoldmaker/utils/meshrefinement.py @@ -5,7 +5,7 @@ import math -from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, \ +from cmlibs.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from cmlibs.zinc.element import Element, Elementbasis from cmlibs.zinc.field import Field @@ -90,7 +90,7 @@ def __init__(self, sourceRegion, targetRegion, sourceAnnotationGroups = []): sourceMarkerGroup = findOrCreateFieldGroup(self._sourceFm, "marker") sourceMarkerName = findOrCreateFieldStoredString(self._sourceFm, name="marker_name") sourceMarkerLocation = findOrCreateFieldStoredMeshLocation(self._sourceFm, self._sourceMesh, name="marker_location") - sourceMarkerNodes = findOrCreateFieldNodeGroup(sourceMarkerGroup, sourceNodes).getNodesetGroup() + sourceMarkerNodes = sourceMarkerGroup.getNodesetGroup(sourceNodes) nodeIter = sourceMarkerNodes.createNodeiterator() node = nodeIter.next() while node.isValid(): @@ -109,7 +109,7 @@ def __init__(self, sourceRegion, targetRegion, sourceAnnotationGroups = []): self._targetMarkerGroup = findOrCreateFieldGroup(self._targetFm, "marker") self._targetMarkerName = findOrCreateFieldStoredString(self._targetFm, name="marker_name") self._targetMarkerLocation = findOrCreateFieldStoredMeshLocation(self._targetFm, self._targetMesh, name="marker_location") - self._targetMarkerNodes = findOrCreateFieldNodeGroup(self._targetMarkerGroup, self._targetNodes).getNodesetGroup() + self._targetMarkerNodes = self._targetMarkerGroup.getOrCreateNodesetGroup(self._targetNodes) self._targetMarkerTemplate = self._targetMarkerNodes.createNodetemplate() self._targetMarkerTemplate.defineField(self._targetMarkerName) self._targetMarkerTemplate.defineField(self._targetMarkerLocation) diff --git a/src/scaffoldmaker/utils/shieldmesh.py b/src/scaffoldmaker/utils/shieldmesh.py index 812e4369..102e50db 100644 --- a/src/scaffoldmaker/utils/shieldmesh.py +++ b/src/scaffoldmaker/utils/shieldmesh.py @@ -434,13 +434,15 @@ def generateNodesForOtherHalf(self, mirrorPlane): self.pd2[n3][2*self.elementsCountUp-n2][n1] = mirror.mirrorVector(self.pd2[n3][n2][n1]) self.pd3[n3][2*self.elementsCountUp-n2][n1] = mirror.mirrorVector(self.pd3[n3][n2][n1]) - def generateNodes(self, fieldmodule, coordinates, startNodeIdentifier, rangeOfRequiredElements, mirrorPlane=None): + def generateNodes(self, fieldmodule, coordinates, startNodeIdentifier, rangeOfRequiredElements=None, + mirrorPlane=None): """ Create shield nodes from coordinates. :param fieldmodule: Zinc fieldmodule to create nodes in. Uses DOMAIN_TYPE_NODES. :param coordinates: Coordinate field to define. :param startNodeIdentifier: First node identifier to use. :param rangeOfRequiredElements: Only the elements and nodes for the given range is generated. + Specify None to create all. :param mirrorPlane: mirror plane ax+by+cz=d in form of [a,b,c,d] :return: next nodeIdentifier. """ @@ -466,10 +468,11 @@ def generateNodes(self, fieldmodule, coordinates, startNodeIdentifier, rangeOfRe for n2 in range(self.elementsCountUpFull + 1): for n3 in range(self.elementsCountAlong+1): for n1 in range(self.elementsCountAcross + 1): - if n3 > rangeOfRequiredElements[2][1] or n3 < rangeOfRequiredElements[2][0]\ - or n2 > rangeOfRequiredElements[0][1] or n2 < rangeOfRequiredElements[0][0]\ - or n1 > rangeOfRequiredElements[1][1] or n1 < rangeOfRequiredElements[1][0]: - continue + if rangeOfRequiredElements: + if n3 > rangeOfRequiredElements[2][1] or n3 < rangeOfRequiredElements[2][0]\ + or n2 > rangeOfRequiredElements[0][1] or n2 < rangeOfRequiredElements[0][0]\ + or n1 > rangeOfRequiredElements[1][1] or n1 < rangeOfRequiredElements[1][0]: + continue if self.px[n3][n2][n1]: node = nodes.createNode(nodeIdentifier, nodetemplate) self.nodeId[n3][n2][n1] = nodeIdentifier @@ -482,7 +485,7 @@ def generateNodes(self, fieldmodule, coordinates, startNodeIdentifier, rangeOfRe return nodeIdentifier - def generateElements(self, fieldmodule, coordinates, startElementIdentifier, rangeOfRequiredElements, + def generateElements(self, fieldmodule, coordinates, startElementIdentifier, rangeOfRequiredElements=None, meshGroupsElementsAlong=[], meshGroups=[]): """ Create shield elements from nodes. @@ -490,11 +493,12 @@ def generateElements(self, fieldmodule, coordinates, startElementIdentifier, ran :param coordinates: Coordinate field to define. :param startElementIdentifier: First element identifier to use. :param rangeOfRequiredElements: Only the elements and nodes for the given range is generated. + Specify None to create all. :param meshGroups, meshGroupsElementsAlong: Zinc mesh groups to add elements to. meshGroupsElementsAlong is a list that specifies number of elements along the cylinder to be added to the same meshGroup. :return: next elementIdentifier. """ - assert len(meshGroupsElementsAlong) == len(meshGroups), 'meshGroups and meshGroupsElementsAlong should have' \ + assert len(meshGroupsElementsAlong) == len(meshGroups), 'meshGroups and meshGroupsElementsAlong should have ' \ 'the same length' elementIdentifier = startElementIdentifier useCrossDerivatives = False @@ -529,10 +533,11 @@ def generateElements(self, fieldmodule, coordinates, startElementIdentifier, ran for e3 in range(self.elementsCountAlong): for e2 in range(self.elementsCountUpFull): for e1 in range(self.elementsCountAcross): - if e3 >= rangeOfRequiredElements[2][1] or e3 < rangeOfRequiredElements[2][0] or\ - e2 >= rangeOfRequiredElements[0][1] or e2 < rangeOfRequiredElements[0][0]\ - or e1 >= rangeOfRequiredElements[1][1] or e1 < rangeOfRequiredElements[1][0]: - continue + if rangeOfRequiredElements: + if e3 >= rangeOfRequiredElements[2][1] or e3 < rangeOfRequiredElements[2][0] or\ + e2 >= rangeOfRequiredElements[0][1] or e2 < rangeOfRequiredElements[0][0]\ + or e1 >= rangeOfRequiredElements[1][1] or e1 < rangeOfRequiredElements[1][0]: + continue eft1 = eft scalefactors = None if self._type == ShieldRimDerivativeMode.SHIELD_RIM_DERIVATIVE_MODE_AROUND: diff --git a/src/scaffoldmaker/utils/zinc_utils.py b/src/scaffoldmaker/utils/zinc_utils.py index d7a55e9a..fdeecc5f 100644 --- a/src/scaffoldmaker/utils/zinc_utils.py +++ b/src/scaffoldmaker/utils/zinc_utils.py @@ -94,229 +94,14 @@ def createFaceMeshGroupExteriorOnFace(fieldmodule : Fieldmodule, elementFaceType isExterior = fieldmodule.createFieldIsExterior() isOnFace = fieldmodule.createFieldIsOnFace(elementFaceType) mesh2d = fieldmodule.findMeshByDimension(2) - faceElementGroup = fieldmodule.createFieldElementGroup(mesh2d) - faceMeshGroup = faceElementGroup.getMeshGroup() + faceGroup = fieldmodule.createFieldGroup() + faceMeshGroup = faceGroup.createMeshGroup(mesh2d) faceMeshGroup.addElementsConditional(fieldmodule.createFieldAnd(isExterior, isOnFace)) del isExterior del isOnFace return faceMeshGroup -def get_highest_dimension_mesh(fieldmodule : Fieldmodule): - ''' - Get highest dimension non-empty mesh. - :return: Zinc Mesh or None if all are empty. - ''' - for dimension in range(3, 0, -1): - mesh = fieldmodule.findMeshByDimension(dimension) - if mesh.getSize() > 0: - return mesh - return None - - -def get_next_unused_node_identifier(nodeset: Nodeset, start_identifier=1) -> int: - """ - :return: Unused node identifier >= start_identifier. - """ - identifier = start_identifier - node = nodeset.findNodeByIdentifier(identifier) - while node.isValid(): - identifier += 1 - node = nodeset.findNodeByIdentifier(identifier) - return identifier - - -def group_add_group_elements(group : FieldGroup, other_group : FieldGroup, only_dimension=None): - ''' - Add to group elements and/or nodes from other_group, which may be in a descendent region. - :param group: The FieldGroup to modify. - :param other_group: FieldGroup within region tree of group's region to add contents from. - :param only_dimension: If set, only add objects of this dimension. - ''' - region = group.getFieldmodule().getRegion() - with HierarchicalChangeManager(region): - other_fieldmodule = other_group.getFieldmodule() - for dimension in [ only_dimension ] if only_dimension else range(4): - if dimension > 0: - mesh = other_fieldmodule.findMeshByDimension(dimension) - element_group = group.getFieldElementGroup(mesh) - if not element_group.isValid(): - element_group = group.createFieldElementGroup(mesh) - mesh_group = element_group.getMeshGroup() - mesh_group.addElementsConditional(other_group.getFieldElementGroup(mesh)) - elif dimension == 0: - nodeset = other_fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - node_group = group.getFieldNodeGroup(nodeset) - if not node_group.isValid(): - node_group = group.createFieldNodeGroup(nodeset) - nodeset_group = node_group.getNodesetGroup() - nodeset_group.addNodesConditional(other_group.getFieldNodeGroup(nodeset)) - - -def group_get_highest_dimension(group : FieldGroup): - ''' - Get highest dimension of elements or nodes in group. - :return: Dimensions from 3-0, or -1 if empty. - ''' - fieldmodule = group.getFieldmodule() - for dimension in range(3, 0, -1): - mesh = fieldmodule.findMeshByDimension(dimension) - element_group = group.getFieldElementGroup(mesh) - if element_group.isValid() and (element_group.getMeshGroup().getSize() > 0): - return dimension - nodeset = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - node_group = group.getFieldNodeGroup(nodeset) - if node_group.isValid() and (node_group.getNodesetGroup().getSize() > 0): - return 0 - return -1 - - -def identifier_ranges_fix(identifier_ranges): - ''' - Sort from lowest to highest identifier and merge adjacent and overlapping - ranges. - :param identifier_ranges: List of identifier ranges. Modified in situ. - ''' - identifier_ranges.sort() - i = 1 - while i < len(identifier_ranges): - if identifier_ranges[i][0] <= (identifier_ranges[i - 1][1] + 1): - if identifier_ranges[i][1] > identifier_ranges[i - 1][1]: - identifier_ranges[i - 1][1] = identifier_ranges[i][1] - identifier_ranges.pop(i) - else: - i += 1 - - -def identifier_ranges_from_string(identifier_ranges_string): - ''' - Parse string containing identifiers and identifier ranges. - Function is suitable for processing manual input with whitespace, trailing non-digits. - Ranges are sorted so strictly increasing. Overlapping ranges are merged. - Future: migrate to use .. as separator for compatibility with EX file groups and cmgui. - :param identifier_ranges_string: Identifier ranges as a string e.g. '1-30,55,66-70'. - '30-1, 55,66-70s' also produces the same result. - :return: Ordered list of identifier ranges e.g. [[1,30],[55,55],[66,70]] - ''' - identifier_ranges = [] - for identifier_range_string in identifier_ranges_string.split(','): - try: - identifier_range_ends = identifier_range_string.split('-') - # after leading whitespace, stop at first non-digit - for e in range(len(identifier_range_ends)): - # strip whitespace, trailing non digits - digits = identifier_range_ends[e].strip() - for i in range(len(digits)): - if not digits[i].isdigit(): - digits = digits[:i] - break - identifier_range_ends[e] = digits - start = int(identifier_range_ends[0]) - if len(identifier_range_ends) == 1: - stop = start - else: - stop = int(identifier_range_ends[1]) - # ensure range is low-high - if stop < start: - start, stop = stop, start - identifier_ranges.append([start, stop]) - except: - pass - identifier_ranges_fix(identifier_ranges) - return identifier_ranges - - -def identifier_ranges_to_string(identifier_ranges): - ''' - Convert ranges to a string, contracting single object ranges. - Future: migrate to use .. as separator for compatibility with EX file groups and cmgui. - :param identifier_ranges: Ordered list of identifier ranges e.g. [[1,30],[55,55],[66,70]] - :return: Identifier ranges as a string e.g. '1-30,55,66-70' - ''' - identifier_ranges_string = '' - first = True - for identifier_range in identifier_ranges: - if identifier_range[0] == identifier_range[1]: - identifier_range_string = str(identifier_range[0]) - else: - identifier_range_string = str(identifier_range[0]) + '-' + str(identifier_range[1]) - if first: - identifier_ranges_string = identifier_range_string - first = False - else: - identifier_ranges_string += ',' + identifier_range_string - return identifier_ranges_string - - -def domain_iterator_to_identifier_ranges(iterator): - ''' - Extract sorted identifier ranges from iterator. - Currently requires iterator to be in lowest-highest identifier order. - Objects must support getIdentifier() method returning unique integer. - :param iterator: A Zinc Elementiterator or Nodeiterator. - :return: List of sorted identifier ranges [start,stop] e.g. [[1,30],[55,55],[66,70]] - ''' - identifier_ranges = [] - obj = iterator.next() - if obj.isValid(): - stop = start = obj.getIdentifier() - obj = iterator.next() - while obj.isValid(): - identifier = obj.getIdentifier() - if identifier == (stop + 1): - stop = identifier - else: - identifier_ranges.append([ start, stop ]) - stop = start = identifier - obj = iterator.next() - identifier_ranges.append([ start, stop ]) - return identifier_ranges - - -def mesh_group_add_identifier_ranges(mesh_group, identifier_ranges): - ''' - Add elements with the supplied identifier ranges to mesh_group. - :param mesh_group: Zinc MeshGroup to modify. - ''' - mesh = mesh_group.getMasterMesh() - fieldmodule = mesh.getFieldmodule() - with ChangeManager(fieldmodule): - for identifier_range in identifier_ranges: - for identifier in range(identifier_range[0], identifier_range[1] + 1): - element = mesh.findElementByIdentifier(identifier) - mesh_group.addElement(element) - - -def mesh_group_to_identifier_ranges(mesh_group): - ''' - :param mesh_group: Zinc MeshGroup. - :return: Ordered list of element identifier ranges e.g. [[1,30],[55,55],[66,70]] - ''' - return domain_iterator_to_identifier_ranges(mesh_group.createElementiterator()) - - -def nodeset_group_add_identifier_ranges(nodeset_group, identifier_ranges): - ''' - Add nodes with the supplied identifier ranges to nodeset_group. - :param nodeset_group: Zinc NodesetGroup to modify. - ''' - nodeset = nodeset_group.getMasterNodeset() - fieldmodule = nodeset.getFieldmodule() - with ChangeManager(fieldmodule): - for identifier_range in identifier_ranges: - for identifier in range(identifier_range[0], identifier_range[1] + 1): - node = nodeset.findNodeByIdentifier(identifier) - nodeset_group.addNode(node) - - -def nodeset_group_to_identifier_ranges(nodeset_group): - ''' - :param nodeset_group: Zinc NodesetGroup. - :return: Ordered list of node identifier ranges e.g. [[1,30],[55,55],[66,70]] - ''' - return domain_iterator_to_identifier_ranges(nodeset_group.createNodeiterator()) - - def mesh_destroy_elements_and_nodes_by_identifiers(mesh, element_identifiers): ''' Deletes elements and related nodes using element identifiers. @@ -328,22 +113,15 @@ def mesh_destroy_elements_and_nodes_by_identifiers(mesh, element_identifiers): # put the elements in a group and use subelement handling to get nodes in use by it destroyGroup = fm.createFieldGroup() destroyGroup.setSubelementHandlingMode(FieldGroup.SUBELEMENT_HANDLING_MODE_FULL) - destroyElementGroup = destroyGroup.createFieldElementGroup(mesh) - destroyMesh = destroyElementGroup.getMeshGroup() + destroyMesh = destroyGroup.createMeshGroup(mesh) for elementIdentifier in element_identifiers: element = mesh.findElementByIdentifier(elementIdentifier) destroyMesh.addElement(element) if destroyMesh.getSize() > 0: - destroyNodeGroup = destroyGroup.getFieldNodeGroup(nodes) - destroyNodes = destroyNodeGroup.getNodesetGroup() # must destroy elements first as Zinc won't destroy nodes that are in use - mesh.destroyElementsConditional(destroyElementGroup) - nodes.destroyNodesConditional(destroyNodeGroup) - # clean up group so no external code hears is notified of its existence - del destroyNodes - del destroyNodeGroup + mesh.destroyElementsConditional(destroyGroup) + nodes.destroyNodesConditional(destroyGroup) del destroyMesh - del destroyElementGroup del destroyGroup return @@ -438,10 +216,7 @@ def set_nodeset_field_parameters(nodeset, field, value_labels, node_field_parame if edit_group_name and changed_node_parameters: if not edit_nodeset_group: edit_group = find_or_create_field_group(fieldmodule, edit_group_name, managed=True) - edit_node_group = edit_group.getFieldNodeGroup(nodeset) - if not edit_node_group.isValid(): - edit_node_group = edit_node_group.createFieldNodeGroup(nodeset) - edit_nodeset_group = edit_node_group.getNodesetGroup() + edit_nodeset_group = edit_group.getOrCreateNodesetGroup(nodeset) edit_nodeset_group.addNode(node) @@ -603,10 +378,7 @@ def setPathParameters(region, nodeValueLabels, nodeValues, editGroupName=None): with ChangeManager(fieldmodule): if editGroupName: editGroup = find_or_create_field_group(fieldmodule, editGroupName, managed=True) - editNodeGroup = editGroup.getFieldNodeGroup(nodes) - if not editNodeGroup.isValid(): - editNodeGroup = editGroup.createFieldNodeGroup(nodes) - editNodesetGroup = editNodeGroup.getNodesetGroup() + editNodesetGroup = editGroup.getOrCreateNodesetGroup(nodes) cache = fieldmodule.createFieldcache() nodeiterator = nodes.createNodeiterator() node = nodeiterator.next() @@ -694,7 +466,7 @@ def exnode_string_from_nodeset_field_parameters( nodes = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) group = fieldmodule.createFieldGroup() group.setName(group_name) - nodeset_group = group.createFieldNodeGroup(nodes).getNodesetGroup() + nodeset_group = group.createNodesetGroup(nodes) # dict mapping from tuple of derivative versions to nodetemplate nodetemplates = {} # create nodes @@ -807,26 +579,3 @@ def disconnectFieldMeshGroupBoundaryNodes(coordinateFields, meshGroup1, meshGrou element = elemiter.next() return nextNodeIdentifier, list(copyIdentifiersMap.values()) - - -def region_get_selection_group(region): - """ - Get current selection group in this region, if any. - Note finds related group from selection field in ancestor regions. - :param region: Region to query. - :return: Selection FieldGroup or None if none. - """ - tmp_region = region - while tmp_region.isValid(): - scene = tmp_region.getScene() - selection_group = scene.getSelectionField().castGroup() - if selection_group.isValid(): - if tmp_region is region: - return selection_group - selection_group_name = selection_group.getName() - selection_group = region.getFieldmodule().findFieldByName(selection_group_name).castGroup() - if selection_group.isValid(): - return selection_group - break - tmp_region = tmp_region.getParent() - return None diff --git a/tests/test_bladder.py b/tests/test_bladder.py index 5af89700..3fa50269 100644 --- a/tests/test_bladder.py +++ b/tests/test_bladder.py @@ -109,7 +109,7 @@ def test_bladderurethra1(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(5, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -178,7 +178,7 @@ def test_bladderurethra1(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(5, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) diff --git a/tests/test_esophagus.py b/tests/test_esophagus.py index 8f92cdf7..0aacaccc 100644 --- a/tests/test_esophagus.py +++ b/tests/test_esophagus.py @@ -154,7 +154,7 @@ def test_esophagus1(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(4, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) diff --git a/tests/test_general.py b/tests/test_general.py index a93ef809..3d18d716 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -3,6 +3,9 @@ from cmlibs.maths.vectorops import dot, magnitude, normalize, sub from cmlibs.utils.zinc.finiteelement import evaluateFieldNodesetRange, findNodeWithName +from cmlibs.utils.zinc.group import identifier_ranges_from_string, identifier_ranges_to_string, \ + mesh_group_add_identifier_ranges, mesh_group_to_identifier_ranges, \ + nodeset_group_add_identifier_ranges, nodeset_group_to_identifier_ranges from cmlibs.zinc.context import Context from cmlibs.zinc.field import Field from cmlibs.zinc.node import Node @@ -16,9 +19,6 @@ from scaffoldmaker.scaffolds import Scaffolds from scaffoldmaker.utils.geometry import getEllipsoidPlaneA, getEllipsoidPolarCoordinatesFromPosition, \ getEllipsoidPolarCoordinatesTangents -from scaffoldmaker.utils.zinc_utils import identifier_ranges_from_string, identifier_ranges_to_string, \ - mesh_group_add_identifier_ranges, mesh_group_to_identifier_ranges, \ - nodeset_group_add_identifier_ranges, nodeset_group_to_identifier_ranges from testutils import assertAlmostEqualList @@ -126,7 +126,7 @@ def test_user_annotation_groups(self): group = annotationGroup1.getGroup() self.assertTrue(group.isValid()) mesh2d = fieldmodule.findMeshByDimension(2) - meshGroup = group.createFieldElementGroup(mesh2d).getMeshGroup() + meshGroup = group.createMeshGroup(mesh2d) mesh_group_add_identifier_ranges(meshGroup, [[1,2],[4,4]]) self.assertEqual(3, meshGroup.getSize()) self.assertEqual(2, annotationGroup1.getDimension()) @@ -139,7 +139,7 @@ def test_user_annotation_groups(self): self.assertTrue(scaffoldPackage.isUserAnnotationGroup(annotationGroup2)) group = annotationGroup2.getGroup() nodes = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - nodesetGroup = group.createFieldNodeGroup(nodes).getNodesetGroup() + nodesetGroup = group.createNodesetGroup(nodes) nodeset_group_add_identifier_ranges(nodesetGroup, identifier_ranges_from_string('1,3-5,7')) self.assertEqual(5, nodesetGroup.getSize()) self.assertEqual(0, annotationGroup2.getDimension()) diff --git a/tests/test_heart.py b/tests/test_heart.py index 1a8b8ed8..96230ada 100644 --- a/tests/test_heart.py +++ b/tests/test_heart.py @@ -76,7 +76,7 @@ def test_heart1(self): one = fieldmodule.createFieldConstant(1.0) epicardiumGroup = fieldmodule.findFieldByName('epicardium').castGroup() self.assertTrue(epicardiumGroup.isValid()) - epicardiumMeshGroup = epicardiumGroup.getFieldElementGroup(mesh2d).getMeshGroup() + epicardiumMeshGroup = epicardiumGroup.getMeshGroup(mesh2d) self.assertTrue(epicardiumMeshGroup.isValid()) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, epicardiumMeshGroup) surfaceAreaField.setNumbersOfPoints(4) @@ -117,7 +117,7 @@ def test_heart1(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(4, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -188,7 +188,7 @@ def test_heart1(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(4, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) diff --git a/tests/test_lung.py b/tests/test_lung.py index a77a1dfd..b9cd181f 100644 --- a/tests/test_lung.py +++ b/tests/test_lung.py @@ -12,7 +12,6 @@ from scaffoldmaker.meshtypes.meshtype_3d_lung1 import MeshType_3d_lung1 from scaffoldmaker.meshtypes.meshtype_3d_lung2 import MeshType_3d_lung2 from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils.zinc_utils import mesh_group_to_identifier_ranges from testutils import assertAlmostEqualList @@ -57,7 +56,7 @@ def test_lung1(self): one = fieldmodule.createFieldConstant(1.0) upperRightFissureGroup = fieldmodule.findFieldByName('upper lobe of right lung').castGroup() self.assertTrue(upperRightFissureGroup.isValid()) - upperRightFissureMeshGroup = upperRightFissureGroup.getFieldElementGroup(mesh2d).getMeshGroup() + upperRightFissureMeshGroup = upperRightFissureGroup.getMeshGroup(mesh2d) self.assertTrue(upperRightFissureMeshGroup.isValid()) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, upperRightFissureMeshGroup) surfaceAreaField.setNumbersOfPoints(4) @@ -99,7 +98,7 @@ def test_lung1(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(9, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -167,7 +166,7 @@ def test_lung1(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(9, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -235,7 +234,7 @@ def test_lung2_human(self): one = fieldmodule.createFieldConstant(1.0) upperRightFissureGroup = fieldmodule.findFieldByName('upper lobe of right lung').castGroup() self.assertTrue(upperRightFissureGroup.isValid()) - upperRightFissureMeshGroup = upperRightFissureGroup.getFieldElementGroup(mesh2d).getMeshGroup() + upperRightFissureMeshGroup = upperRightFissureGroup.getMeshGroup(mesh2d) self.assertTrue(upperRightFissureMeshGroup.isValid()) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, upperRightFissureMeshGroup) surfaceAreaField.setNumbersOfPoints(4) @@ -324,7 +323,7 @@ def test_lung2_human(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(7, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -387,7 +386,7 @@ def test_lung2_human(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(7, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -453,7 +452,7 @@ def test_lung2_mouse(self): one = fieldmodule.createFieldConstant(1.0) upperRightFissureGroup = fieldmodule.findFieldByName('upper lobe of right lung').castGroup() self.assertTrue(upperRightFissureGroup.isValid()) - upperRightFissureMeshGroup = upperRightFissureGroup.getFieldElementGroup(mesh2d).getMeshGroup() + upperRightFissureMeshGroup = upperRightFissureGroup.getMeshGroup(mesh2d) self.assertTrue(upperRightFissureMeshGroup.isValid()) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, upperRightFissureMeshGroup) surfaceAreaField.setNumbersOfPoints(4) @@ -520,7 +519,7 @@ def test_lung2_mouse(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(13, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -588,7 +587,7 @@ def test_lung2_mouse(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(13, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -642,7 +641,7 @@ def test_lung2_human_openFissures(self): one = fieldmodule.createFieldConstant(1.0) upperRightFissureGroup = fieldmodule.findFieldByName('upper lobe of right lung').castGroup() self.assertTrue(upperRightFissureGroup.isValid()) - upperRightFissureMeshGroup = upperRightFissureGroup.getFieldElementGroup(mesh2d).getMeshGroup() + upperRightFissureMeshGroup = upperRightFissureGroup.getMeshGroup(mesh2d) self.assertTrue(upperRightFissureMeshGroup.isValid()) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, upperRightFissureMeshGroup) surfaceAreaField.setNumbersOfPoints(4) @@ -722,7 +721,7 @@ def test_lung2_human_openFissures(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(7, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) @@ -775,7 +774,7 @@ def test_lung2_mouse_openFissures(self): one = fieldmodule.createFieldConstant(1.0) upperRightFissureGroup = fieldmodule.findFieldByName('upper lobe of right lung').castGroup() self.assertTrue(upperRightFissureGroup.isValid()) - upperRightFissureMeshGroup = upperRightFissureGroup.getFieldElementGroup(mesh2d).getMeshGroup() + upperRightFissureMeshGroup = upperRightFissureGroup.getMeshGroup(mesh2d) self.assertTrue(upperRightFissureMeshGroup.isValid()) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, upperRightFissureMeshGroup) surfaceAreaField.setNumbersOfPoints(4) @@ -842,7 +841,7 @@ def test_lung2_mouse_openFissures(self): # test finding a marker in scaffold markerGroup = fieldmodule.findFieldByName("marker").castGroup() - markerNodes = markerGroup.getFieldNodeGroup(nodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(nodes) self.assertEqual(13, markerNodes.getSize()) markerName = fieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid()) diff --git a/tests/test_stomach.py b/tests/test_stomach.py index 7cd0655a..9bb9584f 100644 --- a/tests/test_stomach.py +++ b/tests/test_stomach.py @@ -171,7 +171,7 @@ def test_stomach1(self): # test finding a marker in refined scaffold markerGroup = refineFieldmodule.findFieldByName("marker").castGroup() refinedNodes = refineFieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) - markerNodes = markerGroup.getFieldNodeGroup(refinedNodes).getNodesetGroup() + markerNodes = markerGroup.getNodesetGroup(refinedNodes) self.assertEqual(20, markerNodes.getSize()) markerName = refineFieldmodule.findFieldByName("marker_name") self.assertTrue(markerName.isValid())