Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Marker points #208

Merged
merged 17 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions src/scaffoldmaker/annotation/annotationgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from opencmiss.utils.zinc.field import find_or_create_field_coordinates, find_or_create_field_group, \
find_or_create_field_stored_mesh_location, find_or_create_field_stored_string
from opencmiss.zinc.element import Element, Mesh
from opencmiss.zinc.field import Field, FieldFiniteElement, FieldGroup, FieldStoredMeshLocation, FieldStoredString
from opencmiss.zinc.field import Field, FieldFiniteElement, FieldGroup, FieldStoredMeshLocation, FieldStoredString, \
FieldFindMeshLocation
from opencmiss.zinc.fieldmodule import Fieldmodule
from opencmiss.zinc.node import Node
from opencmiss.zinc.result import RESULT_OK
Expand Down Expand Up @@ -348,13 +349,14 @@ def setMarkerMaterialCoordinates(self, materialCoordinatesField, materialCoordin
assert RESULT_OK == nodetemplate.defineField(materialCoordinatesField)
assert RESULT_OK == markerNode.merge(nodetemplate)
self._markerMaterialCoordinatesField = materialCoordinatesField
fieldcache = fieldmodule.createFieldcache()
if materialCoordinatesField:
if materialCoordinates is not None:
# find nearest location in mesh
constCoordinates = fieldmodule.createFieldConstant(materialCoordinates)
findMeshLocation = fieldmodule.createFieldFindMeshLocation(
constCoordinates, materialCoordinatesField, mesh)
fieldcache = fieldmodule.createFieldcache()
findMeshLocation.setSearchMode(FieldFindMeshLocation.SEARCH_MODE_NEAREST)
fieldcache.setNode(markerNode)
element, xi = findMeshLocation.evaluateMeshLocation(fieldcache, mesh.getDimension())
if not element.isValid():
Expand All @@ -363,12 +365,36 @@ def setMarkerMaterialCoordinates(self, materialCoordinatesField, materialCoordin
return
if not isinstance(xi, list):
xi = [xi] # workaround for Zinc 1-D xi being a plain float
markerLocation = getAnnotationMarkerLocationField(fieldmodule, mesh)
markerLocation.assignMeshLocation(fieldcache, element, xi)
self._markerMaterialCoordinatesField.assignReal(fieldcache, materialCoordinates)
del findMeshLocation
del constCoordinates
else:
element, xi = self.getMarkerLocation()
# use this function to reassign material coordinates to be within mesh
self.setMarkerLocation(element, xi)
# following stores material coordinates at the current location:
fieldcache.setMeshLocation(element, xi)
result, materialCoordinates = self._markerMaterialCoordinatesField.evaluateReal(
fieldcache, self._markerMaterialCoordinatesField.getNumberOfComponents())
fieldcache.setNode(markerNode)
self._markerMaterialCoordinatesField.assignReal(fieldcache, materialCoordinates)

def evaluateMaterialCoordinatesFromElementXi(self, materialCoordinatesField):
rchristie marked this conversation as resolved.
Show resolved Hide resolved
"""
Calculate the material coordinates from element and xi values.
:param materialCoordinatesField: Material coordinates field
:return: material coordinates derived from element and xi
"""
fieldmodule = self._group.getFieldmodule()
rchristie marked this conversation as resolved.
Show resolved Hide resolved
fieldcache = fieldmodule.createFieldcache()
markerNode = self.getMarkerNode()
fieldcache.setNode(markerNode)
element, xi = self.getMarkerLocation()
fieldcache.setMeshLocation(element, xi)
result, evaluatedMaterialCoordinates = \
materialCoordinatesField.evaluateReal(fieldcache, materialCoordinatesField.getNumberOfComponents())

return evaluatedMaterialCoordinates

def getName(self):
return self._name
Expand Down Expand Up @@ -407,6 +433,14 @@ def setName(self, name):
return True
return False

def getMarkerNode(self):
'''
:return: Marker node in annotation group.
'''
rchristie marked this conversation as resolved.
Show resolved Hide resolved
fieldmodule = self._group.getFieldmodule()
rchristie marked this conversation as resolved.
Show resolved Hide resolved
nodes = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
return self.getNodesetGroup(nodes).createNodeiterator().next()
rchristie marked this conversation as resolved.
Show resolved Hide resolved

def getId(self):
return self._id

Expand Down
Loading