[vtkusers] Assigning multiple colors to two merged cylinders

Mirko Boettcher mail at mirkoboettcher.de
Fri Jan 8 06:47:43 EST 2010


Hi, 

I'm facing the following problem in vtk. I have two vtkPolyData objects
each created from vtkCylinderSource. I will combine both into one 
vtkActor, but each one should have a different color. 

While combining the vtkPolyData using vtkAppendPolyData is quite
simple I still have no clue how to implement that each cylinder has 
a different color.

Could someone please hint me at how to carry out this task?

Kind Regards,

Mirko

Here is my code:

       // create the first cylinder
       vtkCylinderSource cyl = new vtkCylinderSource();
        cyl.SetHeight(length);
        cyl.SetCenter(0,length, 0);
        cyl.SetRadius(RADIUS);
        cyl.SetResolution(RESOLUTION);
        cyl.CappingOn();
      
        // get the polydata
        vtkPolyData cylData = cyl.GetOutput();


        // create the second cylinder
        vtkCylinderSource projLine = new vtkCylinderSource();
        projLine.SetHeight(time);
        projLine.SetCenter(0, length2, 0);
        projLine.SetRadius(RADIUS / 50.0);
        projLine.SetResolution(RESOLUTION);
        projLine.CappingOn();
     
        // get the polydata
        vtkPolyData projLineData = projLine.GetOutput();

        // append both polydata sets
        vtkAppendPolyData apd = new vtkAppendPolyData();
        apd.AddInput(cylData);
        apd.AddInput(projLineData);
 

        // create the actor
        vtkActor actor = new vtkActor();
        actor.SetPosition(position);
        actor.RotateX(90);
        actor.SetOrigin(0, 0, 0);

        actor.SetMapper(cylMapper);
        actor.VisibilityOn();




More information about the vtkusers mailing list