Beispiel #1
0
            QOSGWidget::QOSGWidget(QWidget* parent)
                : QGLWidget(parent), osgViewer::Viewer(), _gw(0), _timer() {
                pix_ratio=1.0;
#if QT_VERSION == 0x050000
//fixed in future verions after 5.0
                pix_ratio= parent->window()->windowHandle()->devicePixelRatio();
                printf("pixel ratio %f\n",pix_ratio);
 #endif
                _gw = new osgViewer::GraphicsWindowEmbedded(0,0,width()/pix_ratio,height()/pix_ratio);
                
                setFocusPolicy(Qt::StrongFocus);
                setMouseTracking(true);
                /*#if defined(GL_MULTISAMPLE_ARB)
                QGLFormat fmt; 
                QGLFormat::setDefaultFormat(fmt); 
                fmt.setSamples(4); 
                fmt.setSampleBuffers(true); 
                setFormat(fmt);                    
#endif // GL_MULTISAMPLE_ARB
  */
                osg::Camera* c = getCamera();
                c->setViewport(new osg::Viewport(0,0,width()/pix_ratio,height()/pix_ratio));
                c->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width()/pix_ratio)/static_cast<double>(height()/pix_ratio), 1.0f, 10000.0f);
                c->setGraphicsContext(_gw.get());
                c->setClearColor(osg::Vec4(0.7f, 0.7f, 0.7f, 1.0f));
                setThreadingModel(osgViewer::Viewer::SingleThreaded);
                osg::Matrixd *mat=NULL;
                bool inverseMouse=false;
                _ap=new MyAnimationPath;

                _wwManip = new WorldWindManipulatorNew(this,
                                                       NULL,
                                                       inverseMouse,
                                                       mat,_ap);
                setCameraManipulator(_wwManip);//new ws::app::drawable::CameraController);
                //      _animationManip=new AnimationPathPlayer(_ap);
#if 1
		//#if defined(QT_DEBUG)                      
                addEventHandler(new osgViewer::StatsHandler);
                
                // add the help handler
                addEventHandler(new osgViewer::HelpHandler());
                
                // Allows us to toggle lighting and other basic state items with keyboard
                addEventHandler( new osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet()));
                
                // add the thread model handler
                addEventHandler(new osgViewer::ThreadingHandler);
#endif // QT_DEBUG                
                
                // add the window size toggle handler
                addEventHandler(new osgViewer::WindowSizeHandler);    
                movieCallback = new WindowCaptureCallback();
                //Movie capture callback
                addMovieCallbackToViewer(*this, movieCallback);

                // updateGL will invoke glDraw which invokes paintGL
                connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
                _timer.start(30);
            }
OSGViewWidget::OSGViewWidget( osgViewer::ViewerBase::ThreadingModel threadingModel) : QWidget()
{
	setThreadingModel(threadingModel);
	view = new osgViewer::View;
	// disable the default setting of viewer.done() by pressing Escape.
	setKeyEventSetsDone(0);
	connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
	_timer.start( 10 );	
}
Beispiel #3
0
bool SDLViewer::setUpViewerAsSDLGraphicsWindow(const char *caption, const ScreenSettings & screenSettings)
{
    // inspired by osgViewer::Viewer::setUpViewerAsEmbeddedInWindow()
	setThreadingModel( SingleThreaded );
    SDLGraphicsWindow * gw = new SDLGraphicsWindow(caption, screenSettings);
    getCamera()->setViewport( new osg::Viewport(0, 0, screenSettings.width, screenSettings.height) );
	getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(screenSettings.width)/static_cast<double>(screenSettings.height), 1.0f, 10000.0f);
	getCamera()->setGraphicsContext( gw );
	return gw->valid();
}
Beispiel #4
0
GL_Window::GL_Window(int x, int y, int w, int h, const char *label):
    Fl_Gl_Window(x, y, w, h, label)
{
    _gw = new osgViewer::GraphicsWindowEmbedded(x,y,w,h);

    root = new osg::Group;
    geode = new osg::Geode;

    osg::ref_ptr<osg::Capsule> myCapsule (new osg::Capsule(osg::Vec3f(),1,2));
    osg::ref_ptr<osg::Box> myBox (new osg::Box(osg::Vec3f(),2,2,2));
    osg::ref_ptr<osg::Cylinder> myCylinder (new osg::Cylinder(osg::Vec3f(),.75,2.5));
    osg::ref_ptr<osg::Sphere> mySphere (new osg::Sphere(osg::Vec3f(),1.5));
    osg::ref_ptr<osg::Cone> myCone (new osg::Cone(osg::Vec3f(),1,2));

    shape_vec.push_back(new osg::ShapeDrawable(myBox.get()));
    shape_vec.push_back(new osg::ShapeDrawable(myCapsule.get()));
    shape_vec.push_back(new osg::ShapeDrawable(myCone.get()));
    shape_vec.push_back(new osg::ShapeDrawable(myCylinder.get()));
    shape_vec.push_back(new osg::ShapeDrawable(mySphere.get()));

    geode->addDrawable(shape_vec[1].get());     // default shape to pick from

    root->addChild(geode.get());

    stateset = geode->getOrCreateStateSet();

    // initial material properties
    diffuse_color.set(1, 1, 1, 1.0);
    specular_color.set(1,1,1,1);
    ambient_color.set(1,1,1,1);
    shininess = 10;
    alpha = 1;

    // apply the properties to the material
    material = new osg::Material;
    material->setDiffuse(osg::Material::FRONT, diffuse_color);
    material->setSpecular(osg::Material::FRONT, specular_color);
    material->setShininess(osg::Material::FRONT, shininess);
    material->setAmbient(osg::Material::FRONT, ambient_color);

    stateset->setAttribute(material.get());
    //stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);

    texture = new osg::Texture2D;

    getCamera()->setViewport(new osg::Viewport(0,0,w,h));
    getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(w)/static_cast<double>(h), 1.0f, 10000.0f);
    getCamera()->setGraphicsContext(_gw.get());

    setSceneData(root.get());
    setCameraManipulator(new osgGA::TrackballManipulator);
    addEventHandler(new osgViewer::StatsHandler);
    setThreadingModel(osgViewer::Viewer::SingleThreaded);
}
Beispiel #5
0
ViewerWidget::ViewerWidget(osgViewer::ViewerBase::ThreadingModel threadingModel) :
    QWidget() {

    // Create main layout
    //_mainLayout = new QVBoxLayout;
    // No space between window's element and the border
    //_mainLayout->setMargin(0);
    // No space between window's element


    // Create window title bar
    //_windowTitleBar = new WindowTitleBar;
    // Add window title bar to main layout
    //_mainLayout->addWidget(_windowTitleBar);
    // Put the title bar at the top of the window


    _scene = new osg::Group;
    _viewTopLookDir = osg::Y_AXIS;
    _viewTopUp = osg::Z_AXIS;

    _viewLeftLookDir = osg::Z_AXIS;
    _viewLeftUp = -osg::Y_AXIS;

    _viewFrontLookDir = osg::X_AXIS;
    _viewFrontUp = -osg::Y_AXIS;

    _viewMainLookDir = osg::Y_AXIS;
    _viewMainUp = osg::X_AXIS;

    setThreadingModel(threadingModel);

    _widgetTop   = addViewWidget(createCamera(0,0,10,10), Top  );
    _widgetLeft  = addViewWidget(createCamera(0,0,10,10), Left );
    _widgetFront = addViewWidget(createCamera(0,0,10,10), Front);
    _widgetMain  = addViewWidget(createCamera(0,0,10,10), Main );

    _leftVBoxLayout = new QVBoxLayout;
    _rightVBoxLayout = new QVBoxLayout;

    _mainHBoxLayout = new QHBoxLayout;
    _mainHBoxLayout->addLayout(_leftVBoxLayout);
    _mainHBoxLayout->addLayout(_rightVBoxLayout);

    //_mainLayout->addLayout(_mainHBoxLayout);

    changeViews();

    //setLayout(_mainLayout);
    setLayout(_mainHBoxLayout);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
    _timer.start(10);
}
ViewerQT::ViewerQT(const QGLFormat & format, QWidget * parent, const char * name, 
				   const QGLWidget * shareWidget, WindowFlags f)
: AdapterWidget(format, parent, shareWidget, f)
, _ucsDL(-1)
{
    getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
    getCamera()->setGraphicsContext(getGraphicsWindow());

    setThreadingModel(SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    _timer.start(10);
}
Beispiel #7
0
OSGWidget::OSGWidget(QWidget *parent)
    : QGLWidget(parent)
    , m_mouseButtons(Qt::NoButton)
    , m_mouseModifiers(Qt::NoModifier)
    , m_mouseMode(MM_ORBIT)
    , m_viewingCore(new ViewingCore)
    , m_lastMouseEventTime(QTime::currentTime())
    , m_mouseReleaseJustHappened(false)
    , m_throwTimeTolerance(100)
    , m_throwDistTolerance(0.1)
{
    setObjectName("osgv");
    // Strong focus policy needs to be set to capture keyboard events
    setFocusPolicy(Qt::StrongFocus);
    setMouseTracking(true); // get mouse move events even without button press

    // Construct the embedded graphics window
    m_osgGraphicsWindow = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
    getCamera()->setGraphicsContext(m_osgGraphicsWindow);

    // Set up the camera
    getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
    getCamera()->setProjectionMatrixAsPerspective(30.0f,
            static_cast<double>(width())/static_cast<double>(height()),
            1.0f,
            10000.0f);

    // By default draw everthing that has even 1 bit set in the nodemask
    getCamera()->setCullMask( (unsigned)~0 );
    getCamera()->setDataVariance(osg::Object::DYNAMIC);

    // As of July 2010 there wasn't really a good way to multi-thread OSG
    // under Qt so just set the threading model to be SingleThreaded
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    // draw both sides of polygons
    setLightingTwoSided();

    // wake up and re-draw the window every so often
    connect(&m_redrawTimer, SIGNAL(timeout()), this, SLOT(updateGL()));
    m_redrawTimer.setSingleShot(true);
    m_redrawTimer.start(20);
    //m_frameTimer.start();

    // Signal-slot to handle animating the camera for 'tossing' the geometry
    connect(&m_animateTimer, SIGNAL(timeout()),
            this, SLOT(animateCameraThrow()));

    // Set the minimum size for this viewer window
    setMinimumSize(200, 200);
}
Beispiel #8
0
ViewerQT::ViewerQT(QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f):
    AdapterWidget( parent, name, shareWidget, f)
{
    setCamera(this->getCamera());
    // Camera
     getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
     getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
     getCamera()->setGraphicsContext(getGraphicsWindow());
    getCamera()->setClearColor(osg::Vec4d(51/255.0, 51/255.0, 102/255.0, 0));
    getCamera()->setViewMatrix(osg::Matrix::identity());
//   // getCamera()->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
//   // getCamera()->setClearColor(osg::Vec4d(1, 1, 1, 0));
//    getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
//    getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);
//    getCamera()->setRenderOrder(osg::Camera::POST_RENDER);
//    getCamera()->setUpdateCallback(new AxisCameraUpdateCallback());
//    QString axespath = QCoreApplication::applicationDirPath() + "/axes.osg";
//    osg::Node* axes = osgDB::readNodeFile(axespath.toLatin1().data());
//    qDebug()<<axes->asGroup()->getNumChildren();
//    qDebug()<<axespath;
//    getCamera()->addChild(axes);
    // Trackball
    m_rpTrackball = new osgGA::TrackballManipulator;
  //  setCameraManipulator(m_rpTrackball.get());
    addEventHandler(new osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet()));
   // addEventHandler(new osgViewer::WindowSizeHandler);
    addEventHandler(new osgViewer::StatsHandler);
    // Scene root
    m_rpSceneGroupRoot = new osg::Group;
    setSceneData(m_rpSceneGroupRoot.get());
    osg::Camera* camera = createHUD();
    addSlave(camera, false);
    m_rpSceneGroupRoot->addChild(camera);
    osgText::Text* text = new osgText::Text;
    m_rpSceneGroupRoot->addChild( createHUD_viewPoint( text));//加入HUD文字
//    pickHandler = new PickHandler;
//    addEventHandler(pickHandler);

    addEventHandler(new PickDragHandler(text));
    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator =
            new osgGA::KeySwitchMatrixManipulator;
    keyswitchManipulator->addMatrixManipulator(1,"Trackball",new osgGA::TrackballManipulator());
    keyswitchManipulator->addMatrixManipulator(2,"Flight",new osgGA::FlightManipulator());
    keyswitchManipulator->addMatrixManipulator(3,"Drive",new osgGA::DriveManipulator());
    keyswitchManipulator->addMatrixManipulator(4,"Terrain",new osgGA::TerrainManipulator());
    setCameraManipulator(keyswitchManipulator.get());
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    _timer.start(10);
}
Beispiel #9
0
Viewer::Viewer(std::string earthfile)
{
	setThreadingModel(osgViewer::ViewerBase::SingleThreaded);

	initScene(earthfile);
	initSkyOcean();

	osgEarth::Viewpoint vp;
	vp.setFocalPoint(osg::Vec3d(108.90199,34.04073,0));
	vp.setRange(9668062);
	vp.setPitch(-90);
	_manip->setViewpoint(vp, 2);

	initHandlers();
}
Beispiel #10
0
ViewerWidget::ViewerWidget(QWidget *parent)
    : QWidget(parent)
    , scene(new SceneConf)
{

    load();
    setThreadingModel(threadingModel);

    QWidget *widget1 = addViewWidget(createCamera(0, 0, 100, 100), scene->getSceneGroup());

    QGridLayout *grid = new QGridLayout;
    grid->addWidget(widget1, 0, 0);
    setLayout(grid);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
    _timer.start(10);
}
OSGViewerWidget::OSGViewerWidget(QWidget * parent, const QGLWidget * shareWidget, Qt::WindowFlags f)
  :AdapterWidget(parent, shareWidget, f, true),
  scene_root_(new osg::Group),
  other_root_(new osg::Group),
  gl_thread_(this),
  threaded_painter_(this)
{
  osg::ref_ptr<osg::Group> root = new osg::Group;
  root->addChild(scene_root_);
  root->addChild(other_root_);
  setSceneData(root);

  scene_root_->getOrCreateStateSet()->setAttribute(new osg::Point(2.0f), osg::StateAttribute::ON);
  scene_root_->getOrCreateStateSet()->setAttribute(new osg::LineWidth(1.0f), osg::StateAttribute::ON);

  setCameraManipulator(new osgGA::TrackballManipulator);

  addEventHandler(new osgViewer::HelpHandler);
  addEventHandler(new osgViewer::StatsHandler);
  addEventHandler(new osgViewer::LODScaleHandler);
  addEventHandler(new osgViewer::ThreadingHandler);
  addEventHandler(new osgViewer::ScreenCaptureHandler(new WriteToFile));
  addEventHandler(new RecordCameraPathHandler);

  for (int i = 0; i < 6; ++ i)
  {
    osg::ref_ptr<LightSource> light_source = new LightSource(i);
    light_sources_.push_back(light_source);
    char index = '0'+i;
    addEventHandler(new ToggleHandler(light_source, index, std::string("Toggle Light Source ")+index));
    addChild(light_source, false);
  }

  double w = width();
  double h = height();
  getCamera()->setViewport(new osg::Viewport(0, 0, w, h));
  getCamera()->setProjectionMatrixAsPerspective(60.0f, w/h, 1.0f, 10000.0f);
  getCamera()->setGraphicsContext(getOrganGraphicsWindow());
  getCamera()->setClearColor(osg::Vec4(1, 1, 1, 1.0));

  setThreadingModel(osgViewer::Viewer::SingleThreaded);

  this->doneCurrent();
}
Beispiel #12
0
GraphModelViewer::GraphModelViewer(osgViewer::ViewerBase::ThreadingModel threadingModel, QWidget *parent, bool autoUpdate) : QWidget(parent)
{
	setThreadingModel(threadingModel);

	// disable the default setting of viewer.done() by pressing Escape.
	setKeyEventSetsDone(0);

	group = new osg::Group();

	QWidget* widget1 = addViewWidget( createGraphicsWindow(0,0,100,100), group );
	QGridLayout* grid = new QGridLayout;
	grid->addWidget(widget1, 0, 0 );
	setLayout(grid);

	connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
	if (autoUpdate)
		connect(&timer, SIGNAL(timeout()), this, SLOT(animateStep()));
	timer.start(10);
}
QOSG::ProjectiveARViewer::ProjectiveARViewer( QWidget* parent , const char* name , const QGLWidget* shareWidget , WindowFlags f , osgViewer::Viewer* viewerPerspective ):
    AdapterWidget( parent, name, shareWidget, f )
{
    this->viewerPerspective = viewerPerspective;

    appConf = Util::ApplicationConfig::get();

    renderCamera = new osg::Camera;
    useGraph = true;

    // setup Graph (radius 0.5m)
    graphPos = osg::Vec3d(-0.75, -0.25, 0.25);
    graphRadius = 0.5;

    // setup Viewer
    viewerPos = osg::Vec3d(-1.88, -0.95, 1.72);
    viewerDir = osg::Vec3d( -0.75, 0, 0.238 ) - viewerPos;
    viewerFOV = 90;

    this->setSceneData(createProjectorScene());

    // setup Projector
    projectorPos = osg::Vec3d( -0.665, -1.345, 0.825);
    projectorDir = osg::Vec3d( -0.75, 0, 0.238 ) - projectorPos;
    projectorFOV = 30;

    getCamera()->setViewport( new osg::Viewport( 0,0,width(),height() ) );
    getCamera()->setProjectionMatrixAsPerspective( projectorFOV, static_cast<double>( width() )/static_cast<double>( height() ), 0.01, appConf->getValue( "Viewer.Display.ViewDistance" ).toFloat() );
    getCamera()->setGraphicsContext( getGraphicsWindow() );
    getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

    getCamera()->setClearColor( osg::Vec4( 0, 0, 0, 1 ) );
    getCamera()->setViewMatrixAsLookAt( projectorPos, projectorDir + projectorPos, osg::Vec3d( 0, 0, 1 ) );


    addEventHandler( new osgViewer::StatsHandler );

    setThreadingModel( osgViewer::ViewerBase::SingleThreaded );

    connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );

    _timer.start( 10 );
}
Beispiel #14
0
Osg3dView::Osg3dView(QWidget *parent)
    : QOpenGLWidget(parent)
    , m_viewingCore(new ViewingCore)
    , m_mouseMode(MM_ORBIT)
    , m_mouseIsPressed(false)
{
    setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this, SIGNAL(customContextMenuRequested(QPoint)),
            this, SLOT(customMenuRequested(QPoint)));
#if 0   // This would be interesting to have  Perhaps it belongs in OsgForm
        // Alas, it would be hard to design in qtdesigner
        QToolBar *tb = new QToolBar(this);
        tb->addAction("Hello");
        tb->addAction("goodbye");
#endif
    buildPopupMenu();

    // Construct the embedded graphics window
    m_osgGraphicsWindow = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
    getCamera()->setGraphicsContext(m_osgGraphicsWindow);

    // Set up the camera
    getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
    getCamera()->setProjectionMatrixAsPerspective(30.0f,
            static_cast<double>(width())/static_cast<double>(height()),
            1.0f,
            10000.0f);
    // By default draw everthing that has even 1 bit set in the nodemask
    getCamera()->setCullMask( (unsigned)~0 );
    getCamera()->setDataVariance(osg::Object::DYNAMIC);

    // As of July 2010 there wasn't really a good way to multi-thread OSG
    // under Qt so just set the threading model to be SingleThreaded
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    // draw both sides of polygons
    setLightingTwoSided();

    // this will probably be overwritten but avoids warnings
    setScene(new osg::Node);
    update();
}
Beispiel #15
0
QOSG::ViewerQT::ViewerQT( QWidget* parent , const char* name , const QGLWidget* shareWidget , WindowFlags f , Vwr::CoreGraph* cg ):
	AdapterWidget( parent, name, shareWidget, f )
{
	this->cg = cg;
	cg->setCamera( this->getCamera() );

	this->mIsClicAruco=false;

	appConf = Util::ApplicationConfig::get();

	osg::DisplaySettings::instance()->setStereo( appConf->getValue( "Viewer.Display.Stereoscopic" ).toInt() );
	osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );

	getCamera()->setViewport( new osg::Viewport( 0,0,width(),height() ) );
	getCamera()->setProjectionMatrixAsPerspective( 60, static_cast<double>( width() )/static_cast<double>( height() ), 0.01, appConf->getValue( "Viewer.Display.ViewDistance" ).toFloat() );
	getCamera()->setGraphicsContext( getGraphicsWindow() );
	getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

	manipulator = new Vwr::CameraManipulator( cg );
	QObject::connect( manipulator, SIGNAL( sendMouseRotation( osg::Quat ) ),
					  cg, SLOT( updateGraphRotByMouse( osg::Quat ) ) );
	QObject::connect( manipulator, SIGNAL( sendFaceDetRotation( osg::Quat ) ),
					  cg, SLOT( updateGraphRotByFaceDet( osg::Quat ) ) );

	pickHandler = new Vwr::PickHandler( manipulator, cg );

	addEventHandler( new osgViewer::StatsHandler );
	addEventHandler( pickHandler );
	setCameraManipulator( manipulator );

	// Gloger: background to white color after disabling skybox
	getCamera()->setClearColor( osg::Vec4( 0, 0, 0, 1 ) );
	getCamera()->setViewMatrixAsLookAt( osg::Vec3d( -10, 0, 0 ), osg::Vec3d( 0, 0, 0 ), osg::Vec3d( 0, 1, 0 ) );

	setThreadingModel( osgViewer::ViewerBase::SingleThreaded );

	connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );

	_timer.start( 10 );
}
Beispiel #16
0
    ViewerWidget(osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded)
    {
        setThreadingModel(threadingModel);

        QWidget* widget1 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osg") );
        QWidget* widget2 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        QWidget* widget3 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        QWidget* widget4 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        QWidget* popupWidget = addViewWidget( createCamera(900,100,320,240,"Popup window",true),
                                            osgDB::readNodeFile("D:\\ThirdParty\\OpenSceneGraph-3.0.1\\data\\cow.osgt") );
        popupWidget->show();

        QGridLayout* grid = new QGridLayout(contentWidget());
        grid->addWidget( widget1, 0, 0 );
        grid->addWidget( widget2, 0, 1 );
        grid->addWidget( widget3, 1, 0 );
        grid->addWidget( widget4, 1, 1 );
        //setLayout( grid );

        connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
        _timer.start( 10 );
    }
Beispiel #17
0
CompositeViewer::CompositeViewer()
    : mSimulationTime(0.0)
{
#if QT_VERSION >= 0x050000
    // Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4
    osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded;
#else
    osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
#endif

    setThreadingModel(threadingModel);

    // disable the default setting of viewer.done() by pressing Escape.
    setKeyEventSetsDone(0);

    // Only render when the camera position changed, or content flagged dirty
    //setRunFrameScheme(osgViewer::ViewerBase::ON_DEMAND);
    setRunFrameScheme(osgViewer::ViewerBase::CONTINUOUS);

    connect( &mTimer, SIGNAL(timeout()), this, SLOT(update()) );
    mTimer.start( 10 );
}
Beispiel #18
0
ViewerQOSG::ViewerQOSG(QWidget *parent, const char *name, WindowFlags f):
    QOSGWidget (parent, name, f) {

    getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
    getCamera()->setProjectionMatrixAsPerspective(
        30.0f,
        static_cast<double>(width())/static_cast<double>(height()),
        1.0f,
        10000.0f);
#if 0
#endif

    getCamera()->setGraphicsContext(getGraphicsWindow());

#if 0
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));

    _timer.start(10);
#endif
}
Beispiel #19
0
  ViewerWidget(QWidget* parent = 0,Qt::WindowFlags f = 0,osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded): QWidget(parent,f)
  {
    setThreadingModel(threadingModel);

    // disable the default setting of viewer.done() by pressing Escape.
    setKeyEventSetsDone(0);


    osg::ref_ptr<osg::Node> line = createLine(osg::Vec3(-2,0,2),osg::Vec3(2,0,2));
    osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode(
      osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY);
    overlayNode->setContinuousUpdate(true);
    overlayNode->setOverlaySubgraph(line);
    overlayNode->setOverlayBaseHeight(0.99);
    osg::ref_ptr<osg::Node> cube = osgDB::readNodeFile("cube.osgb");
    overlayNode->addChild(cube);
    osg::ref_ptr<osg::Group> root = new osg::Group;
    root->addChild(overlayNode);
    root->addChild(line);

    QWidget* widget1 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("cow.osgt") );
//     QWidget* widget1 = addViewWidget(createGraphicsWindow(0,0,100,100),root);
    QWidget* widget2 = addViewWidget(createGraphicsWindow(0,0,100,100),osgDB::readRefNodeFile("glider.osgt"));
    QWidget* widget3 = addViewWidget(createGraphicsWindow(0,0,100,100),osgDB::readRefNodeFile("axes.osgt"));
    QWidget* widget4 = addViewWidget(createGraphicsWindow(0,0,100,100),osgDB::readRefNodeFile("fountain.osgt"));
    QWidget* popupWidget = addViewWidget(createGraphicsWindow(900,100,320,240,"Popup window",true),osgDB::readRefNodeFile("dumptruck.osgt"));
    popupWidget->show();

    QGridLayout* grid = new QGridLayout;
    grid->addWidget(widget1,0,0);
    grid->addWidget(widget2,0,1);
    grid->addWidget(widget3,1,0);
    grid->addWidget(widget4,1,1);
    setLayout(grid);

    connect(&_timer,SIGNAL(timeout()),this,SLOT(update()));
    _timer.start(10);
  }
Beispiel #20
0
OsgViewerBase::OsgViewerBase(DisplayMode displayMode, const string& viewType)
{
	_currFrame = 0;

	_mainCamera = NULL;

	_displayMode = displayMode;
	_viewType = viewType;

	/* 将本视窗添加到全局视窗容器中 */
	_allViewers.push_back( this );
	
	_focusedViewer = this;

	_eventStation = new EventStation();

	/* 将视窗的消息站添加到消息中心的消息站容器中 */
	EventCenter::inst()->registerStation( _eventStation );

	_layerManager = new LayerManager( this );
	_screenManager = new ScreenManager( this );
	_pickableManager = new PickableManager( this );


	/* scene */
	Group* dynamicRoot = new Group;
	Group* staticRoot = new Group;
	dynamicRoot->setName("Dynamic root");
	staticRoot->setName("Static root");

	_sceneData = new Group;
	_sceneData->setName("Scene Data");

	if (displayMode == MODE_2D)
	{
		/* 创建静态场景根节点 */
		ref_ptr< StaticNodeGroup > staticNodeGroup = new StaticNodeGroup( this );
		staticNodeGroup->addChild( staticRoot );	
		_sceneData->addChild( staticNodeGroup.get() );
	}
	else
	{
		_sceneData->addChild(staticRoot);
	}
	_sceneData->addChild( dynamicRoot );

	_layerManager->setRoot( staticRoot, dynamicRoot );

	/* screen */

	Group* screenRoot = new Group;
	screenRoot->setName("Screen root");
	_screenManager->setRoot(screenRoot);
	_sceneData->addChild(screenRoot);

    setThreadingModel( osgViewer::Viewer::SingleThreaded );

	//_statsHandler = new StatsHandler(this);


	/* light */

	StateSet* sceneDataState = _sceneData->getOrCreateStateSet();

	Group* lightGroup = new Group;
	lightGroup->setName("Light group");

	_sunLight = new osg::Light;
	_sunLight->setLightNum(0);
	_sunLight->setPosition(osg::Vec4(1.0f, 0.0f, -1.0f, 0.0f));
	_sunLight->setAmbient(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f));
	_sunLight->setDiffuse(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f));

	osg::LightSource* lightS = new osg::LightSource;    
	lightS->setLight(_sunLight);
	lightS->setStateSetModes(*sceneDataState, osg::StateAttribute::ON);

	LightModel* lightModel = new osg::LightModel;
	lightModel->setAmbientIntensity(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
	lightS->getOrCreateStateSet()->setAttribute(lightModel, StateAttribute::ON);

	lightGroup->addChild(lightS);
	_sceneData->addChild(lightGroup);

	sceneDataState->setMode( GL_LIGHTING, StateAttribute::ON );
}
Beispiel #21
0
ViewerWidget::ViewerWidget():
    osgViewer::Viewer()
{
    osg::setNotifyLevel( osg::NOTICE );

    //osg::DisplaySettings::instance()->setNumMultiSamples( 4 );

    setThreadingModel( osgViewer::Viewer::SingleThreaded );

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
    {
        osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
        traits->windowName = "Simple Viewer";
        traits->windowDecoration = true;
        traits->x = 0;
        traits->y = 0;
        traits->width = WINDOW_WIDTH;
        traits->height = WINDOW_HEIGHT;
        traits->doubleBuffer = true;
        traits->alpha = ds->getMinimumNumAlphaBits();
        traits->stencil = ds->getMinimumNumStencilBits();
        traits->sampleBuffers = ds->getMultiSamples();
        traits->samples = ds->getNumMultiSamples();
    }

    setUpViewInWindow( 0, 0, traits->width, traits->height );

    {
        osg::Camera* camera = getCamera();

        camera->setClearColor( osg::Vec4( 204.0/255, 204.0/255, 204.0/255, 1 ) );
        //camera->setViewport( new osg::Viewport( 0, 0, traits->width, traits->height ) );
        //camera->setProjectionMatrixAsPerspective( 30.0f, double( traits->width )/double( traits->height ), 1.0f, 100000.0f );
        //camera->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
        //camera->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);

        _root = new osg::Group;


        // create sunlight
        //setLightingMode( osg::View::SKY_LIGHT );
        //getLight()->setPosition(osg::Vec4(1000,2000,3000,0));
        //getLight()->setDirection(osg::Vec3(-1,-2,-3));
        //getLight()->setAmbient(osg::Vec4( 0.6,0.6,0.6,1 ));
        //getLight()->setDiffuse(osg::Vec4( 0.6,0.6,0.6,1 ));
        //getLight()->setSpecular(osg::Vec4( 0.9,0.9,0.9,1 ));

        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;

        keyswitchManipulator->addMatrixManipulator( '1', "Terrain", new osgGA::TerrainManipulator() );
        keyswitchManipulator->addMatrixManipulator( '2', "Orbit", new osgGA::OrbitManipulator() );
        keyswitchManipulator->addMatrixManipulator( '3', "Trackball", new osgGA::TrackballManipulator() );

        setCameraManipulator( keyswitchManipulator.get() );

        addEventHandler( new osgViewer::WindowSizeHandler );
        addEventHandler( new osgViewer::StatsHandler );
        addEventHandler( new osgGA::StateSetManipulator( getCamera()->getOrCreateStateSet() ) );
        addEventHandler( new osgViewer::ScreenCaptureHandler );

        setFrameStamp( new osg::FrameStamp );

        setSceneData( _root.get() );
    }

    // back alpha blending for "transparency"
    {
        osg::StateSet* ss = _root->getOrCreateStateSet();
        ss->setAttributeAndModes( new osg::CullFace( osg::CullFace::BACK ), osg::StateAttribute::ON );
        ss->setMode( GL_BLEND, osg::StateAttribute::ON );
    }


    // SSAO
    if( 0 ) {
        osg::StateSet* stateset = _root->getOrCreateStateSet();
        //osg::ref_ptr<osg::Program> program = new osg::Program;
        //program->addShader( new osg::Shader(osg::Shader::VERTEX, vertSourceSSAO) );
        //program->addShader( new osg::Shader(osg::Shader::FRAGMENT, fragSourceSSAO) );
        //stateset->setAttributeAndModes( program.get() );
        stateset->addUniform( new osg::Uniform( "m_SubPixelShift", .5f ) );
        stateset->addUniform( new osg::Uniform( "m_SpanMax", 5.f ) );
        stateset->addUniform( new osg::Uniform( "m_ReduceMul", 1.f ) );
        stateset->addUniform( new osg::Uniform( "g_Resolution", osg::Vec2( WINDOW_WIDTH, WINDOW_HEIGHT ) ) );
        osg::Texture2D* texture = new osg::Texture2D();
        texture->setTextureSize( WINDOW_WIDTH,WINDOW_HEIGHT );

        texture->setInternalFormat( GL_RGBA );

        texture->setWrap( osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_EDGE );
        texture->setWrap( osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_EDGE );
        texture->setFilter( osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR );
        texture->setFilter( osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR );

        osg::Camera* camera = new osg::Camera;
        camera->addChild( _root.get() );
        osg::Group* newRoot = new osg::Group;
        newRoot->addChild( camera );
        setSceneData( newRoot );
        camera->setRenderOrder( osg::Camera::PRE_RENDER );
        camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
        //camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
        camera->attach( osg::Camera::COLOR_BUFFER, texture );
        camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        //camera->setProjectionMatrixAsOrtho2D(0, 0, WINDOW_HEIGHT, WINDOW_WIDTH);
        //setCameraManipulator( new osgGA::OrbitManipulator );

        stateset->addUniform( new osg::Uniform( "m_Texture", texture ) );

        // original image view
        if( 1 ) {

            //osg::Texture2D* tex = new osg::Texture2D;

            osg::Geode* geode = new osg::Geode();
            osg::Geometry* geom = new osg::Geometry();
            geode->addDrawable( geom );

            osg::Vec3Array* vtx = new osg::Vec3Array;
            vtx->push_back( osg::Vec3( 0, 0, 0 ) ); // front left
            vtx->push_back( osg::Vec3( WINDOW_WIDTH, 0, 0 ) ); // front right
            vtx->push_back( osg::Vec3( WINDOW_WIDTH, WINDOW_HEIGHT, 0 ) ); // back right
            vtx->push_back( osg::Vec3( 0,WINDOW_HEIGHT, 0 ) ); // back left
            geom->setVertexArray( vtx );

            osg::DrawElementsUInt* quads = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
            quads->push_back( 0 );
            quads->push_back( 1 );
            quads->push_back( 2 );
            quads->push_back( 3 );
            geom->addPrimitiveSet( quads );

            osg::Vec2Array* texcoords = new osg::Vec2Array( 5 );
            ( *texcoords )[0].set( 0.f,0.f ); // tex coord for vertex 0
            ( *texcoords )[1].set( 1.f,0.f ); // tex coord for vertex 1
            ( *texcoords )[2].set( 1.f,1.f ); // tex coord for vertex 1
            ( *texcoords )[3].set( 0.f,1.f ); // tex coord for vertex 1
            geom->setTexCoordArray( 0,texcoords );

            geode->getOrCreateStateSet()->setTextureAttributeAndModes( 0,texture,osg::StateAttribute::ON );
            osg::Camera* normalCamera = new osg::Camera();
            normalCamera->setClearColor( osg::Vec4( 0.4f,0.4f,0.4f,1.0f ) );
            normalCamera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
            normalCamera->setViewport( 0,0,WINDOW_WIDTH,WINDOW_HEIGHT );
            normalCamera->setProjectionMatrixAsOrtho2D( 0,WINDOW_HEIGHT,0,WINDOW_HEIGHT );
            normalCamera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
            normalCamera->setViewMatrix( osg::Matrix::identity() );
            normalCamera->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
            normalCamera->addChild( geode );
            //textureGroup->addChild( normalCamera );
            newRoot->addChild( normalCamera );
        }
    }

    realize();
}