[vtkusers] Fwd: How to color cylinder with different colors

Alex Malyushytskyy alexmalvtk at gmail.com
Wed May 8 17:24:11 EDT 2013


There are multiple choices.

You can create the same number of  cylinders as number of colors with
height divided by number of colors.

a) then define transformation for 2 actors so each actor is above another

http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/TransformActor


b) modify created polydata using transformFilter:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TransformFilter


Google "vtk example transformation"

---------- Forwarded message ----------
From: Arindam <arindam at triassicsolutions.com>
Date: Tue, May 7, 2013 at 10:16 PM
Subject: Re: [vtkusers] How to color cylinder with different colors
To: Alex Malyushytskyy <alexmalvtk at gmail.com>


 If i m combining 2 cylinder i m getting like following.How can i make
cylinders on top of each other?



On 5/8/2013 3:30 AM, Alex Malyushytskyy wrote:

Or you can create 3 cylinders (1 for each color) on top of each other if
you want to follow your own approach.


On Tue, May 7, 2013 at 2:58 PM, Alex Malyushytskyy <alexmalvtk at gmail.com>wrote:

>  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 <%28%2B91%29%20471%202700050> (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
>>
>>
>


_______________________________________________
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



-- 

   Regards,
*ARINDAM SAHA
Software Engineer*

Triassic Solutions Pvt. Ltd.
(+91) 471 2700050 (Office)
9746145220 (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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130508/0a370cc1/attachment.htm>


More information about the vtkusers mailing list