[vtkusers] Flat interpolation under OpenGL2 backend
simon.esneault at gmail.com
Mon Feb 22 08:28:44 EST 2016
Not sure, but maybe a call to
is needed on the mapper ?
You should try to save/load the dataset in paraview after it is processed
to see what's going on with the cell/point data :)
2016-02-22 13:23 GMT+01:00 Fernando Nellmeldin <
f.nellmeldin at open-engineering.com>:
> Hello again.
> Yes, you understood the issue perfectly. And I understand the reason as of
> why is not working anymore, thank you for the great explanation.
> After your advise, I tried using vtkPointDataToCellData, but without
> Here is one small example I wrote. If I activate the line #define USE_P2C,
> I can't see any color (everything is light gray). If that line is
> commented, everything works as expected.
> Do you know what I am missing?
> #include <vtkSmartPointer.h>
> #include <vtkDataSetMapper.h>
> #include <vtkActor.h>
> #include <vtkPointDataToCellData.h>
> #include <vtkUnstructuredGrid.h>
> #include <vtkUnstructuredGridGeometryFilter.h>
> #include <vtkGeometryFilter.h>
> #include <vtkXMLUnstructuredGridReader.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkPointData.h>
> #include <vtkCellData.h>
> #include <vtkRenderWindowInteractor.h>
> int main()
> // Read the grid
> std::string filename = "D:/model.vtu";
> std::string fieldname = "TEMP";
> vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
> vtkSmartPointer<vtkUnstructuredGrid> model = reader->GetOutput();
> vtkSmartPointer<vtkDataSetMapper> colorMapper =
> vtkSmartPointer<vtkActor> colorActor = vtkSmartPointer<vtkActor>::New();
> vtkSmartPointer<vtkGeometryFilter> geometryFilter =
> //============ BEGIN OF SECTION OF INTEREST
> // Convert point to cell data
> vtkSmartPointer<vtkPointDataToCellData> point2CellData =
> #define USE_P2C
> #ifdef USE_P2C
> // Neither of these "setActiveScalars" makes any difference
> geometryFilter->SetInputArrayToProcess(0, 0, 0,
> vtkDataObject::FIELD_ASSOCIATION_CELLS, fieldname.c_str()); // cells
> because I transfered the data
> geometryFilter->SetInputArrayToProcess(0, 0, 0,
> vtkDataObject::FIELD_ASSOCIATION_POINTS, fieldname.c_str());
> //============ END OF SECTION OF INTEREST
> colorMapper->SetScalarRange(297, 637); //hardcoded to reduce code length
> // Usual rendering stuff, nothing of interest from here onwards
> //Create a renderer, render window, and interactor
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> //Add the actor to the scene
> renderer->SetBackground(.3, .6, .3); // Background color green
> //Render and interact
> return EXIT_SUCCESS;
> Thank you!.
> 2016-02-18 17:05 GMT+01:00 Ken Martin <ken.martin at kitware.com>:
>> Hello Fernando,
>> Making sure that I understand the issue. Essentially you have defined
>> scalars/colors on the points of a triangle. With phong shading the colors
>> interpolate across the triangle. With flat shading on the old backend, the
>> system takes the color of the first point and uses that for the entire
>> triangle. On the new backend the colors are still interpolated across the
>> triangle. Is that the issue you see?
>> If so, then the issue is that on the new backend I am interpreting
>> shading to only mean lighting and normal calculations while in the old
>> backend it seems to include vertex color properties (but not other
>> properties such as tcoords, hmm wonder what happens with flat shading and
>> texture based coloring) In modern OpenGL (version 3.2 ) you can specify
>> flat versus smooth interpolation by attribute. So normals could be flat
>> while colors are smooth. Without requiring OpenGL 3.2 we would need to
>> rebuild the VBO each time you switch between flat and smooth, basically
>> treating flat shading as if you had cell colors instead of point colors.
>> If backward compatibility was not an issue :-) I would suggest moving to
>> require OpenGL 3.2 and then modifying vtkProperty so that people can
>> independently specify if they want normals/colors/etc to be
>> One stopgap, you could use vtkPointDataToCellData to essentially
>> accomplish what you want in either back end.
>> On Thu, Feb 18, 2016 at 10:14 AM, Fernando Nellmeldin <
>> f.nellmeldin at open-engineering.com> wrote:
>>> Hello friends.
>>> In our application, we want to allow the user to alternate between a
>>> flat and a smooth shading of the colors in an actor. To do this, we have a
>>> option that allows the user to call setInterpolationToFlat() or
>>> setInterpolationToPhong() in the property of the vtkactor.
>>> The problem is that the call to set flat is not working, there is no
>>> change and the actor is always rendered smooth.
>>> I've tried with VTK 6.3.0 and VTK 7.0.0 under OpenGL2 backend. In VTK
>>> 5.10 (using the old opengl), this works as expected.
>>> And please note that in the three cases, the code is exactly the same.
>>> Well, except the connection between the ugrid and the geometry filter that
>>> I have the usual if:
>>> #if VTK_MAJOR_VERSION <= 5
>>> Therefore, is the support of flat interpolation dropped, or I have to
>>> add something to make it work under OpenGL2 backend?
>>> Thank you!
>>> Powered by www.kitware.com
>>> Visit other Kitware open-source projects at
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>> Follow this link to subscribe/unsubscribe:
>> 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.
> *Fernando NELLMELDIN*
> Software Engineer
> *Open Engineering s.a.*
> Rue Bois Saint-Jean 15/1
> B-4102 Seraing (Belgium)
> Tel: +32.4.353.30.34
> Powered by www.kitware.com
> Visit other Kitware open-source projects at
> Please keep messages on-topic and check the VTK FAQ at:
> Search the list archives at: http://markmail.org/search/?q=vtkusers
> Follow this link to subscribe/unsubscribe:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtkusers