[vtkusers] need help in using vtkPolyDataReader How to change the color?

Tomoko Tateyama tomoko at fc.ritsumei.ac.jp
Mon Sep 16 15:05:25 EDT 2013


Dear vtk user

I'm a new vtk user, Thank you for your kind corporation!
Now, I tried to visualizing some object through vtkpolydataReader as a input.

I can understood steps of visualizing .vtk file and succeed
visualization some organ,
but, as a result, organs were same color.
(ie, my hope, Object1 -> Red and Object2 -> Blue.
but result are Object1 -> Green and  Object2 -> Green  ;-< ) .
I can`t understand why I can't change the each objects color by
Actor.GetProperty().SetColor(R, G, B), and why the color is set
green???

I want to change the color of each object and output it,
 but my result is output with the same color for some reason.
Could you help me some idea to achieve this in VTK?

as following code is my VTK code by Python.
My VTK ver. is VTK 6.0.
My .vtk format is ver.3.0 & DATASET POLYDATA.

-------
#!/usr/bin/env python
import vtk
from vtk.util.misc import vtkGetDataRoot
from vtk.util.colors import red, peacock
import time

VTKFileNameObj1 = "./Object1.vtk"   #Object1s filename
VTKFileNameObj2 = "./Object2.vtk"   #Object2's filename


aRenderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(aRenderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

#Object 1 Load and Set to each actor
Object1reader = vtk.vtkPolyDataReader()
Object1reader.SetFileName(VTKFileNameObj1);
Object1Mapper = vtk.vtkPolyDataMapper()
Object1Mapper.SetInputConnection(Object1reader.GetOutputPort())

Object1Actor = vtk.vtkActor()
Object1Actor.SetMapper(Object1Mapper)
Object1Actor.GetProperty().SetColor(1.0, 0, 0)

#Object 2  Load and Set to aRenderer
Object2reader = vtk.vtkPolyDataReader()
Object2reader.SetFileName(VTKFileNameObj2);
Object2Mapper = vtk.vtkPolyDataMapper()
Object2Mapper.SetInputConnection(Object2reader.GetOutputPort())

Object2Actor = vtk.vtkActor()
Object2Actor.SetMapper(Object2Mapper)
Object2Actor.GetProperty().SetColor(0, 0, 1.0)


#Set a camera Information
aCamera = vtk.vtkCamera()
aCamera.SetViewUp(0, 0, -1)
aCamera.SetPosition(0, 1, 0)
aCamera.SetFocalPoint(0, 0, 0)
aCamera.ComputeViewPlaneNormal()

#Set object to aRenderer
aRenderer.AddActor(Object1Actor)
aRenderer.AddActor(Object2Actor)

aRenderer.SetActiveCamera(aCamera)
aRenderer.ResetCamera()
aCamera.Dolly(1.5)

aRenderer.SetBackground(0, 0, 0)
renWin.SetSize(640, 480)

aRenderer.ResetCameraClippingRange()

# Interact with the data.
iren.Initialize()
renWin.Render()
iren.Start()
-----------------------------------------------------------------------------------------

Thank you in advance

-- 


*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Tomoko Tateyama, Dr of Eng, Assisntant professor
Intelligent Image Processing Lab,
College of Information Science & Engineering,
Ritsumeikan University, Shiga.
Tel:+81-77-561-4968 (Excel ex lab)
Tel:+81-77-561-3003 (Creation Core)
Email: tomoko at fc.ritsumei.ac.jp
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~



More information about the vtkusers mailing list