diff --git a/README.rst b/README.rst index 8f5f4848..7e88aa79 100644 --- a/README.rst +++ b/README.rst @@ -6,3 +6,8 @@ Anatomical scaffold generator using OpenCMISS-Zinc. For the interim, install with the following command:: pip install -e . + +Requires the following Python libraries to be installed: + +- opencmiss.zinc (manual install from opencmiss.org) +- github.com/OpenCMISS-Bindings/opencmiss.utils diff --git a/setup.py b/setup.py index 487d8a85..102e2b93 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,8 @@ def readfile(filename, split=False): # into the 'requirements.txt' file. requires = [ # minimal requirements listing - "opencmiss.utils @ https://api.github.com/repos/OpenCMISS-Bindings/opencmiss.utils/tarball/master", + "opencmiss.utils >= 0.2", + "opencmiss.zinc", # not yet on pypi - need manual install from opencmiss.org "ZincPythonTools @ https://api.github.com/repos/OpenCMISS-Bindings/ZincPythonTools/tarball/master", "scipy", "numpy", @@ -28,7 +29,7 @@ def readfile(filename, split=False): setup( name="scaffoldmaker", - version="0.1.2", + version="0.1.3", description="Python client for generating anatomical scaffolds using OpenCMISS-Zinc", long_description="\n".join(readme) + source_license, classifiers=[ diff --git a/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py b/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py index ca8219bf..2b0736e2 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py @@ -4,11 +4,11 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base class MeshType_1d_path1(Scaffold_base): ''' @@ -56,7 +56,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm, componentsCount=coordinateDimensions) + coordinates = findOrCreateFieldCoordinates(fm, components_count=coordinateDimensions) cache = fm.createFieldcache() ################# diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py index 35f53c6a..75f29abe 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py @@ -4,11 +4,11 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base class MeshType_2d_plate1(Scaffold_base): ''' @@ -61,7 +61,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm, componentsCount=coordinateDimensions) + coordinates = findOrCreateFieldCoordinates(fm, components_count=coordinateDimensions) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py index 95c472d7..8a5b722c 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py @@ -7,12 +7,12 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative class MeshType_2d_platehole1(Scaffold_base): ''' @@ -78,7 +78,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm, componentsCount=coordinateDimensions) + coordinates = findOrCreateFieldCoordinates(fm, components_count=coordinateDimensions) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py index f5f3f51a..e7421edf 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py @@ -4,11 +4,11 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base class MeshType_2d_sphere1(Scaffold_base): ''' @@ -54,7 +54,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplateApex = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py index 3409db65..a4fa9df6 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py @@ -4,11 +4,11 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base class MeshType_2d_tube1(Scaffold_base): ''' @@ -54,7 +54,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py index 891317ca..ecea1e83 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py @@ -4,13 +4,13 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.meshrefinement import MeshRefinement class MeshType_3d_box1(Scaffold_base): ''' @@ -73,7 +73,7 @@ def generateBaseMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py index cb172be5..2e44ea6e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py @@ -7,13 +7,13 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative class MeshType_3d_boxhole1(Scaffold_base): ''' @@ -77,7 +77,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py index 67b13e47..5c5b72ef 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py @@ -13,7 +13,7 @@ from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import tubemesh from scaffoldmaker.utils import vector -from scaffoldmaker.utils import zinc_utils +from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues from opencmiss.zinc.node import Node class MeshType_3d_colon1(Scaffold_base): @@ -32,7 +32,7 @@ class MeshType_3d_colon1(Scaffold_base): 'Length' : 1.0, 'Number of elements' : 8 }, - 'meshEdits' : zinc_utils.exnodeStringFromNodeValues( + 'meshEdits' : exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ 0.0, 0.0, 0.0 ], [ -50.7, 178.2, 0.0 ], [ -24.0, -6.0, -12.0 ], [ -14.0, -1.0, -12.0 ] ], [ [ -47.4, 188.6, 0.0 ], [ -19.3, 177.1, 0.0 ], [ -22.0, -4.0, -8.0 ], [ -4.0, 19.0, 22.0 ] ], @@ -50,7 +50,7 @@ class MeshType_3d_colon1(Scaffold_base): 'Length' : 1.0, 'Number of elements' : 8 }, - 'meshEdits' : zinc_utils.exnodeStringFromNodeValues( + 'meshEdits' : exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ 0.0, 0.0, 0.0 ], [ -34.7, 104.1, -18.1 ], [ -24.0, -6.0, -12.0 ], [ -14.0, -1.0, -12.0 ] ], [ [ -34.5, 114.0, -18.1 ], [ 1.2, 86.6, -3.4 ], [ -22.0, -4.0, -8.0 ], [ -4.0, 19.0, 22.0 ] ], @@ -68,7 +68,7 @@ class MeshType_3d_colon1(Scaffold_base): 'Length' : 1.0, 'Number of elements' : 7 }, - 'meshEdits' : zinc_utils.exnodeStringFromNodeValues( + 'meshEdits' : exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ 0.0, 0.0, 0.0 ], [ 6.0, 12.0, -2.0 ], [ 2.0, 1.0, 2.0 ], [ 6.0, 0.0, 3.0 ] ], [ [ -2.0, 11.0, -3.0 ], [ -8.0, 4.0, 9.0 ], [ 2.0, 2.0, 1.0 ], [ 0.0, 1.0, 2.0 ] ], @@ -85,7 +85,7 @@ class MeshType_3d_colon1(Scaffold_base): 'Length' : 1.0, 'Number of elements' : 4 }, - 'meshEdits' : zinc_utils.exnodeStringFromNodeValues( + 'meshEdits' : exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 13.0 ], [ 0.0, -10.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ 0.0, 0.0, 13.0 ], [ 0.0, 2.0, 28.0 ], [ 0.0, -10.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], @@ -99,7 +99,7 @@ class MeshType_3d_colon1(Scaffold_base): 'Length' : 1.0, 'Number of elements' : 36 }, - 'meshEdits' : zinc_utils.exnodeStringFromNodeValues( + 'meshEdits' : exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ 163.7, -25.2, 12.2 ], [ -21.7, 50.1, -18.1 ], [ 0.0, 0.0, 5.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ 117.2, 32.8, -2.6 ], [ -64.3, 34.4, -3.9 ], [ 0.0, 0.0, 5.0 ], [ 0.0, 0.0, 0.5 ] ], diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py index 04a1ccfb..a6d65268 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py @@ -6,6 +6,10 @@ """ import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldTextureCoordinates +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear @@ -16,10 +20,6 @@ from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import tubemesh from scaffoldmaker.utils import vector -from scaffoldmaker.utils import zinc_utils -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_colonsegment1(Scaffold_base): ''' @@ -1466,7 +1466,7 @@ def createNodesAndElementsTeniaColi(region, fm = region.getFieldmodule() fm.beginChange() cache = fm.createFieldcache() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() @@ -1507,7 +1507,7 @@ def createNodesAndElementsTeniaColi(region, elementtemplate2.defineField(coordinates, -1, eft2) # Create flat coordinates field - flatCoordinates = zinc_utils.getOrCreateFlatCoordinateField(fm) + flatCoordinates = findOrCreateFieldCoordinates(fm, name="flat coordinates") flatNodetemplate1 = nodes.createNodetemplate() flatNodetemplate1.defineField(flatCoordinates) flatNodetemplate1.setValueNumberOfVersions(flatCoordinates, -1, Node.VALUE_LABEL_VALUE, 1) @@ -1552,7 +1552,7 @@ def createNodesAndElementsTeniaColi(region, flatElementtemplate5.defineField(flatCoordinates, -1, eftTexture7) # Create texture coordinates field - textureCoordinates = zinc_utils.getOrCreateTextureCoordinateField(fm) + textureCoordinates = findOrCreateFieldTextureCoordinates(fm) textureNodetemplate1 = nodes.createNodetemplate() textureNodetemplate1.defineField(textureCoordinates) textureNodetemplate1.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_VALUE, 1) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py index 8bf416ff..5eaadd6b 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py @@ -4,17 +4,19 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ + findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier +from opencmiss.zinc.element import Element +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.meshtypes.meshtype_3d_heartatria1 import MeshType_3d_heartatria1 from scaffoldmaker.meshtypes.meshtype_3d_heartventriclesbase1 import MeshType_3d_heartventriclesbase1 from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear -from scaffoldmaker.utils import zinc_utils from scaffoldmaker.utils.meshrefinement import MeshRefinement -from opencmiss.zinc.element import Element -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heart1(Scaffold_base): ''' @@ -120,9 +122,11 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() + mesh = fm.findMeshByDimension(3) + # generate heartventriclesbase1 model and put atria1 on it annotationGroups = MeshType_3d_heartventriclesbase1.generateBaseMesh(region, options) annotationGroups += MeshType_3d_heartatria1.generateBaseMesh(region, options) @@ -131,13 +135,13 @@ def generateBaseMesh(cls, region, options): annotationGroups += [ lFibrousRingGroup, rFibrousRingGroup ] # annotation fiducial points - fiducialGroup = zinc_utils.getOrCreateGroupField(fm, 'fiducial') - fiducialCoordinates = zinc_utils.getOrCreateCoordinateField(fm, 'fiducial_coordinates') - fiducialLabel = zinc_utils.getOrCreateLabelField(fm, 'fiducial_label') - fiducialElementXi = zinc_utils.getOrCreateElementXiField(fm, 'fiducial_element_xi') + fiducialGroup = findOrCreateFieldGroup(fm, 'fiducial') + fiducialCoordinates = findOrCreateFieldCoordinates(fm, 'fiducial_coordinates') + fiducialLabel = findOrCreateFieldStoredString(fm, name='fiducial_label') + fiducialElementXi = findOrCreateFieldStoredMeshLocation(fm, mesh, name='fiducial_element_xi') datapoints = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_DATAPOINTS) - fiducialPoints = zinc_utils.getOrCreateNodesetGroup(fiducialGroup, datapoints) + fiducialPoints = findOrCreateFieldNodeGroup(fiducialGroup, datapoints).getNodesetGroup() datapointTemplateInternal = datapoints.createNodetemplate() datapointTemplateInternal.defineField(fiducialCoordinates) datapointTemplateInternal.defineField(fiducialLabel) @@ -207,12 +211,10 @@ def generateBaseMesh(cls, region, options): # Create elements ################# - mesh = fm.findMeshByDimension(3) - lFibrousRingMeshGroup = lFibrousRingGroup.getMeshGroup(mesh) rFibrousRingMeshGroup = rFibrousRingGroup.getMeshGroup(mesh) - elementIdentifier = startElementIdentifier = zinc_utils.getMaximumElementIdentifier(mesh) + 1 + elementIdentifier = getMaximumElementIdentifier(mesh) + 1 elementtemplate1 = mesh.createElementtemplate() elementtemplate1.setElementShapeType(Element.SHAPE_TYPE_CUBE) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py index ac4e9552..3220183d 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py @@ -4,11 +4,11 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.meshtype_3d_heartatria2 import MeshType_3d_heartatria2 from scaffoldmaker.meshtypes.meshtype_3d_heartventriclesbase2 import MeshType_3d_heartventriclesbase2 from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils import zinc_utils from scaffoldmaker.utils.meshrefinement import MeshRefinement class MeshType_3d_heart2(Scaffold_base): @@ -78,7 +78,7 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() # generate heartventriclesbase2 model and put atria2 on it diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py index b64c9160..cf1ca226 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py @@ -5,19 +5,21 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ + findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, setEftScaleFactorIds from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, createCirclePoints from scaffoldmaker.utils import interpolation as interp -from scaffoldmaker.utils import zinc_utils from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils import vector -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heartarterialroot1(Scaffold_base): ''' @@ -113,9 +115,11 @@ def generateBaseMesh(cls, region, options, baseCentre=[ 0.0, 0.0, 0.0 ], axisSid fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() + mesh = fm.findMeshByDimension(3) + if aorticNotPulmonary: arterialRootGroup = AnnotationGroup(region, 'root of aorta', FMANumber = 3740, lyphID = 'Lyph ID unknown') cuspGroups = [ @@ -133,13 +137,13 @@ def generateBaseMesh(cls, region, options, baseCentre=[ 0.0, 0.0, 0.0 ], axisSid annotationGroups = allGroups + cuspGroups # annotation fiducial points - fiducialGroup = zinc_utils.getOrCreateGroupField(fm, 'fiducial') - fiducialCoordinates = zinc_utils.getOrCreateCoordinateField(fm, 'fiducial_coordinates') - fiducialLabel = zinc_utils.getOrCreateLabelField(fm, 'fiducial_label') - #fiducialElementXi = zinc_utils.getOrCreateElementXiField(fm, 'fiducial_element_xi') + fiducialGroup = findOrCreateFieldGroup(fm, 'fiducial') + fiducialCoordinates = findOrCreateFieldCoordinates(fm, 'fiducial_coordinates') + fiducialLabel = findOrCreateFieldStoredString(fm, name='fiducial_label') + #fiducialElementXi = findOrCreateFieldStoredMeshLocation(fm, mesh, name='fiducial_element_xi') datapoints = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_DATAPOINTS) - fiducialPoints = zinc_utils.getOrCreateNodesetGroup(fiducialGroup, datapoints) + fiducialPoints = findOrCreateFieldNodeGroup(fiducialGroup, datapoints).getNodesetGroup() datapointTemplateExternal = datapoints.createNodetemplate() datapointTemplateExternal.defineField(fiducialCoordinates) datapointTemplateExternal.defineField(fiducialLabel) @@ -168,7 +172,7 @@ def generateBaseMesh(cls, region, options, baseCentre=[ 0.0, 0.0, 0.0 ], axisSid nodetemplateLinearS2S3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_VALUE, 1) nodetemplateLinearS2S3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1) - nodeIdentifier = max(1, zinc_utils.getMaximumNodeIdentifier(nodes) + 1) + nodeIdentifier = max(1, getMaximumNodeIdentifier(nodes) + 1) elementsCountAround = 6 radiansPerElementAround = 2.0*math.pi/elementsCountAround @@ -386,8 +390,6 @@ def generateBaseMesh(cls, region, options, baseCentre=[ 0.0, 0.0, 0.0 ], axisSid # Create elements ################# - mesh = fm.findMeshByDimension(3) - allMeshGroups = [ allGroup.getMeshGroup(mesh) for allGroup in allGroups ] cuspMeshGroups = [ cuspGroup.getMeshGroup(mesh) for cuspGroup in cuspGroups ] @@ -400,7 +402,7 @@ def generateBaseMesh(cls, region, options, baseCentre=[ 0.0, 0.0, 0.0 ], axisSid bicubichermitelinear = eftfactory_bicubichermitelinear(mesh, useCrossDerivatives) eftDefault = bicubichermitelinear.createEftNoCrossDerivatives() - elementIdentifier = max(1, zinc_utils.getMaximumElementIdentifier(mesh) + 1) + elementIdentifier = max(1, getMaximumElementIdentifier(mesh) + 1) elementtemplate1 = mesh.createElementtemplate() elementtemplate1.setElementShapeType(Element.SHAPE_TYPE_CUBE) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py index 27b67c84..52c4248e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py @@ -6,6 +6,11 @@ from __future__ import division import copy import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.meshtypes.meshtype_3d_ostium1 import MeshType_3d_ostium1, generateOstiumMesh @@ -15,13 +20,9 @@ from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getCircleProjectionAxes, getEllipseAngleFromVector, getEllipseArcLength, getEllipseRadiansToX, updateEllipseAngleByArcLength, createCirclePoints from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils from scaffoldmaker.utils import vector from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heartatria1(Scaffold_base): ''' @@ -732,7 +733,7 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() laGroup = AnnotationGroup(region, 'left atrium', FMANumber = 7097, lyphID = 'Lyph ID unknown') @@ -814,11 +815,11 @@ def generateBaseMesh(cls, region, options): nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1) nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS2, 1) - nodeIdentifier = max(1, zinc_utils.getMaximumNodeIdentifier(nodes) + 1) + nodeIdentifier = max(1, getMaximumNodeIdentifier(nodes) + 1) mesh = fm.findMeshByDimension(3) - elementIdentifier = max(1, zinc_utils.getMaximumElementIdentifier(mesh) + 1) + elementIdentifier = max(1, getMaximumElementIdentifier(mesh) + 1) laMeshGroup = laGroup.getMeshGroup(mesh) raMeshGroup = raGroup.getMeshGroup(mesh) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py index 28a55040..daf3d0ec 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py @@ -5,18 +5,20 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, getEllipseRadiansToX, updateEllipseAngleByArcLength from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils +from scaffoldmaker.utils.zinc_utils import computeNodeDerivativeHermiteLagrange, interpolateNodesCubicHermite from scaffoldmaker.utils import vector from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heartatria2(Scaffold_base): ''' @@ -185,7 +187,7 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() laGroup = AnnotationGroup(region, 'left atrium', FMANumber = 7097, lyphID = 'Lyph ID unknown') @@ -218,7 +220,7 @@ def generateBaseMesh(cls, region, options): nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1) nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS2, 1) - nodeIdentifier = max(1, zinc_utils.getMaximumNodeIdentifier(nodes) + 1) + nodeIdentifier = max(1, getMaximumNodeIdentifier(nodes) + 1) aBaseSlopeLength = aBaseWallThickness*math.cos(aBaseSlopeRadians) aBaseSlopeHeight = aBaseWallThickness*math.sin(aBaseSlopeRadians) @@ -589,7 +591,7 @@ def generateBaseMesh(cls, region, options): node1 = nodes.findNodeByIdentifier(nid1) node2 = nodes.findNodeByIdentifier(nid2) - x, dx_ds2, dx_ds1, dx_ds3 = zinc_utils.interpolateNodesCubicHermite(cache, coordinates, 0.5, aFreeWallThickness, \ + x, dx_ds2, dx_ds1, dx_ds3 = interpolateNodesCubicHermite(cache, coordinates, 0.5, aFreeWallThickness, \ node1, Node.VALUE_LABEL_D_DS2, 2.0, Node.VALUE_LABEL_D_DS1, 1.0, \ node2, Node.VALUE_LABEL_D_DS2, -2.0, Node.VALUE_LABEL_D_DS1, -1.0) node3 = nodes.findNodeByIdentifier(nid3) @@ -620,7 +622,7 @@ def generateBaseMesh(cls, region, options): continue node1 = nodes.findNodeByIdentifier(aNodeId[0][n1]) node2 = nodes.findNodeByIdentifier(aNodeId[1][n1]) - dx_ds2 = zinc_utils.computeNodeDerivativeHermiteLagrange(cache, coordinates, node2, Node.VALUE_LABEL_D_DS2, -1.0, node1, -1.0) + dx_ds2 = computeNodeDerivativeHermiteLagrange(cache, coordinates, node2, Node.VALUE_LABEL_D_DS2, -1.0, node1, -1.0) cache.setNode(node1) result = coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, dx_ds2) @@ -893,7 +895,7 @@ def generateBaseMesh(cls, region, options): mesh = fm.findMeshByDimension(3) - elementIdentifier = max(1, zinc_utils.getMaximumElementIdentifier(mesh) + 1) + elementIdentifier = max(1, getMaximumElementIdentifier(mesh) + 1) laMeshGroup = laGroup.getMeshGroup(mesh) raMeshGroup = raGroup.getMeshGroup(mesh) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py index 8c56bb28..41d08361 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py @@ -5,6 +5,11 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ + findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils import vector @@ -13,10 +18,6 @@ from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heartventricles1(Scaffold_base): @@ -243,22 +244,24 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() + mesh = fm.findMeshByDimension(3) + lvGroup = AnnotationGroup(region, 'left ventricle', FMANumber = 7101, lyphID = 'Lyph ID unknown') rvGroup = AnnotationGroup(region, 'right ventricle', FMANumber = 7098, lyphID = 'Lyph ID unknown') vSeptumGroup = AnnotationGroup(region, 'interventricular septum', FMANumber = 7133, lyphID = 'Lyph ID unknown') annotationGroups = [ lvGroup, rvGroup, vSeptumGroup ] # annotation fiducial points - fiducialGroup = zinc_utils.getOrCreateGroupField(fm, 'fiducial') - fiducialCoordinates = zinc_utils.getOrCreateCoordinateField(fm, 'fiducial_coordinates') - fiducialLabel = zinc_utils.getOrCreateLabelField(fm, 'fiducial_label') - fiducialElementXi = zinc_utils.getOrCreateElementXiField(fm, 'fiducial_element_xi') + fiducialGroup = findOrCreateFieldGroup(fm, 'fiducial') + fiducialCoordinates = findOrCreateFieldCoordinates(fm, 'fiducial_coordinates') + fiducialLabel = findOrCreateFieldStoredString(fm, name='fiducial_label') + fiducialElementXi = findOrCreateFieldStoredMeshLocation(fm, mesh, name='fiducial_element_xi') datapoints = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_DATAPOINTS) - fiducialPoints = zinc_utils.getOrCreateNodesetGroup(fiducialGroup, datapoints) + fiducialPoints = findOrCreateFieldNodeGroup(fiducialGroup, datapoints).getNodesetGroup() datapointTemplateInternal = datapoints.createNodetemplate() datapointTemplateInternal.defineField(fiducialCoordinates) datapointTemplateInternal.defineField(fiducialLabel) @@ -706,8 +709,6 @@ def generateBaseMesh(cls, region, options): # Create elements ################# - mesh = fm.findMeshByDimension(3) - lvMeshGroup = lvGroup.getMeshGroup(mesh) rvMeshGroup = rvGroup.getMeshGroup(mesh) vSeptumMeshGroup = vSeptumGroup.getMeshGroup(mesh) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py index 3b78164c..160a91d1 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py @@ -4,6 +4,10 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils import vector @@ -12,10 +16,6 @@ from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heartventricles2(Scaffold_base): @@ -150,7 +150,7 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() lvGroup = AnnotationGroup(region, 'left ventricle', FMANumber = 7101, lyphID = 'Lyph ID unknown') diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py index 34cc93d8..ff631d1f 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py @@ -7,21 +7,23 @@ from __future__ import division import copy import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ + findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node +from opencmiss.zinc.result import RESULT_OK as ZINC_OK from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.meshtype_3d_heartatria1 import MeshType_3d_heartatria1, getAtriumBasePoints from scaffoldmaker.meshtypes.meshtype_3d_heartventricles1 import MeshType_3d_heartventricles1 from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.geometry import createCirclePoints from scaffoldmaker.utils import interpolation as interp -from scaffoldmaker.utils import zinc_utils -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils import vector -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node -from opencmiss.zinc.result import RESULT_OK as ZINC_OK class MeshType_3d_heartventriclesbase1(Scaffold_base): ''' @@ -289,9 +291,11 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() + mesh = fm.findMeshByDimension(3) + # generate heartventricles1 model to add base plane to annotationGroups = MeshType_3d_heartventricles1.generateBaseMesh(region, options) @@ -306,13 +310,13 @@ def generateBaseMesh(cls, region, options): rFibrousRingGroup = AnnotationGroup(region, 'right fibrous ring', FMANumber = 77125, lyphID = 'Lyph ID unknown') # annotation fiducial points - fiducialGroup = zinc_utils.getOrCreateGroupField(fm, 'fiducial') - fiducialCoordinates = zinc_utils.getOrCreateCoordinateField(fm, 'fiducial_coordinates') - fiducialLabel = zinc_utils.getOrCreateLabelField(fm, 'fiducial_label') - fiducialElementXi = zinc_utils.getOrCreateElementXiField(fm, 'fiducial_element_xi') + fiducialGroup = findOrCreateFieldGroup(fm, 'fiducial') + fiducialCoordinates = findOrCreateFieldCoordinates(fm, 'fiducial_coordinates') + fiducialLabel = findOrCreateFieldStoredString(fm, name='fiducial_label') + fiducialElementXi = findOrCreateFieldStoredMeshLocation(fm, mesh, name='fiducial_element_xi') datapoints = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_DATAPOINTS) - fiducialPoints = zinc_utils.getOrCreateNodesetGroup(fiducialGroup, datapoints) + fiducialPoints = findOrCreateFieldNodeGroup(fiducialGroup, datapoints).getNodesetGroup() datapointTemplateExternal = datapoints.createNodetemplate() datapointTemplateExternal.defineField(fiducialCoordinates) datapointTemplateExternal.defineField(fiducialLabel) @@ -336,7 +340,7 @@ def generateBaseMesh(cls, region, options): nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1) nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS2, 1) - nodeIdentifier = startNodeIdentifier = zinc_utils.getMaximumNodeIdentifier(nodes) + 1 + nodeIdentifier = startNodeIdentifier = getMaximumNodeIdentifier(nodes) + 1 # move ventricles to fit atria centred around aorta cosVRotationRadians = math.cos(-vRotationRadians) @@ -763,8 +767,6 @@ def generateBaseMesh(cls, region, options): # Create elements ################# - mesh = fm.findMeshByDimension(3) - lvMeshGroup = lvGroup.getMeshGroup(mesh) rvMeshGroup = rvGroup.getMeshGroup(mesh) vSeptumMeshGroup = vSeptumGroup.getMeshGroup(mesh) @@ -773,7 +775,7 @@ def generateBaseMesh(cls, region, options): tricubichermite = eftfactory_tricubichermite(mesh, useCrossDerivatives) eft = tricubichermite.createEftNoCrossDerivatives() - elementIdentifier = startElementIdentifier = zinc_utils.getMaximumElementIdentifier(mesh) + 1 + elementIdentifier = getMaximumElementIdentifier(mesh) + 1 elementtemplate1 = mesh.createElementtemplate() elementtemplate1.setElementShapeType(Element.SHAPE_TYPE_CUBE) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py index 8e28183b..ee66c78e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py @@ -6,20 +6,22 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.meshtype_3d_heartventricles2 import MeshType_3d_heartventricles2 from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, getEllipseRadiansToX, updateEllipseAngleByArcLength from scaffoldmaker.utils import interpolation as interp -from scaffoldmaker.utils import zinc_utils +from scaffoldmaker.utils.zinc_utils import interpolateNodesCubicHermite from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils import vector -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_heartventriclesbase2(Scaffold_base): ''' @@ -189,7 +191,7 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() ################# @@ -210,7 +212,7 @@ def generateBaseMesh(cls, region, options): nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1) nodetemplateLinearS3.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS2, 1) - nodeIdentifier = startNodeIdentifier = zinc_utils.getMaximumNodeIdentifier(nodes) + 1 + nodeIdentifier = getMaximumNodeIdentifier(nodes) + 1 # node offsets for row, wall in LV, plus first LV node on inside top norl = elementsCountAroundLV @@ -717,7 +719,7 @@ def generateBaseMesh(cls, region, options): #print('lv crest interpolated from nodes', nida, nidb) node1 = nodes.findNodeByIdentifier(nida) node2 = nodes.findNodeByIdentifier(nidb) - x, dx_ds2, dx_ds1, dx_ds3 = zinc_utils.interpolateNodesCubicHermite(cache, coordinates, 0.5, baseThickness, \ + x, dx_ds2, dx_ds1, dx_ds3 = interpolateNodesCubicHermite(cache, coordinates, 0.5, baseThickness, \ node1, Node.VALUE_LABEL_D_DS2, 1.0, Node.VALUE_LABEL_D_DS1, 1.0, \ node2, Node.VALUE_LABEL_D_DS3, -1.0, Node.VALUE_LABEL_D_DS1, 1.0) @@ -784,7 +786,7 @@ def generateBaseMesh(cls, region, options): #print('lv bridge interpolated from nodes', nida, nidb) node1 = nodes.findNodeByIdentifier(nida) node2 = nodes.findNodeByIdentifier(nidb) - x, dx_ds2, dx_ds1, dx_ds3 = zinc_utils.interpolateNodesCubicHermite(cache, coordinates, 0.4, lvOutletWallThickness, \ + x, dx_ds2, dx_ds1, dx_ds3 = interpolateNodesCubicHermite(cache, coordinates, 0.4, lvOutletWallThickness, \ node1, Node.VALUE_LABEL_D_DS2, -1.0, Node.VALUE_LABEL_D_DS1, -1.0, \ node2, Node.VALUE_LABEL_D_DS2, 1.0, Node.VALUE_LABEL_D_DS1, 1.0) # dx_ds1 needs to be larger @@ -860,7 +862,7 @@ def generateBaseMesh(cls, region, options): tricubichermite = eftfactory_tricubichermite(mesh, useCrossDerivatives) eft = tricubichermite.createEftNoCrossDerivatives() - elementIdentifier = startElementIdentifier = zinc_utils.getMaximumElementIdentifier(mesh) + 1 + elementIdentifier = getMaximumElementIdentifier(mesh) + 1 elementtemplate1 = mesh.createElementtemplate() elementtemplate1.setElementShapeType(Element.SHAPE_TYPE_CUBE) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py index fbe4caca..0a1e9489 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py @@ -5,13 +5,13 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.meshtype_3d_solidsphere1 import MeshType_3d_solidsphere1 -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.meshtype_3d_solidsphere1 import MeshType_3d_solidsphere1 +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.meshrefinement import MeshRefinement class MeshType_3d_lens1(Scaffold_base): ''' @@ -93,7 +93,7 @@ def generateBaseMesh(cls, region, options): # generate solidsphere with unit diameter MeshType_3d_solidsphere1.generateBaseMesh(region, options) - sphereCoordinates = zinc_utils.getOrCreateCoordinateField(fm) + sphereCoordinates = findOrCreateFieldCoordinates(fm) # Morph sphere surface to lens surface lensRC = getSphereToLensCoordinates(sphereCoordinates, radiusSphere, radiusAnt, radiusPos, lensThickness, diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py index 0d3bc848..b9d46671 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py @@ -5,6 +5,9 @@ from __future__ import division import copy import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite @@ -13,9 +16,6 @@ from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes from scaffoldmaker.utils import vector -from scaffoldmaker.utils import zinc_utils -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_ostium1(Scaffold_base): ''' @@ -237,7 +237,7 @@ def generateOstiumMesh(region, options, trackSurface, centrePosition, axis1, sta fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache = fm.createFieldcache() # track points in shape of ostium diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py index a82b8b5e..39708825 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py @@ -13,7 +13,7 @@ from scaffoldmaker.utils import tubemesh from scaffoldmaker.utils.tubemesh import CylindricalSegmentTubeMeshInnerPoints from scaffoldmaker.utils import vector -from scaffoldmaker.utils import zinc_utils +from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues from opencmiss.zinc.node import Node class MeshType_3d_smallintestine1(Scaffold_base): @@ -32,7 +32,7 @@ class MeshType_3d_smallintestine1(Scaffold_base): 'Length' : 1.0, 'Number of elements' : 45 }, - 'meshEdits' : zinc_utils.exnodeStringFromNodeValues( + 'meshEdits' : exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ -2.3, 18.5, -4.4 ], [ -4.2, -0.8, 3.7 ], [ 0.0, 5.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -8.6, 16.3, -0.4 ], [ -7.1, -2.7, 1.6 ], [ 0.0, 5.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py index 7c68323d..afe2a28b 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py @@ -5,15 +5,15 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils from scaffoldmaker.utils import vector -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_solidsphere1(Scaffold_base): ''' @@ -83,7 +83,7 @@ def generateBaseMesh(cls, region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplateApex = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py index ee11505c..2d943ffc 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py @@ -5,14 +5,14 @@ from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils import zinc_utils from scaffoldmaker.utils.meshrefinement import MeshRefinement -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_sphereshell1(Scaffold_base): ''' @@ -113,7 +113,7 @@ def generateBaseMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplateApex = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py index 731b28da..3adb6509 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py @@ -9,13 +9,13 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative class MeshType_3d_sphereshellseptum1(Scaffold_base): ''' @@ -87,7 +87,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplateApex = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py index c069279e..18d2a711 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py @@ -5,13 +5,13 @@ from __future__ import division import numpy as np -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldFibres from opencmiss.zinc.context import Context from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scipy.interpolate import splprep, splev class Stomach: @@ -9259,8 +9259,8 @@ def __init__(self,): def generateTube(self,region,circumferentialElements,axialElements,wallElements,wallThickness=1): fieldModule = region.getFieldmodule() fieldModule.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fieldModule) - fibres = zinc_utils.getOrCreateFibreField(fieldModule) + coordinates = findOrCreateFieldCoordinates(fieldModule) + fibres = findOrCreateFieldFibres(fieldModule) nodeset = fieldModule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodeset.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py index 575baaf5..44f99129 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py @@ -5,13 +5,14 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.meshrefinement import MeshRefinement + class MeshType_3d_tube1(Scaffold_base): ''' @@ -83,7 +84,7 @@ def generateBaseMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py index 0b15aa85..96ced388 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py @@ -8,12 +8,13 @@ from __future__ import division import math -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite + class MeshType_3d_tubeseptum1(Scaffold_base): ''' @@ -80,7 +81,7 @@ def generateMesh(region, options): fm = region.getFieldmodule() fm.beginChange() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() diff --git a/src/scaffoldmaker/utils/annulusmesh.py b/src/scaffoldmaker/utils/annulusmesh.py index 356fbd1e..ca918d87 100644 --- a/src/scaffoldmaker/utils/annulusmesh.py +++ b/src/scaffoldmaker/utils/annulusmesh.py @@ -4,15 +4,16 @@ from __future__ import division import copy import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.zinc.element import Element +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabel, setEftScaleFactorIds from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector -from scaffoldmaker.utils import zinc_utils -from opencmiss.zinc.element import Element -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node + def derivativeSignsToExpressionTerms(valueLabels, signs): ''' @@ -101,7 +102,7 @@ def createAnnulusMesh3d(nodes, mesh, nextNodeIdentifier, nextElementIdentifier, fm = mesh.getFieldmodule() fm.beginChange() cache = fm.createFieldcache() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) # Build arrays of points from start to end px = [ [], [] ] diff --git a/src/scaffoldmaker/utils/eftfactory_tricubichermite.py b/src/scaffoldmaker/utils/eftfactory_tricubichermite.py index 244cb7d6..be3b1f1e 100644 --- a/src/scaffoldmaker/utils/eftfactory_tricubichermite.py +++ b/src/scaffoldmaker/utils/eftfactory_tricubichermite.py @@ -1,15 +1,17 @@ ''' Definitions of standard element field templates shared by mesh generators. ''' -from scaffoldmaker.utils.eft_utils import mapEftFunction1Node1Term, remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds -from scaffoldmaker.utils import interpolation as interp -from scaffoldmaker.utils import zinc_utils -from scaffoldmaker.utils import vector +import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.utils.zinc.finiteelement import getElementNodeIdentifiers from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from opencmiss.zinc.status import OK as ZINC_OK -import math +from scaffoldmaker.utils.eft_utils import mapEftFunction1Node1Term, remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds +from scaffoldmaker.utils import interpolation as interp +from scaffoldmaker.utils import vector + class eftfactory_tricubichermite: ''' @@ -956,7 +958,7 @@ def replaceElementWithInlet4(self, origElement, startElementId, nodetemplate, st cache = fm.createFieldcache() diff1 = self._mesh.getChartDifferentialoperator(1, 1) diff2 = self._mesh.getChartDifferentialoperator(1, 2) - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) cache.setMeshLocation(origElement, [0.5, 0.5, 1.0]) result, fc = coordinates.evaluateReal(cache, 3) resulta, a = coordinates.evaluateDerivative(diff1, cache, 3) @@ -1003,7 +1005,7 @@ def replaceElementWithInlet4(self, origElement, startElementId, nodetemplate, st nodeIdentifier = nodeIdentifier + 1 eft0 = origElement.getElementfieldtemplate(coordinates, -1) - nids0 = zinc_utils.getElementNodeIdentifiers(origElement, eft0) + nids0 = getElementNodeIdentifiers(origElement, eft0) orig_nids = [ nids0[0], nids0[2], nids0[3], nids0[1], nids0[4], nids0[6], nids0[7], nids0[5] ] #print('orig_nids',orig_nids) @@ -1081,7 +1083,7 @@ def replaceTwoElementWithInlet6(self, origElement1, origElement2, startElementId nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) fm.beginChange() cache = fm.createFieldcache() - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) a = vector.normalise(inletSide) b = vector.normalise(vector.crossproduct3(inletAxis, inletSide)) @@ -1113,9 +1115,9 @@ def replaceTwoElementWithInlet6(self, origElement1, origElement2, startElementId nodeIdentifier = nodeIdentifier + 1 eft0 = origElement1.getElementfieldtemplate(coordinates, -1) - nids1 = zinc_utils.getElementNodeIdentifiers(origElement1, eft0) + nids1 = getElementNodeIdentifiers(origElement1, eft0) eft0 = origElement2.getElementfieldtemplate(coordinates, -1) - nids2 = zinc_utils.getElementNodeIdentifiers(origElement2, eft0) + nids2 = getElementNodeIdentifiers(origElement2, eft0) orig_nids = [ nids1[0], nids1[2], nids2[2], nids2[3], nids1[3], nids1[1], nids1[4], nids1[6], nids2[6], nids2[7], nids1[7], nids1[5] ] #print('orig_nids',orig_nids) diff --git a/src/scaffoldmaker/utils/exportvtk.py b/src/scaffoldmaker/utils/exportvtk.py index 143b45f7..03b5d058 100644 --- a/src/scaffoldmaker/utils/exportvtk.py +++ b/src/scaffoldmaker/utils/exportvtk.py @@ -4,8 +4,8 @@ import io from sys import version_info -from scaffoldmaker.utils import zinc_utils from opencmiss.zinc.field import Field +from opencmiss.utils.zinc.finiteelement import getElementNodeIdentifiersBasisOrder class ExportVtk: @@ -80,10 +80,7 @@ def _write(self, outstream): element = elementIter.next() while element.isValid(): eft = element.getElementfieldtemplate(coordinates, -1) # assumes all components same - if localNodeCount == 4: - nodeIdentifiers = zinc_utils.getElementNodeIdentifiers4Node(element, eft) - else: - nodeIdentifiers = zinc_utils.getElementNodeIdentifiers8Node(element, eft) + nodeIdentifiers = getElementNodeIdentifiersBasisOrder(element, eft) outstream.write(localNodeCountStr) for localIndex in vtkIndexing: index = nodeIdentifierToIndex[nodeIdentifiers[localIndex]] diff --git a/src/scaffoldmaker/utils/meshrefinement.py b/src/scaffoldmaker/utils/meshrefinement.py index 4d533a5c..a35728cf 100644 --- a/src/scaffoldmaker/utils/meshrefinement.py +++ b/src/scaffoldmaker/utils/meshrefinement.py @@ -3,13 +3,14 @@ ''' from __future__ import division import math -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup -from scaffoldmaker.utils.octree import Octree -from scaffoldmaker.utils import zinc_utils +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from opencmiss.zinc.result import RESULT_OK as ZINC_OK +from scaffoldmaker.annotation.annotationgroup import AnnotationGroup +from scaffoldmaker.utils.octree import Octree + class MeshRefinement: ''' @@ -25,7 +26,7 @@ def __init__(self, sourceRegion, targetRegion, sourceAnnotationGroups = []): self._sourceRegion = sourceRegion self._sourceFm = sourceRegion.getFieldmodule() self._sourceCache = self._sourceFm.createFieldcache() - self._sourceCoordinates = zinc_utils.getOrCreateCoordinateField(self._sourceFm) + self._sourceCoordinates = findOrCreateFieldCoordinates(self._sourceFm) # get range of source coordinates for octree range self._sourceFm.beginChange() sourceNodes = self._sourceFm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) @@ -51,7 +52,7 @@ def __init__(self, sourceRegion, targetRegion, sourceAnnotationGroups = []): self._targetFm = targetRegion.getFieldmodule() self._targetFm.beginChange() self._targetCache = self._targetFm.createFieldcache() - self._targetCoordinates = zinc_utils.getOrCreateCoordinateField(self._targetFm) + self._targetCoordinates = findOrCreateFieldCoordinates(self._targetFm) self._targetNodes = self._targetFm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) self._nodetemplate = self._targetNodes.createNodetemplate() diff --git a/src/scaffoldmaker/utils/tubemesh.py b/src/scaffoldmaker/utils/tubemesh.py index e3c1832c..d1d96c29 100644 --- a/src/scaffoldmaker/utils/tubemesh.py +++ b/src/scaffoldmaker/utils/tubemesh.py @@ -4,16 +4,16 @@ ''' from __future__ import division import math +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldTextureCoordinates +from opencmiss.zinc.element import Element, Elementbasis +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.geometry import createCirclePoints from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import matrix from scaffoldmaker.utils import vector -from scaffoldmaker.utils import zinc_utils -from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node def warpSegmentPoints(xList, d1List, d2List, segmentAxis, segmentLength, @@ -365,7 +365,7 @@ def createNodesAndElements(region, cache = fm.createFieldcache() # Coordinates field - coordinates = zinc_utils.getOrCreateCoordinateField(fm) + coordinates = findOrCreateFieldCoordinates(fm) nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) nodetemplate = nodes.createNodetemplate() nodetemplate.defineField(coordinates) @@ -398,7 +398,7 @@ def createNodesAndElements(region, eftTexture1 = bicubichermitelinear.createEftBasic() eftTexture2 = bicubichermitelinear.createEftOpenTube() - flatCoordinates = zinc_utils.getOrCreateFlatCoordinateField(fm) + flatCoordinates = findOrCreateFieldCoordinates(fm, name="flat coordinates") flatNodetemplate1 = nodes.createNodetemplate() flatNodetemplate1.defineField(flatCoordinates) flatNodetemplate1.setValueNumberOfVersions(flatCoordinates, -1, Node.VALUE_LABEL_VALUE, 1) @@ -424,7 +424,7 @@ def createNodesAndElements(region, flatElementtemplate2.defineField(flatCoordinates, -1, eftTexture2) # Texture coordinates field - textureCoordinates = zinc_utils.getOrCreateTextureCoordinateField(fm) + textureCoordinates = findOrCreateFieldTextureCoordinates(fm) textureNodetemplate1 = nodes.createNodetemplate() textureNodetemplate1.defineField(textureCoordinates) textureNodetemplate1.setValueNumberOfVersions(textureCoordinates, -1, Node.VALUE_LABEL_VALUE, 1) diff --git a/src/scaffoldmaker/utils/zinc_utils.py b/src/scaffoldmaker/utils/zinc_utils.py index c8f62142..5866616c 100644 --- a/src/scaffoldmaker/utils/zinc_utils.py +++ b/src/scaffoldmaker/utils/zinc_utils.py @@ -2,6 +2,8 @@ Utility functions for easing use of Zinc API. ''' +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context from opencmiss.zinc.element import MeshGroup from opencmiss.zinc.field import Field @@ -11,300 +13,6 @@ from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector -class ZincCacheChanges: - """ - Context manager for ensuring beginChange, endChange always called on - supplied object, even with exceptions. - Usage: - with ZincCacheChanges(object): - # make multiple changes to object or objects it owns - """ - - def __init__(self, object): - """ - :param object: Zinc object with beginChange/endChange methods. - """ - self._object = object - - def __enter__(self): - self._object.beginChange() - return self - - def __exit__(self, *args): - self._object.endChange() - - -def getOrCreateCoordinateField(fieldmodule, name='coordinates', componentsCount=3): - ''' - Finds or creates a rectangular cartesian coordinate field. - New field has component names: 'x', 'y', 'z'. - Raises exception if existing field of name is not finite element type or has incorrect attributes. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - :param componentsCount: Number of components / dimension of field, from 1 to 3. - ''' - assert (componentsCount > 0) and (componentsCount <= 3), 'getOrCreateCoordinateField. Dimensions must be from 1 to 3' - coordinates = fieldmodule.findFieldByName(name) - if coordinates.isValid(): - coordinates = coordinates.castFiniteElement() - assert coordinates.isValid(), 'getOrCreateCoordinateField. Existing field \'' + name + '\' is not finite element type' - assert coordinates.getNumberOfComponents() == componentsCount, 'getOrCreateCoordinateField. Existing field \'' + name + '\' does not have ' + str(componentsCount) + ' components' - assert coordinates.getCoordinateSystemType() == Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN, 'getOrCreateCoordinateField. Existing field \'' + name + '\' is not rectangular Cartesian' - return coordinates - with ZincCacheChanges(fieldmodule): - coordinates = fieldmodule.createFieldFiniteElement(componentsCount) - coordinates.setName(name) - coordinates.setManaged(True) - coordinates.setTypeCoordinate(True) - coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN) - for c in range(componentsCount): - coordinates.setComponentName(c + 1, ['x', 'y', 'z'][c]) - return coordinates - -def getOrCreateFibreField(fieldmodule, name='fibres', componentsCount=3): - ''' - Finds or creates a fibre field. - New field has component names: 'fibre angle', 'imbrication angle', 'sheet angle'. - Raises exception if existing field of name is not finite element type or has incorrect attributes. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - :param componentsCount: Number of components of field, from 1 to 3. - ''' - assert (componentsCount > 0) and (componentsCount <= 3), 'getOrCreateFibreField. Dimensions must be from 1 to 3' - fibres = fieldmodule.findFieldByName(name) - if fibres.isValid(): - fibres = fibres.castFiniteElement() - assert fibres.isValid(), 'getOrCreateFibreField. Existing field \'' + name + '\' is not finite element type' - assert fibres.getNumberOfComponents() == componentsCount, 'getOrCreateFibreField. Existing field \'' + name + '\' does not have ' + str(componentsCount) + ' components' - assert fibres.getCoordinateSystemType() == Field.COORDINATE_SYSTEM_TYPE_FIBRE, 'getOrCreateFibreField. Existing field \'' + name + '\' is not fibre' - return fibres - with ZincCacheChanges(fieldmodule): - fibres = fieldmodule.createFieldFiniteElement(componentsCount) - fibres.setName(name) - fibres.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_FIBRE) - for c in range(componentsCount): - fibres.setComponentName(c + 1, ['fibre angle', 'imbrication angle', 'sheet angle'][c]) - return fibres - -def getOrCreateTextureCoordinateField(fieldmodule, name='texture coordinates', componentsCount=3): - ''' - Finds or creates a rectangular cartesian texture coordinate field. - New field has component names: 'u', 'v', 'w'. - Raises exception if existing field of name is not finite element type or has incorrect attributes. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - :param componentsCount: Number of components / dimension of field, from 1 to 3. - ''' - assert (componentsCount > 0) and (componentsCount <= 3), 'getOrCreateTextureCoordinateField. Dimensions must be from 1 to 3' - coordinates = fieldmodule.findFieldByName(name) - if coordinates.isValid(): - coordinates = coordinates.castFiniteElement() - assert coordinates.isValid(), 'getOrCreateTextureCoordinateField. Existing field \'' + name + '\' is not finite element type' - assert coordinates.getNumberOfComponents() == componentsCount, 'getOrCreateTextureCoordinateField. Existing field \'' + name + '\' does not have ' + str(componentsCount) + ' components' - assert coordinates.getCoordinateSystemType() == Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN, 'getOrCreateTextureCoordinateField. Existing field \'' + name + '\' is not rectangular Cartesian' - return coordinates - with ZincCacheChanges(fieldmodule): - coordinates = fieldmodule.createFieldFiniteElement(componentsCount) - coordinates.setName(name) - coordinates.setManaged(True) - coordinates.setTypeCoordinate(True) - coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN) - for c in range(componentsCount): - coordinates.setComponentName(c + 1, ['u', 'v', 'w'][c]) - return coordinates - -def getOrCreateFlatCoordinateField(fieldmodule, name='flat coordinates', componentsCount=3): - ''' - Finds or creates a rectangular cartesian texture coordinate field. - New field has component names: 'x', 'y', 'z'. - Raises exception if existing field of name is not finite element type or has incorrect attributes. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - :param componentsCount: Number of components / dimension of field, from 1 to 3. - ''' - assert (componentsCount > 0) and (componentsCount <= 3), 'getOrCreateFlatCoordinateField. Dimensions must be from 1 to 3' - coordinates = fieldmodule.findFieldByName(name) - if coordinates.isValid(): - coordinates = coordinates.castFiniteElement() - assert coordinates.isValid(), 'getOrCreateFlatCoordinateField. Existing field \'' + name + '\' is not finite element type' - assert coordinates.getNumberOfComponents() == componentsCount, 'getOrCreateFlatCoordinateField. Existing field \'' + name + '\' does not have ' + str(componentsCount) + ' components' - assert coordinates.getCoordinateSystemType() == Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN, 'getOrCreateFlatCoordinateField. Existing field \'' + name + '\' is not rectangular Cartesian' - return coordinates - with ZincCacheChanges(fieldmodule): - coordinates = fieldmodule.createFieldFiniteElement(componentsCount) - coordinates.setName(name) - coordinates.setManaged(True) - coordinates.setTypeCoordinate(True) - coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN) - for c in range(componentsCount): - coordinates.setComponentName(c + 1, ['x', 'y', 'z'][c]) - return coordinates - -def getOrCreateElementXiField(fieldmodule, name='element_xi', mesh=None): - ''' - Finds or creates a stored mesh location field for storing locations in the - supplied mesh e.g. for defining on annotation points with mesh locations. - Raises exception if existing field of name is not stored mesh location type. - Note can't currently verify existing field stores locations in the supplied mesh. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - :param mesh: Mesh to store locations in. - ''' - if mesh is None: - mesh = fieldmodule.findMeshByDimension(3) - assert mesh.isValid(), 'getOrCreateElementXiField. Invalid mesh' - elementXiField = fieldmodule.findFieldByName(name) - if elementXiField.isValid(): - elementXiField = elementXiField.castStoredMeshLocation() - assert elementXiField.isValid(), 'getOrCreateElementXiField. Existing field \'' + name + '\' is not stored mesh location type' - return elementXiField - with ZincCacheChanges(fieldmodule): - elementXiField = fieldmodule.createFieldStoredMeshLocation(mesh) - elementXiField.setName(name) - elementXiField.setManaged(True) - return elementXiField - -def getOrCreateLabelField(fieldmodule, name='label'): - ''' - Finds or creates a stored string field for defining labels on nodes, e.g. annotation points. - Raises exception if existing field of name is not string-valued. - Note can't currently distinguish stored string from constant string fields. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - ''' - labelField = fieldmodule.findFieldByName(name) - if labelField.isValid(): - assert labelField.getValueType() == Field.VALUE_TYPE_STRING, 'getOrCreateLabelField. Existing field \'' + name + '\' is not string valued' - return labelField - with ZincCacheChanges(fieldmodule): - labelField = fieldmodule.createFieldStoredString() - labelField.setName(name) - labelField.setManaged(True) - return labelField - -def getOrCreateGroupField(fieldmodule, name): - ''' - Finds or creates a Group field of the supplied name. - Raises exception if existing field of name is not a group. - :param fieldmodule: Zinc fieldmodule to find or create field in. - :param name: Name of field to find or create. - ''' - group = fieldmodule.findFieldByName(name) - if group.isValid(): - group = group.castGroup() - assert group.isValid(), 'getOrCreateGroupField. Existing field \'' + name + '\' is not a group type' - return group - with ZincCacheChanges(fieldmodule): - group = fieldmodule.createFieldGroup() - group.setName(name) - group.setManaged(True) - return group - -def getOrCreateNodesetGroup(group, nodeset): - ''' - Gets or creates the NodesetGroup for the supplied nodeset in group. - :param group: Zinc FieldGroup. - :param nodeset: A nodeset from group region to get or create subgroup of. - ''' - nodeGroup = group.getFieldNodeGroup(nodeset) - if not nodeGroup.isValid(): - nodeGroup = group.createFieldNodeGroup(nodeset) - return nodeGroup.getNodesetGroup() - -def getElementNodeIdentifiers(element, eft): - ''' - Get identifiers of all nodes used by eft in element. - ''' - nodeIdentifiers = [] - nodeCount = eft.getNumberOfLocalNodes() - for n in range(nodeCount): - node = element.getNode(eft, n + 1) - nodeIdentifiers.append(node.getIdentifier()) - return nodeIdentifiers - -def getElementNodeIdentifiers4Node(element, eft): - ''' - Get 4 node identifiers for an element with 4 basis nodes, handling - collapses e.g. where eft has fewer nodes. Asserts basis has 4 nodes. - :param element: Element to query. - :param eft: Element field template nodes are stored for in element. - :return: List of 4 local node identifiers. - ''' - elementbasis = eft.getElementbasis() - basisNodesCount = elementbasis.getNumberOfNodes() - assert basisNodesCount == 4, 'getElementNodeIdentifiers4Node: Element ' + str(element.getIdentifier()) + ' is not using a 4 node basis' - nodeIdentifiers = [] - fn = 1 - for n in range(basisNodesCount): - ln = eft.getTermLocalNodeIndex(fn, 1) - nodeIdentifiers.append(element.getNode(eft, ln).getIdentifier()) - fn += elementbasis.getNumberOfFunctionsPerNode(n + 1) - return nodeIdentifiers - -def getElementNodeIdentifiers8Node(element, eft): - ''' - Get 8 node identifiers for an element with 8 basis nodes, handling - collapses e.g. where eft has fewer nodes. Asserts basis has 8 nodes. - :param element: Element to query. - :param eft: Element field template nodes are stored for in element. - :return: List of 8 local node identifiers. - ''' - elementbasis = eft.getElementbasis() - basisNodesCount = elementbasis.getNumberOfNodes() - assert basisNodesCount == 8, 'getElementNodeIdentifiers8Node: Element ' + str(element.getIdentifier()) + ' is not using an 8 node basis' - nodeIdentifiers = [] - fn = 1 - for n in range(basisNodesCount): - ln = eft.getTermLocalNodeIndex(fn, 1) - nodeIdentifiers.append(element.getNode(eft, ln).getIdentifier()) - fn += elementbasis.getNumberOfFunctionsPerNode(n + 1) - return nodeIdentifiers - -def getMaximumNodeIdentifier(nodeset): - """ - :return: Maximum node identifier in nodeset or -1 if none. - """ - maximumNodeId = -1 - nodeiterator = nodeset.createNodeiterator() - node = nodeiterator.next() - while node.isValid(): - id = node.getIdentifier() - if id > maximumNodeId: - maximumNodeId = id - node = nodeiterator.next() - return maximumNodeId - -def getMaximumElementIdentifier(mesh): - """ - :return: Maximum element identifier in mesh or -1 if none. - """ - maximumElementId = -1 - elementiterator = mesh.createElementiterator() - element = elementiterator.next() - while element.isValid(): - id = element.getIdentifier() - if id > maximumElementId: - maximumElementId = id - element = elementiterator.next() - return maximumElementId - -def evaluateFieldRange(field : Field, nodeset : Nodeset): - """ - :return: minimums, maximums (as lists for components). - """ - fieldmodule = field.getFieldmodule() - componentsCount = field.getNumberOfComponents() - with ZincCacheChanges(fieldmodule): - fieldNodesetMinimum = fieldmodule.createFieldNodesetMinimum(field, nodeset) - fieldNodesetMaximum = fieldmodule.createFieldNodesetMaximum(field, nodeset) - fieldcache = fieldmodule.createFieldcache() - result, minimums = fieldNodesetMinimum.evaluateReal(fieldcache, componentsCount) - assert result == RESULT_OK - result, maximums = fieldNodesetMaximum.evaluateReal(fieldcache, componentsCount) - assert result == RESULT_OK - del fieldNodesetMinimum - del fieldNodesetMaximum - return minimums, maximums def interpolateNodesCubicHermite(cache, coordinates, xi, normal_scale, \ node1, derivative1, scale1, cross_derivative1, cross_scale1, \ @@ -354,6 +62,7 @@ def interpolateNodesCubicHermite(cache, coordinates, xi, normal_scale, \ return x, dx_ds, dx_ds_cross, dx_ds_normal + def computeNodeDerivativeHermiteLagrange(cache, coordinates, node1, derivative1, scale1, node2, scale2): """ Computes the derivative at node2 from quadratic Hermite-Lagrange interpolation of @@ -375,6 +84,7 @@ def computeNodeDerivativeHermiteLagrange(cache, coordinates, node1, derivative1, d2 = [ d*scale2 for d in d2 ] return d2 + def exnodeStringFromNodeValues( nodeValueLabels = [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1 ], nodeValues = [ @@ -392,9 +102,9 @@ def exnodeStringFromNodeValues( context = Context('exnodeStringFromNodeValues') region = context.getDefaultRegion() fieldmodule = region.getFieldmodule() - with ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): cache = fieldmodule.createFieldcache() - coordinates = getOrCreateCoordinateField(fieldmodule, componentsCount = componentsCount) + coordinates = findOrCreateFieldCoordinates(fieldmodule, components_count = componentsCount) nodes = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) group = fieldmodule.createFieldGroup() group.setName(groupName) @@ -419,12 +129,13 @@ def exnodeStringFromNodeValues( result, exString = srm.getBuffer() return exString + def createFaceMeshGroupExteriorOnFace(fieldmodule : Fieldmodule, elementFaceType) -> MeshGroup: """ Returns mesh group for the exterior surface on the face described by elementFaceType. """ - with ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): isExterior = fieldmodule.createFieldIsExterior() isOnFace = fieldmodule.createFieldIsOnFace(elementFaceType) mesh2d = fieldmodule.findMeshByDimension(2) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_colon.py b/tests/test_colon.py index 04693be9..d0b74bd8 100644 --- a/tests/test_colon.py +++ b/tests/test_colon.py @@ -1,5 +1,7 @@ import copy import unittest +from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange +from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field @@ -9,8 +11,8 @@ from scaffoldmaker.meshtypes.meshtype_3d_colon1 import MeshType_3d_colon1 from scaffoldmaker.meshtypes.meshtype_3d_colonsegment1 import MeshType_3d_colonsegment1 from scaffoldmaker.scaffoldpackage import ScaffoldPackage -from scaffoldmaker.utils import zinc_utils -from tests.testutils import assertAlmostEqualList +from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace, exnodeStringFromNodeValues +from testutils import assertAlmostEqualList class ColonScaffoldTestCase(unittest.TestCase): @@ -27,7 +29,7 @@ def test_colon1(self): 'Length': 1.0, 'Number of elements': 1 }, - 'meshEdits': zinc_utils.exnodeStringFromNodeValues( + 'meshEdits': exnodeStringFromNodeValues( [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2], [ [[163.7, -25.2, 12.2], [-21.7, 50.1, -18.1], [0.0, 0.0, 5.0], [0.0, 0.0, 0.5]], @@ -106,24 +108,24 @@ def test_colon1(self): coordinates = fieldmodule.findFieldByName("coordinates").castFiniteElement() self.assertTrue(coordinates.isValid()) - minimums, maximums = zinc_utils.evaluateFieldRange(coordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes) assertAlmostEqualList(self, minimums, [ 108.05453644074798, -36.659788201178515, -25.896225462626255 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 185.4128545433126, 48.1410866643588, 34.90780743659052 ], 1.0E-6) flatCoordinates = fieldmodule.findFieldByName("flat coordinates").castFiniteElement() self.assertTrue(flatCoordinates.isValid()) - minimums, maximums = zinc_utils.evaluateFieldRange(flatCoordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(flatCoordinates, nodes) assertAlmostEqualList(self, minimums, [ 0.0, 0.0, 0.0 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 186.72664370397405, 77.41890571041102, 3.2000000000000006 ], 1.0E-6) textureCoordinates = fieldmodule.findFieldByName("texture coordinates").castFiniteElement() - minimums, maximums = zinc_utils.evaluateFieldRange(textureCoordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(textureCoordinates, nodes) assertAlmostEqualList(self, minimums, [ 0.0, 0.0, 0.0 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 0.9812487204616481, 1.0, 2.0 ], 1.0E-6) - with zinc_utils.ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): one = fieldmodule.createFieldConstant(1.0) - faceMeshGroup = zinc_utils.createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) + faceMeshGroup = createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, faceMeshGroup) surfaceAreaField.setNumbersOfPoints(4) volumeField = fieldmodule.createFieldMeshIntegral(one, coordinates, mesh3d) @@ -158,9 +160,9 @@ def test_mousecolon1(self): textureCoordinates = fieldmodule.findFieldByName("texture coordinates").castFiniteElement() self.assertTrue(textureCoordinates.isValid()) - with zinc_utils.ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): one = fieldmodule.createFieldConstant(1.0) - faceMeshGroup = zinc_utils.createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) + faceMeshGroup = createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) flatSurfaceAreaField = fieldmodule.createFieldMeshIntegral(one, flatCoordinates, faceMeshGroup) flatSurfaceAreaField.setNumbersOfPoints(4) textureSurfaceAreaField = fieldmodule.createFieldMeshIntegral(one, textureCoordinates, faceMeshGroup) diff --git a/tests/test_colonsegment.py b/tests/test_colonsegment.py index 35132cb5..cfbc05a6 100644 --- a/tests/test_colonsegment.py +++ b/tests/test_colonsegment.py @@ -1,11 +1,13 @@ import unittest +from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange +from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.result import RESULT_OK from scaffoldmaker.meshtypes.meshtype_3d_colonsegment1 import MeshType_3d_colonsegment1 -from scaffoldmaker.utils.zinc_utils import evaluateFieldRange, ZincCacheChanges, createFaceMeshGroupExteriorOnFace -from tests.testutils import assertAlmostEqualList +from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace +from testutils import assertAlmostEqualList class ColonSegmentScaffoldTestCase(unittest.TestCase): @@ -52,22 +54,22 @@ def test_humancolonsegment1(self): coordinates = fieldmodule.findFieldByName("coordinates").castFiniteElement() self.assertTrue(coordinates.isValid()) - minimums, maximums = evaluateFieldRange(coordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes) assertAlmostEqualList(self, minimums, [ -2.172286248499807e-15, -58.70795100094912, -55.299531343601124 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 50.0, 48.620086017242905, 55.29953084925164 ], 1.0E-6) flatCoordinates = fieldmodule.findFieldByName("flat coordinates").castFiniteElement() self.assertTrue(flatCoordinates.isValid()) - minimums, maximums = evaluateFieldRange(flatCoordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(flatCoordinates, nodes) assertAlmostEqualList(self, minimums, [ 0.0, 0.0, 0.0 ], 1.0E-6) assertAlmostEqualList(self, maximums, [397.26513766571264, 50.0, 3.2000000000000006], 1.0E-6) textureCoordinates = fieldmodule.findFieldByName("texture coordinates").castFiniteElement() - minimums, maximums = evaluateFieldRange(textureCoordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(textureCoordinates, nodes) assertAlmostEqualList(self, minimums, [ 0.0, 0.0, 0.0 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 0.9887754554800083, 1.0, 2.0 ], 1.0E-6) - with ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): one = fieldmodule.createFieldConstant(1.0) faceMeshGroup = createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, faceMeshGroup) @@ -104,7 +106,7 @@ def test_mousecolonsegment1(self): textureCoordinates = fieldmodule.findFieldByName("texture coordinates").castFiniteElement() self.assertTrue(textureCoordinates.isValid()) - with ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): one = fieldmodule.createFieldConstant(1.0) faceMeshGroup = createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, faceMeshGroup) diff --git a/tests/test_heart.py b/tests/test_heart.py index 59ca64db..e76c9353 100644 --- a/tests/test_heart.py +++ b/tests/test_heart.py @@ -1,11 +1,11 @@ import unittest +from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange from opencmiss.zinc.context import Context from opencmiss.zinc.field import Field from opencmiss.zinc.result import RESULT_OK from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.meshtypes.meshtype_3d_heart1 import MeshType_3d_heart1 -from scaffoldmaker.utils.zinc_utils import evaluateFieldRange -from tests.testutils import assertAlmostEqualList +from testutils import assertAlmostEqualList class HeartScaffoldTestCase(unittest.TestCase): @@ -46,7 +46,7 @@ def test_heart1(self): coordinates = fieldmodule.findFieldByName("coordinates").castFiniteElement() self.assertTrue(coordinates.isValid()) - minimums, maximums = evaluateFieldRange(coordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes) assertAlmostEqualList(self, minimums, [ -50.7876375290527, -57.76590573823474, -91.6 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 43.81084359764995, 39.03925080604259, 40.71693637558552 ], 1.0E-6) diff --git a/tests/test_smallintestine.py b/tests/test_smallintestine.py index 404a4482..d6996f2f 100644 --- a/tests/test_smallintestine.py +++ b/tests/test_smallintestine.py @@ -1,5 +1,7 @@ import copy import unittest +from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange +from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field @@ -8,8 +10,8 @@ from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion from scaffoldmaker.meshtypes.meshtype_3d_smallintestine1 import MeshType_3d_smallintestine1 from scaffoldmaker.scaffoldpackage import ScaffoldPackage -from scaffoldmaker.utils import zinc_utils -from tests.testutils import assertAlmostEqualList +from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace, exnodeStringFromNodeValues +from testutils import assertAlmostEqualList class SmallIntestineScaffoldTestCase(unittest.TestCase): @@ -26,7 +28,7 @@ def test_smallintestine1(self): 'Length': 1.0, 'Number of elements': 3 }, - 'meshEdits': zinc_utils.exnodeStringFromNodeValues( + 'meshEdits': exnodeStringFromNodeValues( [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2], [ [[-2.3, 18.5, -4.4], [-4.2, -0.8, 3.7], [0.0, 5.0, 0.0], [0.0, 0.0, 0.5]], @@ -84,24 +86,24 @@ def test_smallintestine1(self): coordinates = fieldmodule.findFieldByName("coordinates").castFiniteElement() self.assertTrue(coordinates.isValid()) - minimums, maximums = zinc_utils.evaluateFieldRange(coordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes) assertAlmostEqualList(self, minimums, [ -20.060907893509103, 11.403274743489126, -7.1653294859433965 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ -1.8300388314851923, 19.193885338090105, 0.9770592770891556 ], 1.0E-6) flatCoordinates = fieldmodule.findFieldByName("flat coordinates").castFiniteElement() self.assertTrue(flatCoordinates.isValid()) - minimums, maximums = zinc_utils.evaluateFieldRange(flatCoordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(flatCoordinates, nodes) assertAlmostEqualList(self, minimums, [ -1.3904291168857714, 0.0, 0.0 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 4.891272838311825, 25.32059684030755, 0.1 ], 1.0E-6) textureCoordinates = fieldmodule.findFieldByName("texture coordinates").castFiniteElement() - minimums, maximums = zinc_utils.evaluateFieldRange(textureCoordinates, nodes) + minimums, maximums = evaluateFieldNodesetRange(textureCoordinates, nodes) assertAlmostEqualList(self, minimums, [ 0.0, 0.0, 0.0 ], 1.0E-6) assertAlmostEqualList(self, maximums, [ 0.875, 1.0, 1.0 ], 1.0E-6) - with zinc_utils.ZincCacheChanges(fieldmodule): + with ChangeManager(fieldmodule): one = fieldmodule.createFieldConstant(1.0) - faceMeshGroup = zinc_utils.createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) + faceMeshGroup = createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1) surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, faceMeshGroup) surfaceAreaField.setNumbersOfPoints(4) volumeField = fieldmodule.createFieldMeshIntegral(one, coordinates, mesh3d)