[vtkusers] Assigning multiple colors to two merged cylinders

David Doria daviddoria+vtk at gmail.com
Fri Jan 8 08:55:32 EST 2010


On Fri, Jan 8, 2010 at 6:47 AM, Mirko Boettcher <mail at mirkoboettcher.de> wrote:
> 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();
>

I made a shell example if anyone wants to add the coloring code:

http://www.cmake.org/Wiki/VTK/Examples/ColorAnActor

Thanks,

David



More information about the vtkusers mailing list