From 35864321e8099abf74f5b0f6d1694da2a7c0d366 Mon Sep 17 00:00:00 2001 From: hsorby Date: Thu, 4 Nov 2021 14:50:02 +1300 Subject: [PATCH] Optimise imports and perform some PEP8 fixes. --- setup.py | 11 +- src/scaffoldmaker/__init__.py | 2 - .../annotation/annotationgroup.py | 3 +- .../meshtypes/meshtype_1d_bifurcationtree1.py | 5 +- .../meshtypes/meshtype_1d_path1.py | 5 +- .../meshtypes/meshtype_2d_plate1.py | 3 +- .../meshtypes/meshtype_2d_platehole1.py | 3 + .../meshtypes/meshtype_2d_sphere1.py | 3 + .../meshtypes/meshtype_2d_tube1.py | 3 + .../meshtypes/meshtype_2d_tubebifurcation1.py | 2 + .../meshtype_2d_tubebifurcationtree1.py | 6 +- .../meshtypes/meshtype_3d_bladder1.py | 8 +- .../meshtypes/meshtype_3d_bladderurethra1.py | 9 +- .../meshtypes/meshtype_3d_box1.py | 5 +- .../meshtypes/meshtype_3d_boxhole1.py | 3 + .../meshtypes/meshtype_3d_brainstem.py | 52 +- .../meshtypes/meshtype_3d_cecum1.py | 9 +- .../meshtypes/meshtype_3d_colon1.py | 168 ++--- .../meshtypes/meshtype_3d_colonsegment1.py | 614 +++++++++--------- .../meshtypes/meshtype_3d_heart1.py | 7 +- .../meshtypes/meshtype_3d_heart2.py | 5 +- .../meshtype_3d_heartarterialroot1.py | 13 +- .../meshtype_3d_heartarterialvalve1.py | 18 +- .../meshtypes/meshtype_3d_heartatria1.py | 16 +- .../meshtypes/meshtype_3d_heartatria2.py | 9 +- .../meshtypes/meshtype_3d_heartventricles1.py | 8 +- .../meshtypes/meshtype_3d_heartventricles2.py | 8 +- .../meshtypes/meshtype_3d_heartventricles3.py | 10 +- .../meshtype_3d_heartventriclesbase1.py | 10 +- .../meshtype_3d_heartventriclesbase2.py | 13 +- .../meshtypes/meshtype_3d_lens1.py | 5 +- .../meshtypes/meshtype_3d_lung1.py | 10 +- .../meshtypes/meshtype_3d_ostium1.py | 7 +- .../meshtypes/meshtype_3d_smallintestine1.py | 6 +- .../meshtypes/meshtype_3d_solidcylinder1.py | 11 +- .../meshtypes/meshtype_3d_solidsphere1.py | 9 +- .../meshtypes/meshtype_3d_sphereshell1.py | 5 +- .../meshtype_3d_sphereshellseptum1.py | 3 + .../meshtypes/meshtype_3d_stellate1.py | 15 +- .../meshtypes/meshtype_3d_stomach1.py | 168 ++--- .../meshtypes/meshtype_3d_stomachhuman1.py | 2 + .../meshtypes/meshtype_3d_tube1.py | 4 +- .../meshtypes/meshtype_3d_tubeseptum1.py | 4 +- .../meshtypes/meshtype_3d_wholebody1.py | 11 +- src/scaffoldmaker/meshtypes/scaffold_base.py | 4 +- src/scaffoldmaker/scaffoldpackage.py | 4 +- src/scaffoldmaker/scaffolds.py | 4 +- src/scaffoldmaker/utils/annulusmesh.py | 10 +- src/scaffoldmaker/utils/bifurcation.py | 2 +- src/scaffoldmaker/utils/cylindermesh.py | 15 +- src/scaffoldmaker/utils/derivativemoothing.py | 6 +- .../utils/eftfactory_bicubichermitelinear.py | 6 +- .../utils/eftfactory_tricubichermite.py | 5 +- src/scaffoldmaker/utils/exportvtk.py | 2 + src/scaffoldmaker/utils/geometry.py | 3 + src/scaffoldmaker/utils/interpolation.py | 6 +- src/scaffoldmaker/utils/meshrefinement.py | 2 + src/scaffoldmaker/utils/mirror.py | 2 + src/scaffoldmaker/utils/octree.py | 2 + src/scaffoldmaker/utils/shieldmesh.py | 15 +- src/scaffoldmaker/utils/tracksurface.py | 4 +- src/scaffoldmaker/utils/tubemesh.py | 11 +- src/scaffoldmaker/utils/zinc_utils.py | 2 +- tests/test_bladder.py | 3 + tests/test_cecum.py | 3 + tests/test_colon.py | 3 + tests/test_colonsegment.py | 3 + tests/test_cylinder.py | 3 +- tests/test_general.py | 5 +- tests/test_heart.py | 7 +- tests/test_lung.py | 7 +- tests/test_smallintestine.py | 3 + tests/test_stomach.py | 3 + 73 files changed, 793 insertions(+), 643 deletions(-) diff --git a/setup.py b/setup.py index 257f5f03..a16a06e1 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,10 @@ -from setuptools import setup, find_packages -from setuptools.command.install import install -import os import io +import os + +from setuptools import setup, find_packages SETUP_DIR = os.path.dirname(os.path.abspath(__file__)) -# List all of your Python package dependencies in the -# requirements.txt file def readfile(filename, split=False): with io.open(filename, encoding="utf-8") as stream: @@ -14,6 +12,7 @@ def readfile(filename, split=False): return stream.read().split("\n") return stream.read() + readme = readfile("README.rst", split=True)[3:] # skip title # For requirements not hosted on PyPi place listings # into the 'requirements.txt' file. @@ -46,4 +45,4 @@ def readfile(filename, split=False): include_package_data=True, zip_safe=False, install_requires=requires, - ) +) diff --git a/src/scaffoldmaker/__init__.py b/src/scaffoldmaker/__init__.py index 8d17c21c..e69de29b 100644 --- a/src/scaffoldmaker/__init__.py +++ b/src/scaffoldmaker/__init__.py @@ -1,2 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) - diff --git a/src/scaffoldmaker/annotation/annotationgroup.py b/src/scaffoldmaker/annotation/annotationgroup.py index e48f0ab7..1fa8ab75 100644 --- a/src/scaffoldmaker/annotation/annotationgroup.py +++ b/src/scaffoldmaker/annotation/annotationgroup.py @@ -2,14 +2,15 @@ Describes subdomains of a scaffold with attached names and terms. """ +from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.field import Field, FieldGroup from opencmiss.zinc.result import RESULT_OK -from opencmiss.utils.zinc.general import ChangeManager from scaffoldmaker.utils.zinc_utils import group_get_highest_dimension, \ identifier_ranges_from_string, identifier_ranges_to_string, \ mesh_group_add_identifier_ranges, mesh_group_to_identifier_ranges, \ nodeset_group_add_identifier_ranges, nodeset_group_to_identifier_ranges + class AnnotationGroup(object): ''' Describes subdomains of a scaffold with attached names and terms. diff --git a/src/scaffoldmaker/meshtypes/meshtype_1d_bifurcationtree1.py b/src/scaffoldmaker/meshtypes/meshtype_1d_bifurcationtree1.py index 4e0cd891..4fdf6228 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_1d_bifurcationtree1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_1d_bifurcationtree1.py @@ -3,11 +3,12 @@ """ from __future__ import division -from math import cos, radians, sin, sqrt +from math import cos, radians, sin + from opencmiss.maths.vectorops import add, cross, magnitude, mult, normalize, sub from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldFiniteElement -from opencmiss.zinc.element import Element, Elementbasis from opencmiss.utils.zinc.general import ChangeManager +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 diff --git a/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py b/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py index d0f1427d..7a8dc880 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_1d_path1.py @@ -3,16 +3,15 @@ """ from __future__ import division -import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup from opencmiss.utils.zinc.general import ChangeManager 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.interpolation import DerivativeScalingMode, smoothCubicHermiteDerivativesLine, smoothCubicHermiteCrossDerivativesLine from scaffoldmaker.utils import vector -from opencmiss.zinc.result import RESULT_OK +from scaffoldmaker.utils.interpolation import smoothCubicHermiteCrossDerivativesLine class MeshType_1d_path1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py index 54c560d9..6a80220f 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_plate1.py @@ -3,13 +3,14 @@ """ from __future__ import division -import math + 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): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py index d06f9211..e277f662 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_platehole1.py @@ -6,7 +6,9 @@ """ 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 @@ -14,6 +16,7 @@ from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative + class MeshType_2d_platehole1(Scaffold_base): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py index e51634e5..ce02d97c 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_sphere1.py @@ -3,13 +3,16 @@ """ 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 + class MeshType_2d_sphere1(Scaffold_base): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py index 8b0a2ef9..b2f56497 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_tube1.py @@ -3,13 +3,16 @@ """ from __future__ import division + import math + 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): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcation1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcation1.py index 094edef6..de61dd73 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcation1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcation1.py @@ -3,7 +3,9 @@ """ from __future__ import division + import math + from opencmiss.maths.vectorops import cross, mult, normalize, sub from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.field import Field diff --git a/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcationtree1.py b/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcationtree1.py index ed0f137b..9bd34097 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcationtree1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_2d_tubebifurcationtree1.py @@ -4,16 +4,14 @@ from __future__ import division import math -from opencmiss.maths.vectorops import cross, mult, normalize, sub + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from scaffoldmaker.meshtypes.meshtype_1d_bifurcationtree1 import MeshType_1d_bifurcationtree1 from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage -from scaffoldmaker.utils.bifurcation import get_curve_circle_points, \ - make_tube_bifurcation_points, make_tube_bifurcation_elements_2d -from scaffoldmaker.utils.geometry import createCirclePoints +from scaffoldmaker.utils.bifurcation import get_curve_circle_points from scaffoldmaker.utils.interpolation import getCubicHermiteArcLength diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py index 384a37e7..921dbb46 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_bladder1.py @@ -3,8 +3,10 @@ """ from __future__ import division -import math + import copy +import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field @@ -14,11 +16,11 @@ from scaffoldmaker.meshtypes.meshtype_3d_ostium1 import MeshType_3d_ostium1, generateOstiumMesh from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage +from scaffoldmaker.utils import interpolation as interp +from scaffoldmaker.utils import vector from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear -from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.interpolation import getCubicHermiteBasis, smoothCubicHermiteDerivativesLine -from scaffoldmaker.utils import vector from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py index cfe8f1b1..61c888e2 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_bladderurethra1.py @@ -6,6 +6,11 @@ import copy import math + +from opencmiss.utils.zinc.field import findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.zinc.element import Element +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.bladder_terms import get_bladder_term from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion @@ -21,10 +26,6 @@ from scaffoldmaker.utils.interpolation import smoothCubicHermiteDerivativesLine from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues, mesh_destroy_elements_and_nodes_by_identifiers -from opencmiss.utils.zinc.field import findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString -from opencmiss.zinc.element import Element -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_bladderurethra1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py index f1c222ec..1028cb8e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_box1.py @@ -3,15 +3,16 @@ """ from __future__ import division -import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.zinc.element import Element, Elementbasis +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 scaffoldmaker.utils.meshrefinement import MeshRefinement + class MeshType_3d_box1(Scaffold_base): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py index c51d3bc0..ce5d2e91 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py @@ -6,7 +6,9 @@ """ 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 @@ -15,6 +17,7 @@ from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative + class MeshType_3d_boxhole1(Scaffold_base): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py b/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py index 5a0a76fd..d66b4ff1 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_brainstem.py @@ -3,25 +3,31 @@ """ from __future__ import division + import copy + from opencmiss.zinc.element import Element from opencmiss.zinc.node import Node -from opencmiss.zinc.field import Field, FieldFindMeshLocation -from opencmiss.utils.zinc.field import Field, findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.zinc.field import FieldFindMeshLocation +from opencmiss.utils.zinc.field import Field, findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, \ + findOrCreateFieldStoredString from opencmiss.utils.zinc.finiteelement import getMaximumNodeIdentifier from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm from scaffoldmaker.annotation.brainstem_terms import get_brainstem_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion +from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1 +from scaffoldmaker.scaffoldpackage import ScaffoldPackage +from scaffoldmaker.utils.cylindermesh import CylinderMesh, CylinderShape, CylinderEnds, CylinderCentralPath from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils.cylindermesh import CylinderMesh, CylinderShape, CylinderEnds, Tapered, ConeBaseProgression, CylinderCentralPath from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues -from scaffoldmaker.scaffoldpackage import ScaffoldPackage class MeshType_3d_brainstem1(Scaffold_base): """ - Generates a tapered cylinder for the brainstem based on solid cylinder mesh, with variable numbers of elements in major, minor and length directions. Regions of the brainstem are annotated. + Generates a tapered cylinder for the brainstem based on + solid cylinder mesh, with variable numbers of elements + in major, minor and length directions. Regions of the + brainstem are annotated. """ centralPathDefaultScaffoldPackages = { @@ -33,7 +39,7 @@ class MeshType_3d_brainstem1(Scaffold_base): 'Length': 3.0, 'Number of elements': 6 }, - 'meshEdits': exnodeStringFromNodeValues( # dimensional. + 'meshEdits': exnodeStringFromNodeValues( # dimensional. [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2, Node.VALUE_LABEL_D_DS3, Node.VALUE_LABEL_D2_DS1DS3], [ [ [0.0,0.0,0.0], [0.0,0.0,1.0], [1.0,0.0,0.0], [0.0,0.0,0.0], [-0.0,1.0,0.0], [0.0,0.0,0.0] ], @@ -77,7 +83,7 @@ class MeshType_3d_brainstem1(Scaffold_base): 'Length': 3.0, 'Number of elements': 6 }, - 'meshEdits': exnodeStringFromNodeValues( # dimensional. + 'meshEdits': exnodeStringFromNodeValues( # dimensional. [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2, Node.VALUE_LABEL_D_DS3, Node.VALUE_LABEL_D2_DS1DS3], [ # [ [0.0,1.0,-5.0], [0.0,0.0,4.5], [5.0,0.0,0.0], [1.0,0.0,0.0], [0.0,2.4,0.0], [0.0,2.2,0.0] ], @@ -218,7 +224,7 @@ class MeshType_3d_brainstem1(Scaffold_base): [ [0.0,-1.1, 1.2], [0.0,-0.7,1.6], [2.7,0.0,0.0], [-0.2,0.0,0.0], [-0.0,1.8,0.8], [ 0.0, 0.1,-0.1] ], [ [0.0,-1.5, 3.0], [0.0,-1.1,1.9], [2.2,0.0,0.0], [-0.1,0.0,0.0], [-0.0,1.7,1.0], [ 0.0,-0.4, 0.4] ], [ [0.0,-3.3, 4.6], [0.0,-2.4,1.3], [2.7,0.0,0.0], [ 1.1,0.0,0.0], [-0.0,0.9,1.7], [ 0.0,-1.2, 1.0] ] - ]), + ]), 'userAnnotationGroups': [ { '_AnnotationGroup': True, @@ -403,21 +409,21 @@ def generateBaseMesh(cls, region, options): # foramenCaecum = findOrCreateAnnotationGroupForTerm(annotationGroups, region, # get_brainstem_term('foramen caecum of medulla oblongata')) dorsalMidCaudalGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem dorsal midline caudal point')) + get_brainstem_term('brainstem dorsal midline caudal point')) ventralMidCaudalGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem ventral midline caudal point')) + get_brainstem_term('brainstem ventral midline caudal point')) dorsalMidCranGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem dorsal midline cranial point')) + get_brainstem_term('brainstem dorsal midline cranial point')) ventralMidCranGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem ventral midline cranial point')) + get_brainstem_term('brainstem ventral midline cranial point')) dorsalMidMedullaPonsJunction = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term ('brainstem dorsal midline pons-medulla junction')) + get_brainstem_term('brainstem dorsal midline pons-medulla junction')) ventralMidMedullaPonsJunction = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem ventral midline pons-medulla junction')) + get_brainstem_term('brainstem ventral midline pons-medulla junction')) dorsalMidMidbrainPonsJunction = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem dorsal midline midbrain-pons junction')) + get_brainstem_term('brainstem dorsal midline midbrain-pons junction')) ventralMidMidbrainPonsJunction = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_brainstem_term('brainstem ventral midline midbrain-pons junction')) + get_brainstem_term('brainstem ventral midline midbrain-pons junction')) ####################### # CREATE MAIN BODY MESH @@ -490,7 +496,7 @@ def generateBaseMesh(cls, region, options): # point markers ################ pointMarkers = [ - {"group" : dorsalMidCaudalGroup, "marker_brainstem_coordinates" : [ 0.0, 1.0, 0.0 ]}, + {"group": dorsalMidCaudalGroup, "marker_brainstem_coordinates": [0.0, 1.0, 0.0]}, {"group": ventralMidCaudalGroup, "marker_brainstem_coordinates": [0.0, -1.0, 0.0]}, {"group": dorsalMidCranGroup, "marker_brainstem_coordinates": [0.0, 1.0, 8.0]}, {"group": ventralMidCranGroup, "marker_brainstem_coordinates": [0.0, -1.0, 8.0]}, @@ -588,6 +594,7 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): get_brainstem_term(groupName)) subFaceGroup.getMeshGroup(mesh2d).addElementsConditional(is_subface_ext) + def createCranialNerveEmergentMarkers(region, mesh, coordinatesName): # create marker points for locations the cranial nerves emerge from brainstem mesh, based on the USF cat brainstem data. # return element xi @@ -609,9 +616,9 @@ def createCranialNerveEmergentMarkers(region, mesh, coordinatesName): rightDict = {} for key in nerveDict.keys(): - nerveName = key.split('_')[0]+'_right' - xyz = [-1*nerveDict[key][0], nerveDict[key][1], nerveDict[key][2]] - rightDict.update({nerveName:xyz}) + nerveName = key.split('_')[0] + '_right' + xyz = [-1 * nerveDict[key][0], nerveDict[key][1], nerveDict[key][2]] + rightDict.update({nerveName: xyz}) nerveDict.update(rightDict) nerveNames = list(nerveDict.keys()) @@ -649,7 +656,7 @@ def createCranialNerveEmergentMarkers(region, mesh, coordinatesName): element, xi = found_mesh_location.evaluateMeshLocation(cache, 3) marker_name = dataNamesField.evaluateString(cache) if element.isValid(): - addProjection = {marker_name:{"elementID": element.getIdentifier(), "xi": xi,"nodeID": node.getIdentifier()}} + addProjection = {marker_name: {"elementID": element.getIdentifier(), "xi": xi, "nodeID": node.getIdentifier()}} xi_projected_data.update(addProjection) node = nodeIter.next() @@ -659,4 +666,3 @@ def createCranialNerveEmergentMarkers(region, mesh, coordinatesName): xi_projected_data = {} return xi_projected_data - diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_cecum1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_cecum1.py index 18d19591..6cbb2cc7 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_cecum1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_cecum1.py @@ -6,6 +6,9 @@ import copy import math + +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.annotation.colon_terms import get_colon_term from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion @@ -14,15 +17,13 @@ from scaffoldmaker.meshtypes.meshtype_3d_ostium1 import MeshType_3d_ostium1, generateOstiumMesh from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage -from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import matrix -from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition from scaffoldmaker.utils import tubemesh from scaffoldmaker.utils import vector +from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d +from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues, mesh_destroy_elements_and_nodes_by_identifiers -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_cecum1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py index 8285999a..ca4bb936 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_colon1.py @@ -5,18 +5,20 @@ """ import copy + +from opencmiss.zinc.node import Node from opencmiss.zinc.element import Element -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, findAnnotationGroupByName, getAnnotationGroupForTerm +from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.colon_terms import get_colon_term from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion -from scaffoldmaker.meshtypes.meshtype_3d_colonsegment1 import MeshType_3d_colonsegment1, ColonSegmentTubeMeshInnerPoints,\ +from scaffoldmaker.meshtypes.meshtype_3d_colonsegment1 import MeshType_3d_colonsegment1, ColonSegmentTubeMeshInnerPoints, \ getTeniaColi, createFlatCoordinatesTeniaColi, createColonCoordinatesTeniaColi, createNodesAndElementsTeniaColi from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import tubemesh from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues -from opencmiss.zinc.node import Node + class MeshType_3d_colon1(Scaffold_base): ''' @@ -28,14 +30,14 @@ class MeshType_3d_colon1(Scaffold_base): ''' centralPathDefaultScaffoldPackages = { - 'Cattle 1' : ScaffoldPackage(MeshType_1d_path1, { - 'scaffoldSettings' : { - 'Coordinate dimensions' : 3, + 'Cattle 1': ScaffoldPackage(MeshType_1d_path1, { + 'scaffoldSettings': { + 'Coordinate dimensions': 3, 'D2 derivatives': True, - 'Length' : 1.0, - 'Number of elements' : 52 - }, - 'meshEdits' : exnodeStringFromNodeValues( + 'Length': 1.0, + 'Number of elements': 52 + }, + 'meshEdits': exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ -245.3, 444.6, -49.1 ], [ -267.7, -53.1, -20.2 ], [ 0.0, 0.0, 15.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -380.3, 484.8, -45.0 ], [ 24.5, 102.7, 15.7 ], [ 0.0, 0.0, 15.0 ], [ 0.0, 0.0, 0.5 ] ], @@ -90,15 +92,15 @@ class MeshType_3d_colon1(Scaffold_base): [ [ -318.1, 641.9, -8.5 ], [ 166.7, 17.6, 5.5 ], [ 3.0, -13.0, -39.4 ], [ -8.3, -3.3, -0.9 ] ], [ [ -158.3, 634.7, -1.9 ], [ 176.5, -14.0, 10.8 ], [ -4.3, -11.5, -34.6 ], [ -3.1, 2.7, 5.3 ] ], [ [ 32.7, 611.7, 13.6 ], [ 205.5, -32.2, 20.0 ], [ -2.4, -7.3, -28.7 ], [ 6.9, 5.6, 6.4 ] ] ] ) - } ), - 'Human 1' : ScaffoldPackage(MeshType_1d_path1, { - 'scaffoldSettings' : { - 'Coordinate dimensions' : 3, + }), + 'Human 1': ScaffoldPackage(MeshType_1d_path1, { + 'scaffoldSettings': { + 'Coordinate dimensions': 3, 'D2 derivatives': True, - 'Length' : 1.0, - 'Number of elements' : 8 - }, - 'meshEdits' : exnodeStringFromNodeValues( + 'Length': 1.0, + 'Number of elements': 8 + }, + '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 ] ], @@ -109,15 +111,15 @@ class MeshType_3d_colon1(Scaffold_base): [ [ 475.2, 168.0, 0.0 ], [ -0.8, -112.4, 0.0 ], [ 20.0, 0.0, -20.0 ], [ 15.0, -1.0, -10.0 ] ], [ [ 432.6, -32.3, 0.0 ], [ -90.5, -59.0, 0.0 ], [ 6.0, -9.0, -14.0 ], [ 8.0, -11.0, -13.0 ] ], [ [ 272.4, 7.5, 0.0 ], [ -79.0, 47.4, 0.0 ], [ 1.0, -11.0, -18.0 ], [ 4.0, -12.0, -12.0 ] ] ] ) - } ), - 'Human 2' : ScaffoldPackage(MeshType_1d_path1, { - 'scaffoldSettings' : { - 'Coordinate dimensions' : 3, + }), + 'Human 2': ScaffoldPackage(MeshType_1d_path1, { + 'scaffoldSettings': { + 'Coordinate dimensions': 3, 'D2 derivatives': True, - 'Length' : 1.0, - 'Number of elements' : 8 - }, - 'meshEdits' : exnodeStringFromNodeValues( + 'Length': 1.0, + 'Number of elements': 8 + }, + '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 ] ], @@ -128,15 +130,15 @@ class MeshType_3d_colon1(Scaffold_base): [ [ 354.0, 105.3, -24.4 ], [ -6.3, -143.7, 20.3 ], [ 20.0, 0.0, -20.0 ], [ 15.0, -1.0, -10.0 ] ], [ [ 296.5, -121.2, -0.6 ], [ -90.5, -59.0, 0.0 ], [ 6.0, -9.0, -14.0 ], [ 8.0, -11.0, -13.0 ] ], [ [ 169.8, -73.4, -33.5 ], [ -72.2, 43.4, -27.4 ], [ 1.0, -11.0, -18.0 ], [ 4.0, -12.0, -12.0 ] ] ] ) - } ), - 'Mouse 1' : ScaffoldPackage(MeshType_1d_path1, { - 'scaffoldSettings' : { - 'Coordinate dimensions' : 3, + }), + 'Mouse 1': ScaffoldPackage(MeshType_1d_path1, { + 'scaffoldSettings': { + 'Coordinate dimensions': 3, 'D2 derivatives': True, - 'Length' : 1.0, - 'Number of elements' : 7 - }, - 'meshEdits' : exnodeStringFromNodeValues( + 'Length': 1.0, + 'Number of elements': 7 + }, + '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 ] ], @@ -146,30 +148,30 @@ class MeshType_3d_colon1(Scaffold_base): [ [ -7.0, -8.0, 0.0 ], [ 5.0, -1.0, -14.0 ], [ 0.0, -3.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -1.0, -6.0, -1.0 ], [ 2.0, -2.0, 9.0 ], [ 1.0, -3.0, -1.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -2.0, -14.0, 5.0 ], [ -2.0, -4.0, 2.0 ], [ 1.0, -2.0, -2.0 ], [ 0.0, 0.0, 0.5 ] ] ] ) - } ), - 'Mouse 2' : ScaffoldPackage(MeshType_1d_path1, { - 'scaffoldSettings' : { - 'Coordinate dimensions' : 3, + }), + 'Mouse 2': ScaffoldPackage(MeshType_1d_path1, { + 'scaffoldSettings': { + 'Coordinate dimensions': 3, 'D2 derivatives': True, - 'Length' : 1.0, - 'Number of elements' : 4 - }, - 'meshEdits' : exnodeStringFromNodeValues( + 'Length': 1.0, + 'Number of elements': 4 + }, + '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 ] ], [ [ -14.0, -2.0, 13.0 ], [ 0.0, -3.0, -19.0 ], [ 0.0, -10.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -14.0, -1.0, -10.0 ], [ 1.0, 1.0, -17.0 ], [ 0.0, -10.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -14.0, 0.0, -28.0 ], [ 0.0, 0.0, -11.0 ], [ 0.0, -10.0, 0.0 ], [ 0.0, 0.0, 0.5 ] ] ] ) - } ), - 'Pig 1' : ScaffoldPackage(MeshType_1d_path1, { - 'scaffoldSettings' : { - 'Coordinate dimensions' : 3, + }), + 'Pig 1': ScaffoldPackage(MeshType_1d_path1, { + 'scaffoldSettings': { + 'Coordinate dimensions': 3, 'D2 derivatives': True, - 'Length' : 1.0, - 'Number of elements' : 39 - }, - 'meshEdits' : exnodeStringFromNodeValues( + 'Length': 1.0, + 'Number of elements': 39 + }, + 'meshEdits': exnodeStringFromNodeValues( [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D2_DS1DS2 ], [ [ [ -7.2, 83.3, -20.7 ], [ -65.2, -8.1, 7.6 ], [ 0.0, 0.0, 5.0 ], [ 0.0, 0.0, 0.5 ] ], [ [ -68.5, 52.8, -9.6 ], [ -40.1, -36.1, 10.7 ], [ 0.0, 0.0, 5.0 ], [ 0.0, 0.0, 0.5 ] ], @@ -211,7 +213,7 @@ class MeshType_3d_colon1(Scaffold_base): [ [ -20.9, 15.3, -77.9 ], [ -51.2, -30.6, 21.1 ], [ 7.1, -7.7, 12.2 ], [ 0.0, 0.0, 0.5 ] ], [ [ -47.6, 33.9, -112.2 ], [ 32.6, 30.7, -27.8 ], [ -12.8, -0.5, -1.6 ], [ 0.0, 0.0, 0.5 ] ], [ [ 19.6, 96.0, -167.5 ], [ 19.9, 19.1, -18.4 ], [ -12.6, 1.3, -8.1 ], [ 0.0, 0.0, 0.5 ] ] ] ) - } ), + }), 'Pig 2': ScaffoldPackage(MeshType_1d_path1, { 'scaffoldSettings': { 'Coordinate dimensions': 3, @@ -225,8 +227,8 @@ class MeshType_3d_colon1(Scaffold_base): [ [ 30.0, 0.0, 0.0 ], [ 30.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ], [ [ 60.0, 0.0, 0.0 ], [ 30.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ], [ [ 90.0, 0.0, 0.0 ], [ 30.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] ] ) - } ), - } + }), + } @staticmethod def getName(): @@ -261,16 +263,16 @@ def getDefaultOptions(cls, parameterSetName='Default'): else: centralPathOption = cls.centralPathDefaultScaffoldPackages['Human 1'] if 'Cattle' in parameterSetName: - segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName = 'Cattle 1') + segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName='Cattle 1') elif 'Mouse' in parameterSetName: - segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName = 'Mouse 1') + segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName='Mouse 1') elif 'Pig' in parameterSetName: - segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName = 'Pig 1') + segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName='Pig 1') else: - segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName = 'Human 1') + segmentProfileOption = ScaffoldPackage(MeshType_3d_colonsegment1, defaultParameterSetName='Human 1') options = { - 'Central path' : copy.deepcopy(centralPathOption), - 'Segment profile' : segmentProfileOption, + 'Central path': copy.deepcopy(centralPathOption), + 'Segment profile': segmentProfileOption, 'Number of segments': 30, 'Start phase': 0.0, 'Proximal length': 420.0, @@ -284,11 +286,11 @@ def getDefaultOptions(cls, parameterSetName='Default'): 'Transverse-distal tenia coli width': 10.0, 'Distal inner radius': 31.5, 'Distal tenia coli width': 10.0, - 'Refine' : False, - 'Refine number of elements around' : 1, - 'Refine number of elements along' : 1, - 'Refine number of elements through wall' : 1 - } + 'Refine': False, + 'Refine number of elements around': 1, + 'Refine number of elements along': 1, + 'Refine number of elements through wall': 1 + } if 'Cattle 1' in parameterSetName: options['Number of segments'] = 40 options['Proximal length'] = 900.0 @@ -368,14 +370,14 @@ def getOrderedOptionNames(): 'Refine', 'Refine number of elements around', 'Refine number of elements along', - 'Refine number of elements through wall' ] + 'Refine number of elements through wall'] @classmethod def getOptionValidScaffoldTypes(cls, optionName): if optionName == 'Central path': - return [ MeshType_1d_path1 ] + return [MeshType_1d_path1] if optionName == 'Segment profile': - return [ MeshType_3d_colonsegment1 ] + return [MeshType_3d_colonsegment1] return [] @classmethod @@ -404,7 +406,7 @@ def getOptionScaffoldPackage(cls, optionName, scaffoldType, parameterSetName=Non if optionName == 'Segment profile': if not parameterSetName: parameterSetName = scaffoldType.getParameterSetNames()[0] - return ScaffoldPackage(scaffoldType, defaultParameterSetName = parameterSetName) + return ScaffoldPackage(scaffoldType, defaultParameterSetName=parameterSetName) assert False, cls.__name__ + '.getOptionScaffoldPackage: Option ' + optionName + ' is not a scaffold' @classmethod @@ -467,7 +469,7 @@ def generateBaseMesh(cls, region, options): segmentLengthMidDerivativeFactor = segmentSettings['Segment length mid derivative factor'] tcCount = segmentSettings['Number of tenia coli'] tcThickness = segmentSettings['Tenia coli thickness'] - elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum)*tcCount + elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum) * tcCount elementsCountAlongSegment = segmentSettings['Number of elements along segment'] elementsCountThroughWall = segmentSettings['Number of elements through wall'] @@ -477,14 +479,14 @@ def generateBaseMesh(cls, region, options): circularRelThickness = segmentSettings['Circular muscle layer relative thickness'] longitudinalRelThickness = segmentSettings['Longitudinal muscle layer relative thickness'] useCrossDerivatives = segmentSettings['Use cross derivatives'] - useCubicHermiteThroughWall = not(segmentSettings['Use linear through wall']) - elementsCountAlong = int(elementsCountAlongSegment*segmentCount) + useCubicHermiteThroughWall = not (segmentSettings['Use linear through wall']) + elementsCountAlong = int(elementsCountAlongSegment * segmentCount) # Colon coordinates lengthToDiameterRatio = 24 wallThicknessToDiameterRatio = 0.1 - teniaColiThicknessToDiameterRatio = 0.25*wallThicknessToDiameterRatio - relativeThicknessListColonCoordinates = [1.0/elementsCountThroughWall for n3 in range(elementsCountThroughWall)] + teniaColiThicknessToDiameterRatio = 0.25 * wallThicknessToDiameterRatio + relativeThicknessListColonCoordinates = [1.0 / elementsCountThroughWall for n3 in range(elementsCountThroughWall)] firstNodeIdentifier = 1 firstElementIdentifier = 1 @@ -502,8 +504,8 @@ def generateBaseMesh(cls, region, options): # find arclength of colon length = 0.0 elementsCountIn = len(cx) - 1 - sd1 = interp.smoothCubicHermiteDerivativesLine(cx, cd1, fixAllDirections = True, - magnitudeScalingMode = interp.DerivativeScalingMode.HARMONIC_MEAN) + sd1 = interp.smoothCubicHermiteDerivativesLine(cx, cd1, fixAllDirections=True, + magnitudeScalingMode=interp.DerivativeScalingMode.HARMONIC_MEAN) for e in range(elementsCountIn): arcLength = interp.getCubicHermiteArcLength(cx[e], sd1[e], cx[e + 1], sd1[e + 1]) # print(e+1, arcLength) @@ -531,16 +533,16 @@ def generateBaseMesh(cls, region, options): # Account for reduced haustrum appearance in transverse and distal pig colon if tcCount == 2: - haustrumInnerRadiusFactorList = [haustrumInnerRadiusFactor, haustrumInnerRadiusFactor*0.75, - haustrumInnerRadiusFactor*0.5, haustrumInnerRadiusFactor*0.2] + haustrumInnerRadiusFactorList = [haustrumInnerRadiusFactor, haustrumInnerRadiusFactor * 0.75, + haustrumInnerRadiusFactor * 0.5, haustrumInnerRadiusFactor * 0.2] haustrumInnerRadiusFactorAlongElementList = \ interp.sampleParameterAlongLine(lengthList, haustrumInnerRadiusFactorList, elementsCountAlong)[0] else: - haustrumInnerRadiusFactorAlongElementList = [haustrumInnerRadiusFactor]*(elementsCountAlong+1) + haustrumInnerRadiusFactorAlongElementList = [haustrumInnerRadiusFactor] * (elementsCountAlong + 1) # Create annotation groups for colon sections - elementsAlongInProximal = round(proximalLength/elementAlongLength) - elementsAlongInTransverse = round(transverseLength/elementAlongLength) + elementsAlongInProximal = round(proximalLength / elementAlongLength) + elementsAlongInTransverse = round(transverseLength / elementAlongLength) elementsAlongInDistal = elementsCountAlong - elementsAlongInProximal - elementsAlongInTransverse elementsCountAlongGroups = [elementsAlongInProximal, elementsAlongInTransverse, elementsAlongInDistal] @@ -623,7 +625,7 @@ def generateBaseMesh(cls, region, options): closedProximalEnd=False) # Store points along length - xExtrude += xWarpedList if nSegment == 0 else xWarpedList[elementsCountAround:] + xExtrude += xWarpedList if nSegment == 0 else xWarpedList[elementsCountAround:] d1Extrude += d1WarpedList if nSegment == 0 else d1WarpedList[elementsCountAround:] d2Extrude += d2WarpedList if nSegment == 0 else d2WarpedList[elementsCountAround:] d3UnitExtrude += d3WarpedUnitList if nSegment == 0 else d3WarpedUnitList[elementsCountAround:] @@ -633,8 +635,8 @@ def generateBaseMesh(cls, region, options): # Create coordinates and derivatives xList, d1List, d2List, d3List, curvatureList = tubemesh.getCoordinatesFromInner(xExtrude, d1Extrude, - d2Extrude, d3UnitExtrude, contractedWallThicknessList, relativeThicknessList, - elementsCountAround, elementsCountAlong, elementsCountThroughWall, transitElementList) + d2Extrude, d3UnitExtrude, contractedWallThicknessList, relativeThicknessList, + elementsCountAround, elementsCountAlong, elementsCountThroughWall, transitElementList) relaxedLengthList, xiList = colonSegmentTubeMeshInnerPoints.getRelaxedLengthAndXiList() diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py index de0252f5..8fe0f004 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_colonsegment1.py @@ -7,20 +7,23 @@ 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.annotation.annotationgroup import AnnotationGroup, mergeAnnotationGroups, findOrCreateAnnotationGroupForTerm, findAnnotationGroupByName, getAnnotationGroupForTerm +from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, mergeAnnotationGroups, findOrCreateAnnotationGroupForTerm, findAnnotationGroupByName, \ + getAnnotationGroupForTerm from scaffoldmaker.annotation.colon_terms import get_colon_term 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.geometry import createCirclePoints -from scaffoldmaker.utils import matrix from scaffoldmaker.utils import interpolation as interp +from scaffoldmaker.utils import matrix from scaffoldmaker.utils import tubemesh from scaffoldmaker.utils import vector +from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import createCirclePoints + class MeshType_3d_colonsegment1(Scaffold_base): ''' @@ -35,6 +38,7 @@ class MeshType_3d_colonsegment1(Scaffold_base): rounded corners at the inter-haustral septa, and a clover profile in the intra-haustral region. ''' + @staticmethod def getName(): return '3D Colon Segment 1' @@ -51,10 +55,10 @@ def getParameterSetNames(): @staticmethod def getDefaultOptions(parameterSetName='Default'): options = { - 'Number of elements around tenia coli' : 2, - 'Number of elements around haustrum' : 8, - 'Number of elements along segment' : 4, - 'Number of elements through wall' : 4, + 'Number of elements around tenia coli': 2, + 'Number of elements around haustrum': 8, + 'Number of elements along segment': 4, + 'Number of elements through wall': 4, 'Start phase': 0.0, 'Start inner radius': 43.5, 'Start inner radius derivative': 0.0, @@ -76,12 +80,12 @@ def getDefaultOptions(parameterSetName='Default'): 'Submucosa relative thickness': 0.3, 'Circular muscle layer relative thickness': 0.3, 'Longitudinal muscle layer relative thickness': 0.1, - 'Use cross derivatives' : False, - 'Use linear through wall' : True, - 'Refine' : False, - 'Refine number of elements around' : 1, - 'Refine number of elements along segment' : 1, - 'Refine number of elements through wall' : 1 + 'Use cross derivatives': False, + 'Use linear through wall': True, + 'Refine': False, + 'Refine number of elements around': 1, + 'Refine number of elements along segment': 1, + 'Refine number of elements through wall': 1 } if 'Cattle' in parameterSetName: options['Start inner radius'] = 10.5 @@ -202,7 +206,7 @@ def checkOptions(options): 'Mucosa relative thickness', 'Submucosa relative thickness', 'Circular muscle layer relative thickness', - 'Longitudinal muscle layer relative thickness' ]: + 'Longitudinal muscle layer relative thickness']: if options[key] < 0.0: options[key] = 0.0 if options['Corner inner radius factor'] < 0.1: @@ -219,12 +223,12 @@ def checkOptions(options): for key in [ 'Start tenia coli width', 'End tenia coli width']: - if options[key] < 0.2*min(options['Start inner radius'], options['End inner radius']): - options[key] = round(0.2*min(options['Start inner radius'], options['End inner radius']), 2) - if options['Start tenia coli width'] > round(math.sqrt(3)*0.5*options['Start inner radius'], 2): - options['Start tenia coli width'] = round(math.sqrt(3)*0.5*options['Start inner radius'], 2) - if options['End tenia coli width'] > round(math.sqrt(3)*0.5*options['End inner radius'], 2): - options['End tenia coli width'] = round(math.sqrt(3)*0.5*options['End inner radius'], 2) + if options[key] < 0.2 * min(options['Start inner radius'], options['End inner radius']): + options[key] = round(0.2 * min(options['Start inner radius'], options['End inner radius']), 2) + if options['Start tenia coli width'] > round(math.sqrt(3) * 0.5 * options['Start inner radius'], 2): + options['Start tenia coli width'] = round(math.sqrt(3) * 0.5 * options['Start inner radius'], 2) + if options['End tenia coli width'] > round(math.sqrt(3) * 0.5 * options['End inner radius'], 2): + options['End tenia coli width'] = round(math.sqrt(3) * 0.5 * options['End inner radius'], 2) @classmethod def generateBaseMesh(cls, region, options): @@ -260,16 +264,16 @@ def generateBaseMesh(cls, region, options): circularRelThickness = options['Circular muscle layer relative thickness'] longitudinalRelThickness = options['Longitudinal muscle layer relative thickness'] useCrossDerivatives = options['Use cross derivatives'] - useCubicHermiteThroughWall = not(options['Use linear through wall']) - elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum)*tcCount + useCubicHermiteThroughWall = not (options['Use linear through wall']) + elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum) * tcCount firstNodeIdentifier = 1 firstElementIdentifier = 1 # Central path - cx = [ [ 0.0, 0.0, 0.0 ], [ segmentLength, 0.0, 0.0 ] ] - cd1 = [ [ segmentLength, 0.0, 0.0 ], [ segmentLength, 0.0, 0.0 ] ] - cd2 = [ [ 0.0, 1.0, 0.0 ], [ 0.0, 1.0, 0.0 ] ] - cd12 = [ [0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] + cx = [[0.0, 0.0, 0.0], [segmentLength, 0.0, 0.0]] + cd1 = [[segmentLength, 0.0, 0.0], [segmentLength, 0.0, 0.0]] + cd2 = [[0.0, 1.0, 0.0], [0.0, 1.0, 0.0]] + cd12 = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] # Sample central path sx, sd1, se, sxi, ssf = interp.sampleCubicHermiteCurves(cx, cd1, elementsCountAlongSegment) @@ -281,7 +285,7 @@ def generateBaseMesh(cls, region, options): tcWidthAlongSegment = [] for n2 in range(elementsCountAlongSegment + 1): - xi = 1/elementsCountAlongSegment * n2 + xi = 1 / elementsCountAlongSegment * n2 radius = interp.interpolateCubicHermite([startRadius], [startRadiusDerivative], [endRadius], [endRadiusDerivative], xi)[0] radiusAlongSegment.append(radius) @@ -292,7 +296,7 @@ def generateBaseMesh(cls, region, options): [endTCWidth], [endTCWidthDerivative], xi)[0] tcWidthAlongSegment.append(tcWidth) - haustrumInnerRadiusFactorAlongSegment = [haustrumInnerRadiusFactor]*(elementsCountAlongSegment + 1) + haustrumInnerRadiusFactorAlongSegment = [haustrumInnerRadiusFactor] * (elementsCountAlongSegment + 1) colonSegmentTubeMeshInnerPoints = ColonSegmentTubeMeshInnerPoints( region, elementsCountAroundTC, elementsCountAroundHaustrum, elementsCountAlongSegment, @@ -302,7 +306,7 @@ def generateBaseMesh(cls, region, options): # Create annotation colonGroup = AnnotationGroup(region, get_colon_term("colon")) - annotationGroupsAlong = [ ] + annotationGroupsAlong = [] for i in range(elementsCountAlongSegment): annotationGroupsAlong.append([colonGroup]) @@ -341,8 +345,9 @@ def generateBaseMesh(cls, region, options): # Create coordinates and derivatives xList, d1List, d2List, d3List, curvatureList = tubemesh.getCoordinatesFromInner(xWarpedList, d1WarpedList, - d2WarpedList, d3WarpedUnitList, contractedWallThicknessList, relativeThicknessList, - elementsCountAround, elementsCountAlongSegment, elementsCountThroughWall, transitElementList) + d2WarpedList, d3WarpedUnitList, contractedWallThicknessList, relativeThicknessList, + elementsCountAround, elementsCountAlongSegment, elementsCountThroughWall, + transitElementList) xColonSegment = d1ColonSegment = d2ColonSegment = [] @@ -425,17 +430,17 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): mucosaInnerSurface = findOrCreateAnnotationGroupForTerm(annotationGroups, region, get_colon_term("luminal surface of the colonic mucosa")) mucosaInnerSurface.getMeshGroup(mesh2d).addElementsConditional(is_mucosaInnerSurface) + class ColonSegmentTubeMeshInnerPoints: """ Generates inner profile of a colon segment for use by tubemesh. """ def __init__(self, region, elementsCountAroundTC, elementsCountAroundHaustrum, - elementsCountAlongSegment, tcCount, segmentLengthEndDerivativeFactor, - segmentLengthMidDerivativeFactor, segmentLength, wallThickness, - cornerInnerRadiusFactor, haustrumInnerRadiusFactorAlongElementList, innerRadiusAlongElementList, - dInnerRadiusAlongElementList, tcWidthAlongElementList, startPhase): - + elementsCountAlongSegment, tcCount, segmentLengthEndDerivativeFactor, + segmentLengthMidDerivativeFactor, segmentLength, wallThickness, + cornerInnerRadiusFactor, haustrumInnerRadiusFactorAlongElementList, innerRadiusAlongElementList, + dInnerRadiusAlongElementList, tcWidthAlongElementList, startPhase): self._region = region self._elementsCountAroundTC = elementsCountAroundTC self._elementsCountAroundHaustrum = elementsCountAroundHaustrum @@ -457,14 +462,13 @@ def __init__(self, region, elementsCountAroundTC, elementsCountAroundHaustrum, self._startPhase = startPhase def getColonSegmentTubeMeshInnerPoints(self, nSegment): - # Unpack parameter variation along elements - radiusSegmentList = self._innerRadiusAlongElementList[nSegment*self._elementsCountAlongSegment: - (nSegment + 1)*self._elementsCountAlongSegment + 1] - dRadiusSegmentList = self._dInnerRadiusAlongElementList[nSegment*self._elementsCountAlongSegment: - (nSegment + 1)*self._elementsCountAlongSegment + 1] - tcWidthSegmentList = self._tcWidthAlongElementList[nSegment*self._elementsCountAlongSegment: - (nSegment + 1)*self._elementsCountAlongSegment + 1] + radiusSegmentList = self._innerRadiusAlongElementList[nSegment * self._elementsCountAlongSegment: + (nSegment + 1) * self._elementsCountAlongSegment + 1] + dRadiusSegmentList = self._dInnerRadiusAlongElementList[nSegment * self._elementsCountAlongSegment: + (nSegment + 1) * self._elementsCountAlongSegment + 1] + tcWidthSegmentList = self._tcWidthAlongElementList[nSegment * self._elementsCountAlongSegment: + (nSegment + 1) * self._elementsCountAlongSegment + 1] haustrumInnerRadiusFactorSegmentList = self._haustrumInnerRadiusFactorAlongElementList[ nSegment * self._elementsCountAlongSegment: @@ -473,12 +477,12 @@ def getColonSegmentTubeMeshInnerPoints(self, nSegment): xInner, d1Inner, d2Inner, transitElementList, xiSegment, relaxedLengthSegment, contractedWallThicknessSegment, \ segmentAxis, annotationGroupsAround = \ getColonSegmentInnerPoints(self._region, - self._elementsCountAroundTC, self._elementsCountAroundHaustrum, self._elementsCountAlongSegment, - self._tcCount, self._segmentLengthEndDerivativeFactor, self._segmentLengthMidDerivativeFactor, - self._segmentLength, self._wallThickness, - self._cornerInnerRadiusFactor, haustrumInnerRadiusFactorSegmentList, - radiusSegmentList, dRadiusSegmentList, tcWidthSegmentList, - self._startPhase) + self._elementsCountAroundTC, self._elementsCountAroundHaustrum, self._elementsCountAlongSegment, + self._tcCount, self._segmentLengthEndDerivativeFactor, self._segmentLengthMidDerivativeFactor, + self._segmentLength, self._wallThickness, + self._cornerInnerRadiusFactor, haustrumInnerRadiusFactorSegmentList, + radiusSegmentList, dRadiusSegmentList, tcWidthSegmentList, + self._startPhase) startIdx = 0 if nSegment == 0 else 1 for i in range(startIdx, self._elementsCountAlongSegment + 1): @@ -505,13 +509,14 @@ def getRelaxedLengthAndXiList(self): def getContractedWallThicknessList(self): return self._contractedWallThicknessList + def getColonSegmentInnerPoints(region, elementsCountAroundTC, - elementsCountAroundHaustrum, elementsCountAlongSegment, - tcCount, segmentLengthEndDerivativeFactor, - segmentLengthMidDerivativeFactor, segmentLength, wallThickness, - cornerInnerRadiusFactor, haustrumInnerRadiusFactorSegmentList, - radiusSegmentList, dRadiusSegmentList, tcWidthSegmentList, - startPhase): + elementsCountAroundHaustrum, elementsCountAlongSegment, + tcCount, segmentLengthEndDerivativeFactor, + segmentLengthMidDerivativeFactor, segmentLength, wallThickness, + cornerInnerRadiusFactor, haustrumInnerRadiusFactorSegmentList, + radiusSegmentList, dRadiusSegmentList, tcWidthSegmentList, + startPhase): """ Generates a 3-D colon segment mesh with variable numbers of tenia coli, numbers of elements around, along the central path, and through wall. @@ -561,15 +566,15 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, :return annotationGroupsAround: annotation groups for elements around. """ - transitElementListHaustrum = ([0]*int(elementsCountAroundTC*0.5) + [1] + - [0]*int(elementsCountAroundHaustrum - 2) + [1] + - [0]*int(elementsCountAroundTC*0.5)) + transitElementListHaustrum = ([0] * int(elementsCountAroundTC * 0.5) + [1] + + [0] * int(elementsCountAroundHaustrum - 2) + [1] + + [0] * int(elementsCountAroundTC * 0.5)) transitElementList = transitElementListHaustrum * tcCount # create nodes - x = [ 0.0, 0.0, 0.0 ] - dx_ds1 = [ 0.0, 0.0, 0.0 ] - dx_ds2 = [ 0.0, 0.0, 0.0 ] + x = [0.0, 0.0, 0.0] + dx_ds1 = [0.0, 0.0, 0.0] + dx_ds2 = [0.0, 0.0, 0.0] sampleElementOut = 20 segmentAxis = [0.0, 0.0, 1.0] @@ -586,7 +591,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, xForSampling = [] d1ForSampling = [] - elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum)*tcCount + elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum) * tcCount if tcCount == 1: for n2 in range(elementsCountAlongSegment + 1): @@ -594,19 +599,19 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, tcWidth = tcWidthSegmentList[n2] xHalfSet, d1HalfSet = createHalfSetInterHaustralSegment(elementsCountAroundTC, - elementsCountAroundHaustrum, tcCount, tcWidth, radius, cornerInnerRadiusFactor, sampleElementOut) + elementsCountAroundHaustrum, tcCount, tcWidth, radius, cornerInnerRadiusFactor, sampleElementOut) for i in range(len(xHalfSet)): d2HalfSet.append([0.0, 0.0, 0.0]) x, d1, _ = getFullProfileFromHalfHaustrum(xHalfSet, d1HalfSet, d2HalfSet, tcCount) - z = segmentLength/elementsCountAlongSegment * n2 + z = segmentLength / elementsCountAlongSegment * n2 d1Final = d1Final + d1 xFace = [] for n1 in range(elementsCountAroundTC + elementsCountAroundHaustrum): xFinal.append([x[n1][0], x[n1][1], z]) xFace.append([x[n1][0], x[n1][1], z]) xiFace, lengthAroundFace = getXiListFromOuterLengthProfile(xFace, d1, segmentAxis, - wallThickness, transitElementList) + wallThickness, transitElementList) xiList.append(xiFace) relaxedLengthList.append(lengthAroundFace) contractedWallThicknessList.append(wallThickness) @@ -617,8 +622,8 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, for n2 in range(elementsCountAlongSegment + 1): n = elementsCountAround * n2 + n1 xUp.append(xFinal[n]) - d2 = [ xFinal[n + elementsCountAround][i] - xFinal[n][i] if n2 < elementsCountAlongSegment else - xFinal[n][i] - xFinal[n - elementsCountAround][i] for i in range(3)] + d2 = [xFinal[n + elementsCountAround][i] - xFinal[n][i] if n2 < elementsCountAlongSegment else + xFinal[n][i] - xFinal[n - elementsCountAround][i] for i in range(3)] d2Up.append(d2) d2Smoothed = interp.smoothCubicHermiteDerivativesLine(xUp, d2Up) d2Raw.append(d2Smoothed) @@ -631,7 +636,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, # Create annotation groups for mouse colon mzGroup = AnnotationGroup(region, get_colon_term("mesenteric zone")) nonmzGroup = AnnotationGroup(region, get_colon_term("non-mesenteric zone")) - elementsCountAroundGroups = [int(elementsCountAroundTC*0.5), + elementsCountAroundGroups = [int(elementsCountAroundTC * 0.5), elementsCountAroundHaustrum, int(elementsCountAroundTC * 0.5)] @@ -644,7 +649,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, annotationGroupsAround.append(annotationGroupAround[i]) else: - elementsCountAroundHalfHaustrum = int((elementsCountAroundTC + elementsCountAroundHaustrum)*0.5) + elementsCountAroundHalfHaustrum = int((elementsCountAroundTC + elementsCountAroundHaustrum) * 0.5) d1AtStartOfEachMidFace = [] d1Corrected = [] @@ -689,21 +694,21 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, xFace = [] d1Face = [] for n1 in range(elementsCountAroundHalfHaustrum + 1): - radiansAround = (math.pi*2/(tcCount*2)) / elementsCountAroundHalfHaustrum * n1 - d2Start = [ sdRadius*0.5, 0.0, segmentLength*0.5 ] - d2Mid = [ sdRadius*0.5, 0.0, segmentLength*0.5 ] - d2End = [ sdRadius*0.5, 0.0, segmentLength*0.5 ] + radiansAround = (math.pi * 2 / (tcCount * 2)) / elementsCountAroundHalfHaustrum * n1 + d2Start = [sdRadius * 0.5, 0.0, segmentLength * 0.5] + d2Mid = [sdRadius * 0.5, 0.0, segmentLength * 0.5] + d2End = [sdRadius * 0.5, 0.0, segmentLength * 0.5] - if n1 > elementsCountAroundTC*0.5: + if n1 > elementsCountAroundTC * 0.5: # Non tenia coli # Rotate about segment axis (z-axis) d2StartRot = matrix.rotateAboutZAxis(d2Start, radiansAround) d2MidRot = matrix.rotateAboutZAxis(d2Mid, radiansAround) d2EndRot = matrix.rotateAboutZAxis(d2End, radiansAround) - d1 = [ c*segmentLengthEndDerivativeFactor for c in d2StartRot ] - d2 = [ c*segmentLengthMidDerivativeFactor for c in d2MidRot ] - d3 = [ c*segmentLengthEndDerivativeFactor for c in d2EndRot ] + d1 = [c * segmentLengthEndDerivativeFactor for c in d2StartRot] + d2 = [c * segmentLengthMidDerivativeFactor for c in d2MidRot] + d3 = [c * segmentLengthEndDerivativeFactor for c in d2EndRot] else: # Tenia coli do not have haustra so not subjected to derivative scaling along segment @@ -712,17 +717,17 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, d3 = d2End v1 = [xHalfSetStart[n1][0], xHalfSetStart[n1][1], 0.0] - v2 = [xHalfSetMid[n1][0], xHalfSetMid[n1][1], segmentLength/2] + v2 = [xHalfSetMid[n1][0], xHalfSetMid[n1][1], segmentLength / 2] v3 = [xHalfSetStart[n1][0], xHalfSetStart[n1][1], segmentLength] nx = [v1, v2, v3] nd1 = [d1, d2, d3] - sx, sd1, se, sxi, _ = interp.sampleCubicHermiteCurves(nx, nd1, elementsCountAlongSegment) + sx, sd1, se, sxi, _ = interp.sampleCubicHermiteCurves(nx, nd1, elementsCountAlongSegment) # Find start phase - faceStartPhase = (360.0/elementsCountAlongSegment * n2 + startPhase) % 360.0 - offsetLength = (360.0/elementsCountAlongSegment * n2 + startPhase) // 360.0 + faceStartPhase = (360.0 / elementsCountAlongSegment * n2 + startPhase) % 360.0 + offsetLength = (360.0 / elementsCountAlongSegment * n2 + startPhase) // 360.0 # Find start point phasePerElementAlongSegment = 360.0 / elementsCountAlongSegment @@ -732,7 +737,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, xStart = interp.interpolateCubicHermite(sx[downstreamStartFaceIdx], sd1[downstreamStartFaceIdx], sx[downstreamStartFaceIdx + 1], sd1[downstreamStartFaceIdx + 1], xiStartPhase) - xStart[2] = xStart[2] + offsetLength*segmentLength + xStart[2] = xStart[2] + offsetLength * segmentLength d1Start = interp.interpolateCubicHermiteDerivative(sx[downstreamStartFaceIdx], sd1[downstreamStartFaceIdx], sx[downstreamStartFaceIdx + 1], @@ -753,7 +758,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, d1ForSamplingAlong.append(d1ForSampling[n2][n1]) xResampled, d1Resampled, se, sxi, _ = interp.sampleCubicHermiteCurves(xForSamplingAlong, d1ForSamplingAlong, elementsCountAlongSegment, - arcLengthDerivatives = True) + arcLengthDerivatives=True) xInnerRaw.append(xResampled) dx_ds2InnerRaw.append(d1Resampled) @@ -764,7 +769,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, xAround = [] d2Around = [] - for n1 in range(elementsCountAroundHalfHaustrum+1): + for n1 in range(elementsCountAroundHalfHaustrum + 1): x = xInnerRaw[n1][n2] # Bring first face back to origin x = [x[0], x[1], x[2] - lengthToFirstPhase] @@ -775,7 +780,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, dx_ds1InnerAroundList = [] if startPhase == 0.0 and n2 == 0: d1Corrected = d1Phase0FirstFace - elif startPhase == 0.0 and elementsCountAlongSegment%2 == 0 and n2 == int(elementsCountAlongSegment*0.5): + elif startPhase == 0.0 and elementsCountAlongSegment % 2 == 0 and n2 == int(elementsCountAlongSegment * 0.5): dx_ds1InnerAroundList = dx_ds1InnerAroundList + d1Phase0MidFace elif startPhase == 0.0 and n2 > elementsCountAlongSegment - 1: d1Corrected = d1Phase0LastFace @@ -784,7 +789,7 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, dx_ds1InnerAroundList = dx_ds1InnerAroundList + d1180FirstFace elif startPhase == 180.0 and n2 > elementsCountAlongSegment - 1: dx_ds1InnerAroundList = dx_ds1InnerAroundList + d1180LastFace - elif startPhase == 180.0 and elementsCountAlongSegment%2 == 0 and n2 == int(elementsCountAlongSegment*0.5): + elif startPhase == 180.0 and elementsCountAlongSegment % 2 == 0 and n2 == int(elementsCountAlongSegment * 0.5): d1Corrected = d1180MidFace else: @@ -794,38 +799,38 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, d1 = d1AtStartOfEachMidFace[n2] if n1 == 0 else [v2[c] - v1[c] for c in range(3)] d2 = [v2[c] - v1[c] for c in range(3)] arcLengthAround = interp.computeCubicHermiteArcLength(v1, d1, v2, d2, True) - dx_ds1 = [c*arcLengthAround for c in vector.normalise(d1) ] + dx_ds1 = [c * arcLengthAround for c in vector.normalise(d1)] dx_ds1InnerAroundList.append(dx_ds1) # Account for d1 of node sitting on half haustrum d1 = vector.normalise([xAround[elementsCountAroundHalfHaustrum][c] - xAround[elementsCountAroundHalfHaustrum - 1][c] for c in range(3)]) - dx_ds1 = [c*arcLengthAround for c in d1] + dx_ds1 = [c * arcLengthAround for c in d1] dx_ds1InnerAroundList.append(dx_ds1) if dx_ds1InnerAroundList: d1Smoothed = interp.smoothCubicHermiteDerivativesLine(xAround, dx_ds1InnerAroundList, - fixStartDerivative = True) - d1TCEdge = vector.setMagnitude(d1Smoothed[int(elementsCountAroundTC*0.5)], - vector.magnitude(d1Smoothed[int(elementsCountAroundTC*0.5 - 1)])) - d1Transition = vector.setMagnitude(d1Smoothed[int(elementsCountAroundTC*0.5 + 1)], - vector.magnitude(d1Smoothed[int(elementsCountAroundTC*0.5 + 2)])) + fixStartDerivative=True) + d1TCEdge = vector.setMagnitude(d1Smoothed[int(elementsCountAroundTC * 0.5)], + vector.magnitude(d1Smoothed[int(elementsCountAroundTC * 0.5 - 1)])) + d1Transition = vector.setMagnitude(d1Smoothed[int(elementsCountAroundTC * 0.5 + 1)], + vector.magnitude(d1Smoothed[int(elementsCountAroundTC * 0.5 + 2)])) d1Corrected = [] - d1Corrected = d1Corrected + d1Smoothed[:int(elementsCountAroundTC*0.5)] + d1Corrected = d1Corrected + d1Smoothed[:int(elementsCountAroundTC * 0.5)] d1Corrected.append(d1TCEdge) d1Corrected.append(d1Transition) - d1Corrected = d1Corrected + d1Smoothed[int(elementsCountAroundTC*0.5 + 2):] + d1Corrected = d1Corrected + d1Smoothed[int(elementsCountAroundTC * 0.5 + 2):] xAlongList, d1AlongList, d2AlongList = getFullProfileFromHalfHaustrum(xAround, d1Corrected, d2Around, tcCount) # Calculate xiList for relaxed state xHalfSetRelaxed, d1HalfSetRelaxed = createHalfSetIntraHaustralSegment(elementsCountAroundTC, - elementsCountAroundHaustrum, tcCount, tcWidthSegmentList[n2], radiusSegmentList[n2], - cornerInnerRadiusFactor, sampleElementOut, haustrumInnerRadiusFactor) + elementsCountAroundHaustrum, tcCount, tcWidthSegmentList[n2], radiusSegmentList[n2], + cornerInnerRadiusFactor, sampleElementOut, haustrumInnerRadiusFactor) xRelaxed, d1Relaxed, _ = getFullProfileFromHalfHaustrum(xHalfSetRelaxed, d1HalfSetRelaxed, d2Around, tcCount) xiFace, relaxedLengthAroundFace = getXiListFromOuterLengthProfile(xRelaxed, d1Relaxed, segmentAxis, - wallThickness, transitElementList) + wallThickness, transitElementList) xiList.append(xiFace) relaxedLengthList.append(relaxedLengthAroundFace) @@ -841,13 +846,14 @@ def getColonSegmentInnerPoints(region, elementsCountAroundTC, # Create annotation groups annotationGroupsAround = [] for i in range(elementsCountAround): - annotationGroupsAround.append([ ]) + annotationGroupsAround.append([]) return xFinal, d1Final, d2Final, transitElementList, xiList, relaxedLengthList, contractedWallThicknessList, \ segmentAxis, annotationGroupsAround + def createHalfSetInterHaustralSegment(elementsCountAroundTC, elementsCountAroundHaustrum, - tcCount, tcWidth, radius, cornerInnerRadiusFactor, sampleElementOut): + tcCount, tcWidth, radius, cornerInnerRadiusFactor, sampleElementOut): """ Find locations and derivative of nodes in half of an inter-haustral segment. Circular profile for segment @@ -873,16 +879,16 @@ def createHalfSetInterHaustralSegment(elementsCountAroundTC, elementsCountAround d1HalfSetInterHaustra = [] # Set up profile - if tcCount < 3: # Circular profile - xLoop, d1Loop = createCirclePoints([ 0.0, 0.0, 0.0 ], [ radius, 0.0, 0.0 ], [ 0.0, radius, 0.0 ], - sampleElementOut, startRadians = 0.0) + if tcCount < 3: # Circular profile + xLoop, d1Loop = createCirclePoints([0.0, 0.0, 0.0], [radius, 0.0, 0.0], [0.0, radius, 0.0], + sampleElementOut, startRadians=0.0) - else: # tcCount == 3, Triangular profile - cornerRC = cornerInnerRadiusFactor*radius - radiansRangeRC = [7*math.pi/4, 0.0, math.pi/4] + else: # tcCount == 3, Triangular profile + cornerRC = cornerInnerRadiusFactor * radius + radiansRangeRC = [7 * math.pi / 4, 0.0, math.pi / 4] for n1 in range(3): - radiansAround = n1*2.0*math.pi / 3.0 + radiansAround = n1 * 2.0 * math.pi / 3.0 cosRadiansAround = math.cos(radiansAround) sinRadiansAround = math.sin(radiansAround) xc = [(radius - cornerRC) * cosRadiansAround, (radius - cornerRC) * sinRadiansAround, 0.0] @@ -891,14 +897,14 @@ def createHalfSetInterHaustralSegment(elementsCountAroundTC, elementsCountAround radiansRC = radiansAround + radiansRangeRC[n] cosRadiansRC = math.cos(radiansRC) sinRadiansRC = math.sin(radiansRC) - x = [xc[0] + cornerRC*cosRadiansRC, xc[1] + cornerRC*sinRadiansRC, 0.0] + x = [xc[0] + cornerRC * cosRadiansRC, xc[1] + cornerRC * sinRadiansRC, 0.0] xAround.append(x) - d1 = [ cornerRC*math.pi/4.0 * -sinRadiansRC, cornerRC*math.pi/4.0 * cosRadiansRC, 0.0] + d1 = [cornerRC * math.pi / 4.0 * -sinRadiansRC, cornerRC * math.pi / 4.0 * cosRadiansRC, 0.0] d1Around.append(d1) - xSample = xAround[1:9] +[xAround[0], xAround[1]] - d1Sample = d1Around[1:9] +[d1Around[0], d1Around[1]] - sx, sd1, _, _, _= interp.sampleCubicHermiteCurves(xSample, d1Sample, sampleElementOut) + xSample = xAround[1:9] + [xAround[0], xAround[1]] + d1Sample = d1Around[1:9] + [d1Around[0], d1Around[1]] + sx, sd1, _, _, _ = interp.sampleCubicHermiteCurves(xSample, d1Sample, sampleElementOut) xLoop = sx[:-1] d1Loop = interp.smoothCubicHermiteDerivativesLoop(sx[:-1], sd1[:-1]) @@ -907,7 +913,7 @@ def createHalfSetInterHaustralSegment(elementsCountAroundTC, elementsCountAround arcLength = arcDistance * sampleElementOut arcStart = 0.0 numberOfHalves = tcCount * 2 - arcEnd = arcLength/numberOfHalves + arcEnd = arcLength / numberOfHalves # Find edge of TC arcDistanceTCEdge = findEdgeOfTeniaColi(xLoop, d1Loop, tcWidth, arcStart, arcEnd) @@ -917,15 +923,16 @@ def createHalfSetInterHaustralSegment(elementsCountAroundTC, elementsCountAround # Sample haustrum into equally sized elements xHaustrum, d1Haustrum, _, _ = sampleHaustrum(xLoop, d1Loop, xTC[-1], d1TC[-1], - arcLength/numberOfHalves, arcDistanceTCEdge, elementsCountAroundHaustrum) + arcLength / numberOfHalves, arcDistanceTCEdge, elementsCountAroundHaustrum) xHalfSetInterHaustra = xHalfSetInterHaustra + xTC + xHaustrum[1:] d1HalfSetInterHaustra = d1HalfSetInterHaustra + d1TC + d1Haustrum[1:] return xHalfSetInterHaustra, d1HalfSetInterHaustra + def createHalfSetIntraHaustralSegment(elementsCountAroundTC, elementsCountAroundHaustrum, - tcCount, tcWidth, radius, cornerInnerRadiusFactor, sampleElementOut, haustrumInnerRadiusFactor): + tcCount, tcWidth, radius, cornerInnerRadiusFactor, sampleElementOut, haustrumInnerRadiusFactor): """ Find locations and derivative of nodes in half of an intra-haustral segment. Bow-tie profile for segment with two tenia coli and @@ -954,34 +961,34 @@ def createHalfSetIntraHaustralSegment(elementsCountAroundTC, elementsCountAround d1HalfSetIntraHaustra = [] # Set up profile - cornerRC = cornerInnerRadiusFactor*radius - haustrumRadius = (haustrumInnerRadiusFactor + 1)*radius - if tcCount == 2: # Bow-tie profile - originRC = (radius*radius - haustrumRadius*haustrumRadius)/(-2.0*haustrumRadius) + cornerRC = cornerInnerRadiusFactor * radius + haustrumRadius = (haustrumInnerRadiusFactor + 1) * radius + if tcCount == 2: # Bow-tie profile + originRC = (radius * radius - haustrumRadius * haustrumRadius) / (-2.0 * haustrumRadius) RC = haustrumRadius - originRC - thetaStart = math.asin(-originRC/ RC) + thetaStart = math.asin(-originRC / RC) thetaEnd = math.pi - thetaStart - rotOriginRC = [ 0.0, -originRC, 0.0 ] - - else: # tcCount == 3, Clover profile - xc = [(radius - cornerRC)* math.cos(0.0), (radius - cornerRC)*math.sin(0.0), 0.0] - pt1 = [xc[0] + cornerRC*math.cos(0.0), xc[1] + cornerRC*math.sin(0.0), 0.0] - xTC2 = radius* math.cos(2.0*math.pi/3.0) - yTC2 = radius* math.sin(2.0*math.pi/3.0) - originRC = (xTC2*xTC2 + yTC2*yTC2 - haustrumRadius*haustrumRadius) / (2*(-xTC2 - haustrumRadius)) + rotOriginRC = [0.0, -originRC, 0.0] + + else: # tcCount == 3, Clover profile + xc = [(radius - cornerRC) * math.cos(0.0), (radius - cornerRC) * math.sin(0.0), 0.0] + pt1 = [xc[0] + cornerRC * math.cos(0.0), xc[1] + cornerRC * math.sin(0.0), 0.0] + xTC2 = radius * math.cos(2.0 * math.pi / 3.0) + yTC2 = radius * math.sin(2.0 * math.pi / 3.0) + originRC = (xTC2 * xTC2 + yTC2 * yTC2 - haustrumRadius * haustrumRadius) / (2 * (-xTC2 - haustrumRadius)) RC = haustrumRadius - originRC # Rotate to find originRC of 1st haustrum yTC1 = pt1[1] - rotOriginRC = [ originRC*math.cos(-2.0/3.0*math.pi), originRC*math.sin(-2.0/3.0*math.pi), 0.0] + rotOriginRC = [originRC * math.cos(-2.0 / 3.0 * math.pi), originRC * math.sin(-2.0 / 3.0 * math.pi), 0.0] thetaStart = math.asin((yTC1 + rotOriginRC[1]) / RC) - thetaEnd = math.pi - math.asin((yTC2 + rotOriginRC[1])/ RC) + thetaEnd = math.pi - math.asin((yTC2 + rotOriginRC[1]) / RC) - thetaHalfHaustrum = (thetaEnd + thetaStart)*0.5 + thetaHalfHaustrum = (thetaEnd + thetaStart) * 0.5 concaveFactor = 0.15 - thetaConcave = (thetaEnd - thetaStart)*concaveFactor + thetaStart - thetaCircularStart = (thetaEnd - thetaStart)*(concaveFactor + 0.5)*0.5 + thetaStart + thetaConcave = (thetaEnd - thetaStart) * concaveFactor + thetaStart + thetaCircularStart = (thetaEnd - thetaStart) * (concaveFactor + 0.5) * 0.5 + thetaStart thetaSet = [thetaStart, thetaConcave] xConcave, _ = getCircleXandD1FromRadians(thetaSet, RC, rotOriginRC) @@ -992,11 +999,11 @@ def createHalfSetIntraHaustralSegment(elementsCountAroundTC, elementsCountAround xCircular, d1Circular = getCircleXandD1FromRadians(thetaCircularSet, RC, rotOriginRC) nxHaustrum = nxHaustrum + xCircular nd1Haustrum = nd1Haustrum + d1Circular - smoothd1 = interp.smoothCubicHermiteDerivativesLine(nxHaustrum, nd1Haustrum, fixStartDirection = True, - fixEndDirection = True) + smoothd1 = interp.smoothCubicHermiteDerivativesLine(nxHaustrum, nd1Haustrum, fixStartDirection=True, + fixEndDirection=True) # Find max x along path - sxHaustrum, sd1Haustrum, _, _ , _ = interp.sampleCubicHermiteCurves(nxHaustrum, smoothd1, sampleElementOut) + sxHaustrum, sd1Haustrum, _, _, _ = interp.sampleCubicHermiteCurves(nxHaustrum, smoothd1, sampleElementOut) xVal = [] for i in range(len(sxHaustrum)): xVal.append(sxHaustrum[i][0]) @@ -1005,13 +1012,13 @@ def createHalfSetIntraHaustralSegment(elementsCountAroundTC, elementsCountAround yAtMaxValue = sxHaustrum[maxIndex][1] arcLength = 0.0 - for e in range(len(nxHaustrum)-1): - arcDistance = interp.getCubicHermiteArcLength(nxHaustrum[e], smoothd1[e], nxHaustrum[e+1], smoothd1[e+1]) + for e in range(len(nxHaustrum) - 1): + arcDistance = interp.getCubicHermiteArcLength(nxHaustrum[e], smoothd1[e], nxHaustrum[e + 1], smoothd1[e + 1]) arcLength = arcLength + arcDistance arcDistanceAtMaxValue = arcLength / sampleElementOut * maxIndex - arcStart = 0.0 if yAtMaxValue > tcWidth*0.5 else arcDistanceAtMaxValue - arcEnd = arcDistanceAtMaxValue if yAtMaxValue > tcWidth*0.5 else arcLength + arcStart = 0.0 if yAtMaxValue > tcWidth * 0.5 else arcDistanceAtMaxValue + arcEnd = arcDistanceAtMaxValue if yAtMaxValue > tcWidth * 0.5 else arcLength # Find edge of TC arcDistanceTCEdge = findEdgeOfTeniaColi(nxHaustrum, smoothd1, tcWidth, arcStart, arcEnd) @@ -1029,6 +1036,7 @@ def createHalfSetIntraHaustralSegment(elementsCountAroundTC, elementsCountAround return xHalfSetIntraHaustra, d1HalfSetIntraHaustra + def findEdgeOfTeniaColi(nx, nd1, tcWidth, arcStart, arcEnd): """ Locate edge of tenia coli on a cubic hermite interpolated @@ -1044,9 +1052,9 @@ def findEdgeOfTeniaColi(nx, nd1, tcWidth, arcStart, arcEnd): """ xTol = 1.0E-6 for iter in range(100): - arcDistance = (arcStart + arcEnd)*0.5 + arcDistance = (arcStart + arcEnd) * 0.5 x, d1, _, _ = interp.getCubicHermiteCurvesPointAtArcDistance(nx, nd1, arcDistance) - diff = x[1] - tcWidth*0.5 + diff = x[1] - tcWidth * 0.5 if abs(diff) > xTol: if diff < 0.0: arcStart = arcDistance @@ -1056,10 +1064,11 @@ def findEdgeOfTeniaColi(nx, nd1, tcWidth, arcStart, arcEnd): arcDistanceTCEdge = arcDistance break if iter > 99: - print('Search for TC boundary - Max iters reached:',iter) + print('Search for TC boundary - Max iters reached:', iter) return arcDistanceTCEdge + def sampleTeniaColi(nx, nd1, arcDistanceTCEdge, elementsCountAroundTC): """ Get systematically spaced points and derivatives over the width of @@ -1074,8 +1083,8 @@ def sampleTeniaColi(nx, nd1, arcDistanceTCEdge, elementsCountAroundTC): """ xTC = [] d1TC = [] - arcDistancePerElementTC = arcDistanceTCEdge / (elementsCountAroundTC*0.5) - for e in range(int(elementsCountAroundTC*0.5)+1): + arcDistancePerElementTC = arcDistanceTCEdge / (elementsCountAroundTC * 0.5) + for e in range(int(elementsCountAroundTC * 0.5) + 1): arcDistance = arcDistancePerElementTC * e x, d1, _, _ = interp.getCubicHermiteCurvesPointAtArcDistance(nx, nd1, arcDistance) d1Scaled = vector.setMagnitude(d1, arcDistancePerElementTC) @@ -1084,8 +1093,9 @@ def sampleTeniaColi(nx, nd1, arcDistanceTCEdge, elementsCountAroundTC): return xTC, d1TC, arcDistancePerElementTC + def sampleHaustrum(nx, nd1, xTCLast, d1TCLast, arcLength, arcDistanceTCEdge, - elementsCountAroundHaustrum): + elementsCountAroundHaustrum): """ Get systematically spaced points and derivatives over the width of haustrum over a cubic hermite interpolated curves defined by nodes @@ -1108,8 +1118,8 @@ def sampleHaustrum(nx, nd1, xTCLast, d1TCLast, arcLength, arcDistanceTCEdge, addLengthStart = 0.5 * vector.magnitude(d1TCLast) lengthFractionStart = 0.5 proportionStart = 1.0 - elementLengthMid = (length - addLengthStart) / (elementsCountOut - 1.0 + proportionStart*lengthFractionStart) - elementLengthProportionStart = proportionStart*lengthFractionStart*elementLengthMid + elementLengthMid = (length - addLengthStart) / (elementsCountOut - 1.0 + proportionStart * lengthFractionStart) + elementLengthProportionStart = proportionStart * lengthFractionStart * elementLengthMid elementLengthProportionEnd = elementLengthMid for e in range(elementsCountOut): @@ -1127,12 +1137,13 @@ def sampleHaustrum(nx, nd1, xTCLast, d1TCLast, arcLength, arcDistanceTCEdge, for e in range(elementsCountOut): arcDistance = arcDistance + elementLengths[e] x, d1, _, _ = interp.getCubicHermiteCurvesPointAtArcDistance(nx, nd1, arcDistance) - d1Scaled = vector.setMagnitude(d1, elementLengths[e] if e > 0 else elementLengths[e+1]) + d1Scaled = vector.setMagnitude(d1, elementLengths[e] if e > 0 else elementLengths[e + 1]) xHaustrum.append(x) d1Haustrum.append(d1Scaled) return xHaustrum, d1Haustrum, haustrumElementLength, transitionElementLength + def getCircleXandD1FromRadians(thetaSet, radius, origin): """ Gets the coordinates and derivatives along a circular path @@ -1148,19 +1159,20 @@ def getCircleXandD1FromRadians(thetaSet, radius, origin): dTheta = thetaSet[1] - thetaSet[0] for n in range(2): theta = thetaSet[n] - x = [radius*math.cos(theta) - origin[0], - radius*math.sin(theta) - origin[1], - 0.0] - d1 = [-radius*math.sin(theta)*dTheta, - radius*math.cos(theta)*dTheta, - 0.0] + x = [radius * math.cos(theta) - origin[0], + radius * math.sin(theta) - origin[1], + 0.0] + d1 = [-radius * math.sin(theta) * dTheta, + radius * math.cos(theta) * dTheta, + 0.0] nx.append(x) nd1.append(d1) return nx, nd1 + def getFullProfileFromHalfHaustrum(xHaustrumHalfSet, d1HaustrumHalfSet, - d2HaustrumHalfSet, tcCount): + d2HaustrumHalfSet, tcCount): """ Gets the coordinates and derivatives of the entire profile using points from first half of the first sector. The first @@ -1184,25 +1196,25 @@ def getFullProfileFromHalfHaustrum(xHaustrumHalfSet, d1HaustrumHalfSet, xHaustra = [] d1Haustra = [] d2Haustra = [] - rotAng = 2*math.pi/tcCount + rotAng = 2 * math.pi / tcCount - for n in range(1,len(xHaustrumHalfSet)): - idx = -n + len(xHaustrumHalfSet) - 1 + for n in range(1, len(xHaustrumHalfSet)): + idx = -n + len(xHaustrumHalfSet) - 1 x = xHaustrumHalfSet[idx] d1 = d1HaustrumHalfSet[idx] xReflect = [x[0], -x[1], x[2]] d1Reflect = [d1[0], -d1[1], d1[2]] - xRot = [xReflect[0]*math.cos(rotAng) - xReflect[1]*math.sin(rotAng), - xReflect[0]*math.sin(rotAng) + xReflect[1]*math.cos(rotAng), + xRot = [xReflect[0] * math.cos(rotAng) - xReflect[1] * math.sin(rotAng), + xReflect[0] * math.sin(rotAng) + xReflect[1] * math.cos(rotAng), xReflect[2]] - d1Rot = [-(d1Reflect[0]*math.cos(rotAng) - d1Reflect[1]*math.sin(rotAng)), - -(d1Reflect[0]*math.sin(rotAng) + d1Reflect[1]*math.cos(rotAng)), - -d1Reflect[2]] + d1Rot = [-(d1Reflect[0] * math.cos(rotAng) - d1Reflect[1] * math.sin(rotAng)), + -(d1Reflect[0] * math.sin(rotAng) + d1Reflect[1] * math.cos(rotAng)), + -d1Reflect[2]] d2 = d2HaustrumHalfSet[idx] d2Reflect = [d2[0], -d2[1], d2[2]] - d2Rot = [(d2Reflect[0]*math.cos(rotAng) - d2Reflect[1]*math.sin(rotAng)), - (d2Reflect[0]*math.sin(rotAng) + d2Reflect[1]*math.cos(rotAng)), - d2Reflect[2]] + d2Rot = [(d2Reflect[0] * math.cos(rotAng) - d2Reflect[1] * math.sin(rotAng)), + (d2Reflect[0] * math.sin(rotAng) + d2Reflect[1] * math.cos(rotAng)), + d2Reflect[2]] xHaustrumHalfSet2.append(xRot) d1HaustrumHalfSet2.append(d1Rot) d2HaustrumHalfSet2.append(d2Rot) @@ -1216,26 +1228,27 @@ def getFullProfileFromHalfHaustrum(xHaustrumHalfSet, d1HaustrumHalfSet, d1Haustra = d1Haustra + d1Haustrum[:-1] d2Haustra = d2Haustra + d2Haustrum[:-1] - ang = [ 2/3*math.pi, -2/3*math.pi] if tcCount == 3 else [math.pi] + ang = [2 / 3 * math.pi, -2 / 3 * math.pi] if tcCount == 3 else [math.pi] for i in range(tcCount - 1): rotAng = ang[i] cosRotAng = math.cos(rotAng) sinRotAng = math.sin(rotAng) - for n in range(len(xHaustrum)- 1): + for n in range(len(xHaustrum) - 1): x = xHaustrum[n] d1 = d1Haustrum[n] d2 = d2Haustrum[n] - x = [ x[0]*cosRotAng - x[1]*sinRotAng, x[0]*sinRotAng + x[1]*cosRotAng, x[2]] + x = [x[0] * cosRotAng - x[1] * sinRotAng, x[0] * sinRotAng + x[1] * cosRotAng, x[2]] xHaustra.append(x) - dx_ds1 = [ d1[0]*cosRotAng - d1[1]*sinRotAng, d1[0]*sinRotAng + d1[1]*cosRotAng, d1[2]] + dx_ds1 = [d1[0] * cosRotAng - d1[1] * sinRotAng, d1[0] * sinRotAng + d1[1] * cosRotAng, d1[2]] d1Haustra.append(dx_ds1) - dx_ds2 = [ d2[0]*cosRotAng - d2[1]*sinRotAng, d2[0]*sinRotAng + d2[1]*cosRotAng, d2[2]] + dx_ds2 = [d2[0] * cosRotAng - d2[1] * sinRotAng, d2[0] * sinRotAng + d2[1] * cosRotAng, d2[2]] d2Haustra.append(dx_ds2) return xHaustra, d1Haustra, d2Haustra + def getXiListFromOuterLengthProfile(xInner, d1Inner, segmentAxis, - wallThickness, transitElementList): + wallThickness, transitElementList): """ Gets a list of xi for flat coordinates calculated from outer arclength of elements around a segment (most relaxed state). @@ -1260,30 +1273,30 @@ def getXiListFromOuterLengthProfile(xInner, d1Inner, segmentAxis, for n in range(len(xInner)): norm = unitNormList[n] # Calculate outer coordinates - x = [xInner[n][i] + norm[i]*wallThickness for i in range(3)] + x = [xInner[n][i] + norm[i] * wallThickness for i in range(3)] xOuter.append(x) # Calculate curvature along elements around prevIdx = n - 1 if (n != 0) else len(xInner) - 1 nextIdx = n + 1 if (n < (len(xInner) - 1)) else 0 kappam = interp.getCubicHermiteCurvatureSimple(xInner[prevIdx], d1Inner[prevIdx], xInner[n], d1Inner[n], 1.0) kappap = interp.getCubicHermiteCurvatureSimple(xInner[n], d1Inner[n], xInner[nextIdx], d1Inner[nextIdx], 0.0) - if not transitElementList[n] and not transitElementList[(n-1)%(len(xInner))]: - curvatureAround = 0.5*(kappam + kappap) + if not transitElementList[n] and not transitElementList[(n - 1) % (len(xInner))]: + curvatureAround = 0.5 * (kappam + kappap) elif transitElementList[n]: curvatureAround = kappam - elif transitElementList[(n-1) % (len(xInner))]: + elif transitElementList[(n - 1) % (len(xInner))]: curvatureAround = kappap curvatureInner.append(curvatureAround) for n in range(len(xOuter)): factor = 1.0 + wallThickness * curvatureInner[n] - dx_ds1 = [ factor*c for c in d1Inner[n]] + dx_ds1 = [factor * c for c in d1Inner[n]] d1Outer.append(dx_ds1) arcLengthList = [] for n1 in range(len(xOuter)): arcLengthPerElement = interp.getCubicHermiteArcLength(xOuter[n1], d1Outer[n1], - xOuter[(n1+1) % len(xOuter)], d1Outer[(n1+1)% len(xOuter)]) + xOuter[(n1 + 1) % len(xOuter)], d1Outer[(n1 + 1) % len(xOuter)]) arcLengthList.append(arcLengthPerElement) # Total arcLength @@ -1300,10 +1313,11 @@ def getXiListFromOuterLengthProfile(xInner, d1Inner, segmentAxis, return xiList, totalArcLengthOuter + def getTeniaColi(region, xList, d1List, d2List, d3List, curvatureList, - tcCount, elementsCountAroundTC, elementsCountAroundHaustrum, - elementsCountAlong, elementsCountThroughWall, - tubeTCWidthList, tcThickness, sx, annotationGroupsAround, closedProximalEnd): + tcCount, elementsCountAroundTC, elementsCountAroundHaustrum, + elementsCountAlong, elementsCountThroughWall, + tubeTCWidthList, tcThickness, sx, annotationGroupsAround, closedProximalEnd): """ Create equally spaced points for tenia coli over the outer surface of the colon. Points are sampled from a cubic @@ -1354,30 +1368,30 @@ def getTeniaColi(region, xList, d1List, d2List, d3List, curvatureList, elementsCountAround * elementsCountThroughWall + \ N * (elementsCountAroundTC + elementsCountAroundHaustrum) unitNorm = vector.normalise(d3List[idxTCMid]) - xMid = [xList[idxTCMid][i] + unitNorm[i]*tcThickness for i in range(3)] + xMid = [xList[idxTCMid][i] + unitNorm[i] * tcThickness for i in range(3)] d1Mid = d1List[idxTCMid] - TCStartIdx = idxTCMid - int(elementsCountAroundTC*0.5) if N > 0 else \ - idxTCMid + tcCount*(elementsCountAroundTC + elementsCountAroundHaustrum) - int(elementsCountAroundTC*0.5) - TCEndIdx = idxTCMid + int(elementsCountAroundTC*0.5) + TCStartIdx = idxTCMid - int(elementsCountAroundTC * 0.5) if N > 0 else \ + idxTCMid + tcCount * (elementsCountAroundTC + elementsCountAroundHaustrum) - int(elementsCountAroundTC * 0.5) + TCEndIdx = idxTCMid + int(elementsCountAroundTC * 0.5) if closedProximalEnd: tcWidth = vector.magnitude([xList[TCStartIdx][c] - xList[TCEndIdx][c] for c in range(3)]) v1 = xList[TCStartIdx] v2 = xMid - d1MidScaled = [c*tcWidth*TCEdgeFactor for c in vector.normalise(d1Mid)] + d1MidScaled = [c * tcWidth * TCEdgeFactor for c in vector.normalise(d1Mid)] v3 = xList[TCEndIdx] nx = [v1, v2, v3] nd1 = [d1List[TCStartIdx], d1MidScaled, d1List[TCEndIdx]] - sxTC, sd1TC, _, _, _ = interp.sampleCubicHermiteCurves(nx, nd1, elementsCountAroundTC) + sxTC, sd1TC, _, _, _ = interp.sampleCubicHermiteCurves(nx, nd1, elementsCountAroundTC) xTCRaw = xTCRaw + sxTC[1:-1] if elementsCountAroundTC == 2: p = [v2[i] - v1[i] for i in range(3)] - A = vector.dotproduct(unitNorm, p) # A<0 if v2 is higher than v1 - d1 = [c*tcWidth*0.5 for c in vector.normalise(d1Mid)] if A < 0 else d1MidScaled + A = vector.dotproduct(unitNorm, p) # A<0 if v2 is higher than v1 + d1 = [c * tcWidth * 0.5 for c in vector.normalise(d1Mid)] if A < 0 else d1MidScaled d1TCRaw = d1TCRaw + sd1TC[1:-1] if elementsCountAroundTC > 2 else d1TCRaw + [d1] - xTCInnerSet = list(range(TCStartIdx+1, TCEndIdx)) if N > 0 else \ - list(range(TCStartIdx + 1, TCStartIdx + int(elementsCountAroundTC * 0.5))) +\ - list(range(idxTCMid, idxTCMid + int(elementsCountAroundTC * 0.5))) + xTCInnerSet = list(range(TCStartIdx + 1, TCEndIdx)) if N > 0 else \ + list(range(TCStartIdx + 1, TCStartIdx + int(elementsCountAroundTC * 0.5))) + \ + list(range(idxTCMid, idxTCMid + int(elementsCountAroundTC * 0.5))) for n in range(elementsCountAroundTC - 1): xTCInner = xList[xTCInnerSet[n]] @@ -1386,25 +1400,25 @@ def getTeniaColi(region, xList, d1List, d2List, d3List, curvatureList, d3TCRaw.append(d3) d3List[xTCInnerSet[n]] = d3 - innerIdx = xTCInnerSet[n] - elementsCountThroughWall*elementsCountAround + innerIdx = xTCInnerSet[n] - elementsCountThroughWall * elementsCountAround curvature = curvatureList[innerIdx] distanceToInnerIdx = vector.magnitude([xTCOuter[i] - xList[innerIdx][i] for i in range(3)]) - factor = 1.0 - curvature*distanceToInnerIdx - d2 = [factor*c for c in d2List[innerIdx]] + factor = 1.0 - curvature * distanceToInnerIdx + d2 = [factor * c for c in d2List[innerIdx]] d2TCRaw.append(d2) - xTCArranged = xTCArranged + xTCRaw[int(elementsCountAroundTC*0.5 -1):] + \ - xTCRaw[:int(elementsCountAroundTC*0.5 -1)] - d1TCArranged = d1TCArranged + d1TCRaw[int(elementsCountAroundTC*0.5 -1):] + \ - d1TCRaw[:int(elementsCountAroundTC*0.5 -1)] - d2TCArranged = d2TCArranged + d2TCRaw[int(elementsCountAroundTC*0.5 -1):] + \ - d2TCRaw[:int(elementsCountAroundTC*0.5 -1)] - d3TCArranged = d3TCArranged + d3TCRaw[int(elementsCountAroundTC*0.5 -1):] + \ - d3TCRaw[:int(elementsCountAroundTC*0.5 -1)] + xTCArranged = xTCArranged + xTCRaw[int(elementsCountAroundTC * 0.5 - 1):] + \ + xTCRaw[:int(elementsCountAroundTC * 0.5 - 1)] + d1TCArranged = d1TCArranged + d1TCRaw[int(elementsCountAroundTC * 0.5 - 1):] + \ + d1TCRaw[:int(elementsCountAroundTC * 0.5 - 1)] + d2TCArranged = d2TCArranged + d2TCRaw[int(elementsCountAroundTC * 0.5 - 1):] + \ + d2TCRaw[:int(elementsCountAroundTC * 0.5 - 1)] + d3TCArranged = d3TCArranged + d3TCRaw[int(elementsCountAroundTC * 0.5 - 1):] + \ + d3TCRaw[:int(elementsCountAroundTC * 0.5 - 1)] x, d1, d2, d3 = combineTeniaColiWithColon(xList, d1List, d2List, d3List, xTCArranged, d1TCArranged, - d2TCArranged, d3TCArranged, (elementsCountAroundTC - 1)*tcCount, elementsCountAround, - elementsCountAlong, elementsCountThroughWall, closedProximalEnd) + d2TCArranged, d3TCArranged, (elementsCountAroundTC - 1) * tcCount, elementsCountAround, + elementsCountAlong, elementsCountThroughWall, closedProximalEnd) # Update annotation groups if tcCount == 2 or closedProximalEnd: @@ -1427,9 +1441,10 @@ def getTeniaColi(region, xList, d1List, d2List, d3List, curvatureList, return x, d1, d2, d3, annotationGroupsAround + def combineTeniaColiWithColon(xList, d1List, d2List, d3List, xTC, d1TC, d2TC, - d3TC, nodesCountAroundTC, elementsCountAround, elementsCountAlong, - elementsCountThroughWall, closedProximalEnd): + d3TC, nodesCountAroundTC, elementsCountAround, elementsCountAlong, + elementsCountThroughWall, closedProximalEnd): """ Arranges coordinates and derivatives around inner surface to outer surface, followed by tenia coli points before extending @@ -1483,10 +1498,11 @@ def combineTeniaColiWithColon(xList, d1List, d2List, d3List, xTC, d1TC, d2TC, return x, d1, d2, d3 + def createFlatCoordinatesTeniaColi(xiList, relaxedLengthList, - totalLengthAlong, wallThickness, relativeThicknessList, tcCount, tcThickness, - elementsCountAroundTC, elementsCountAroundHaustrum, - elementsCountAlong, elementsCountThroughWall, transitElementList, closedProximalEnd): + totalLengthAlong, wallThickness, relativeThicknessList, tcCount, tcThickness, + elementsCountAroundTC, elementsCountAroundHaustrum, + elementsCountAlong, elementsCountThroughWall, transitElementList, closedProximalEnd): """ Calculates flat coordinates for a colon scaffold with tenia coli when it is opened up into a flat preparation. @@ -1511,7 +1527,7 @@ def createFlatCoordinatesTeniaColi(xiList, relaxedLengthList, # Calculate flat coordinates factor = 3.0 if tcCount == 3 else 2.0 - elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum )*tcCount + elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum) * tcCount # Find flat coordinates for colon xFlatColon, d1FlatColon, d2FlatColon = tubemesh.createFlatCoordinates(xiList, relaxedLengthList, totalLengthAlong, @@ -1527,20 +1543,20 @@ def createFlatCoordinatesTeniaColi(xiList, relaxedLengthList, for n2 in range(elementsCountAlong + 1): xiFace = xiList[n2] relaxedLength = relaxedLengthList[n2] - xPad = (relaxedLengthList[0] - relaxedLength)*0.5 + xPad = (relaxedLengthList[0] - relaxedLength) * 0.5 for N in range(tcCount + 1): - idxTCMid = N*(elementsCountAroundTC + elementsCountAroundHaustrum) - TCStartIdx = idxTCMid - int(elementsCountAroundTC*0.5) - TCEndIdx = idxTCMid + int(elementsCountAroundTC*0.5) - dTC = (xiFace[idxTCMid] - xiFace[TCStartIdx])*relaxedLength if N > 0 else \ - (xiFace[TCEndIdx] - xiFace[idxTCMid])*relaxedLength - v1 = [xiFace[TCStartIdx]*relaxedLength, 0.0, wallThickness] if N > 0 else \ - [-dTC, 0.0, wallThickness] - v2 = [ xiFace[idxTCMid]*relaxedLength, 0.0, wallThickness + tcThickness] - v3 = [ xiFace[TCEndIdx]*relaxedLength, 0.0, wallThickness] if N < tcCount else \ - [ relaxedLength + dTC, 0.0, wallThickness] + idxTCMid = N * (elementsCountAroundTC + elementsCountAroundHaustrum) + TCStartIdx = idxTCMid - int(elementsCountAroundTC * 0.5) + TCEndIdx = idxTCMid + int(elementsCountAroundTC * 0.5) + dTC = (xiFace[idxTCMid] - xiFace[TCStartIdx]) * relaxedLength if N > 0 else \ + (xiFace[TCEndIdx] - xiFace[idxTCMid]) * relaxedLength + v1 = [xiFace[TCStartIdx] * relaxedLength, 0.0, wallThickness] if N > 0 else \ + [-dTC, 0.0, wallThickness] + v2 = [xiFace[idxTCMid] * relaxedLength, 0.0, wallThickness + tcThickness] + v3 = [xiFace[TCEndIdx] * relaxedLength, 0.0, wallThickness] if N < tcCount else \ + [relaxedLength + dTC, 0.0, wallThickness] d1 = d3 = [dTC, 0.0, 0.0] - d2 = [c*factor for c in [dTC, 0.0, 0.0]] + d2 = [c * factor for c in [dTC, 0.0, 0.0]] nx = [v1, v2, v3] nd1 = [d1, d2, d3] sx, sd1, _, _, _ = interp.sampleCubicHermiteCurves(nx, nd1, elementsCountAroundTC) @@ -1548,38 +1564,39 @@ def createFlatCoordinatesTeniaColi(xiList, relaxedLengthList, w = sx[1:-1] dw = sd1[1:-1] if elementsCountAroundTC > 2 else nd1[1:-1] elif N == 0: - w = sx[int(elementsCountAroundTC*0.5):-1] - dw = sd1[int(elementsCountAroundTC*0.5):-1] if elementsCountAroundTC > 2 else \ - nd1[int(elementsCountAroundTC*0.5):-1] + w = sx[int(elementsCountAroundTC * 0.5):-1] + dw = sd1[int(elementsCountAroundTC * 0.5):-1] if elementsCountAroundTC > 2 else \ + nd1[int(elementsCountAroundTC * 0.5):-1] else: - w = sx[1:int(elementsCountAroundTC*0.5)+1] - dw = sd1[1:int(elementsCountAroundTC*0.5)+1] if elementsCountAroundTC > 2 else \ - nd1[1:int(elementsCountAroundTC*0.5)+1] + w = sx[1:int(elementsCountAroundTC * 0.5) + 1] + dw = sd1[1:int(elementsCountAroundTC * 0.5) + 1] if elementsCountAroundTC > 2 else \ + nd1[1:int(elementsCountAroundTC * 0.5) + 1] for n in range(len(w)): - x = [ xPad + w[n][0], - totalLengthAlong / elementsCountAlong * n2, - w[n][2]] + x = [xPad + w[n][0], + totalLengthAlong / elementsCountAlong * n2, + w[n][2]] xFlatListTC.append(x) d1FlatListTC.append(dw[n]) for n2 in range(elementsCountAlong): - for n1 in range((elementsCountAroundTC - 1)*tcCount + 1): - nodeIdx = n2*((elementsCountAroundTC - 1)*tcCount + 1) + n1 - nodeNextElementAlong = nodeIdx + ((elementsCountAroundTC - 1)*tcCount + 1) + for n1 in range((elementsCountAroundTC - 1) * tcCount + 1): + nodeIdx = n2 * ((elementsCountAroundTC - 1) * tcCount + 1) + n1 + nodeNextElementAlong = nodeIdx + ((elementsCountAroundTC - 1) * tcCount + 1) v1 = xFlatListTC[nodeNextElementAlong] v2 = xFlatListTC[nodeIdx] d1 = d2 = [v1[i] - v2[i] for i in range(3)] arclength = interp.computeCubicHermiteArcLength(v1, d1, v2, d2, True) d2Flat = vector.setMagnitude(d1, arclength) d2FlatListTC.append(d2Flat) - d2FlatListTC = d2FlatListTC + d2FlatListTC[-((elementsCountAroundTC - 1)*tcCount + 1):] + d2FlatListTC = d2FlatListTC + d2FlatListTC[-((elementsCountAroundTC - 1) * tcCount + 1):] xFlat, d1Flat, d2Flat, _ = combineTeniaColiWithColon(xFlatColon, d1FlatColon, d2FlatColon, [], - xFlatListTC, d1FlatListTC, d2FlatListTC, [], (elementsCountAroundTC - 1)*tcCount + 1, - elementsCountAround + 1, elementsCountAlong, elementsCountThroughWall, closedProximalEnd) + xFlatListTC, d1FlatListTC, d2FlatListTC, [], (elementsCountAroundTC - 1) * tcCount + 1, + elementsCountAround + 1, elementsCountAlong, elementsCountThroughWall, closedProximalEnd) return xFlat, d1Flat, d2Flat + def createColonCoordinatesTeniaColi(xiList, relativeThicknessList, lengthToDiameterRatio, wallThicknessToDiameterRatio, teniaColiThicknessToDiameterRatio, tcCount, elementsCountAroundTC, elementsCountAroundHaustrum, elementsCountAlong, elementsCountThroughWall, @@ -1603,13 +1620,13 @@ def createColonCoordinatesTeniaColi(xiList, relativeThicknessList, lengthToDiame :return: coordinates and derivatives of colon coordinates field. """ # Calculate organ coordinates - elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum )*tcCount + elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum) * tcCount # Find organ coordinates for colon xColon, d1Colon, d2Colon = tubemesh.createOrganCoordinates(xiList, relativeThicknessList, lengthToDiameterRatio, - wallThicknessToDiameterRatio, elementsCountAround, - elementsCountAlong, elementsCountThroughWall, - transitElementList) + wallThicknessToDiameterRatio, elementsCountAround, + elementsCountAlong, elementsCountThroughWall, + transitElementList) # Find organ coordinates for tenia coli xTC = [] @@ -1623,11 +1640,11 @@ def createColonCoordinatesTeniaColi(xiList, relativeThicknessList, lengthToDiame d1TCRaw = [] d2TCRaw = [] for N in range(tcCount): - TCMidIdx = faceStartIdx + N*(elementsCountAroundTC + elementsCountAroundHaustrum) + TCMidIdx = faceStartIdx + N * (elementsCountAroundTC + elementsCountAroundHaustrum) TCStartIdx = TCMidIdx - int(elementsCountAroundTC * 0.5) if N > 0 else \ - TCMidIdx + tcCount * (elementsCountAroundTC + elementsCountAroundHaustrum) - int( - elementsCountAroundTC * 0.5) - TCEndIdx = TCMidIdx + int(elementsCountAroundTC*0.5) + TCMidIdx + tcCount * (elementsCountAroundTC + elementsCountAroundHaustrum) - int( + elementsCountAroundTC * 0.5) + TCEndIdx = TCMidIdx + int(elementsCountAroundTC * 0.5) v1 = xColon[TCStartIdx] norm = vector.setMagnitude( vector.crossproduct3(vector.normalise(d1Colon[TCMidIdx]), vector.normalise(d2Colon[TCMidIdx])), @@ -1636,7 +1653,7 @@ def createColonCoordinatesTeniaColi(xiList, relativeThicknessList, lengthToDiame v3 = xColon[TCEndIdx] nx = [v1, v2, v3] nd1 = [d1Colon[TCStartIdx], - vector.setMagnitude(d1Colon[TCMidIdx], 2.0*vector.magnitude(d1Colon[TCMidIdx])), + vector.setMagnitude(d1Colon[TCMidIdx], 2.0 * vector.magnitude(d1Colon[TCMidIdx])), d1Colon[TCEndIdx]] sx, sd1 = interp.sampleCubicHermiteCurves(nx, nd1, elementsCountAroundTC)[0:2] xTCRaw += sx[1:-1] @@ -1654,15 +1671,16 @@ def createColonCoordinatesTeniaColi(xiList, relativeThicknessList, lengthToDiame return xColon, d1Colon, d2Colon + def createNodesAndElementsTeniaColi(region, - x, d1, d2, d3, - xFlat, d1Flat, d2Flat, - xOrgan, d1Organ, d2Organ, organCoordinateFieldName, - elementsCountAroundTC, elementsCountAroundHaustrum, - elementsCountAlong, elementsCountThroughWall, tcCount, - annotationGroupsAround, annotationGroupsAlong, annotationGroupsThroughWall, - firstNodeIdentifier, firstElementIdentifier, - useCubicHermiteThroughWall, useCrossDerivatives, closedProximalEnd): + x, d1, d2, d3, + xFlat, d1Flat, d2Flat, + xOrgan, d1Organ, d2Organ, organCoordinateFieldName, + elementsCountAroundTC, elementsCountAroundHaustrum, + elementsCountAlong, elementsCountThroughWall, tcCount, + annotationGroupsAround, annotationGroupsAlong, annotationGroupsThroughWall, + firstNodeIdentifier, firstElementIdentifier, + useCubicHermiteThroughWall, useCrossDerivatives, closedProximalEnd): """ Create nodes and elements for the coordinates and flat coordinates fields. Note that flat coordinates not implemented for closedProximalEnd yet. @@ -1689,10 +1707,10 @@ def createNodesAndElementsTeniaColi(region, nodeIdentifier = firstNodeIdentifier elementIdentifier = firstElementIdentifier - elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum )*tcCount + elementsCountAround = (elementsCountAroundTC + elementsCountAroundHaustrum) * tcCount # Create coordinates field - zero = [ 0.0, 0.0, 0.0 ] + zero = [0.0, 0.0, 0.0] fm = region.getFieldmodule() fm.beginChange() cache = fm.createFieldcache() @@ -1810,7 +1828,7 @@ def createNodesAndElementsTeniaColi(region, organElementtemplate2.setElementShapeType(Element.SHAPE_TYPE_CUBE) eftOrgan2 = bicubichermitelinear.createEftWedgeXi1Zero() organElementtemplate2.defineField(organCoordinates, -1, eftOrgan2) - + # create nodes for coordinates field for n in range(len(x)): node = nodes.createNode(nodeIdentifier, nodetemplate) @@ -1820,10 +1838,10 @@ def createNodesAndElementsTeniaColi(region, coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, d2[n]) coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS3, 1, d3[n]) if useCrossDerivatives: - coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero) - coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS3, 1, zero) - coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS2DS3, 1, zero) - coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D3_DS1DS2DS3, 1, zero) + coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero) + coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS3, 1, zero) + coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS2DS3, 1, zero) + coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D3_DS1DS2DS3, 1, zero) # print('NodeIdentifier = ', nodeIdentifier, x[n], d1[n], d2[n]) nodeIdentifier = nodeIdentifier + 1 @@ -1833,8 +1851,8 @@ def createNodesAndElementsTeniaColi(region, for n2 in range(elementsCountAlong + 1): for n3 in range(elementsCountThroughWall + 1): for n1 in range(elementsCountAround): - i = n2*(elementsCountAround + 1)*(elementsCountThroughWall + 1) + \ - (elementsCountAround + 1)*n3 + n1 + n2*((elementsCountAroundTC - 1)*tcCount + 1) + i = n2 * (elementsCountAround + 1) * (elementsCountThroughWall + 1) + \ + (elementsCountAround + 1) * n3 + n1 + n2 * ((elementsCountAroundTC - 1) * tcCount + 1) node = nodes.findNodeByIdentifier(nodeIdentifier) node.merge(flatNodetemplate2 if n1 == 0 else flatNodetemplate1) cache.setNode(node) @@ -1846,15 +1864,15 @@ def createNodesAndElementsTeniaColi(region, flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero) if n1 == 0: # print('NodeIdentifier', nodeIdentifier, 'version 2', xFlatList[i+elementsCountAround]) - flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 2, xFlat[i+elementsCountAround]) - flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 2, d1Flat[i+elementsCountAround]) - flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 2, d2Flat[i+elementsCountAround]) + flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 2, xFlat[i + elementsCountAround]) + flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 2, d1Flat[i + elementsCountAround]) + flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 2, d2Flat[i + elementsCountAround]) if useCrossDerivatives: flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 2, zero) nodeIdentifier = nodeIdentifier + 1 # Create flat coordinates nodes for tenia coli - for nTC in range((elementsCountAroundTC - 1)*tcCount): + for nTC in range((elementsCountAroundTC - 1) * tcCount): j = i + 2 + nTC node = nodes.findNodeByIdentifier(nodeIdentifier) node.merge(flatNodetemplate2 if nTC == 0 else flatNodetemplate1) @@ -1865,9 +1883,9 @@ def createNodesAndElementsTeniaColi(region, if useCrossDerivatives: flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero) if nTC == 0: - flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 2, xFlat[j+(elementsCountAroundTC-1)*tcCount]) - flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 2, d1Flat[j+(elementsCountAroundTC-1)*tcCount]) - flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 2, d2Flat[j+(elementsCountAroundTC-1)*tcCount]) + flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 2, xFlat[j + (elementsCountAroundTC - 1) * tcCount]) + flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 2, d1Flat[j + (elementsCountAroundTC - 1) * tcCount]) + flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 2, d2Flat[j + (elementsCountAroundTC - 1) * tcCount]) if useCrossDerivatives: flatCoordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 2, zero) nodeIdentifier = nodeIdentifier + 1 @@ -1995,10 +2013,10 @@ def createNodesAndElementsTeniaColi(region, bni21 = elementsCountThroughWall + 1 bni22 = bni21 + elementsCountAround * elementsCountThroughWall + int(elementsCountAroundTC * 0.5) + \ - elementsCountAroundHaustrum + N*(elementsCountAroundTC + elementsCountAroundHaustrum) + eTC + 1 + elementsCountAroundHaustrum + N * (elementsCountAroundTC + elementsCountAroundHaustrum) + eTC + 1 bni23 = bni22 + 1 - bni31 = bni21 + elementsCountAround*(elementsCountThroughWall + 1) + int(elementsCountAroundTC*0.5) + \ - N*(elementsCountAroundTC - 1) + eTC + 1 + bni31 = bni21 + elementsCountAround * (elementsCountThroughWall + 1) + int(elementsCountAroundTC * 0.5) + \ + N * (elementsCountAroundTC - 1) + eTC + 1 if eTC == 0: eft5 = eftfactory.createEftTetrahedronXi1Zero(va * 10000, vb * 10000) @@ -2011,7 +2029,7 @@ def createNodesAndElementsTeniaColi(region, elif eTC > 0 and eTC < elementsCountAroundTC - 1: eft6 = eftfactory.createEftPyramidBottomSimple(va * 10000, vb * 10000) elementtemplate6.defineField(coordinates, -1, eft6) - nodeIdentifiers = [bni21, bni22, bni23, bni31-1, bni31] + nodeIdentifiers = [bni21, bni22, bni23, bni31 - 1, bni31] element = mesh.createElement(elementIdentifier, elementtemplate6) element.setNodesByIdentifier(eft6, nodeIdentifiers) element.setScaleFactors(eft6, scalefactors) @@ -2040,17 +2058,17 @@ def createNodesAndElementsTeniaColi(region, # set general linear map coefficients radiansAround = va * radiansPerElementAround radiansAroundNext = vb * radiansPerElementAround - scalefactors = [ -1.0, - math.sin(radiansAround), math.cos(radiansAround), radiansPerElementAround, - math.sin(radiansAroundNext), math.cos(radiansAroundNext), radiansPerElementAround] + scalefactors = [-1.0, + math.sin(radiansAround), math.cos(radiansAround), radiansPerElementAround, + math.sin(radiansAroundNext), math.cos(radiansAroundNext), radiansPerElementAround] bni21 = elementsCountThroughWall + 1 bni22 = bni21 + elementsCountAround * (elementsCountThroughWall + 1) - \ - int(elementsCountAroundTC*0.5) + eTC + 1 + int(elementsCountAroundTC * 0.5) + eTC + 1 if elementsCountAroundTC > 2: bni23 = bni21 + elementsCountAround * elementsCountThroughWall + 1 \ - if eTC == int(elementsCountAroundTC * 0.5 - 1) \ - else bni22 + 1 + if eTC == int(elementsCountAroundTC * 0.5 - 1) \ + else bni22 + 1 bni31 = bni21 + elementsCountAround * (elementsCountThroughWall + 1) + \ int(tcCount - 1) * (elementsCountAroundTC - 1) + \ int(elementsCountAroundTC * 0.5) + eTC + (0 if eTC > 0 else 1) @@ -2058,7 +2076,7 @@ def createNodesAndElementsTeniaColi(region, bni23 = bni21 + elementsCountAround * elementsCountThroughWall + eTC + 1 bni31 = bni21 + elementsCountAround * (elementsCountThroughWall + 1) + 1 bni32 = bni21 + elementsCountAround * (elementsCountThroughWall + 1) + 1 \ - if eTC == int(elementsCountAroundTC * 0.5 - 1) else bni31 + 1 + if eTC == int(elementsCountAroundTC * 0.5 - 1) else bni31 + 1 tetrahedralElement = (eTC == 0) if tetrahedralElement: @@ -2124,7 +2142,7 @@ def createNodesAndElementsTeniaColi(region, meshGroup.addElement(element) # Add elements for tenia coli - for eTC in range(int(elementsCountAroundTC*0.5)): + for eTC in range(int(elementsCountAroundTC * 0.5)): if closedProximalEnd: bni21 = elementsCountThroughWall + 1 + (e2 - 1) * now + elementsCountThroughWall * elementsCountAround + \ eTC + 1 + tcOffset1 @@ -2144,14 +2162,14 @@ def createNodesAndElementsTeniaColi(region, else: nodeIdentifiers = [bni21, bni22, bni21 + now + tcOffset, bni22 + now + tcOffset, bni31, bni31 + now + tcOffset] - element = mesh.createElement(elementIdentifier, elementtemplate if eTC < int(elementsCountAroundTC*0.5) - 1 else elementtemplate1) - element.setNodesByIdentifier(eft if eTC < int(elementsCountAroundTC*0.5) - 1 else eft1, nodeIdentifiers) + element = mesh.createElement(elementIdentifier, elementtemplate if eTC < int(elementsCountAroundTC * 0.5) - 1 else elementtemplate1) + element.setNodesByIdentifier(eft if eTC < int(elementsCountAroundTC * 0.5) - 1 else eft1, nodeIdentifiers) if xFlat: - element.merge(flatElementtemplate1 if eTC < int(elementsCountAroundTC*0.5) - 1 else flatElementtemplate3) - element.setNodesByIdentifier(eftFlat3 if eTC < int(elementsCountAroundTC*0.5) - 1 else eftFlat5, nodeIdentifiers) + element.merge(flatElementtemplate1 if eTC < int(elementsCountAroundTC * 0.5) - 1 else flatElementtemplate3) + element.setNodesByIdentifier(eftFlat3 if eTC < int(elementsCountAroundTC * 0.5) - 1 else eftFlat5, nodeIdentifiers) if xOrgan: - element.merge(organElementtemplate if eTC < int(elementsCountAroundTC*0.5) - 1 else organElementtemplate1) - element.setNodesByIdentifier(eftOrgan if eTC < int(elementsCountAroundTC*0.5) - 1 else eftOrgan1, nodeIdentifiers) + element.merge(organElementtemplate if eTC < int(elementsCountAroundTC * 0.5) - 1 else organElementtemplate1) + element.setNodesByIdentifier(eftOrgan if eTC < int(elementsCountAroundTC * 0.5) - 1 else eftOrgan1, nodeIdentifiers) elementIdentifier = elementIdentifier + 1 annotationGroups = annotationGroupsAround[elementsCountAround + eTC] + annotationGroupsAlong[e2] + \ ([longitudinalMuscleGroup] if longitudinalMuscle else []) @@ -2165,11 +2183,11 @@ def createNodesAndElementsTeniaColi(region, for eTC in range(elementsCountAroundTC): if closedProximalEnd: bni21 = elementsCountThroughWall + 1 + ( - e2 - 1) * now + elementsCountThroughWall * elementsCountAround \ + e2 - 1) * now + elementsCountThroughWall * elementsCountAround \ + eTC + 1 + tcOffset1 + int(elementsCountAroundTC * 0.5) + \ (N + 1) * elementsCountAroundHaustrum + N * elementsCountAroundTC bni22 = elementsCountThroughWall + 1 + ( - e2 - 1) * now + elementsCountThroughWall * elementsCountAround \ + e2 - 1) * now + elementsCountThroughWall * elementsCountAround \ + eTC + 2 + tcOffset1 + int(elementsCountAroundTC * 0.5) + \ (N + 1) * elementsCountAroundHaustrum + N * elementsCountAroundTC bni31 = elementsCountThroughWall + 1 + e2 * now + eTC + 1 + tcOffset1 + \ @@ -2179,10 +2197,10 @@ def createNodesAndElementsTeniaColi(region, else: bni21 = e2 * now + elementsCountThroughWall * elementsCountAround + eTC + 1 + tcOffset1 + \ int(elementsCountAroundTC * 0.5) + ( - N + 1) * elementsCountAroundHaustrum + N * elementsCountAroundTC + N + 1) * elementsCountAroundHaustrum + N * elementsCountAroundTC bni22 = e2 * now + elementsCountThroughWall * elementsCountAround + eTC + 2 + tcOffset1 + \ int(elementsCountAroundTC * 0.5) + ( - N + 1) * elementsCountAroundHaustrum + N * elementsCountAroundTC + N + 1) * elementsCountAroundHaustrum + N * elementsCountAroundTC bni31 = (e2 + 1) * now + eTC + 1 + tcOffset1 + int(elementsCountAroundTC * 0.5) - 1 + \ N * (elementsCountAroundTC - 1) bni32 = (e2 + 1) * now + eTC + 2 + tcOffset1 + int(elementsCountAroundTC * 0.5) - 1 + \ @@ -2230,7 +2248,7 @@ def createNodesAndElementsTeniaColi(region, meshGroup = annotationGroup.getMeshGroup(mesh) meshGroup.addElement(element) - for eTC in range(int(elementsCountAroundTC*0.5)): + for eTC in range(int(elementsCountAroundTC * 0.5)): if closedProximalEnd: bni21 = elementsCountThroughWall + 1 + (e2 - 1) * now + elementsCountThroughWall * elementsCountAround + \ eTC + 1 + tcOffset1 + int(elementsCountAroundTC * 0.5) + tcCount * elementsCountAroundHaustrum + \ @@ -2257,7 +2275,7 @@ def createNodesAndElementsTeniaColi(region, else: nodeIdentifiers = [bni21, bni22, bni21 + now + tcOffset, bni22 + now + tcOffset, bni32, bni32 + now + tcOffset] - onOpening = (eTC == int(elementsCountAroundTC*0.5 - 1)) + onOpening = (eTC == int(elementsCountAroundTC * 0.5 - 1)) element = mesh.createElement(elementIdentifier, elementtemplate if eTC > 0 else elementtemplate2) element.setNodesByIdentifier(eft if eTC > 0 else eft2, nodeIdentifiers) if xFlat: diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py index 4b2d92e8..32f6851e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heart1.py @@ -3,22 +3,23 @@ """ 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 from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm, mergeAnnotationGroups +from scaffoldmaker.annotation.annotationgroup import findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm, mergeAnnotationGroups from scaffoldmaker.annotation.heart_terms import get_heart_term -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.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.meshrefinement import MeshRefinement + class MeshType_3d_heart1(Scaffold_base): ''' Generates a 3-D heart model including ventricles, base and atria. diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py index c52f48f9..aa21258d 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heart2.py @@ -3,14 +3,15 @@ """ from __future__ import division -import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, mergeAnnotationGroups +from scaffoldmaker.annotation.annotationgroup import mergeAnnotationGroups 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.meshrefinement import MeshRefinement + class MeshType_3d_heart2(Scaffold_base): ''' Generates a 3-D heart model including ventricles, base and atria. diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py index 7791890d..5f7d93f5 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialroot1.py @@ -4,9 +4,10 @@ """ from __future__ import division + import math -from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString + +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 @@ -14,13 +15,13 @@ from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.annotation.heart_terms import get_heart_term 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 vector +from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, createCirclePoints from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import vector + class MeshType_3d_heartarterialroot1(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialvalve1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialvalve1.py index 3b6fa711..7f9da0fb 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialvalve1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartarterialvalve1.py @@ -5,27 +5,29 @@ """ from __future__ import division + import math + from opencmiss.maths.vectorops import eulerToRotationMatrix3 from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.utils.zinc.finiteelement import getMaximumElementIdentifier, getMaximumNodeIdentifier from opencmiss.utils.zinc.general import ChangeManager 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.geometry import createCirclePoints -from scaffoldmaker.utils.interpolation import interpolateLagrangeHermiteDerivative, smoothCubicHermiteDerivativesLine +from scaffoldmaker.utils import vector from scaffoldmaker.utils.eft_utils import setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import createCirclePoints +from scaffoldmaker.utils.interpolation import interpolateLagrangeHermiteDerivative, smoothCubicHermiteDerivativesLine from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import vector + class MeshType_3d_heartarterialvalve1(Scaffold_base): - ''' + """ Generates a 3-D heart arterial valve scaffold with semilunar valve, for attaching to a 6-element-around bicubic-linear orifice. - ''' + """ @staticmethod def getName(): @@ -86,9 +88,9 @@ def getOrderedOptionNames(): @staticmethod def checkOptions(options): - ''' + """ :return: True if dependent options changed, otherwise False. - ''' + """ dependentChanges = False for key in [ 'Unit scale', diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py index ba5479b0..5cfbc0ce 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py @@ -4,8 +4,10 @@ """ 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 @@ -14,17 +16,19 @@ from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.heart_terms import get_heart_term -from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.meshtypes.meshtype_3d_ostium1 import MeshType_3d_ostium1, generateOstiumMesh +from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage -from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d -from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds -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 vector +from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d +from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes +from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getCircleProjectionAxes, getEllipseAngleFromVector, getEllipseArcLength, getEllipseRadiansToX, \ + updateEllipseAngleByArcLength, createCirclePoints +from scaffoldmaker.utils.meshrefinement import MeshRefinement +from scaffoldmaker.utils.tracksurface import TrackSurface, calculate_surface_axes + class MeshType_3d_heartatria1(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py index fb216b50..74deb158 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartatria2.py @@ -4,7 +4,9 @@ """ 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 @@ -13,13 +15,14 @@ from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.annotation.heart_terms import get_heart_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils import interpolation as interp +from scaffoldmaker.utils import vector from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite 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.zinc_utils import computeNodeDerivativeHermiteLagrange, interpolateNodesCubicHermite -from scaffoldmaker.utils import vector -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite + class MeshType_3d_heartatria2(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py index ae4c687e..ad812ac8 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py @@ -4,20 +4,22 @@ """ 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.element import Element, Elementbasis from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.heart_terms import get_heart_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds -from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, updateEllipseAngleByArcLength -from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, updateEllipseAngleByArcLength from scaffoldmaker.utils.meshrefinement import MeshRefinement diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py index 5aba3bb5..549cf081 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles2.py @@ -3,19 +3,21 @@ """ from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +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.annotation.heart_terms import get_heart_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base +from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabel, setEftScaleFactorIds -from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, updateEllipseAngleByArcLength -from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, updateEllipseAngleByArcLength from scaffoldmaker.utils.meshrefinement import MeshRefinement diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py index bcf83d9f..eb16cc04 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventricles3.py @@ -4,11 +4,13 @@ """ 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, Elementfieldtemplate +from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm @@ -16,13 +18,13 @@ from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils import vector from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.geometry import createEllipsoidPoints, getApproximateEllipsePerimeter, getEllipseArcLength, getEllipseRadiansToX from scaffoldmaker.utils.interpolation import computeCubicHermiteDerivativeScaling, getCubicHermiteArcLength, interpolateSampleCubicHermite, \ - sampleCubicHermiteCurves, sampleCubicHermiteCurvesSmooth, smoothCubicHermiteDerivativesLine -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite + sampleCubicHermiteCurves, smoothCubicHermiteDerivativesLine from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.shieldmesh import ShieldMesh -from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes +from scaffoldmaker.utils.tracksurface import TrackSurface, calculate_surface_axes class MeshType_3d_heartventricles3(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py index 5523a558..1defc75d 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase1.py @@ -5,26 +5,28 @@ """ 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.element import Element 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, getAnnotationGroupForTerm from scaffoldmaker.annotation.heart_terms import get_heart_term 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 import interpolation as interp +from scaffoldmaker.utils import vector 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.meshrefinement import MeshRefinement -from scaffoldmaker.utils import vector + class MeshType_3d_heartventriclesbase1(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py index 00e1473d..5d6dc32e 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_heartventriclesbase2.py @@ -5,24 +5,27 @@ """ 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.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, getAnnotationGroupForTerm from scaffoldmaker.annotation.heart_terms import get_heart_term 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.zinc_utils import interpolateNodesCubicHermite +from scaffoldmaker.utils import vector +from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import getApproximateEllipsePerimeter, getEllipseArcLength, getEllipseRadiansToX, updateEllipseAngleByArcLength from scaffoldmaker.utils.meshrefinement import MeshRefinement -from scaffoldmaker.utils import vector +from scaffoldmaker.utils.zinc_utils import interpolateNodesCubicHermite + class MeshType_3d_heartventriclesbase2(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py index 6be165ca..e107a294 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_lens1.py @@ -4,15 +4,16 @@ """ 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.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): ''' Generates a 3-D spherical lens mesh with variable numbers diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py index 1657ce2d..4461fa92 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_lung1.py @@ -2,17 +2,17 @@ Generates 3D lung surface mesh. ''' +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ + findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString +from opencmiss.zinc.element import Element +from opencmiss.zinc.field import Field +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.lung_terms import get_lung_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, setEftScaleFactorIds from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement -from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ - findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString -from opencmiss.zinc.element import Element -from opencmiss.zinc.field import Field -from opencmiss.zinc.node import Node class MeshType_3d_lung1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py index 5780136f..396aa1df 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_ostium1.py @@ -3,19 +3,22 @@ """ 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 import interpolation as interp +from scaffoldmaker.utils import vector from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.geometry import createCirclePoints, getCircleProjectionAxes -from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes -from scaffoldmaker.utils import vector + class MeshType_3d_ostium1(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py index bf1eae7d..f8757bb3 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_smallintestine1.py @@ -5,6 +5,8 @@ """ import copy + +from opencmiss.zinc.node import Node from scaffoldmaker.annotation.annotationgroup import AnnotationGroup from scaffoldmaker.annotation.smallintestine_terms import get_smallintestine_term from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion @@ -12,10 +14,10 @@ from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import tubemesh -from scaffoldmaker.utils.tubemesh import CylindricalSegmentTubeMeshInnerPoints from scaffoldmaker.utils import vector +from scaffoldmaker.utils.tubemesh import CylindricalSegmentTubeMeshInnerPoints from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues -from opencmiss.zinc.node import Node + class MeshType_3d_smallintestine1(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_solidcylinder1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_solidcylinder1.py index 4c7824a9..93bc1268 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_solidcylinder1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_solidcylinder1.py @@ -4,16 +4,17 @@ """ from __future__ import division -import math + import copy + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates +from opencmiss.zinc.node import Node +from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1 from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.meshrefinement import MeshRefinement +from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.utils.cylindermesh import CylinderMesh, CylinderShape, CylinderEnds, CylinderCentralPath +from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues -from scaffoldmaker.scaffoldpackage import ScaffoldPackage -from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1 -from opencmiss.zinc.node import Node class MeshType_3d_solidcylinder1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py index 035cbd40..407f2dba 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_solidsphere1.py @@ -4,16 +4,19 @@ """ from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +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 import interpolation as interp -from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils import vector +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.meshrefinement import MeshRefinement + class MeshType_3d_solidsphere1(Scaffold_base): ''' diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py index 13f339a4..96a395f8 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshell1.py @@ -4,9 +4,11 @@ """ from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +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 @@ -14,6 +16,7 @@ from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.meshrefinement import MeshRefinement + class MeshType_3d_sphereshell1(Scaffold_base): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py index becf3c18..a72e03b8 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_sphereshellseptum1.py @@ -8,7 +8,9 @@ """ 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 @@ -17,6 +19,7 @@ from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative + class MeshType_3d_sphereshellseptum1(Scaffold_base): ''' classdocs diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py index f53b560e..aab0b280 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_stellate1.py @@ -3,22 +3,23 @@ """ from __future__ import division + import math -from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString + +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, findOrCreateFieldStoredMeshLocation, \ + findOrCreateFieldStoredString from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node -from opencmiss.zinc.context import Context -from opencmiss.utils.zinc.finiteelement import getElementNodeIdentifiersBasisOrder from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.stellate_terms import get_stellate_term from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear -from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds, remapEftLocalNodes -from scaffoldmaker.utils.matrix import rotateAboutZAxis -from scaffoldmaker.utils.vector import magnitude, setMagnitude +from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.interpolation import smoothCubicHermiteDerivativesLine +from scaffoldmaker.utils.matrix import rotateAboutZAxis +from scaffoldmaker.utils.meshrefinement import MeshRefinement +from scaffoldmaker.utils.vector import setMagnitude class MeshType_3d_stellate1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py index cdea05d9..1715d938 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_stomach1.py @@ -5,23 +5,29 @@ """ from __future__ import division -import math + import copy -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, mergeAnnotationGroups, \ - getAnnotationGroupForTerm, findOrCreateAnnotationGroupForTerm -from scaffoldmaker.annotation.stomach_terms import get_stomach_term +import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ findOrCreateFieldStoredString, findOrCreateFieldStoredMeshLocation, findOrCreateFieldNodeGroup from opencmiss.utils.zinc.finiteelement import get_element_node_identifiers from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node +from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, mergeAnnotationGroups, \ + getAnnotationGroupForTerm, findOrCreateAnnotationGroupForTerm +from scaffoldmaker.annotation.stomach_terms import get_stomach_term from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1, extractPathParametersFromRegion from scaffoldmaker.meshtypes.meshtype_3d_ostium1 import MeshType_3d_ostium1, generateOstiumMesh from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base from scaffoldmaker.scaffoldpackage import ScaffoldPackage +from scaffoldmaker.utils import interpolation as interp +from scaffoldmaker.utils import matrix +from scaffoldmaker.utils import vector from scaffoldmaker.utils.annulusmesh import createAnnulusMesh3d from scaffoldmaker.utils.bifurcation import get_bifurcation_triple_point +from scaffoldmaker.utils.eft_utils import scaleEftNodeValueLabels, setEftScaleFactorIds, remapEftNodeValueLabel from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.eft_utils import scaleEftNodeValueLabels, setEftScaleFactorIds, remapEftNodeValueLabel, \ @@ -29,9 +35,6 @@ from scaffoldmaker.utils.geometry import createEllipsePoints from scaffoldmaker.utils.tracksurface import TrackSurface from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues -from scaffoldmaker.utils import interpolation as interp -from scaffoldmaker.utils import matrix -from scaffoldmaker.utils import vector class MeshType_3d_stomach1(Scaffold_base): @@ -98,7 +101,7 @@ class MeshType_3d_stomach1(Scaffold_base): 'name': get_stomach_term('duodenum')[0], 'ontId': get_stomach_term('duodenum')[1] }] - }), + }), 'Mouse 1': ScaffoldPackage(MeshType_1d_path1, { 'scaffoldSettings': { 'Coordinate dimensions': 3, @@ -120,7 +123,7 @@ class MeshType_3d_stomach1(Scaffold_base): [ [ -6.2, 3.2, 0.0 ], [ -0.4, 0.9, 0.0 ], [ -0.8, -0.3, 0.0 ], [ 0.1, -0.0, 0.0 ], [ 0.0, 0.0, 0.9 ], [ 0.0, 0.0, -0.2 ] ], [ [ -6.8, 4.1, 0.0 ], [ -0.7, 0.9, 0.0 ], [ -1.1, -0.5, 0.0 ], [ -0.7, -0.4, 0.0 ], [ 0.0, 0.0, 1.1 ], [ 0.0, 0.0, 0.6 ] ] ] ), - 'userAnnotationGroups': [ + 'userAnnotationGroups': [ { '_AnnotationGroup': True, 'dimension': 1, @@ -341,7 +344,7 @@ def getDefaultOptions(cls, parameterSetName='Default'): 'Gastro-esophagal junction': copy.deepcopy(ostiumOption), 'Gastro-esophagal junction position along factor': 0.35, 'Cardia derivative factor': 1.0, - 'Use linear through wall' : True, + 'Use linear through wall': True, 'Refine': False, 'Refine number of elements surface': 4, 'Refine number of elements through wall': 1 @@ -430,7 +433,7 @@ def checkOptions(cls, options): if not options['Gastro-esophagal junction'].getScaffoldType() in cls.getOptionValidScaffoldTypes( 'Gastro-esophagal junction'): options['Gastro-esophagal junction'] = cls.getOptionScaffoldPackage('Gastro-esophagal junction', - MeshType_3d_ostium1) + MeshType_3d_ostium1) if options['Number of elements around esophagus'] < 8: options['Number of elements around esophagus'] = 8 if options['Number of elements around esophagus'] % 4 > 0: @@ -528,7 +531,7 @@ def generateBaseMesh(cls, region, options): centralPath.generate(tmpRegion) cxGroup, cd1Group, cd2Group, cd3Group, cd12Group, cd13Group = \ extractPathParametersFromRegion(tmpRegion, [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, - Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D_DS3, + Node.VALUE_LABEL_D_DS2, Node.VALUE_LABEL_D_DS3, Node.VALUE_LABEL_D2_DS1DS2, Node.VALUE_LABEL_D2_DS1DS3], groupName=stomachTermsAlong[i]) @@ -554,10 +557,10 @@ def generateBaseMesh(cls, region, options): # Create annotation groups for stomach sections allAnnotationGroups = [] stomachCentralPathLength = sum(arcLengthOfGroupsAlong[1:]) - fundusEndPositionAlongFactor = arcLengthOfGroupsAlong[1]/stomachCentralPathLength + fundusEndPositionAlongFactor = arcLengthOfGroupsAlong[1] / stomachCentralPathLength arcLengthRatioForGroupsFromFundusEnd = [] for i in range(2, len(stomachTermsAlong)): - arcLengthRatio = (arcLengthOfGroupsAlong[i])/(stomachCentralPathLength - arcLengthOfGroupsAlong[1]) + arcLengthRatio = (arcLengthOfGroupsAlong[i]) / (stomachCentralPathLength - arcLengthOfGroupsAlong[1]) arcLengthRatioForGroupsFromFundusEnd.append(arcLengthRatio) stomachGroup = AnnotationGroup(region, get_stomach_term("stomach")) @@ -729,7 +732,7 @@ def generateBaseMesh(cls, region, options): d2AlongDownFundus = [] xAlongDownFundus.append(xFundusEnd) d2AlongDownFundus.append(d2FundusEnd) - startIdx = fundusEndPositionAlongFactor*elementsCountAlongTrackSurface + startIdx = fundusEndPositionAlongFactor * elementsCountAlongTrackSurface startIdx = math.ceil(startIdx) + (1 if startIdx - math.ceil(startIdx) == 0 else 0) for n2 in range(startIdx, len(xSampledAll)): xAlongDownFundus.append(xSampledAll[n2][0]) @@ -793,8 +796,8 @@ def generateBaseMesh(cls, region, options): xAlongGCEsoToFundusEnd, d2AlongGCEsoToFundusEnd = \ interp.sampleCubicHermiteCurvesSmooth(xAlongUpFundus, d2AlongUpFundus, elementsAlongGCFromEsoToFundusEnd, - derivativeMagnitudeStart= vector.magnitude(d2AlongUpFundus[0]), - derivativeMagnitudeEnd = vector.magnitude(d2AlongUpFundus[-1]))[0:2] + derivativeMagnitudeStart=vector.magnitude(d2AlongUpFundus[0]), + derivativeMagnitudeEnd=vector.magnitude(d2AlongUpFundus[-1]))[0:2] xEsoToDuodGC = xAlongGCEsoToFundusEnd[:-1] + xAlongGCFundusEndToDuod d2EsoToDuodGC = d2AlongGCEsoToFundusEnd[:-1] + d2AlongGCFundusEndToDuod @@ -974,7 +977,7 @@ def generateBaseMesh(cls, region, options): startRadians=0.0) d1Around = interp.smoothCubicHermiteDerivativesLoop(xAround, d1Around, - magnitudeScalingMode = interp.DerivativeScalingMode.HARMONIC_MEAN) + magnitudeScalingMode=interp.DerivativeScalingMode.HARMONIC_MEAN) xAroundEllipse.append(xAround) d1AroundEllipse.append(d1Around) @@ -1002,7 +1005,7 @@ def generateBaseMesh(cls, region, options): p1d = [rotFrame[j][0] * d[0] + rotFrame[j][1] * d[1] + rotFrame[j][2] * d[2] for j in range(3)] p1d_6pt = [cardiaDerivativeFactor * c for c in p1d] - p2x_6pt = xAve[int(len(xAve)*0.5) + 1] + p2x_6pt = xAve[int(len(xAve) * 0.5) + 1] p2d_6pt = findDerivativeBetweenPoints(p2x_6pt, xAve[int(len(xAve) * 0.5) + 2]) p3x_6pt = xAve[int(len(xAve) * 0.5) - 1] @@ -1019,8 +1022,8 @@ def generateBaseMesh(cls, region, options): xAlongAround = [] d1AlongAround = [] for n2 in range(elementsAroundQuarterEso + 1, elementsAroundHalfEso): - xi = n/elementsAroundQuarterEso - derivativeMagnitude = xi * distBetween6ptJunctionOstium + (1-xi) * distAnnulusAtQuarterEso + xi = n / elementsAroundQuarterEso + derivativeMagnitude = xi * distBetween6ptJunctionOstium + (1 - xi) * distAnnulusAtQuarterEso ostiumIdx = n2 GCIdx = elementsAroundHalfDuod - 1 + n2 GCPosition, d1GC = findClosestPositionAndDerivativeOnTrackSurface(xEsoToDuodGC[GCIdx], ptsOnTrackSurfaceGC, @@ -1201,7 +1204,7 @@ def generateBaseMesh(cls, region, options): trackSurfaceStomach, 0.0, elementsCountAlongTrackSurface)[1] for nSide in range(2): - if nSide == 0: # Right side + if nSide == 0: # Right side xAroundRight.append(xEsoToDuodGC[GCIdx]) d1AroundRight.append(d1GC) xOnLastLoopRight = xLoopsRight[-1][loopIdx] @@ -1242,12 +1245,12 @@ def generateBaseMesh(cls, region, options): xAroundRight += xSampled[:2] d1AroundRight += dSampled[:2] - else: # connected to triple point + else: # connected to triple point xAroundRight += [xLoopsRight[0][loopIdx]] + [xTriplePts[0]] d1AroundRight += [findDerivativeBetweenPoints(xLoopsRight[0][loopIdx], xTriplePts[0])] + \ [d1TriplePts[0]] - else: # left side + else: # left side if loopIdx < elementsAroundQuarterEso: # additional elements upstream of triple point xLoop = xLoopsLeft[0][loopIdx] xLoopPosition = trackSurfaceStomach.findNearestPosition(xLoop) @@ -1351,7 +1354,7 @@ def generateBaseMesh(cls, region, options): for n in range(1, len(xLoopsLeft)): xRow2Left.append(xLoopsLeft[n][loopIdx]) - d1Row2Left.append(findDerivativeBetweenPoints(xLoopsLeft[n-1][loopIdx], xLoopsLeft[n][loopIdx])) + d1Row2Left.append(findDerivativeBetweenPoints(xLoopsLeft[n - 1][loopIdx], xLoopsLeft[n][loopIdx])) xRow2Left.append(xUp[0][-1]) d1Row2Left.append(findDerivativeBetweenPoints(xLoopsLeft[-1][1], xUp[0][-1])) @@ -1367,13 +1370,13 @@ def generateBaseMesh(cls, region, options): junctionIdx = n2 + 1 xLoopTripleTo6Pt += xAlongAround[junctionIdx][int(len(xAlongAround[junctionIdx]) * 0.5):] + \ xAlongAround[junctionIdx][0: int(len(xAlongAround[junctionIdx]) * 0.5 + 1)] - for n2 in range(elementsAroundQuarterEso - 1): # Note order here - going upstream + for n2 in range(elementsAroundQuarterEso - 1): # Note order here - going upstream idx = junctionIdx - 1 - n2 xLoopTripleTo6Pt.append(xAlongAround[idx][int(len(xAlongAround[idx]) * 0.5) + 1]) xLoopTripleTo6Pt += xBifurcationRings[0][int(len(xBifurcationRings[0]) * 0.5 + 1):] for n in range(len(xLoopTripleTo6Pt)): - d = findDerivativeBetweenPoints(xLoopTripleTo6Pt[n], xLoopTripleTo6Pt[(n+1) % len(xLoopTripleTo6Pt)]) + d = findDerivativeBetweenPoints(xLoopTripleTo6Pt[n], xLoopTripleTo6Pt[(n + 1) % len(xLoopTripleTo6Pt)]) dLoopTripleTo6Pt.append(d) dSmoothLoopTripleTo6Pt = interp.smoothCubicHermiteDerivativesLoop(xLoopTripleTo6Pt, dLoopTripleTo6Pt) @@ -1396,7 +1399,7 @@ def generateBaseMesh(cls, region, options): xLoopGCTriplePt += xBifurcationRings[1][int(len(xBifurcationRings[1]) * 0.5) + 1:] for n in range(len(xLoopGCTriplePt)): - d = findDerivativeBetweenPoints(xLoopGCTriplePt[n], xLoopGCTriplePt[(n+1) % len(xLoopGCTriplePt)]) + d = findDerivativeBetweenPoints(xLoopGCTriplePt[n], xLoopGCTriplePt[(n + 1) % len(xLoopGCTriplePt)]) dLoopGCTriplePt.append(d) dSmoothLoopGCTriplePt = interp.smoothCubicHermiteDerivativesLoop(xLoopGCTriplePt, dLoopGCTriplePt) @@ -1420,19 +1423,19 @@ def generateBaseMesh(cls, region, options): elif n2 > 1 and n2 < elementsAroundQuarterEso + 2: xAround = xUp[countUp] - if n2 < elementsAroundQuarterEso: # upstream of triple pt + if n2 < elementsAroundQuarterEso: # upstream of triple pt d1Around = d1Up[countUp] d1Around = smoothD1Around(xAround, d1Around) - elif n2 == elementsAroundQuarterEso: # upstream bifurcation + elif n2 == elementsAroundQuarterEso: # upstream bifurcation # take smoothed d1 from dSmoothTripleTo6Pt d1Around = dSmoothLoopTripleTo6Pt[: int(len(xBifurcationRings[0]) * 0.5) + 1] + \ - dSmoothLoopTripleTo6Pt[-int(len(xBifurcationRings[0]) * 0.5) : ] + dSmoothLoopTripleTo6Pt[-int(len(xBifurcationRings[0]) * 0.5):] - elif n2 > elementsAroundQuarterEso: # downstream bifurcation + elif n2 > elementsAroundQuarterEso: # downstream bifurcation # take smoothed d1 from dSmoothGCToTriplePt d1Around = dSmoothLoopGCTriplePt[: int(len(xBifurcationRings[1]) * 0.5) + 1] + \ - dSmoothLoopGCTriplePt[-int(len(xBifurcationRings[1]) * 0.5) : ] + dSmoothLoopGCTriplePt[-int(len(xBifurcationRings[1]) * 0.5):] countUp += 1 elif n2 > elementsAroundQuarterEso + 1: @@ -1442,13 +1445,13 @@ def generateBaseMesh(cls, region, options): if n2 < elementsAroundHalfEso + 1: d1Around = smoothD1Around(xAround, d1Around) - elif n2 == elementsAroundHalfEso + 1: # 6 point junction ring + elif n2 == elementsAroundHalfEso + 1: # 6 point junction ring # take smoothed d1 from dSmoothedTripleTo6Pt startRightIdx = int(len(xBifurcationRings[0]) * 0.5 + elementsAroundQuarterEso + len(xAlongAround[junctionIdx]) * 0.5) endRightIdx = startRightIdx + int(len(xAlongAround[junctionIdx]) * 0.5) + 1 startLeftIdx = startRightIdx - int(len(xAlongAround[junctionIdx]) * 0.5) + 1 d1Around = dSmoothLoopTripleTo6Pt[startRightIdx: endRightIdx] + \ - dSmoothLoopTripleTo6Pt[startLeftIdx : startRightIdx] + dSmoothLoopTripleTo6Pt[startLeftIdx: startRightIdx] countDown += 1 xOuter.append(xAround) @@ -1472,7 +1475,7 @@ def generateBaseMesh(cls, region, options): xRegularLoop.append(xOuter[n2 + 1][int(len(xOuter[n2 + 1]) * 0.5 + n1 + (1 if n2 >= elementsAroundHalfEso else 2))]) for n in range(len(xRegularLoop) - 1): - d = findDerivativeBetweenPoints(xRegularLoop[n], xRegularLoop[n+1]) + d = findDerivativeBetweenPoints(xRegularLoop[n], xRegularLoop[n + 1]) d2RegularLoop.append(d) d2RegularLoop.append(d) @@ -1568,7 +1571,7 @@ def generateBaseMesh(cls, region, options): d2Around.append(d2RegularLoops[n1][int(len(xRegularLoops[n1]) * 0.5)]) nextIdx = n1 + 1 - elif n2 == 1: # Row 2 + elif n2 == 1: # Row 2 d2Around.append(d2RegularLoops[nextIdx][int(len(xRegularLoops[nextIdx]) * 0.5)]) for n1 in range(nextIdx, -1, -1): @@ -1599,14 +1602,14 @@ def generateBaseMesh(cls, region, options): # Annulus right d2 = dSmoothLoopGCTriplePt[int(len(xLoopGCTriplePt) * 0.5) - n2 + (1 if n2 > elementsAroundQuarterEso else 0)] - if n2 <= elementsAroundQuarterEso: # Rotate to point towards duodenum + if n2 <= elementsAroundQuarterEso: # Rotate to point towards duodenum rotAxis = vector.normalise(vector.crossproduct3(vector.normalise(d1Outer[n2][int(len(d1Outer[n2]) * 0.5)]), - vector.normalise(d2))) + vector.normalise(d2))) rotFrame = matrix.getRotationMatrixFromAxisAngle(rotAxis, math.pi) d2Around.append( [rotFrame[j][0] * d2[0] + rotFrame[j][1] * d2[1] + rotFrame[j][2] * d2[2] for j in range(3)]) else: - d2Around.append(d2) # just take d2 as-is cos we are going to remove this point later + d2Around.append(d2) # just take d2 as-is cos we are going to remove this point later # Annulus left d2Around.append(dSmoothLoopGCTriplePt[int(len(xLoopGCTriplePt) * 0.5) + n2 - (1 if n2 > elementsAroundQuarterEso else 0)]) @@ -1644,7 +1647,7 @@ def generateBaseMesh(cls, region, options): rotAxis = vector.normalise( vector.crossproduct3(vector.normalise(d1Outer[n2][int(len(d1Outer[n2]) * 0.5 + 1)]), vector.normalise(d2))) - else: # use d2 on previous overlapping point to rotate + else: # use d2 on previous overlapping point to rotate rotAxis = vector.normalise( vector.crossproduct3(vector.normalise(d1), vector.normalise(d2))) rotFrame = matrix.getRotationMatrixFromAxisAngle(rotAxis, math.pi) @@ -1759,14 +1762,14 @@ def generateBaseMesh(cls, region, options): for n2 in range(elementsCountAlong + 1): d1CurvatureAround = [] d2CurvatureAround = [] - if n2 == 0: # GC + if n2 == 0: # GC for i in range(elementsAroundHalfDuod - 2): d1CurvatureAround.append(curvatureAlongGC[i]) d2CurvatureAround.append(curvatureLoopGCTriplePt[int(len(curvatureLoopGCTriplePt) * 0.5)]) for n1 in range(len(xOuter[0]) - 1): d2CurvatureAround.append(curvatureRegularLoops[n1][int(len(curvatureRegularLoops[n1]) * 0.5)]) nextIdx = n1 + 1 - elif n2 == 1: #Row 2 + elif n2 == 1: # Row 2 d1CurvatureAround.append(curvatureAlongGC[i + n2]) for n in range(int(len(xOuter[1]) * 0.5) - 1, -1, -1): d1CurvatureAround.append(curvatureAlong2Left[n]) @@ -1782,7 +1785,7 @@ def generateBaseMesh(cls, region, options): for n1 in range(nextIdx + 1): d2CurvatureAround.append(curvatureRegularLoops[n1][int(len(curvatureRegularLoops[n1]) * 0.5) + n2]) - elif n2 > 1 and n2 < elementsAroundQuarterEso + 2: # Before triple pt & triple point + elif n2 > 1 and n2 < elementsAroundQuarterEso + 2: # Before triple pt & triple point xAround = xOuter[n2] if n2 < elementsAroundQuarterEso: # upstream of triple pt d1Around = d1Outer[n2] @@ -1808,7 +1811,7 @@ def generateBaseMesh(cls, region, options): d2CurvatureAround.append(curvatureRegularLoops[n1][int(len(curvatureRegularLoops[n1]) * 0.5) - n2]) # Annulus right d2CurvatureAround.append(curvatureLoopGCTriplePt[ - int(len(curvatureLoopGCTriplePt) * 0.5) - n2 + (1 if n2 > elementsAroundQuarterEso else 0)]) + int(len(curvatureLoopGCTriplePt) * 0.5) - n2 + (1 if n2 > elementsAroundQuarterEso else 0)]) # Annulus left d2CurvatureAround.append(curvatureLoopGCTriplePt[int(len(curvatureLoopGCTriplePt) * 0.5) + n2 - ( 1 if n2 > elementsAroundQuarterEso else 0)]) @@ -1818,7 +1821,7 @@ def generateBaseMesh(cls, region, options): # Row 2 left d2CurvatureAround.append(curvatureAlong2Left[len(xOuter[0]) + n2 - 1]) - elif n2 > elementsAroundQuarterEso + 1: # Downstream of triple point + elif n2 > elementsAroundQuarterEso + 1: # Downstream of triple point xAround = xOuter[n2] d1Around = d1Outer[n2] normsAround = d3UnitOuter[n2] @@ -1835,10 +1838,10 @@ def generateBaseMesh(cls, region, options): d1CurvatureAround = curvatureLoopTripleTo6Pt[startRightIdx: endRightIdx] + \ curvatureLoopTripleTo6Pt[startLeftIdx: startRightIdx] - if n2 > elementsAroundHalfEso + 1: # closed rings beyond 6 point junction + if n2 > elementsAroundHalfEso + 1: # closed rings beyond 6 point junction xLoop = xAround[int(len(xAround) * 0.5 + 1):] + xAround[: int(len(xAround) * 0.5 + 1)] d1Loop = d1Around[int(len(d1Around) * 0.5 + 1):] + d1Around[: int(len(d1Around) * 0.5 + 1)] - normsLoop = normsAround[int(len(normsAround) * 0.5 + 1):] + normsAround[ : int(len(normsAround) * 0.5 + 1)] + normsLoop = normsAround[int(len(normsAround) * 0.5 + 1):] + normsAround[: int(len(normsAround) * 0.5 + 1)] curvature = findCurvatureAroundLoop(xLoop, d1Loop, normsLoop) # Rearrange to correct order d1CurvatureAround = curvature[int(len(xLoop) * 0.5) - 1:] + curvature[: int(len(xAround) * 0.5) - 1] @@ -1859,7 +1862,7 @@ def generateBaseMesh(cls, region, options): d2CurvatureAround.append(curvatureLoopTripleTo6Pt[idx]) # Annulus left d2CurvatureAround.append(curvatureLoopTripleTo6Pt[-idx]) - elif n2 > elementsAroundHalfEso + 1: # Beyond 6 pt junction + elif n2 > elementsAroundHalfEso + 1: # Beyond 6 pt junction # LC d2CurvatureAround.append(curvatureAlongLC[n2 - (elementsAroundHalfEso + 1) - 1]) # Regular down left @@ -2066,7 +2069,7 @@ def generateBaseMesh(cls, region, options): setEftScaleFactorIds(eft1, [1], []) remapEftNodeValueLabel(eft1, [1, 5], Node.VALUE_LABEL_D_DS1, [(Node.VALUE_LABEL_D_DS2, [1])]) remapEftNodeValueLabel(eft1, [1, 5], Node.VALUE_LABEL_D_DS2, [(Node.VALUE_LABEL_D_DS1, [])]) - remapEftNodeValueLabel(eft1, [2, 6], Node.VALUE_LABEL_D_DS2,[(Node.VALUE_LABEL_D_DS1, [1])]) + remapEftNodeValueLabel(eft1, [2, 6], Node.VALUE_LABEL_D_DS2, [(Node.VALUE_LABEL_D_DS1, [1])]) remapEftNodeValueLabel(eft1, [2, 6], Node.VALUE_LABEL_D_DS1, [(Node.VALUE_LABEL_D_DS2, [])]) elif e1 == 1: # Bottom right wedge scaleFactors = [-1.0] @@ -2270,7 +2273,7 @@ def generateBaseMesh(cls, region, options): eft1 = eftfactory.createEftNoCrossDerivatives() setEftScaleFactorIds(eft1, [1], []) remapEftNodeValueLabel(eft1, [1, 5], Node.VALUE_LABEL_D_DS2, [(Node.VALUE_LABEL_D_DS1, [1])]) - remapEftNodeValueLabel(eft1, [1, 5], Node.VALUE_LABEL_D_DS1, [(Node.VALUE_LABEL_D_DS2, [ ])]) + remapEftNodeValueLabel(eft1, [1, 5], Node.VALUE_LABEL_D_DS1, [(Node.VALUE_LABEL_D_DS2, [])]) elementtemplateX.defineField(coordinates, -1, eft1) elementtemplate1 = elementtemplateX @@ -2342,7 +2345,7 @@ def generateBaseMesh(cls, region, options): bni12 = startNode + e3 * elementsCountAround1 + (e1 + 1) % elementsCountAround1 bni21 = startNode + elementsAroundThroughWall + e1 + elementsCountAround2 * e3 bni22 = startNode + elementsAroundThroughWall + ( - e1 + 1) % elementsCountAround2 + elementsCountAround2 * e3 + e1 + 1) % elementsCountAround2 + elementsCountAround2 * e3 nodeIdentifiers = [bni11, bni12, bni21, bni22, bni11 + elementsCountAround1, bni12 + elementsCountAround1, bni21 + elementsCountAround2, bni22 + elementsCountAround2] @@ -2406,7 +2409,7 @@ def generateBaseMesh(cls, region, options): endPoints_d2[n3][nAround] = d2List[idx - stomachStartNode] endNode_Id[n3][nAround] = idx - if n3 == len(thicknessIdx) - 1: # outer layer + if n3 == len(thicknessIdx) - 1: # outer layer endPosition = trackSurfaceStomach.findNearestPosition(endPoints_x[n3][nAround]) endProportions.append(trackSurfaceStomach.getProportion(endPosition)) @@ -2438,9 +2441,9 @@ def generateBaseMesh(cls, region, options): nodes, mesh, nodeIdentifier, elementIdentifier, o1_x, o1_d1, o1_d2, None, o1_NodeId, None, endPoints_x, endPoints_d1, endPoints_d2, None, endNode_Id, endDerivativesMap, - elementsCountRadial = elementsCountAcrossCardia, meshGroups= [stomachMeshGroup, cardiaMeshGroup], - tracksurface=trackSurfaceStomach, startProportions = startProportions, endProportions = endProportions, - rescaleStartDerivatives = True, rescaleEndDerivatives = True) + elementsCountRadial=elementsCountAcrossCardia, meshGroups=[stomachMeshGroup, cardiaMeshGroup], + tracksurface=trackSurfaceStomach, startProportions=startProportions, endProportions=endProportions, + rescaleStartDerivatives=True, rescaleEndDerivatives=True) elementIdxThroughWall = [] n = lastDuodenumElementIdentifier - 1 @@ -2467,7 +2470,8 @@ def generateBaseMesh(cls, region, options): for group in [stomachGroup, GEJLCGroup]: group.getNodesetGroup(nodes).addNode(markerPoint) - fundusBodyJunctionGroup = findOrCreateAnnotationGroupForTerm(allAnnotationGroups, region, get_stomach_term("limiting ridge on greater curvature" if limitingRidge else "junction between fundus and body on greater curvature")) + fundusBodyJunctionGroup = findOrCreateAnnotationGroupForTerm(allAnnotationGroups, region, get_stomach_term( + "limiting ridge on greater curvature" if limitingRidge else "junction between fundus and body on greater curvature")) fundusBodyJunctionElement = mesh.findElementByIdentifier(fundusBodyJunctionElementIdentifier) fundusBodyJunctionXi = [0.0, 0.0 if limitingRidge else 1.0, 1.0] cache.setMeshLocation(fundusBodyJunctionElement, fundusBodyJunctionXi) @@ -2527,9 +2531,9 @@ def generateBaseMesh(cls, region, options): for n2 in range(elementsAlongEsophagus + 1): for n3 in range(elementsThroughEsophagusWall + 1): - nodeIdxOnGCMargin = 1 + n2 * (elementsThroughEsophagusWall + 1 ) * elementsCountAroundEso + n3 * elementsCountAroundEso + nodeIdxOnGCMargin = 1 + n2 * (elementsThroughEsophagusWall + 1) * elementsCountAroundEso + n3 * elementsCountAroundEso nodesOnSplitMargin.append(nodeIdxOnGCMargin) - nodeIdxOnLCMargin = 1 + elementsAroundHalfEso + n2 * (elementsThroughEsophagusWall + 1 ) * elementsCountAroundEso + n3 * elementsCountAroundEso + nodeIdxOnLCMargin = 1 + elementsAroundHalfEso + n2 * (elementsThroughEsophagusWall + 1) * elementsCountAroundEso + n3 * elementsCountAroundEso nodesOnSplitMargin.append(nodeIdxOnLCMargin) nodesOnLCMargin.append(nodeIdxOnLCMargin) nodesOnSplitMargin += nodeIdxGC + nodeIdxLC @@ -2609,9 +2613,9 @@ def generateBaseMesh(cls, region, options): closedLoopElementId = nextElementIdentifier - elementsCountAroundEso * elementsCountAcrossCardia - \ elementsCountAroundDuod * elementsCountThroughWall * (elementsAlongCardiaToDuod + 1) - allValueLabels = [ Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, - Node.VALUE_LABEL_D2_DS1DS2, Node.VALUE_LABEL_D_DS3, Node.VALUE_LABEL_D2_DS1DS3, - Node.VALUE_LABEL_D2_DS2DS3, Node.VALUE_LABEL_D3_DS1DS2DS3] + allValueLabels = [Node.VALUE_LABEL_VALUE, Node.VALUE_LABEL_D_DS1, Node.VALUE_LABEL_D_DS2, + Node.VALUE_LABEL_D2_DS1DS2, Node.VALUE_LABEL_D_DS3, Node.VALUE_LABEL_D2_DS1DS3, + Node.VALUE_LABEL_D2_DS2DS3, Node.VALUE_LABEL_D3_DS1DS2DS3] while element.isValid(): eft = element.getElementfieldtemplate(coordinates, -1) @@ -2735,22 +2739,22 @@ def defineFaceAnnotations(cls, region, options, annotationGroups): get_stomach_term("mucosa of stomach")) outerSplitMarginGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("serosa split margin")) + get_stomach_term("serosa split margin")) esoSplitMarginGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("esophagus on serosa split margin")) + get_stomach_term("esophagus on serosa split margin")) fundusSplitMarginGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("fundus on serosa split margin")) + get_stomach_term("fundus on serosa split margin")) bodySplitMarginGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("body on serosa split margin")) + get_stomach_term("body on serosa split margin")) antrumSplitMarginGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("antrum on serosa split margin")) + get_stomach_term("antrum on serosa split margin")) pylorusSplitMarginGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("pylorus on serosa split margin")) + get_stomach_term("pylorus on serosa split margin")) serosaDorsalGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("serosa of dorsal stomach")) + get_stomach_term("serosa of dorsal stomach")) serosaVentralGroup = findOrCreateAnnotationGroupForTerm(annotationGroups, region, - get_stomach_term("serosa of ventral stomach")) + get_stomach_term("serosa of ventral stomach")) stomachGroup = getAnnotationGroupForTerm(annotationGroups, get_stomach_term("stomach")) bodyGroup = getAnnotationGroupForTerm(annotationGroups, get_stomach_term("body of stomach")) @@ -2827,10 +2831,11 @@ def findClosestPositionAndDerivativeOnTrackSurface(x, nx, trackSurface, nxPropor return xPosition, d + def getSmoothedSampledPointsOnTrackSurface(trackSurface, startProportion1, startProportion2, endProportion1, - endProportion2, elementsOut, startDerivative = None, endDerivative = None, - startDerivativeMagnitude = None, endDerivativeMagnitude = None, - curveMode = 1): + endProportion2, elementsOut, startDerivative=None, endDerivative=None, + startDerivativeMagnitude=None, endDerivativeMagnitude=None, + curveMode=1): """ Create smoothly spaced out hermite curve points between two points a and b on the surface, each defined by their proportions over the surface in directions 1 and 2. @@ -2855,6 +2860,7 @@ def getSmoothedSampledPointsOnTrackSurface(trackSurface, startProportion1, start endDerivativeMagnitude)[0:2] return xSampled, dSampled + def smoothD1Around(xAround, d1Around): """ Rearrange points around so that the group of points starts from left side of the annulus to the greater curvature @@ -2865,15 +2871,16 @@ def smoothD1Around(xAround, d1Around): :param d1Around: derivative of points. :return: smoothed derivatives in the original order. """ - xLoop = xAround[int(len(xAround) * 0.5 + 1): ] + xAround[: int(len(xAround) * 0.5 + 1)] - d1Loop = d1Around[int(len(d1Around) * 0.5 + 1): ] + d1Around[: int(len(d1Around) * 0.5 + 1)] + xLoop = xAround[int(len(xAround) * 0.5 + 1):] + xAround[: int(len(xAround) * 0.5 + 1)] + d1Loop = d1Around[int(len(d1Around) * 0.5 + 1):] + d1Around[: int(len(d1Around) * 0.5 + 1)] d1LoopSmooth = interp.smoothCubicHermiteDerivativesLine(xLoop, d1Loop, fixStartDerivative=True, - fixEndDerivative=True) + fixEndDerivative=True) # Rearrange to correct order - d1Around = d1LoopSmooth[int(len(xAround) * 0.5) : ] + d1LoopSmooth[: int(len(xAround) * 0.5) : ] + d1Around = d1LoopSmooth[int(len(xAround) * 0.5):] + d1LoopSmooth[: int(len(xAround) * 0.5):] return d1Around + def findD1CurvatureAround(xAround, d1Around, normsAround): """ Rearrange points around so that the group of points starts from left side of the annulus to the greater curvature @@ -2894,6 +2901,7 @@ def findD1CurvatureAround(xAround, d1Around, normsAround): return d1CurvatureAround + def findDerivativeBetweenPoints(v1, v2): """ Find vector difference between two points and rescale vector difference using cubic hermite arclength @@ -2908,6 +2916,7 @@ def findDerivativeBetweenPoints(v1, v2): return d + def findCurvatureAroundLoop(nx, nd, radialVectors): """ Calculate curvature for points lying along a loop. @@ -2926,6 +2935,7 @@ def findCurvatureAroundLoop(nx, nd, radialVectors): return curvature + def findCurvatureAlongLine(nx, nd, radialVectors): """ Calculate curvature for points lying along a line. @@ -2942,7 +2952,7 @@ def findCurvatureAlongLine(nx, nd, radialVectors): curvature.append(interp.getCubicHermiteCurvature(nx[n - 1], nd[n - 1], nx[n], nd[n], radialVectors[n], 1.0)) else: curvature.append(0.5 * ( - interp.getCubicHermiteCurvature(nx[n], nd[n], nx[n + 1], nd[n + 1], radialVectors[n], 0.0) + - interp.getCubicHermiteCurvature(nx[n - 1], nd[n - 1], nx[n], nd[n], radialVectors[n], 1.0))) + interp.getCubicHermiteCurvature(nx[n], nd[n], nx[n + 1], nd[n + 1], radialVectors[n], 0.0) + + interp.getCubicHermiteCurvature(nx[n - 1], nd[n - 1], nx[n], nd[n], radialVectors[n], 1.0))) return curvature diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py index abf3c519..4d156d17 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_stomachhuman1.py @@ -4,6 +4,7 @@ """ from __future__ import division + import numpy as np from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldFibres from opencmiss.zinc.context import Context @@ -14,6 +15,7 @@ from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scipy.interpolate import splprep, splev + class Stomach: ''' Loads stomach mesh generated by Dr. Kumar Mithraratne (p.mithraratne@auckland.ac.nz) diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py index 594b4fa0..94df9d63 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_tube1.py @@ -4,9 +4,11 @@ """ from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.zinc.element import Element, Elementbasis +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 diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py index bdb9b105..8d372f2f 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_tubeseptum1.py @@ -7,9 +7,11 @@ """ from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates -from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate +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 diff --git a/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py b/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py index 692fe1bf..5c860c48 100644 --- a/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py +++ b/src/scaffoldmaker/meshtypes/meshtype_3d_wholebody1.py @@ -4,26 +4,27 @@ """ from __future__ import division -import math + import copy -from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup,\ + +from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, \ findOrCreateFieldStoredString, findOrCreateFieldStoredMeshLocation, findOrCreateFieldNodeGroup from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base -from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.cylindermesh import CylinderMesh, CylinderShape, CylinderEnds, CylinderCentralPath -from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1 from opencmiss.zinc.node import Node from opencmiss.zinc.element import Element -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm, mergeAnnotationGroups +from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findOrCreateAnnotationGroupForTerm, getAnnotationGroupForTerm from scaffoldmaker.annotation.body_terms import get_body_term from scaffoldmaker.annotation import heart_terms, bladder_terms, lung_terms, stomach_terms, brainstem_terms from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.field import Field, FieldFindMeshLocation from opencmiss.utils.zinc.finiteelement import get_element_node_identifiers from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabelsVersion +from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.vector import setMagnitude +from scaffoldmaker.utils.zinc_utils import exnodeStringFromNodeValues class MeshType_3d_wholebody1(Scaffold_base): diff --git a/src/scaffoldmaker/meshtypes/scaffold_base.py b/src/scaffoldmaker/meshtypes/scaffold_base.py index 57e91214..7a196785 100644 --- a/src/scaffoldmaker/meshtypes/scaffold_base.py +++ b/src/scaffoldmaker/meshtypes/scaffold_base.py @@ -3,13 +3,15 @@ Describes methods each scaffold must or may override. """ import copy + from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.field import Field -from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.derivativemoothing import DerivativeSmoothing from scaffoldmaker.utils.interpolation import DerivativeScalingMode +from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.zinc_utils import extract_node_field_parameters, print_node_field_parameters + class Scaffold_base: ''' Base class for scaffolds / mesh generator scripts. diff --git a/src/scaffoldmaker/scaffoldpackage.py b/src/scaffoldmaker/scaffoldpackage.py index 5b4c61c2..918ed833 100644 --- a/src/scaffoldmaker/scaffoldpackage.py +++ b/src/scaffoldmaker/scaffoldpackage.py @@ -5,12 +5,14 @@ import copy import math + +from opencmiss.maths.vectorops import euler_to_rotation_matrix from opencmiss.utils.zinc.field import createFieldEulerAnglesRotationMatrix from opencmiss.utils.zinc.general import ChangeManager -from opencmiss.maths.vectorops import euler_to_rotation_matrix from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, findAnnotationGroupByName from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base + class ScaffoldPackage: ''' Class packaging a scaffold type, options and modifications. diff --git a/src/scaffoldmaker/scaffolds.py b/src/scaffoldmaker/scaffolds.py index 87a34088..b53ef1c3 100644 --- a/src/scaffoldmaker/scaffolds.py +++ b/src/scaffoldmaker/scaffolds.py @@ -3,6 +3,7 @@ """ import json + from scaffoldmaker.meshtypes.meshtype_1d_bifurcationtree1 import MeshType_1d_bifurcationtree1 from scaffoldmaker.meshtypes.meshtype_1d_path1 import MeshType_1d_path1 from scaffoldmaker.meshtypes.meshtype_2d_plate1 import MeshType_2d_plate1 @@ -10,7 +11,6 @@ from scaffoldmaker.meshtypes.meshtype_2d_sphere1 import MeshType_2d_sphere1 from scaffoldmaker.meshtypes.meshtype_2d_tube1 import MeshType_2d_tube1 from scaffoldmaker.meshtypes.meshtype_2d_tubebifurcation1 import MeshType_2d_tubebifurcation1 -from scaffoldmaker.meshtypes.meshtype_2d_tubebifurcationtree1 import MeshType_2d_tubebifurcationtree1 from scaffoldmaker.meshtypes.meshtype_3d_bladder1 import MeshType_3d_bladder1 from scaffoldmaker.meshtypes.meshtype_3d_bladderurethra1 import MeshType_3d_bladderurethra1 from scaffoldmaker.meshtypes.meshtype_3d_box1 import MeshType_3d_box1 @@ -34,8 +34,8 @@ from scaffoldmaker.meshtypes.meshtype_3d_lung1 import MeshType_3d_lung1 from scaffoldmaker.meshtypes.meshtype_3d_ostium1 import MeshType_3d_ostium1 from scaffoldmaker.meshtypes.meshtype_3d_smallintestine1 import MeshType_3d_smallintestine1 -from scaffoldmaker.meshtypes.meshtype_3d_solidsphere1 import MeshType_3d_solidsphere1 from scaffoldmaker.meshtypes.meshtype_3d_solidcylinder1 import MeshType_3d_solidcylinder1 +from scaffoldmaker.meshtypes.meshtype_3d_solidsphere1 import MeshType_3d_solidsphere1 from scaffoldmaker.meshtypes.meshtype_3d_sphereshell1 import MeshType_3d_sphereshell1 from scaffoldmaker.meshtypes.meshtype_3d_sphereshellseptum1 import MeshType_3d_sphereshellseptum1 from scaffoldmaker.meshtypes.meshtype_3d_stellate1 import MeshType_3d_stellate1 diff --git a/src/scaffoldmaker/utils/annulusmesh.py b/src/scaffoldmaker/utils/annulusmesh.py index d3271432..9cdbd105 100644 --- a/src/scaffoldmaker/utils/annulusmesh.py +++ b/src/scaffoldmaker/utils/annulusmesh.py @@ -2,16 +2,18 @@ Utility functions for generating annulus mesh between start and end loops of points. ''' from __future__ import division -from collections.abc import Sequence + import copy +from collections.abc import Sequence + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates from opencmiss.zinc.element import Element 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.eft_utils import remapEftNodeValueLabel, setEftScaleFactorIds +from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite def derivativeSignsToExpressionTerms(valueLabels, signs, scaleFactorIdx = None): diff --git a/src/scaffoldmaker/utils/bifurcation.py b/src/scaffoldmaker/utils/bifurcation.py index 4ac03b44..31b90fe0 100644 --- a/src/scaffoldmaker/utils/bifurcation.py +++ b/src/scaffoldmaker/utils/bifurcation.py @@ -3,9 +3,9 @@ """ from __future__ import division + from opencmiss.maths.vectorops import add, cross, dot, magnitude, mult, normalize, sub from opencmiss.zinc.element import Element, Elementbasis -from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds from scaffoldmaker.utils.geometry import createCirclePoints diff --git a/src/scaffoldmaker/utils/cylindermesh.py b/src/scaffoldmaker/utils/cylindermesh.py index 5652cbf4..c93d2147 100644 --- a/src/scaffoldmaker/utils/cylindermesh.py +++ b/src/scaffoldmaker/utils/cylindermesh.py @@ -4,17 +4,18 @@ a solid truncated cone. It also can be used for transition from a 2D base to another base (e.g., ellipse to a circle). """ -from enum import Enum -from scaffoldmaker.utils import vector, geometry import math -from opencmiss.zinc.field import Field +from enum import Enum + from opencmiss.utils.zinc.finiteelement import getMaximumNodeIdentifier, getMaximumElementIdentifier -from scaffoldmaker.utils.shieldmesh import ShieldMesh, ShieldShape, ShieldRimDerivativeMode -from scaffoldmaker.utils.interpolation import sampleCubicHermiteCurves, interpolateSampleCubicHermite, \ - smoothCubicHermiteDerivativesLine, interpolateSampleLinear +from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node -from scaffoldmaker.utils.mirror import Mirror from scaffoldmaker.meshtypes.meshtype_1d_path1 import extractPathParametersFromRegion +from scaffoldmaker.utils import vector, geometry +from scaffoldmaker.utils.interpolation import sampleCubicHermiteCurves, interpolateSampleCubicHermite, \ + smoothCubicHermiteDerivativesLine +from scaffoldmaker.utils.mirror import Mirror +from scaffoldmaker.utils.shieldmesh import ShieldMesh, ShieldShape, ShieldRimDerivativeMode class CylinderShape(Enum): diff --git a/src/scaffoldmaker/utils/derivativemoothing.py b/src/scaffoldmaker/utils/derivativemoothing.py index 90d372db..dd5aed60 100644 --- a/src/scaffoldmaker/utils/derivativemoothing.py +++ b/src/scaffoldmaker/utils/derivativemoothing.py @@ -2,14 +2,14 @@ Class for globally smoothing field derivatives. ''' from __future__ import division + import math -from opencmiss.maths.vectorops import add, magnitude + +from opencmiss.maths.vectorops import magnitude from opencmiss.utils.zinc.field import findOrCreateFieldGroup from opencmiss.utils.zinc.general import ChangeManager 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.utils.interpolation import DerivativeScalingMode, getCubicHermiteArcLength, interpolateHermiteLagrangeDerivative, interpolateLagrangeHermiteDerivative from scaffoldmaker.utils.vector import setMagnitude diff --git a/src/scaffoldmaker/utils/eftfactory_bicubichermitelinear.py b/src/scaffoldmaker/utils/eftfactory_bicubichermitelinear.py index 5e1450de..f3096eb9 100644 --- a/src/scaffoldmaker/utils/eftfactory_bicubichermitelinear.py +++ b/src/scaffoldmaker/utils/eftfactory_bicubichermitelinear.py @@ -1,10 +1,10 @@ ''' Definitions of standard element field templates using bicubic Hermite x linear Lagrange basis. ''' -from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, setEftScaleFactorIds -from opencmiss.zinc.element import Elementbasis, Elementfieldtemplate +from opencmiss.zinc.element import Elementbasis from opencmiss.zinc.node import Node -from opencmiss.zinc.status import OK as ZINC_OK +from scaffoldmaker.utils.eft_utils import remapEftLocalNodes, remapEftNodeValueLabel, setEftScaleFactorIds + class eftfactory_bicubichermitelinear: ''' diff --git a/src/scaffoldmaker/utils/eftfactory_tricubichermite.py b/src/scaffoldmaker/utils/eftfactory_tricubichermite.py index c9154a0a..88c37846 100644 --- a/src/scaffoldmaker/utils/eftfactory_tricubichermite.py +++ b/src/scaffoldmaker/utils/eftfactory_tricubichermite.py @@ -2,15 +2,14 @@ Definitions of standard element field templates shared by mesh generators. ''' 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 -from scaffoldmaker.utils.eft_utils import mapEftFunction1Node1Term, remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds -from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector +from scaffoldmaker.utils.eft_utils import mapEftFunction1Node1Term, remapEftLocalNodes, remapEftNodeValueLabel, scaleEftNodeValueLabels, setEftScaleFactorIds class eftfactory_tricubichermite: diff --git a/src/scaffoldmaker/utils/exportvtk.py b/src/scaffoldmaker/utils/exportvtk.py index a9f14c42..3203a6dd 100644 --- a/src/scaffoldmaker/utils/exportvtk.py +++ b/src/scaffoldmaker/utils/exportvtk.py @@ -5,11 +5,13 @@ import io import os from sys import version_info + from opencmiss.utils.zinc.finiteelement import getElementNodeIdentifiersBasisOrder from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.field import Field from opencmiss.zinc.result import RESULT_OK + class ExportVtk: ''' Class for exporting a Scaffold from Zinc to legacy vtk text format. diff --git a/src/scaffoldmaker/utils/geometry.py b/src/scaffoldmaker/utils/geometry.py index bc53ec5b..e0dc7fa3 100644 --- a/src/scaffoldmaker/utils/geometry.py +++ b/src/scaffoldmaker/utils/geometry.py @@ -3,10 +3,13 @@ ''' from __future__ import division + import copy import math + from scaffoldmaker.utils import vector + def getApproximateEllipsePerimeter(a, b): ''' Get perimeter of ellipse using Ramanujan II approximation. diff --git a/src/scaffoldmaker/utils/interpolation.py b/src/scaffoldmaker/utils/interpolation.py index 1fb221fb..3ae637e7 100644 --- a/src/scaffoldmaker/utils/interpolation.py +++ b/src/scaffoldmaker/utils/interpolation.py @@ -3,10 +3,12 @@ ''' from __future__ import division -from collections.abc import Sequence + import copy -from enum import Enum import math +from collections.abc import Sequence +from enum import Enum + from scaffoldmaker.utils import vector gaussXi3 = ( (-math.sqrt(0.6)+1.0)/2.0, 0.5, (+math.sqrt(0.6)+1.0)/2.0 ) diff --git a/src/scaffoldmaker/utils/meshrefinement.py b/src/scaffoldmaker/utils/meshrefinement.py index 880877f2..e79b575d 100644 --- a/src/scaffoldmaker/utils/meshrefinement.py +++ b/src/scaffoldmaker/utils/meshrefinement.py @@ -2,7 +2,9 @@ Class for refining a mesh from one region to another. ''' from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldGroup, findOrCreateFieldNodeGroup, \ findOrCreateFieldStoredMeshLocation, findOrCreateFieldStoredString from opencmiss.zinc.element import Element, Elementbasis diff --git a/src/scaffoldmaker/utils/mirror.py b/src/scaffoldmaker/utils/mirror.py index ce454a9a..94801e94 100644 --- a/src/scaffoldmaker/utils/mirror.py +++ b/src/scaffoldmaker/utils/mirror.py @@ -3,8 +3,10 @@ ''' from __future__ import division + from scaffoldmaker.utils import vector + class Mirror: ''' Utilities for getting a mirror image of a scaffold. diff --git a/src/scaffoldmaker/utils/octree.py b/src/scaffoldmaker/utils/octree.py index 7e190762..4eefa3bf 100644 --- a/src/scaffoldmaker/utils/octree.py +++ b/src/scaffoldmaker/utils/octree.py @@ -2,9 +2,11 @@ Octree for searching for objects by coordinates ''' from __future__ import division + import copy import math + class Octree: ''' Octree for searching for objects by coordinates diff --git a/src/scaffoldmaker/utils/shieldmesh.py b/src/scaffoldmaker/utils/shieldmesh.py index 4822a09a..058c0400 100644 --- a/src/scaffoldmaker/utils/shieldmesh.py +++ b/src/scaffoldmaker/utils/shieldmesh.py @@ -4,19 +4,20 @@ merge to form a triangle. ''' from __future__ import division -import copy -import math + +from enum import Enum + from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node from scaffoldmaker.utils import vector -from scaffoldmaker.utils.mirror import Mirror -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.eft_utils import remapEftNodeValueLabel, setEftScaleFactorIds +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite from scaffoldmaker.utils.interpolation import DerivativeScalingMode, sampleCubicHermiteCurves, \ - smoothCubicHermiteDerivativesLine, interpolateSampleCubicHermite -from scaffoldmaker.utils.tracksurface import TrackSurface, TrackSurfacePosition, calculate_surface_axes -from enum import Enum + smoothCubicHermiteDerivativesLine +from scaffoldmaker.utils.mirror import Mirror +from scaffoldmaker.utils.tracksurface import TrackSurface, calculate_surface_axes + class ShieldShape(Enum): SHIELD_SHAPE_FULL = 1 diff --git a/src/scaffoldmaker/utils/tracksurface.py b/src/scaffoldmaker/utils/tracksurface.py index fc404122..a254b6ff 100644 --- a/src/scaffoldmaker/utils/tracksurface.py +++ b/src/scaffoldmaker/utils/tracksurface.py @@ -3,9 +3,11 @@ ''' from __future__ import division + import copy -from enum import Enum import math +from enum import Enum + from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector diff --git a/src/scaffoldmaker/utils/tubemesh.py b/src/scaffoldmaker/utils/tubemesh.py index 8a3caf1f..0cdbfaa0 100644 --- a/src/scaffoldmaker/utils/tubemesh.py +++ b/src/scaffoldmaker/utils/tubemesh.py @@ -3,18 +3,21 @@ using a segment profile. ''' from __future__ import division + import math + from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates, findOrCreateFieldTextureCoordinates from opencmiss.zinc.element import Element from opencmiss.zinc.field import Field from opencmiss.zinc.node import Node -from scaffoldmaker.annotation.annotationgroup import AnnotationGroup, mergeAnnotationGroups -from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear -from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite -from scaffoldmaker.utils.geometry import createCirclePoints +from scaffoldmaker.annotation.annotationgroup import mergeAnnotationGroups from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import matrix from scaffoldmaker.utils import vector +from scaffoldmaker.utils.eftfactory_bicubichermitelinear import eftfactory_bicubichermitelinear +from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite +from scaffoldmaker.utils.geometry import createCirclePoints + def getPlaneProjectionOnCentralPath(x, elementsCountAround, elementsCountAlong, segmentLength, sx, sd1, sd2, sd12): diff --git a/src/scaffoldmaker/utils/zinc_utils.py b/src/scaffoldmaker/utils/zinc_utils.py index 03df2734..5413d7cd 100644 --- a/src/scaffoldmaker/utils/zinc_utils.py +++ b/src/scaffoldmaker/utils/zinc_utils.py @@ -8,7 +8,7 @@ from opencmiss.zinc.element import MeshGroup from opencmiss.zinc.field import Field, FieldGroup from opencmiss.zinc.fieldmodule import Fieldmodule -from opencmiss.zinc.node import Node, Nodeset +from opencmiss.zinc.node import Node from opencmiss.zinc.result import RESULT_OK from scaffoldmaker.utils import interpolation as interp from scaffoldmaker.utils import vector diff --git a/tests/test_bladder.py b/tests/test_bladder.py index 6ccb628b..7cff9694 100644 --- a/tests/test_bladder.py +++ b/tests/test_bladder.py @@ -1,5 +1,6 @@ import copy import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange, findNodeWithName from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context @@ -11,8 +12,10 @@ from scaffoldmaker.meshtypes.meshtype_3d_bladderurethra1 import MeshType_3d_bladderurethra1 from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace + from testutils import assertAlmostEqualList + class BladderScaffoldTestCase(unittest.TestCase): def test_bladderurethra1(self): diff --git a/tests/test_cecum.py b/tests/test_cecum.py index 37a933bd..70c4a5c8 100644 --- a/tests/test_cecum.py +++ b/tests/test_cecum.py @@ -1,4 +1,5 @@ import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context @@ -7,8 +8,10 @@ from opencmiss.zinc.result import RESULT_OK from scaffoldmaker.meshtypes.meshtype_3d_cecum1 import MeshType_3d_cecum1 from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace + from testutils import assertAlmostEqualList + class CecumScaffoldTestCase(unittest.TestCase): def test_cecum1(self): diff --git a/tests/test_colon.py b/tests/test_colon.py index d73a87a9..0fd391b3 100644 --- a/tests/test_colon.py +++ b/tests/test_colon.py @@ -1,5 +1,6 @@ import copy import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context @@ -12,8 +13,10 @@ from scaffoldmaker.meshtypes.meshtype_3d_colonsegment1 import MeshType_3d_colonsegment1 from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace, exnodeStringFromNodeValues + from testutils import assertAlmostEqualList + class ColonScaffoldTestCase(unittest.TestCase): def test_colon1(self): diff --git a/tests/test_colonsegment.py b/tests/test_colonsegment.py index 2f010ba6..ad73a193 100644 --- a/tests/test_colonsegment.py +++ b/tests/test_colonsegment.py @@ -1,4 +1,5 @@ import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context @@ -7,8 +8,10 @@ from opencmiss.zinc.result import RESULT_OK from scaffoldmaker.meshtypes.meshtype_3d_colonsegment1 import MeshType_3d_colonsegment1 from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace + from testutils import assertAlmostEqualList + class ColonSegmentScaffoldTestCase(unittest.TestCase): def test_humancolonsegment1(self): diff --git a/tests/test_cylinder.py b/tests/test_cylinder.py index 669fab14..d32a77d8 100644 --- a/tests/test_cylinder.py +++ b/tests/test_cylinder.py @@ -1,11 +1,12 @@ import unittest -import copy + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context from opencmiss.zinc.field import Field from opencmiss.zinc.result import RESULT_OK from scaffoldmaker.meshtypes.meshtype_3d_solidcylinder1 import MeshType_3d_solidcylinder1 + from testutils import assertAlmostEqualList diff --git a/tests/test_general.py b/tests/test_general.py index c1a9d446..1743837d 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1,4 +1,5 @@ import unittest + from opencmiss.maths.vectorops import magnitude from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange, findNodeWithName from opencmiss.zinc.context import Context @@ -10,12 +11,12 @@ from scaffoldmaker.meshtypes.meshtype_3d_heartatria1 import MeshType_3d_heartatria1 from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.scaffolds import Scaffolds -from testutils import assertAlmostEqualList - from scaffoldmaker.utils.zinc_utils import identifier_ranges_from_string, identifier_ranges_to_string, \ mesh_group_add_identifier_ranges, mesh_group_to_identifier_ranges, \ nodeset_group_add_identifier_ranges, nodeset_group_to_identifier_ranges +from testutils import assertAlmostEqualList + class GeneralScaffoldTestCase(unittest.TestCase): diff --git a/tests/test_heart.py b/tests/test_heart.py index 1e503010..52c1f30a 100644 --- a/tests/test_heart.py +++ b/tests/test_heart.py @@ -1,16 +1,19 @@ -import unittest import copy +import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange, findNodeWithName from opencmiss.utils.zinc.general import ChangeManager 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, getAnnotationGroupForTerm +from scaffoldmaker.annotation.annotationgroup import getAnnotationGroupForTerm from scaffoldmaker.annotation.heart_terms import get_heart_term from scaffoldmaker.meshtypes.meshtype_3d_heart1 import MeshType_3d_heart1 from scaffoldmaker.utils.meshrefinement import MeshRefinement + from testutils import assertAlmostEqualList + class HeartScaffoldTestCase(unittest.TestCase): def test_heart1(self): diff --git a/tests/test_lung.py b/tests/test_lung.py index 36e551f9..63666457 100644 --- a/tests/test_lung.py +++ b/tests/test_lung.py @@ -1,16 +1,19 @@ -import unittest import copy +import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange, findNodeWithName from opencmiss.utils.zinc.general import ChangeManager 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, getAnnotationGroupForTerm +from scaffoldmaker.annotation.annotationgroup import getAnnotationGroupForTerm from scaffoldmaker.annotation.lung_terms import get_lung_term from scaffoldmaker.meshtypes.meshtype_3d_lung1 import MeshType_3d_lung1 from scaffoldmaker.utils.meshrefinement import MeshRefinement + from testutils import assertAlmostEqualList + class LungScaffoldTestCase(unittest.TestCase): def test_lung1(self): diff --git a/tests/test_smallintestine.py b/tests/test_smallintestine.py index 425d6418..2ce42950 100644 --- a/tests/test_smallintestine.py +++ b/tests/test_smallintestine.py @@ -1,5 +1,6 @@ import copy import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context @@ -11,8 +12,10 @@ from scaffoldmaker.meshtypes.meshtype_3d_smallintestine1 import MeshType_3d_smallintestine1 from scaffoldmaker.scaffoldpackage import ScaffoldPackage from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace, exnodeStringFromNodeValues + from testutils import assertAlmostEqualList + class SmallIntestineScaffoldTestCase(unittest.TestCase): def test_smallintestine1(self): diff --git a/tests/test_stomach.py b/tests/test_stomach.py index a6d535fd..021055e8 100644 --- a/tests/test_stomach.py +++ b/tests/test_stomach.py @@ -1,5 +1,6 @@ import copy import unittest + from opencmiss.utils.zinc.finiteelement import evaluateFieldNodesetRange, findNodeWithName from opencmiss.utils.zinc.general import ChangeManager from opencmiss.zinc.context import Context @@ -11,8 +12,10 @@ from scaffoldmaker.meshtypes.meshtype_3d_stomach1 import MeshType_3d_stomach1 from scaffoldmaker.utils.meshrefinement import MeshRefinement from scaffoldmaker.utils.zinc_utils import createFaceMeshGroupExteriorOnFace + from testutils import assertAlmostEqualList + class StomachScaffoldTestCase(unittest.TestCase): def test_stomach1(self):