Hi Andras, maybe this is a simple question, but I really need your help. I have the requirement of using gradient color jpg file make a texture mapping on 3D surface, I have draft code with pure vtk, and it got the expected result:
import vtk
Create a render window
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(480,480)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
Generate a sphere
sphere = vtk.vtkSphereSource()
Read the image data from a file
reader = vtk.vtkJPEGReader()
reader.SetFileName(“gradientColor.jpeg”)
Create texture object
texture = vtk.vtkTexture()
texture.SetInputConnection(reader.GetOutputPort())
#Map texture coordinates
map_to_plane = vtk.vtkTextureMapToPlane()
map_to_plane.SetInputConnection(sphere.GetOutputPort())
Create mapper and set the mapped texture as input
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(map_to_plane.GetOutputPort())
Create actor and set the mapper and the texture
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetTexture(texture)
ren.AddActor(actor)
iren.Initialize()
renWin.Render()
iren.Start()
The result as below picture:
I have two questions here:
The first one:
When I try to use SlicerIGT extension Texture Model, it has not got the expected result. The steps as below:
v = slicer.util.getNode(‘View1’)
v.SetBoxVisible(False)
Sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetCenter(0,0,0)
sphereSource.SetRadius(60.0)
sphereSource.Update()
sphereSource = sphereSource.GetOutput() # vtkPolyData()
Create a model with the sphere and add it to scene
modelNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLModelNode’)
modelNode.SetAndObservePolyData(sphereSource)
modelNode.CreateDefaultDisplayNodes()
modelNode.SetName(‘My sphere’)
and then I come back to main UI in 3D Slicer and use the Texture model as below:
But as you see, the result is not expected. What am I wrong here?
The second one is: How can I use python script to generate the texture mapping model? Should I use below code:
def showTextureOnModel(self, modelNode, textureImageNode):
modelDisplayNode = modelNode.GetDisplayNode()
modelDisplayNode.SetBackfaceCulling(0)
textureImageFlipVert = vtk.vtkImageFlip()
textureImageFlipVert.SetFilteredAxis(1)
textureImageFlipVert.SetInputConnection(textureImageNode.GetImageDataConnection())
modelDisplayNode.SetTextureImageDataConnection(textureImageFlipVert.GetOutputPort())
maybe the question is simple and stupid, but I really need your help and suggestion. And I cannot access the website: onedrive.live.com, is there another website for the SlicerIGT tutorial?
Thanks in advance!