[Ves] How to color polydata with Scalars in VES
Bo Yu
yubo1983 at gmail.com
Wed Feb 26 23:47:14 EST 2014
Yes, Aashish, Thank you, now the triangle is colored.
On Thu, Feb 27, 2014 at 3:30 AM, Aashish Chaudhary <
aashish.chaudhary at kitware.com> wrote:
> Hi Bo,
>
> Do this in your code
>
> polydata->GetPointData()->SetScalars(colors);
>
> What Casey said is right but that would be needed if you want to color
> faces. In your code, you have to set colors on the points because that's
> where we look for it.
>
> - Aashish
>
>
>
> On Tue, Feb 25, 2014 at 1:11 PM, Aashish Chaudhary <
> aashish.chaudhary at kitware.com> wrote:
>
>> Let me have a look at it. Will report back to you soon.
>>
>> - Aashish
>>
>>
>>
>> On Tue, Feb 25, 2014 at 10:26 AM, Bo Yu <yubo1983 at gmail.com> wrote:
>>
>>> Thank you, Aashish, I tried to set name of a vtkDataArray, but that
>>> didn't make change,I still only see model with no color (or white color).
>>> if you have time could you please check my code below?
>>> I just create a simple triangle and try to paint it to red use
>>> colorByScale.
>>> However, It seems I can not change the color mode of "rep" in the last
>>> three lines. It always have the value as "Solid color"....
>>> Sorry, I just start to learn ves, and thank you so much for your reply
>>> and patient.
>>>
>>> Sincerely yours,
>>>
>>> Bo Yu
>>> /////////////////////
>>> /////testing
>>> // Setup points
>>> vtkSmartPointer<vtkPoints> points =
>>> vtkSmartPointer<vtkPoints>::New();
>>> vtkSmartPointer<vtkCellArray> vertices =
>>> vtkSmartPointer<vtkCellArray>::New();
>>> points->InsertNextPoint(0.0, 0.0, 0.0);
>>> points->InsertNextPoint(1.0, 0.0, 0.0);
>>> points->InsertNextPoint(0.0, 1.0, 0.0);
>>>
>>> // Setup colors
>>> unsigned char red[3] = {1, 0, 0};
>>> vtkSmartPointer<vtkUnsignedCharArray> colors =
>>> vtkSmartPointer<vtkUnsignedCharArray>::New();
>>> colors->SetNumberOfComponents(3);
>>> colors->SetName("Colors");
>>> colors->InsertNextTupleValue(red);
>>>
>>> vtkDataArray *colorArray = vtkDataArray::SafeDownCast(colors);
>>> colorArray->SetName("ColorsArray"); ////set color array name
>>>
>>> vtkSmartPointer<vtkCellArray> triangles
>>> =vtkSmartPointer<vtkCellArray>::New();
>>> vtkSmartPointer<vtkTriangle> triangle =
>>> vtkSmartPointer<vtkTriangle>::New();
>>> triangle->GetPointIds()->SetId(0, 0);
>>> triangle->GetPointIds()->SetId(1, 1);
>>> triangle->GetPointIds()->SetId(2, 2);
>>> triangles->InsertNextCell(triangle);
>>>
>>> vtkSmartPointer<vtkPolyData> polydata =
>>> vtkSmartPointer<vtkPolyData>::New();
>>>
>>> polydata->SetPoints(points);
>>> polydata->SetPolys(triangles);
>>> polydata->GetCellData()->SetScalars(colors);
>>> ////////////
>>>
>>> vesKiwiPolyDataRepresentation::Ptr rep =
>>> std::tr1::dynamic_pointer_cast<vesKiwiPolyDataRepresentation>(self->mKiwiApp->dataRepresentations()[0]);
>>> rep->setPolyData(polydata);//(currentPolydata->getPolydata(),
>>> newColorLookupTable);
>>> rep->colorByScalars("ColorsArray"); //colorArray->GetName()//(1.0,
>>> 0.0, 0.0, 1.0);
>>> ////////////////////////////////////////////
>>>
>>>
>>> - -! I forgot to cc to mail list.
>>>
>>>
>>> On Tue, Feb 25, 2014 at 11:37 PM, Aashish Chaudhary <
>>> aashish.chaudhary at kitware.com> wrote:
>>>
>>>> Bo,
>>>>
>>>> If I remember it correctly, you can name your scalar array "foo" and
>>>> then pass that array name to the Kiwi (have a look at the documentation for
>>>> the exact signature)
>>>>
>>>> vtkDataArray* da = ....;
>>>> da->SetArrayName("foo");
>>>>
>>>>
>>>>
>>>> On Tue, Feb 25, 2014 at 9:34 AM, Bo Yu <yubo1983 at gmail.com> wrote:
>>>>
>>>>> Hi, I am so sorry to interrupt again.
>>>>> This time I want to paint the polydata with different colors in each
>>>>> region. I found there is a method called
>>>>> void vesKiwiPolyDataRepresentation::colorByScalars(const std::string&
>>>>> arrayName)
>>>>> , which seem similar to the one I used before to set color of a
>>>>> polydata in VTK.
>>>>> polydata->GetCellData()->SetScalars(vtkDataArray *da).
>>>>>
>>>>> But why the input is a string called arrayName? If you know, Could you
>>>>> tell me how to use this method or give me some simple examples?
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>> Bo Yu
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> | Aashish Chaudhary
>>>> | R&D Engineer
>>>> | Kitware Inc.
>>>> | www.kitware.com
>>>>
>>>
>>>
>>
>>
>> --
>> | Aashish Chaudhary
>> | R&D Engineer
>> | Kitware Inc.
>> | www.kitware.com
>>
>
>
>
> --
> | Aashish Chaudhary
> | R&D Engineer
> | Kitware Inc.
> | www.kitware.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/ves/attachments/20140227/fcfa9a6a/attachment-0003.html>
More information about the Ves
mailing list