[vtkusers] How to color cylinder with different colors

Alex Malyushytskyy alexmalvtk at gmail.com
Tue May 7 17:58:50 EDT 2013


Your cylinder source produces  polydata.

Common ways to define color for polydata in vtk  for cells or nodes ( in
your case you want cells )
is either define color as rgb values in a char array:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TriangleSolidColor

or as a value which later can be mapped using LookUp table:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColorCells

You will have to make sure your cylinder has at least 3 cells along the
axis to obtain desired results.

Alex




On Mon, May 6, 2013 at 10:03 PM, Divya <divya at triassicsolutions.com> wrote:

>  Dear All,
>
> I want to color a cylinder like the image attached. I have tried combining
> 2 different cylinder source with different colors but I am getting the
> following result
>
>
>  Any help will be greatly appreciated.
>
> My source code is as follows:
>
> vtkCylinderSource catheter = vtkCylinderSource.New();
>             catheter.SetRadius(1);
>             catheter.SetHeight(15.0);
>             catheter.Update();
>             //catheter.CappingOn();
>
>             vtkFloatArray cylColor1 = vtkFloatArray.New();
>             cylColor1.SetNumberOfComponents(3);
>             cylColor1.SetName("Color1");
>
>             for (int i = 0; i < catheter.GetOutput().GetNumberOfPoints();
> i++)
>             {
>                 cylColor1.InsertTuple3(i, 255, 0, 0);
>             }
>             catheter.GetOutput().GetPointData().SetScalars(cylColor1);
>
>             vtkCylinderSource catheter2 = vtkCylinderSource.New();
>             catheter2.SetRadius(1);
>             catheter2.SetHeight(10.0);
>             catheter2.Update();
>             //catheter2.CappingOn();
>
>             vtkFloatArray cylColor = vtkFloatArray.New();
>             cylColor.SetNumberOfComponents(3);
>             cylColor.SetName("Color2");
>
>             for (int i = 0; i < catheter2.GetOutput().GetNumberOfPoints();
> i++)
>             {
>                 cylColor.InsertTuple3(i, 0, 0, 255);
>             }
>             catheter2.GetOutput().GetPointData().SetScalars(cylColor);
>
>             // append both polydata sets
>             vtkAppendPolyData apd = new vtkAppendPolyData();
>             apd.AddInput(catheter.GetOutput());
>             apd.AddInput(catheter2.GetOutput());
>             apd.Update();
>
>             ////vtkCleanPolyData cleanFilter = vtkCleanPolyData.New();
>             ////cleanFilter.SetInput(apd.GetOutput());
>             ////cleanFilter.Update();
>
>             vtkPolyDataMapper catheterMapper = vtkPolyDataMapper.New();
>             catheterMapper.SetInputConnection(apd.GetOutputPort());
>             catheterActor.SetMapper(catheterMapper);
>
> --
>
>    Regards,
> *DIVYA SADANANDAN
> Software Engineer*
> Triassic Solutions Pvt. Ltd.
> (+91) 471 2700050 (Office)
> 7736382699 (Mobile)  <http://www.triassicsolutions.com>
> Disclaimer: This e-mail contains confidential information intended solely
> for the intended recipient. If you are not the intended recipient, please
> notify the sender by e-mail and delete this email permanently from your
> records. Do not copy or distribute this e-mail and any such actions are
> unlawful. Except where this email is sent in the usual course of business,
> the views expressed in this email are those of the sender. Triassic
> Solutions Pvt. Ltd. accepts no responsibility for any indirect damage or
> loss suffered by reason of inaccuracy or incorrectness of the information
> in this email.
> + Please consider our environment before printing this e-mail.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130507/a9012646/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpg
Size: 6447 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130507/a9012646/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 14361 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130507/a9012646/attachment.png>


More information about the vtkusers mailing list