16 #include <osgGA/MultiTouchTrackballManipulator>
20 #include <QMdiSubWindow>
38 std::cout <<
"*** this=" <<
this <<
" entering " << __func__ << std::endl;
42 std::cout <<
"*** this=" <<
this <<
" leaving " << __func__ << std::endl;
60 !bIsInit,
"is already init. Leaving...",
"SimpleAdapterVisu::init"))
66 "No viewer attached. Leaving ...",
67 "SimpleAdapterVisu::init"))
74 connect(&timerUpdate, SIGNAL(timeout()),
this, SLOT(update()));
75 timerUpdate.start(10);
87 #if(FEVV_USE_QT5) // FOR_QT6
88 osg::ref_ptr< osg::Node > _scene =
static_cast< BaseViewerOSG *
>(myViewer)->getRootNode();
91 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
92 #ifdef OSG_GL3_AVAILABLE
93 format.setVersion(3, 2);
94 format.setProfile(QSurfaceFormat::CoreProfile);
95 format.setRenderableType(QSurfaceFormat::OpenGL);
96 format.setOption(QSurfaceFormat::DebugContext);
99 format.setVersion(2, 0);
100 format.setProfile(QSurfaceFormat::CompatibilityProfile);
101 format.setRenderableType(QSurfaceFormat::OpenGL);
102 format.setOption(QSurfaceFormat::DebugContext);
105 format.setDepthBufferSize(24);
107 format.setSamples(8);
108 format.setStencilBufferSize(8);
109 format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
110 QSurfaceFormat::setDefaultFormat(format);
113 my_osgQOpenGLWindow =
new osgQOpenGLWindow();
115 const osgQOpenGLWindow *my_osgQOpenGLWindow_const = my_osgQOpenGLWindow;
116 const Viewer *myViewer_const = myViewer;
118 QObject::connect(my_osgQOpenGLWindow_const, &osgQOpenGLWindow::initialized, [ my_osgQOpenGLWindow_const, _scene, myViewer_const ]
123 osgQOpenGLWindow *my_osgQOpenGLWindow2 =
const_cast<osgQOpenGLWindow *
>(my_osgQOpenGLWindow_const);
124 Viewer *myViewer2 =
const_cast<Viewer *
>(myViewer_const);
126 osg::Camera *camera = my_osgQOpenGLWindow2->getOsgViewer()->getCamera();
131 camera->setClearColor(osg::Vec4(0.2, 0.3, 0.6, 1.0));
139 camera->setProjectionMatrixAsPerspective(
141 static_cast< double >(my_osgQOpenGLWindow2->width()) /
142 static_cast< double >(my_osgQOpenGLWindow2->height()),
148 viewer->
hudText =
new osgText::Text;
149 my_osgQOpenGLWindow2->getOsgViewer()->addEventHandler(
153 my_osgQOpenGLWindow2->getOsgViewer()->setSceneData(_scene);
154 my_osgQOpenGLWindow2->getOsgViewer()->addEventHandler(
new osgViewer::StatsHandler);
155 my_osgQOpenGLWindow2->getOsgViewer()->setCameraManipulator(
new osgGA::MultiTouchTrackballManipulator);
165 layout->addWidget(my_osgQOpenGLWindow->asWidget());
168 addViewWidget(createGraphicsWindow(0, 0, 500, 500,
"Viewer"),
190 return bIsInit && (myViewer !=
nullptr);
194 #if(FEVV_USE_QT5) // FOR_QT6
200 osg::ref_ptr< osgQt::GraphicsWindowQt > _gw,
201 osg::ref_ptr< osg::Node > _scene)
203 if(myGraphicsWindow ==
nullptr)
205 myGraphicsWindow = _gw.get();
213 osgViewer::View *view =
dynamic_cast< osgViewer::View *
>(bv);
215 osg::Camera *camera = view->getCamera();
216 camera->setGraphicsContext(myGraphicsWindow);
218 const osg::GraphicsContext::Traits *traits = myGraphicsWindow->getTraits();
220 camera->setClearColor(osg::Vec4(0.2, 0.2, 0.6, 1.0));
221 camera->setViewport(
new osg::Viewport(0, 0, traits->width, traits->height));
225 camera->setDrawBuffer(GL_BACK);
226 camera->setReadBuffer(GL_BACK);
228 camera->setProjectionMatrixAsPerspective(
230 static_cast< double >(traits->width) /
231 static_cast< double >(traits->height),
238 viewer->
hudText =
new osgText::Text;
239 view->addEventHandler(
243 view->setSceneData(_scene);
244 view->addEventHandler(
new osgViewer::StatsHandler);
245 view->setCameraManipulator(
new osgGA::MultiTouchTrackballManipulator);
248 auto *osgWidget = myGraphicsWindow->getGLWidget();
249 osgWidget->setParent(
this);
255 layout->addWidget(osgWidget);
260 osg::ref_ptr< osgQt::GraphicsWindowQt >
266 const std::string &_name,
267 bool _windowDecoration)
const
269 osg::DisplaySettings *ds = osg::DisplaySettings::instance().get();
270 osg::ref_ptr< osg::GraphicsContext::Traits > traits =
271 new osg::GraphicsContext::Traits;
272 traits->windowName = _name;
273 traits->windowDecoration = _windowDecoration;
278 traits->doubleBuffer =
true;
279 traits->alpha = ds->getMinimumNumAlphaBits();
280 traits->stencil = ds->getMinimumNumStencilBits();
281 traits->sampleBuffers = ds->getMultiSamples();
288 return new osgQt::GraphicsWindowQt(traits.get());
334 FEVV::SimpleAdapterVisu::keyPressEvent(QKeyEvent *event)
336 QString keyString =
event->text();
337 const char *keyData = keyString.toLocal8Bit().data();
339 if(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_S)
341 std::cout <<
"Received CTRL + S " <<
event->text().toStdString()
343 myViewer->saveScreenshot(
"export_screenshot");
347 this->getEventQueue()->keyPress(osgGA::GUIEventAdapter::KeySymbol(*keyData));
353 FEVV::SimpleAdapterVisu::keyReleaseEvent(QKeyEvent *event)
355 QString keyString =
event->text();
356 const char *keyData = keyString.toLocal8Bit().data();
358 this->getEventQueue()->keyRelease(
359 osgGA::GUIEventAdapter::KeySymbol(*keyData));
367 FEVV::SimpleAdapterVisu::getEventQueue()
const
370 "myGraphicsWindow is not initialized.",
371 "SimpleAdapterVisu::getEventQueue");
373 osgGA::EventQueue *eventQueue = myGraphicsWindow->getEventQueue();
381 throw std::runtime_error(
"Unable to obtain valid event queue");
391 bool handled = QWidget::event(_event);
399 switch(_event->type())
401 case QEvent::KeyPress:
402 case QEvent::KeyRelease:
403 case QEvent::ShortcutOverride:
426 switch(_event->type())
442 case QEvent::KeyPress:
443 case QEvent::KeyRelease:
445 QKeyEvent *ke =
static_cast< QKeyEvent *
>(_event);
455 return QWidget::eventFilter(_obj, _event);
480 std::vector< FEVV::PMapsContainer * > properties_maps;
486 meshes = viewer->getSelectedMeshes();
487 properties_maps = viewer->getSelected_properties_maps();
490 if(meshes.
size() > 0)
495 for(
unsigned i = 0; i < meshes.
size(); i++)
497 std::cout <<
"Applying filter" << std::endl;
500 if(meshes[i].second ==
"POLYHEDRON")
503 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
505 if(meshes[i].second ==
"SURFACEMESH")
508 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
510 if(meshes[i].second ==
"LCC")
512 auto mesh_ptr =
static_cast< FEVV::MeshLCC*
>(meshes[i].first);
513 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
515 if(meshes[i].second ==
"CGALPOINTSET")
518 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
520 #endif //FEVV_USE_CGAL
522 #ifdef FEVV_USE_OPENMESH
523 if(meshes[i].second ==
"OPENMESH")
526 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
528 #endif //FEVV_USE_OPENMESH
531 if(meshes[i].second ==
"AIF")
533 auto mesh_ptr =
static_cast< FEVV::MeshAIF*
>(meshes[i].first);
534 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
536 #endif //FEVV_USE_AIF
539 if(meshes[i].second ==
"PCLPOINTCLOUD")
542 myPlugin->
apply(
this, mesh_ptr, properties_maps[i]);
544 #endif //FEVV_USE_PCL
551 myPlugin->
apply(
this,
static_cast< void *
>(
nullptr),
nullptr);