[vtkusers] opengl2 : set the RGB color to a vertex with vtkPolyData and vtkPolyDataMapper

Ken Martin ken.martin at kitware.com
Thu Jan 21 14:43:39 EST 2016


It does not look like you ever set the number of points.  From the
documentation for vtkPoints::SetPoint

Insert point into object. No range checking performed (fast!). Make sure
you use SetNumberOfPoints()
<http://www.vtk.org/doc/nightly/html/classvtkPoints.html#ab290ea156aa2635aa7d2d64998dc04e2>
to
allocate memory prior to using SetPoint()
<http://www.vtk.org/doc/nightly/html/classvtkPoints.html#a0ca9c77d1efbeb7dff8d15ec34b19192>
.

Resize allocates memory but I do not believe it sets the number of points.
So from the mapper's perspective you still had zero points. InsertNextPoint
is slower but it handles adjust the memory and number of points
automatically.

Thanks
Ken



On Mon, Jan 18, 2016 at 12:45 PM, MOUSSAUD David 244079 <
David.MOUSSAUD at cea.fr> wrote:

> Hi,
>
>
>
> I have finally found how to display my colored points.
>
>
>
> Instead of using
>
>     points->SetPoint(0, 0.1, 0.0, 0.0);
>
> I have used
>
>     points->InsertNextPoint(0.1, 0.0, 0.0);
>
>
>
> and it works like a charm !
>
>
>
> Could someone explain me(us) why, calling this API, it does not make
> appear the 2 warning messages below ?
>
>
>
> Best regards,
>
> David.
> ------------------------------
> *De :* vtkusers [vtkusers-bounces at vtk.org] de la part de MOUSSAUD David
> 244079
> *Envoyé :* jeudi 14 janvier 2016 09:51
> *À :* vtkusers at vtk.org
> *Objet :* [PROVENANCE INTERNET] [vtkusers] opengl2 : set the RGB color to
> a vertex with vtkPolyData and vtkPolyDataMapper
>
> Dear all,
>
>
>
> I'm trying to use the opengl2 backend rendering. I am with the 6.3 release
> version.
>
>
>
> I have a working code to display 3 colored vertex that works with opengl1
> (cf below and attached file).
>
>
>
>
>
>     // Setup points
>
>     points = vtkSmartPointer<vtkPoints>::New();
>
>
>      // Setup the colors array
>
>     colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
>
>     colors->SetNumberOfComponents(3);
>
>     colors->SetName("Colors");
>
>
>     // create a vertex
>
>     vertex = vtkSmartPointer<vtkVertex>::New();
>
>
>     // list of all the vertices
>
>     vertices= vtkSmartPointer<vtkCellArray>::New();
>
>
>     nb_points = 3;
>
>     points->Resize(nb_points);
>
>     vertices->Initialize();
>
>     colors->Initialize();
>
>
>     points->SetPoint(0, 0.1, 0.0, 0.0);
>
>     vertex->GetPointIds()->SetId(0,0);
>
>     vertices->InsertNextCell(vertex);
>
>     colors->InsertNextTuple3(255,0,0);
>
>
>     points->SetPoint(1, 0, 0.1, 0.0);
>
>     vertex->GetPointIds()->SetId(0,1);
>
>     vertices->InsertNextCell(vertex);
>
>     colors->InsertNextTuple3(0,255,0);
>
>
>     points->SetPoint(2, 0, 0.0, 0.1);
>
>     vertex->GetPointIds()->SetId(0,2);
>
>     vertices->InsertNextCell(vertex);
>
>     colors->InsertNextTuple3(0,0,255);
>
>
>     // Create a polydata object and add everything to it
>
>     polydata = vtkSmartPointer<vtkPolyData>::New();
>
>     polydata->SetPoints(points);
>
>     polydata->SetVerts(vertices);
>
>     polydata->GetPointData()->SetScalars(colors);
>
>
>     mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
>
>
>     mapper->SetInputData(polydata);
>
>
>     actor = vtkSmartPointer<vtkActor>::New();
>
>     actor->SetMapper(mapper);
>
>     actor->GetProperty()->SetPointSize(5);
>
>
>     // Setup window
>
>     renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
>
>
>     // Setup renderer
>
>     renderer = vtkSmartPointer<vtkRenderer>::New();
>
>     renderWindow->AddRenderer(renderer);
>
>
>     renderer->AddActor(actor);
>
>     renderer->ResetCamera();
>
>
>     this->SetRenderWindow(renderWindow);
>
>
>
> When I compile the same project with my vtk library compiled with the
> opengl2 backend rendering,
>
>
>
> I have this error :
>
>
>
> ERROR: In
> C:\work\lib\vtk\VTK-6.3.0\VTK-6.3.0\Rendering\OpenGL2\vtkOpenGLPolyDataMapper.cxx,
> line 1223
> vtkOpenGLPolyDataMapper (0000000000501B90): Error setting 'vertexMC' in
> shader VAO.
>
> ERROR: In
> C:\work\lib\vtk\VTK-6.3.0\VTK-6.3.0\Rendering\OpenGL2\vtkOpenGLPolyDataMapper.cxx,
> line 1250
> vtkOpenGLPolyDataMapper (0000000000501B90): Error setting 'scalarColor' in
> shader VAO.
>
>
>
> For information, I've tried the same with a vtkPlyReader based project and
> I've succeed to render it with opengl2 backend (and it works very much
> better !)
>
>
>
> Best Regards,
>
> David.
>
>
>
>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Ken Martin PhD
Chairman & CFO
Kitware Inc.
28 Corporate Drive
Clifton Park NY 12065
518 371 3971

This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee.  Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160121/b5443443/attachment.html>


More information about the vtkusers mailing list