Hello
I have made 3d model of nasal cavity ,now I want to add another segment in which I will create a plane surface with zero thickness , how can I do that?
Hello
I have made 3d model of nasal cavity ,now I want to add another segment in which I will create a plane surface with zero thickness , how can I do that?
If you want a model. You can add a modelNode to the scene and set its polydata from vtk.vtkPlaneSource()
I’m sure you’ll find vtk examples on how to use that filter and you can use this from the scriptRepository:
# Create model node and add to scene
modelsLogic = slicer.modules.models.logic()
model = modelsLogic.AddModel(sphere.GetOutput())
Instead of sphere it should be your plane.
But can I export this plane as a STL geometry , how can I do that please help
You can save the plane as a json file, which contains the plane position and normal, size, etc. You can also create a model node from the markup node using this code snippet that can be saved as STL, PLY, etc. file format:
planeNode = getNode('P')
# Get plane geometry
import numpy as np
origin = np.array(planeNode.GetOriginWorld())
axisX = np.zeros(3)
axisY = np.zeros(3)
axisZ = np.zeros(3)
planeNode.GetAxesWorld(axisX, axisY, axisZ)
corner = origin - 0.5 * size[0]*axisX - 0.5 * size[1]*axisY
size = planeNode.GetSize()
# Create polygonal mesh model that can be saved as ply, obj, stl,... file
planeSource = vtk.vtkPlaneSource()
planeSource.SetOrigin(corner)
planeSource.SetPoint1(corner+size[0]*axisX)
planeSource.SetPoint2(corner+size[1]*axisY)
planeModel = slicer.modules.models.logic().AddModel(planeSource.GetOutputPort())
Why do you need this plane as an STL file?
Where should I write the code? I am not getting any option
I need this plane because i will use this plane to select patches in my geometry for giving boundary conditions
Your can open the Python console from the View menu.
This code works for any vtkMRMLMarkupsPlaneNode (any sizeMode, any planeType):
planeNode = getNode('P')
cornerPoints = vtk.vtkPoints()
planeNode.GetPlaneCornerPoints(cornerPoints)
from vtk.util.numpy_support import vtk_to_numpy
cornerPoints_np = vtk_to_numpy(cornerPoints.GetData())
import numpy as np
def sort_points(pts):
"""Sort 4 points in a winding order"""
pts = np.array(pts)
centroid = np.sum(pts, axis=0) / pts.shape[0]
vector_from_centroid = pts - centroid
vector_angle = np.arctan2(
vector_from_centroid[:, 1], vector_from_centroid[:, 0])
# Find the indices that give a sorted vector_angle array
sort_order = np.argsort(-vector_angle)
# Apply sort_order to original pts array.
return list(sort_order)
order = sort_points(cornerPoints_np)
# Create polygonal mesh model that can be saved as ply, obj, stl,... file
planeSource = vtk.vtkPlaneSource()
planeSource.SetOrigin(cornerPoints_np[order[0]])
planeSource.SetPoint1(cornerPoints_np[order[1]])
planeSource.SetPoint2(cornerPoints_np[order[-1]])
planeModel = slicer.modules.models.logic().AddModel(planeSource.GetOutputPort())
Hope it helps
corner = origin - 0.5 * size[0]*axisX - 0.5 * size[1]*axisY
size = planeNode.GetSize()
These two lines seems have to be swapped since the variable “size” is used before defined?
Thank you, prof. Lasso, this code is helpful !