[vtkusers] vtkRenderer->UseShadowOn() & QVTKWidget

Remi Charrier remi.charrier at gmail.com
Wed Sep 7 06:00:23 EDT 2016


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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160907/309cd5ad/attachment.html>


More information about the vtkusers mailing list