Hi Dear 3DSlicer developers
I want to define one pyramid with cross-section of polygon (for example polygon with 160 vertices) using VTK.
I think that I must use vtkFrustumSource. Is it ok?
How can I do it?
Please guide me.
Shahrokh
Hi Dear 3DSlicer developers
I want to define one pyramid with cross-section of polygon (for example polygon with 160 vertices) using VTK.
I think that I must use vtkFrustumSource. Is it ok?
How can I do it?
Please guide me.
Shahrokh
Yes, any vtkPolyData from vtk (either a source or the result of a pipeline) should be usable with a vtkMRMLModelNode.
https://lorensen.github.io/VTKExamples/site/Python/#geometric-objects
vtkFrustumSource
can only create rectangular pyramid. If you need to extrude arbitrary polygons then you may use vtkLinearExtrusionFilter
.
Thanks a lot for your guidance.
To implement a polygon in Python interactor, I wrote the code to run in 3DSlicer.
In short, I mention to the geometry considered with me and it is shown in the following figures (IDs and spatial coordinates).
As you see, I have 23 points in RAS coordinate system (RS plane). After doing it, I want to create a polygon model and access to it in Data module. The following figure is shown these points and the polygon.
The following lines are the code I wrote.
import vtk
polygonPoints = vtk.vtkPoints()
polygonPoints.SetNumberOfPoints(23)
polygonPoints.InsertPoint(0,4,0,0)
polygonPoints.InsertPoint(1,1,0,1)
polygonPoints.InsertPoint(2,2,0,1.5)
polygonPoints.InsertPoint(3,3,0,2.5)
polygonPoints.InsertPoint(4,2,0,3.5)
polygonPoints.InsertPoint(5,1,0,4.5)
polygonPoints.InsertPoint(6,-1,0,5)
polygonPoints.InsertPoint(7,-2,0,4)
polygonPoints.InsertPoint(8,-3,0,3.5)
polygonPoints.InsertPoint(9,-4,0,3)
polygonPoints.InsertPoint(10,-4.5,0,2)
polygonPoints.InsertPoint(11,-5,0,1)
polygonPoints.InsertPoint(12,-5,0,0)
polygonPoints.InsertPoint(13,-4.5,0,-1)
polygonPoints.InsertPoint(14,-3,0,-2)
polygonPoints.InsertPoint(15,-2,0,-2.5)
polygonPoints.InsertPoint(16,-1,0,-3)
polygonPoints.InsertPoint(17,0,0,-5)
polygonPoints.InsertPoint(18,1,0,-5)
polygonPoints.InsertPoint(19,2,0,-4.5)
polygonPoints.InsertPoint(20,3,0,-3)
polygonPoints.InsertPoint(21,3,0,-2)
polygonPoints.InsertPoint(22,3,0,-1)
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(polygonPoints)
model = slicer.vtkMRMLModelNode()
model.SetAndObservePolyData(polygonPolyData)
modelDisplay = slicer.vtkMRMLModelDisplayNode()
modelDisplay.SetColor(1, 1, 0)
modelDisplay.BackfaceCullingOff()
modelDisplay.SetOpacity(0.5)
modelDisplay.SetPointSize(3)
modelDisplay.SetSliceIntersectionVisibility(True)
modelDisplay.SetVisibility(True)
slicer.mrmlScene.AddNode(modelDisplay)
model.SetAndObserveDisplayNodeID(modelDisplay.GetID())
modelDisplay.SetInputPolyDataConnection(model.GetPolyDataConnection())
slicer.mrmlScene.AddNode(model)
When I enter this code in Python interactor of 3DSlicer, I see that a new node is created in Data module as is shown in the following figure.
Unfortunately, I do not see this model (polygon with 23 sides) in 3D window and I can not change it (for example rotation and translation).
Why?
What’s wrong with me?
Please guide me.
Thanks a lot.
Shahrokh.
You added points, but you’ve forgot to add a polygon cell. You need to do something like this:
You can find many examples of how to create polydata manually on VTK examples site.
Thanks a lot for your help.
As mentioned you, I add the following lines
…
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(polygonPoints)#Create Cell
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(23)
for i in range(0,22):
polygons.InsertCellPoint(i)
polygons.Modified()
polygonPolyData.SetPolys(polygons)model = slicer.vtkMRMLModelNode()
model.SetAndObservePolyData(polygonPolyData)
…
At now, I can see my polygon model in Wireframe Representation as following figure:
It is ok.
Unfortunately, this varies slightly when I see it in Surface with WireFrame representations as following figures:
Or
As see you, Why do not they match (edges (black color wireframe) with the edges of polygon surface (yellow surface))?
Is this a visual error or I made a mistake again?
Thanks a lot for your support.
Shahrokh.
OpenGL can only render convex filled polygons. If you need to display non-convex polygon then you can triangulate it using vtkTriangleFilter.