[Ves] How to color polydata with Scalars in VES

Aashish Chaudhary aashish.chaudhary at kitware.com
Thu Feb 27 10:00:20 EST 2014


Bo,


On Thu, Feb 27, 2014 at 12:22 AM, Bo Yu <yubo1983 at gmail.com> wrote:

> Thank you for your suggestion, Casey.
> If I understand correctly, now I am try to use "vesKiwiViewerApp", and I
> didn't call any shader init function in it,  so I think I am using the
> default shader.
>

Yes.


> Now I can color the model via vertexes using default shader with helps
> from you and Aashish.
>


> However, if I want to specify colors for some cells of the model, do I
> have to call the functions related with the shaders in vesKiwiViewerApp?
>

So basically you want to have color per face (or cell) rather than color
per vertices right? In that can you can run your polydata through
vtkCellDataToPointData filter as s
suggested by Casey earlier. I have a branch that does it internally when
you sent the polydata on the representation that will be available in
master tomorrow if all goes well.


> Sorry but I know little about this, is there some documents about how to
> achieve this goal?
> Thank you very much.
>

http://www.vtk.org/doc/nightly/html/classvtkCellDataToPointData.html

>
> Best regards,
> Bo Yu
>
>
>
> On Thu, Feb 27, 2014 at 12:01 AM, Casey Goodlett <
> casey.goodlett at kitware.com> wrote:
>
>> Bo,
>>
>> Are you using the default shader?  I think you should specify colors
>> per-vertex rather than per-cell with the default shader.
>>
>>
>>  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
>>>>
>>>
>>>
>>> _______________________________________________
>>> Ves mailing list
>>> Ves at public.kitware.com
>>> http://public.kitware.com/cgi-bin/mailman/listinfo/ves
>>>
>>>
>>
>>
>> --
>> Casey B. Goodlett, Ph.D.
>> R&D Engineer
>> Kitware, Inc. - North Carolina Office
>> http://www.kitware.com
>> (919) 969-6990 x310
>>
>
>


-- 
| 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/02c7a4e1/attachment-0003.html>


More information about the Ves mailing list