how to display model in red viewer

classic Classic list List threaded Threaded
2 messages Options
mag
Reply | Threaded
Open this post in threaded view
|

how to display model in red viewer

mag
Hi,

I am trying to draw a polygon on the axial viewer given the coordinates of
some fiducial points. I am using a model created from a polydata object so I
can easily export it for my analysis.
I used this code in a scripted module and the polygon is correctly displayed
in the 3D view but I don't know how to display it in the red view as well,
which is what I need. Is that possible?
I've attached a screenshot at the end.

fidList = slicer.util.getNode('F')
if not fidList:
    print "No points found"
    return
numFids = fidList.GetNumberOfFiducials()

# Setup points
points = vtk.vtkPoints()
#Setup polygon
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(numFids)

points_coords = []
for i in range(numFids):
    fid_ras_coord = [0, 0, 0]
    fidList.GetNthFiducialPosition(i, fid_ras_coord)
    points.InsertNextPoint(fid_ras_coord)
    polygon.GetPointIds().SetId(i, i)
    points_coords.append(fid_ras_coord)

# Add the polygon to a list of polygons
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
# Create PolyData
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(points)
polygonPolyData.SetPolys(polygons)

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)

<http://slicer-devel.65872.n3.nabble.com/file/n4038490/screenshot.png>



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/how-to-display-model-in-red-viewer-tp4038490.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: how to display model in red viewer

lasso2
We moved discussions to http://discourse.slicer.org. Please post this question there, in the Development category. Thank you,
Andras

-----Original Message-----
From: slicer-devel [mailto:[hidden email]] On Behalf Of mag
Sent: Wednesday, April 26, 2017 1:02 PM
To: SPL Slicer Devel <[hidden email]>
Subject: [slicer-devel] how to display model in red viewer

Hi,

I am trying to draw a polygon on the axial viewer given the coordinates of some fiducial points. I am using a model created from a polydata object so I can easily export it for my analysis.
I used this code in a scripted module and the polygon is correctly displayed in the 3D view but I don't know how to display it in the red view as well, which is what I need. Is that possible?
I've attached a screenshot at the end.

fidList = slicer.util.getNode('F')
if not fidList:
    print "No points found"
    return
numFids = fidList.GetNumberOfFiducials()

# Setup points
points = vtk.vtkPoints()
#Setup polygon
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(numFids)

points_coords = []
for i in range(numFids):
    fid_ras_coord = [0, 0, 0]
    fidList.GetNthFiducialPosition(i, fid_ras_coord)
    points.InsertNextPoint(fid_ras_coord)
    polygon.GetPointIds().SetId(i, i)
    points_coords.append(fid_ras_coord)

# Add the polygon to a list of polygons
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
# Create PolyData
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(points)
polygonPolyData.SetPolys(polygons)

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)

<http://slicer-devel.65872.n3.nabble.com/file/n4038490/screenshot.png>



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/how-to-display-model-in-red-viewer-tp4038490.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ