Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move most zinc_utils to opencmiss.utils #64

Merged
merged 4 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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=[
Expand Down
6 changes: 3 additions & 3 deletions src/scaffoldmaker/meshtypes/meshtype_1d_path1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()

#################
Expand Down
6 changes: 3 additions & 3 deletions src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/scaffoldmaker/meshtypes/meshtype_3d_box1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 ] ],
Expand All @@ -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 ] ],
Expand All @@ -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 ] ],
Expand All @@ -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 ] ],
Expand All @@ -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 ] ],
Expand Down
14 changes: 7 additions & 7 deletions src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 15 additions & 13 deletions src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Loading