<div dir="ltr">Dear all,<div><br></div><div>Sorry to come back to this but I didn't have any answer to my previous message and I am really blocked here. </div><div><br></div><div>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). </div><div><br></div><div>Any idea on what could be wrong would be appreciated. </div><div><br></div><div>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...</div><div><br></div><div>Rémi</div><div><br></div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2016-08-30 16:20 GMT+02:00 Remi Charrier <span dir="ltr"><<a href="mailto:remi.charrier@gmail.com" target="_blank">remi.charrier@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear all,<div><br></div><div>I am trying for quiet a long time to make the projected shadows visible in a vtkRenderWindow. </div><div>I am working with vtk7.0 and OpenGL2 Backend.</div><div>I am using scene lights and the function useShadowOn() (much more practical than the available examples: TestShadowMapPass.cxx ;) ).</div><div><br></div><div>This works well and creates the shadows as I expected them. </div><div><br></div><div>However, I am trying to integrate this in a QVTKWidget and problem start there. </div><div>As soon as I combine shadows and QVTKWidget it crashes without any message. </div><div>I am using Qt-5.7</div><div><br></div><div>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?</div><div><br></div><div>Please find my code below: </div><div><br></div><div><br></div><div>CMAKELIST.txt</div><div>/*****************************<wbr>*****************************/</div><div><div>PROJECT(TestShadows)</div><div><br></div><div>set(CMAKE_INCLUDE_CURRENT_DIR ON)<br></div><div>set(CMAKE_AUTOMOC ON)<br></div><div><br></div><div>find_package (VTK COMPONENTS</div><div> vtkCommonCore</div><div> vtkFiltersSources</div><div> vtkInteractionStyle</div><div> vtkRenderingCore</div><div> vtkIOCore</div><div> vtkIOGeometry</div><div> vtkIOPLY</div><div> vtkRenderingCore</div><div> vtkRenderingVolumeOpenGL2</div><div> vtkRenderingOpenGL2${VTK_<wbr>RENDERING_BACKEND}</div><div> vtkRenderingVolume${VTK_<wbr>RENDERING_BACKEND}</div><div> <br></div><div>#for qt app</div><div> vtkGUISupportQt</div><div> vtkIOImage</div><div>)</div><div><br></div><div>include ( ${VTK_USE_FILE} )</div><div><br></div><div>include_Directories (${CMAKE_CURRENT_BINARY_DIR})</div><div> <br></div><div>SET(LOGIC_SOURCE</div><div> main.cxx )</div><div><br></div><div>find_package(Qt5 COMPONENTS Core REQUIRED QUIET)</div><div><br></div><div>ADD_EXECUTABLE(TestShadows ${LOGIC_HEADERS} ${LOGIC_SOURCE})<br></div><div>qt5_use_modules(TestShadows Core Gui Widgets)</div><div>TARGET_LINK_LIBRARIES(<wbr>TestShadows ${VTK_LIBRARIES} )</div></div><div><br></div><div>/*****************************<wbr>******************************<wbr>*************/</div><div><br></div><div>main.cxx:</div><div><div><br></div><div>int main(int argc, char** argv)</div><div>{</div><div> QApplication app(argc, argv);<br></div><div><br></div><div> // load 3D model<br></div><div> const char* fileName = "D:/RCH-CHUV/Data/testdata/<wbr>dragon.ply";</div><div> vtkNew<vtkPLYReader> reader;</div><div> reader->SetFileName(fileName);</div><div> reader->Update();</div><div><br></div><div> vtkNew<vtkPolyDataMapper> mapper;</div><div> mapper->SetInputConnection(<wbr>reader->GetOutputPort());</div><div><br></div><div> // create corresponding actor</div><div> vtkNew<vtkActor> actor;</div><div> actor->SetMapper(mapper.Get())<wbr>;</div><div> actor->GetProperty()-><wbr>SetAmbientColor(0.135, 0.2225, 0.3);</div><div> actor->GetProperty()-><wbr>SetDiffuseColor(0.54, 0.89, 0.63);</div><div> actor->GetProperty()-><wbr>SetSpecularColor(1.0, 1.0, 1.0);</div><div> actor->GetProperty()-><wbr>SetSpecular(0.51);</div><div> actor->GetProperty()-><wbr>SetDiffuse(0.7);</div><div> actor->GetProperty()-><wbr>SetAmbient(0.7);</div><div> actor->GetProperty()-><wbr>SetSpecularPower(30.0);</div><div> actor->GetProperty()-><wbr>SetOpacity(1.0);</div><div> </div><div> const char* fileName2 = "D:/RCH-CHUV/Data/CMR-1/<wbr>meshes/Left-Right/model.stl";</div><div> vtkNew<vtkSTLReader> reader2;</div><div> reader2->SetFileName(<wbr>fileName2);</div><div> reader2->Update();</div><div><br></div><div> vtkNew<vtkPolyDataMapper> mapper2;</div><div> mapper2->SetInputConnection(<wbr>reader2->GetOutputPort());</div><div><br></div><div> // create corresponding actor</div><div> vtkNew<vtkActor> actor2;</div><div> actor2->SetMapper(mapper2.Get(<wbr>));</div><div> actor2->GetProperty()-><wbr>SetAmbientColor(0.135, 0.2225, 0.3);</div><div> actor2->GetProperty()-><wbr>SetDiffuseColor(0.54, 0.89, 0.63);</div><div> actor2->GetProperty()-><wbr>SetSpecularColor(1.0, 1.0, 1.0);</div><div> actor2->GetProperty()-><wbr>SetSpecular(0.51);</div><div> actor2->GetProperty()-><wbr>SetDiffuse(0.7);</div><div> actor2->GetProperty()-><wbr>SetAmbient(0.7);</div><div> actor2->GetProperty()-><wbr>SetSpecularPower(30.0);</div><div> actor2->GetProperty()-><wbr>SetOpacity(1.0);</div><div> actor2->SetPosition(-0.6, -0.6, -0.6);</div><div> actor2->SetScale(0.01);</div><div><br></div><div>// create vtkrenderer</div><div> vtkNew<vtkRenderer> renderer;</div><div> renderer->SetBackground(0.3, 0.4, 0.6);</div><div> vtkSmartPointer<<wbr>vtkRenderWindow> renderWindow = vtkSmartPointer<<wbr>vtkRenderWindow>::New();</div><div> renderWindow->SetSize(600, 600);</div><div> renderWindow->AddRenderer(<wbr>renderer.Get());</div><div> vtkNew<<wbr>vtkRenderWindowInteractor> iren;</div><div> iren->SetRenderWindow(<wbr>renderWindow.Get());</div><div><br></div><div>//create lights</div><div> vtkNew<vtkLight> light1;</div><div> light1->SetPositional(0); // 0 and 1 works</div><div> light1->SetFocalPoint(0, 0, 0);</div><div> light1->SetPosition(0, 1, 0.2);</div><div> light1->SetColor(0.95, 0.97, 1.0);</div><div> light1->SetIntensity(0.8);</div><div> renderer->AddLight(light1.Get(<wbr>));</div><div><br></div><div> vtkNew<vtkLight> light2;</div><div> light2->SetPositional(0); // 0 and 1 works</div><div> light2->SetFocalPoint(0, 0, 0);</div><div> light2->SetPosition(1.0, 1.0, 1.0);</div><div> light2->SetColor(1.0, 0.8, 0.7);</div><div> light2->SetIntensity(0.3);</div><div> renderer->AddLight(light2.Get(<wbr>));</div><div><br></div><div><br></div><div> // add a plane</div><div> vtkNew<vtkPlaneSource> plane;</div><div> double *plybounds = mapper->GetBounds();</div><div> plane->SetOrigin(-0.2, plybounds[2], -0.2);</div><div> plane->SetPoint1(0.2, plybounds[2], -0.2);</div><div> plane->SetPoint2(-0.2, plybounds[2], 0.2);</div><div> vtkNew<vtkPolyDataMapper> planeMapper;</div><div> planeMapper-><wbr>SetInputConnection(plane-><wbr>GetOutputPort());</div><div> vtkNew<vtkActor> planeActor;</div><div> planeActor->SetMapper(<wbr>planeMapper.Get());</div><div> renderer->AddActor(planeActor.<wbr>Get());</div><div> renderer->AddActor(actor.Get()<wbr>);</div><div> renderer->AddActor(actor2.Get(<wbr>));</div><div> renderWindow->SetMultiSamples(<wbr>0);</div><div> </div><div>// this lines is the line that leads to crash when added (it crashes when the QVTKwidget tries to render)</div><div> renderer->UseShadowsOn();</div><div> </div><div><br></div><div><br></div><div> vtkNew<vtkTimerLog> timer;</div><div> timer->StartTimer();</div><div> renderWindow->Render();</div><div> timer->StopTimer();</div><div> double firstRender = timer->GetElapsedTime();</div><div> cerr << "first render time: " << firstRender << endl;</div><div><br></div><div> timer->StartTimer();</div><div> int numRenders = 8;</div><div> for (int i = 0; i < numRenders; ++i)</div><div> {</div><div><span style="white-space:pre-wrap"> </span> renderer->GetActiveCamera()-><wbr>Azimuth(80.0 / numRenders);</div><div><span style="white-space:pre-wrap"> </span> renderer->GetActiveCamera()-><wbr>Elevation(80.0 / numRenders);</div><div><span style="white-space:pre-wrap"> </span> renderWindow->Render();</div><div> }</div><div> timer->StopTimer();</div><div> double elapsed = timer->GetElapsedTime();</div><div> cerr << "interactive render time: " << elapsed / numRenders << endl;</div><div> unsigned int numTris = reader->GetOutput()->GetPolys(<wbr>)->GetNumberOfCells();</div><div> cerr << "number of triangles: " << numTris << endl;</div><div> cerr << "triangles per second: " << numTris*(numRenders / elapsed) << endl;</div><div><br></div><div> renderer->GetActiveCamera()-><wbr>SetPosition(-0.2, 0.2, 1);</div><div> renderer->GetActiveCamera()-><wbr>SetFocalPoint(0, 0, 0);</div><div> renderer->GetActiveCamera()-><wbr>SetViewUp(0, 1, 0);</div><div> renderer->GetActiveCamera()-><wbr>OrthogonalizeViewUp();</div><div> renderer->ResetCamera();</div><div> renderer->GetActiveCamera()-><wbr>Zoom(2.5);</div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span>// Declaration of a QVTKWidget associated to the renderWindow</span></div><div><span style="white-space:pre-wrap"> </span> <br></div><div> QVTKWidget * m_3Dwidget = new QVTKWidget();</div><div> m_3Dwidget->update();<br></div><div> m_3Dwidget->resize(600, 600);</div><div> m_3Dwidget->SetRenderWindow(<wbr>renderWindow);</div><div> m_3Dwidget->update();</div><div><br></div><div> QVTKInteractor * minteractor = QVTKInteractor::New();<br></div><div> minteractor->Initialize();<br></div><div><br></div><div> m_3Dwidget->GetRenderWindow()-<wbr>>SetInteractor(minteractor);<br></div><div> m_3Dwidget->GetRenderWindow()-<wbr>>Render();<br></div><div> <br></div><div> app.exec();</div><div> </div><div> return EXIT_SUCCESS;<br></div><div> </div><div> </div><div>}</div></div><div><br></div><div><br></div><div>Rémi</div><div><br></div><div><br></div></div>
</blockquote></div><br></div></div>