[vtkusers] vtkRenderer->UseShadowOn() & QVTKWidget

Remi Charrier remi.charrier at gmail.com
Wed Sep 7 09:39:35 EDT 2016


Dear Shawn,
Thanks for your prompt answer and for your effort (next time, I will use
simpler objects when sharing my code...). I just tried with the opengl
backend but it seems that the UseShadowOn() function has no effect in this
mode. I did not have time to investigate it further today but I will
continue to investigate this option.

If the rendering backend guru have any other ideas that I can try, please
do not hesitate.
Thanks again!
Rémi


2016-09-07 14:23 GMT+02:00 Shawn Waldon <shawn.waldon at kitware.com>:

> Hi Remi,
>
> My first guess (that it was a Qt4 vs Qt5 issue) was wrong. I'm getting the
> crash either way.  The crash is in the rendering backend.  This may be an
> OpenGL2 issue... have you tried it with the old backend?  I'm CCing the
> main rendering backend guru, he may be able to figure this out.
>
> For Ken and/or others on the list who try to track this down, I've
> attached an updated version of the code (with the #includes put back in and
> the missing data files replaced with sphere sources).  It still reproduces
> the crash.  Here is the backtrace:
>
> #0  0x00007ffff64e7d82 in std::vector<vtkSmartPointer<vtkTextureObject>,
> std::allocator<vtkSmartPointer<vtkTextureObject> > >::operator[]
> (this=0x0, __n=0)
>     at /usr/include/c++/5/bits/stl_vector.h:780
> #1  0x00007ffff6652ade in vtkShadowMapPass::Render (this=0xaad230,
>     s=0x7fffffffd500)
>     at /home/shawn/dev/vtk/src/Rendering/OpenGL2/vtkShadowMapPass.cxx:189
> #2  0x00007ffff65f0f9e in vtkOpenGLRenderer::UpdateGeometry
> (this=0x686a20)
>     at /home/shawn/dev/vtk/src/Rendering/OpenGL2/vtkOpenGLRenderer.cxx:209
> #3  0x00007ffff65f09f1 in vtkOpenGLRenderer::DeviceRender (this=0x686a20)
>     at /home/shawn/dev/vtk/src/Rendering/OpenGL2/vtkOpenGLRenderer.cxx:164
> #4  0x00007ffff60b8e86 in vtkRenderer::Render (this=0x686a20)
>     at /home/shawn/dev/vtk/src/Rendering/Core/vtkRenderer.cxx:327
> #5  0x00007ffff60b6e1e in vtkRendererCollection::Render (this=0x685cc0)
>     at /home/shawn/dev/vtk/src/Rendering/Core/vtkRendererCollection.cxx:51
> #6  0x00007ffff60d0cd1 in vtkRenderWindow::DoStereoRender (this=0x687420)
>     at /home/shawn/dev/vtk/src/Rendering/Core/vtkRenderWindow.cxx:768
> #7  0x00007ffff60d0bac in vtkRenderWindow::DoFDRender (this=0x687420)
>     at /home/shawn/dev/vtk/src/Rendering/Core/vtkRenderWindow.cxx:737
> #8  0x00007ffff60d0550 in vtkRenderWindow::DoAARender (this=0x687420)
>     at /home/shawn/dev/vtk/src/Rendering/Core/vtkRenderWindow.cxx:616
> #9  0x00007ffff60cfa9a in vtkRenderWindow::Render (this=0x687420)
>     at /home/shawn/dev/vtk/src/Rendering/Core/vtkRenderWindow.cxx:432
> #10 0x00007ffff65e8fc4 in vtkOpenGLRenderWindow::Render (this=0x687420)
>    /shawn/dev/vtk/src/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx:681
> #11 0x00007ffff66ad108 in vtkXOpenGLRenderWindow::Render (this=0x687420)
>     at /home/shawn/dev/vtk/src/Rendering/OpenGL2/
> vtkXOpenGLRenderWindow.cxx:1823
> #12 0x000000000040466d in main ()
>
> HTH,
> Shawn
>
> On Wed, Sep 7, 2016 at 6:00 AM, Remi Charrier <remi.charrier at gmail.com>
> wrote:
>
>> Dear all,
>>
>> Sorry to come back to this but I didn't have any answer to my previous
>> message and I am really blocked here.
>>
>> Thanks to the function UseShadowOn() of the vtkRenderer I am able to
>> create the shadows I expected in a vtkRenderWindow however as soon as I try
>> to link this renderwindow to a QVTKWidget my program crashes with no
>> message (which is not the case when shadows are disabled).
>>
>> Any idea on what could be wrong would be appreciated.
>>
>> My ultimate solution would be to stop using the QVTKWidget and have a GUI
>> without an integrated renderwindow but this would not be optimal at all...
>>
>> Rémi
>>
>>
>>
>>
>>
>> 2016-08-30 16:20 GMT+02:00 Remi Charrier <remi.charrier at gmail.com>:
>>
>>> Dear all,
>>>
>>> I am trying for quiet a long time to make the projected shadows visible
>>> in a vtkRenderWindow.
>>> I am working with vtk7.0 and OpenGL2 Backend.
>>> I am using scene lights and the function useShadowOn() (much more
>>> practical than the available examples: TestShadowMapPass.cxx ;) ).
>>>
>>> This works well and creates the shadows as I expected them.
>>>
>>> However, I am trying to integrate this in a QVTKWidget and problem start
>>> there.
>>> As soon as I combine shadows and QVTKWidget it crashes without any
>>> message.
>>> I am using Qt-5.7
>>>
>>> I didn't find any relevant information helping me to understand this
>>> problem and how to solve it. Does anyone as any idea about what could be
>>> wrong in my code or in the elements I am using?
>>>
>>> Please find my code below:
>>>
>>>
>>> CMAKELIST.txt
>>> /**********************************************************/
>>> PROJECT(TestShadows)
>>>
>>> set(CMAKE_INCLUDE_CURRENT_DIR ON)
>>> set(CMAKE_AUTOMOC ON)
>>>
>>> find_package (VTK COMPONENTS
>>>   vtkCommonCore
>>>   vtkFiltersSources
>>>   vtkInteractionStyle
>>>   vtkRenderingCore
>>>   vtkIOCore
>>>   vtkIOGeometry
>>>   vtkIOPLY
>>>   vtkRenderingCore
>>>   vtkRenderingVolumeOpenGL2
>>>   vtkRenderingOpenGL2${VTK_RENDERING_BACKEND}
>>>   vtkRenderingVolume${VTK_RENDERING_BACKEND}
>>>
>>> #for qt app
>>>   vtkGUISupportQt
>>>   vtkIOImage
>>> )
>>>
>>> include ( ${VTK_USE_FILE} )
>>>
>>> include_Directories (${CMAKE_CURRENT_BINARY_DIR})
>>>
>>> SET(LOGIC_SOURCE
>>>     main.cxx )
>>>
>>> find_package(Qt5 COMPONENTS Core REQUIRED QUIET)
>>>
>>> ADD_EXECUTABLE(TestShadows ${LOGIC_HEADERS} ${LOGIC_SOURCE})
>>> qt5_use_modules(TestShadows Core Gui Widgets)
>>> TARGET_LINK_LIBRARIES(TestShadows  ${VTK_LIBRARIES} )
>>>
>>> /***********************************************************
>>> *************/
>>>
>>> main.cxx:
>>>
>>> int main(int argc, char** argv)
>>> {
>>>   QApplication app(argc, argv);
>>>
>>>   // load 3D model
>>>   const char* fileName = "D:/RCH-CHUV/Data/testdata/dragon.ply";
>>>   vtkNew<vtkPLYReader> reader;
>>>   reader->SetFileName(fileName);
>>>   reader->Update();
>>>
>>>   vtkNew<vtkPolyDataMapper> mapper;
>>>   mapper->SetInputConnection(reader->GetOutputPort());
>>>
>>>   // create corresponding actor
>>>   vtkNew<vtkActor> actor;
>>>   actor->SetMapper(mapper.Get());
>>>   actor->GetProperty()->SetAmbientColor(0.135, 0.2225, 0.3);
>>>   actor->GetProperty()->SetDiffuseColor(0.54, 0.89, 0.63);
>>>   actor->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
>>>   actor->GetProperty()->SetSpecular(0.51);
>>>   actor->GetProperty()->SetDiffuse(0.7);
>>>   actor->GetProperty()->SetAmbient(0.7);
>>>   actor->GetProperty()->SetSpecularPower(30.0);
>>>   actor->GetProperty()->SetOpacity(1.0);
>>>
>>>   const char* fileName2 = "D:/RCH-CHUV/Data/CMR-1/meshes
>>> /Left-Right/model.stl";
>>>   vtkNew<vtkSTLReader> reader2;
>>>   reader2->SetFileName(fileName2);
>>>   reader2->Update();
>>>
>>>   vtkNew<vtkPolyDataMapper> mapper2;
>>>   mapper2->SetInputConnection(reader2->GetOutputPort());
>>>
>>>   // create corresponding actor
>>>   vtkNew<vtkActor> actor2;
>>>   actor2->SetMapper(mapper2.Get());
>>>   actor2->GetProperty()->SetAmbientColor(0.135, 0.2225, 0.3);
>>>   actor2->GetProperty()->SetDiffuseColor(0.54, 0.89, 0.63);
>>>   actor2->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
>>>   actor2->GetProperty()->SetSpecular(0.51);
>>>   actor2->GetProperty()->SetDiffuse(0.7);
>>>   actor2->GetProperty()->SetAmbient(0.7);
>>>   actor2->GetProperty()->SetSpecularPower(30.0);
>>>   actor2->GetProperty()->SetOpacity(1.0);
>>>   actor2->SetPosition(-0.6, -0.6, -0.6);
>>>   actor2->SetScale(0.01);
>>>
>>> // create vtkrenderer
>>>   vtkNew<vtkRenderer> renderer;
>>>   renderer->SetBackground(0.3, 0.4, 0.6);
>>>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>>> vtkSmartPointer<vtkRenderWindow>::New();
>>>   renderWindow->SetSize(600, 600);
>>>   renderWindow->AddRenderer(renderer.Get());
>>>   vtkNew<vtkRenderWindowInteractor>  iren;
>>>   iren->SetRenderWindow(renderWindow.Get());
>>>
>>> //create lights
>>>   vtkNew<vtkLight> light1;
>>>   light1->SetPositional(0); // 0 and 1 works
>>>   light1->SetFocalPoint(0, 0, 0);
>>>   light1->SetPosition(0, 1, 0.2);
>>>   light1->SetColor(0.95, 0.97, 1.0);
>>>   light1->SetIntensity(0.8);
>>>   renderer->AddLight(light1.Get());
>>>
>>>   vtkNew<vtkLight> light2;
>>>   light2->SetPositional(0); // 0 and 1 works
>>>   light2->SetFocalPoint(0, 0, 0);
>>>   light2->SetPosition(1.0, 1.0, 1.0);
>>>   light2->SetColor(1.0, 0.8, 0.7);
>>>   light2->SetIntensity(0.3);
>>>   renderer->AddLight(light2.Get());
>>>
>>>
>>>   // add a plane
>>>   vtkNew<vtkPlaneSource> plane;
>>>   double *plybounds = mapper->GetBounds();
>>>   plane->SetOrigin(-0.2, plybounds[2], -0.2);
>>>   plane->SetPoint1(0.2, plybounds[2], -0.2);
>>>   plane->SetPoint2(-0.2, plybounds[2], 0.2);
>>>   vtkNew<vtkPolyDataMapper> planeMapper;
>>>   planeMapper->SetInputConnection(plane->GetOutputPort());
>>>   vtkNew<vtkActor> planeActor;
>>>   planeActor->SetMapper(planeMapper.Get());
>>>   renderer->AddActor(planeActor.Get());
>>>   renderer->AddActor(actor.Get());
>>>   renderer->AddActor(actor2.Get());
>>>   renderWindow->SetMultiSamples(0);
>>>
>>> // this lines is the line that leads to crash when added (it crashes
>>> when the QVTKwidget tries to render)
>>>   renderer->UseShadowsOn();
>>>
>>>
>>>
>>>   vtkNew<vtkTimerLog> timer;
>>>   timer->StartTimer();
>>>   renderWindow->Render();
>>>   timer->StopTimer();
>>>   double firstRender = timer->GetElapsedTime();
>>>   cerr << "first render time: " << firstRender << endl;
>>>
>>>   timer->StartTimer();
>>>   int numRenders = 8;
>>>   for (int i = 0; i < numRenders; ++i)
>>>   {
>>>  renderer->GetActiveCamera()->Azimuth(80.0 / numRenders);
>>>  renderer->GetActiveCamera()->Elevation(80.0 / numRenders);
>>>  renderWindow->Render();
>>>   }
>>>   timer->StopTimer();
>>>   double elapsed = timer->GetElapsedTime();
>>>   cerr << "interactive render time: " << elapsed / numRenders << endl;
>>>   unsigned int numTris = reader->GetOutput()->GetPolys(
>>> )->GetNumberOfCells();
>>>   cerr << "number of triangles: " << numTris << endl;
>>>   cerr << "triangles per second: " << numTris*(numRenders / elapsed) <<
>>> endl;
>>>
>>>   renderer->GetActiveCamera()->SetPosition(-0.2, 0.2, 1);
>>>   renderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
>>>   renderer->GetActiveCamera()->SetViewUp(0, 1, 0);
>>>   renderer->GetActiveCamera()->OrthogonalizeViewUp();
>>>   renderer->ResetCamera();
>>>   renderer->GetActiveCamera()->Zoom(2.5);
>>>
>>>
>>> // Declaration of a QVTKWidget associated to the renderWindow
>>>
>>>   QVTKWidget * m_3Dwidget = new QVTKWidget();
>>>   m_3Dwidget->update();
>>>   m_3Dwidget->resize(600, 600);
>>>   m_3Dwidget->SetRenderWindow(renderWindow);
>>>   m_3Dwidget->update();
>>>
>>>   QVTKInteractor * minteractor = QVTKInteractor::New();
>>>   minteractor->Initialize();
>>>
>>>   m_3Dwidget->GetRenderWindow()->SetInteractor(minteractor);
>>>   m_3Dwidget->GetRenderWindow()->Render();
>>>
>>>   app.exec();
>>>
>>>   return EXIT_SUCCESS;
>>>
>>>
>>> }
>>>
>>>
>>> Rémi
>>>
>>>
>>>
>>
>> _______________________________________________
>> 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160907/7bc1c209/attachment.html>


More information about the vtkusers mailing list