// The widget already exists. It is created in the main thread with some default values. No camera, no graphics context.
widget->AddCloud();
osg::Vec3d eye, up;
widget->getCameraManipulator()->getHomePosition(eye, center, up);
distance = widget->getCameraManipulator()->getFusionDistanceValue();
// The widget already exists. It is created in the main thread with some default values. No camera, no graphics context.
widget->AddCloud();
osg::Vec3d eye, up;
widget->getCameraManipulator()->getHomePosition(eye, center, up);
distance = widget->getCameraManipulator()->getFusionDistanceValue();
To copy to clipboard, switch view to plain text mode
void QOSGViewer::AddCloud(void) {
std::cout << "Loading cloud from file: " << cloud_file.c_str() << "\n";
int fileformat_idx( cloud_filepath.find(".pcd") );
std::string aux( cloud_filepath.substr(0, fileformat_idx) );
aux += "_octree/tree.oct_idx";
CreateCamera(0,0,100,100),
ReadOctree(aux)
);
qDebug() << "YAY"; // REACHES THIS
grid->setContentsMargins(1,1,1,1);
grid->addWidget( widget, 0, 0 );
this->setLayout( grid );
}
osg::Camera* QOSGViewer::CreateCamera(
int x,
int y,
int w,
int h,
const std::string &name,
bool windowDecoration
) {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
// camera = new osg::Camera;
osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
camera->setGraphicsContext( gc.get() );
camera->setClearColor( osg::Vec4(0,0,0,1) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setProjectionMatrixAsPerspective(
30.0f,
static_cast<double>(traits->width)/static_cast<double>(traits->height),
1.0f,
10000.0f
);
return camera.release();
}
osg::Node* QOSGViewer::ReadOctree(const std::string &file) {
osg::Group* group = new osg::Group;
group->addChild( osgDB::readNodeFile(file, options) );
return group;
}
QWidget* QOSGViewer
::AddViewWidget(
osg::Camera *camera,
osg::Node *scene
) {
osgViewer::View* view = new osgViewer::View;
// view = new osgViewer::View;
view->setCamera( camera );
view->setSceneData( scene );
addView( view );
view->addEventHandler( new osgViewer::StatsHandler );
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(
camera->getGraphicsContext()
);
return gw ? gw->getGLWidget() : 0;
}
void QOSGViewer::AddCloud(void) {
std::cout << "Loading cloud from file: " << cloud_file.c_str() << "\n";
int fileformat_idx( cloud_filepath.find(".pcd") );
std::string aux( cloud_filepath.substr(0, fileformat_idx) );
aux += "_octree/tree.oct_idx";
QWidget* widget = AddViewWidget(
CreateCamera(0,0,100,100),
ReadOctree(aux)
);
qDebug() << "YAY"; // REACHES THIS
QGridLayout* grid = new QGridLayout;
grid->setContentsMargins(1,1,1,1);
grid->addWidget( widget, 0, 0 );
this->setLayout( grid );
}
osg::Camera* QOSGViewer::CreateCamera(
int x,
int y,
int w,
int h,
const std::string &name,
bool windowDecoration
) {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
// camera = new osg::Camera;
osg::ref_ptr<osgQt::GraphicsWindowQt> gc = new osgQt::GraphicsWindowQt(traits.get());
camera->setGraphicsContext( gc.get() );
camera->setClearColor( osg::Vec4(0,0,0,1) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setProjectionMatrixAsPerspective(
30.0f,
static_cast<double>(traits->width)/static_cast<double>(traits->height),
1.0f,
10000.0f
);
return camera.release();
}
osg::Node* QOSGViewer::ReadOctree(const std::string &file) {
osg::Group* group = new osg::Group;
group->addChild( osgDB::readNodeFile(file, options) );
return group;
}
QWidget* QOSGViewer::AddViewWidget(
osg::Camera *camera,
osg::Node *scene
) {
osgViewer::View* view = new osgViewer::View;
// view = new osgViewer::View;
view->setCamera( camera );
view->setSceneData( scene );
addView( view );
view->addEventHandler( new osgViewer::StatsHandler );
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(
camera->getGraphicsContext()
);
return gw ? gw->getGLWidget() : 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks