[vtkusers] Flat interpolation under OpenGL2 backend

Fernando Nellmeldin f.nellmeldin at open-engineering.com
Mon Feb 22 09:21:48 EST 2016


Hi, thank you for your response Simon.
I tried your suggestions. Adding SetScalarModeToUseCellData didn't solve
the problem :( (still I'm seeing all the model in white)
I saved my results to load them in ParaView and indeed I can see a new Cell
Data named "TEMP" with the values of the Point Data as I wish.
Thus, I think that the point2celldata is working properly, and I have only
a problem of configuring something to see it, but where?

Any thoughs?

Thank you.

2016-02-22 14:28 GMT+01:00 Simon ESNEAULT <simon.esneault at gmail.com>:

> Hello,
>
> Not sure, but maybe a call to
> SetScalarModeToUseCellData()
> 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 :)
>
> Good luck
> Simon
>
>
>
> 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
>> success.
>> 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<vtkXMLUnstructuredGridReader>::New();
>> reader->SetFileName(filename.c_str());
>> reader->Update();
>> vtkSmartPointer<vtkUnstructuredGrid> model = reader->GetOutput();
>>
>> vtkSmartPointer<vtkDataSetMapper> colorMapper =
>> vtkSmartPointer<vtkDataSetMapper>::New();
>> vtkSmartPointer<vtkActor> colorActor = vtkSmartPointer<vtkActor>::New();
>> vtkSmartPointer<vtkGeometryFilter> geometryFilter =
>> vtkSmartPointer<vtkGeometryFilter>::New();
>>
>> //============ BEGIN OF SECTION OF INTEREST
>> // Convert point to cell data
>> vtkSmartPointer<vtkPointDataToCellData> point2CellData =
>> vtkSmartPointer<vtkPointDataToCellData>::New();
>> point2CellData->PassPointDataOn();
>> point2CellData->SetInputData(model);
>> point2CellData->Update();
>>
>> #define USE_P2C
>> #ifdef USE_P2C
>> // Neither of these "setActiveScalars" makes any difference
>> //model->GetCellData()->SetActiveScalars(fieldname.c_str());
>> //model->GetPointData()->SetActiveScalars(fieldname.c_str());
>> geometryFilter->SetInputData(point2CellData->GetOutput());
>> geometryFilter->SetInputArrayToProcess(0, 0, 0,
>> vtkDataObject::FIELD_ASSOCIATION_CELLS, fieldname.c_str()); // cells
>> because I transfered the data
>> #else
>> model->GetPointData()->SetActiveScalars(fieldname.c_str());
>> geometryFilter->SetInputData(model);
>> geometryFilter->SetInputArrayToProcess(0, 0, 0,
>> vtkDataObject::FIELD_ASSOCIATION_POINTS, fieldname.c_str());
>> #endif
>>
>> colorMapper->SetInputConnection(geometryFilter->GetOutputPort());
>>
>> //============ END OF SECTION OF INTEREST
>>
>> colorMapper->SetScalarRange(297, 637); //hardcoded to reduce code length
>> colorActor->SetMapper(colorMapper);
>> colorMapper->ScalarVisibilityOn();
>>
>> // Usual rendering stuff, nothing of interest from here onwards
>> //Create a renderer, render window, and interactor
>> vtkSmartPointer<vtkRenderer> renderer =
>> vtkSmartPointer<vtkRenderer>::New();
>> vtkSmartPointer<vtkRenderWindow> renderWindow =
>> vtkSmartPointer<vtkRenderWindow>::New();
>> renderWindow->AddRenderer(renderer);
>> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>> renderWindowInteractor->SetRenderWindow(renderWindow);
>> //Add the actor to the scene
>> renderer->AddActor(colorActor);
>> renderer->SetBackground(.3, .6, .3); // Background color green
>> //Render and interact
>> renderWindow->Render();
>> renderWindowInteractor->Start();
>> 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
>>> flat/smooth/perspective.
>>>
>>> One stopgap, you could use vtkPointDataToCellData to essentially
>>> accomplish what you want in either back end.
>>>
>>> Thanks
>>> Ken
>>>
>>>
>>>
>>> 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
>>>> geometryFilter->SetInputConnection(m_model->GetProducerPort());
>>>> #else
>>>> geometryFilter->SetInputData(m_model);
>>>> #endif
>>>>
>>>> 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
>>>> 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.
>>>
>>
>>
>>
>> --
>> *Fernando NELLMELDIN*
>> Software Engineer
>> *_______________________________________________________________*
>>
>> *Open Engineering s.a.*
>>
>> Rue Bois Saint-Jean 15/1
>> B-4102 Seraing (Belgium)
>> Tel: +32.4.353.30.34
>>
>> http://www.open-engineering.com
>> https://www.linkedin.com/company/open-engineering?trk=biz-companies-cym
>>
>>
>> *_________________________________________________________________________*
>>
>> _______________________________________________
>> 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
>>
>>
>
>
> --
> ------------------------------------------------------------------
> Simon Esneault
> Rennes, France
> ------------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160222/f27cd313/attachment.html>


More information about the vtkusers mailing list