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

Markups planes export #12

Merged
merged 5 commits into from
Jan 2, 2023
Merged
Changes from 4 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
40 changes: 37 additions & 3 deletions OpenAnatomyExport/OpenAnatomyExport.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def exportModel(self, inputItem, outputFolder=None, reductionFactor=None, output

modelNodes = vtk.vtkCollection()
shNode.GetDataNodesInBranch(inputShFolderItemId, modelNodes, "vtkMRMLModelNode")
self._numberOfExpectedModels = modelNodes.GetNumberOfItems()
planeNodes = vtk.vtkCollection()
shNode.GetDataNodesInBranch(inputShFolderItemId, planeNodes, "vtkMRMLMarkupsPlaneNode")
self._numberOfExpectedModels = modelNodes.GetNumberOfItems() + planeNodes.GetNumberOfItems()
self._numberOfProcessedModels = 0
self._gltfNodes = []
self._gltfMeshes = []
Expand Down Expand Up @@ -349,8 +351,15 @@ def addModelsToRenderer(self, shFolderItemId, boostGouraudColor=False):
for itemIdIndex in range(childIds.GetNumberOfIds()):
shItemId = childIds.GetId(itemIdIndex)
dataNode = shNode.GetItemDataNode(shItemId)
if dataNode and dataNode.IsA("vtkMRMLModelNode"):
inputModelNode = dataNode
if (
mauigna06 marked this conversation as resolved.
Show resolved Hide resolved
dataNode and (
dataNode.IsA("vtkMRMLModelNode") or dataNode.IsA("vtkMRMLMarkupsPlaneNode")
)
):
if dataNode.IsA("vtkMRMLModelNode"):
inputModelNode = dataNode
else:
inputModelNode = self.createPlaneModelFromMarkupsPlane(dataNode)
meshName = dataNode.GetName()
self._numberOfProcessedModels += 1
self.addLog("Model {0}/{1}: {2}".format(self._numberOfProcessedModels, self._numberOfExpectedModels, meshName))
Expand Down Expand Up @@ -380,6 +389,9 @@ def addModelsToRenderer(self, shFolderItemId, boostGouraudColor=False):
gltfMeshNodeIndex = len(self._gltfNodes)
self._gltfNodes.append({'mesh': gltfMeshIndex, 'name': meshName})
gltfFolderNodeChildren.append(gltfMeshNodeIndex)

if dataNode and dataNode.IsA("vtkMRMLMarkupsPlaneNode"):
slicer.mrmlScene.RemoveNode(inputModelNode)

# Write all children of this child item
grandChildIds = vtk.vtkIdList()
Expand Down Expand Up @@ -499,6 +511,28 @@ def addModelToRenderer(self, inputModelNode, outputModelNode, boostGouraudColor=

return True

def createPlaneModelFromMarkupsPlane(self,planeMarkup):
planeBounds = planeMarkup.GetPlaneBounds()
objectToWorld = vtk.vtkMatrix4x4()
planeMarkup.GetObjectToWorldMatrix(objectToWorld)

# Create plane polydata
planeSource = vtk.vtkPlaneSource()
planeSource.SetOrigin(objectToWorld.MultiplyPoint([planeBounds[0], planeBounds[2], 0.0, 1.0])[0:3])
planeSource.SetPoint1(objectToWorld.MultiplyPoint([planeBounds[1], planeBounds[2], 0.0, 1.0])[0:3])
planeSource.SetPoint2(objectToWorld.MultiplyPoint([planeBounds[0], planeBounds[3], 0.0, 1.0])[0:3])
planeModel = slicer.modules.models.logic().AddModel(planeSource.GetOutputPort())

# Copy props from markups to model
planeMarkupDisplayNode = planeMarkup.GetDisplayNode()
planeModelDisplayNode = planeModel.GetDisplayNode()
planeColor = planeMarkupDisplayNode.GetSelectedColor()
mauigna06 marked this conversation as resolved.
Show resolved Hide resolved
planeModelDisplayNode.SetColor(planeColor)
planeOpacity = planeMarkupDisplayNode.GetFillOpacity()
planeModelDisplayNode.SetOpacity(planeOpacity)
planeModel.SetName(planeMarkup.GetName())

return planeModel

class OpenAnatomyExportTest(ScriptedLoadableModuleTest):
"""
Expand Down