From d743eb2d955d86a21f945b1c668d77d02b3baedf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Sep 2007 19:14:29 +0000 Subject: [PATCH] Added support for intensityMap and fix naming of --panoramic-sd and --3d-sd command line arguments --- src/osgViewer/View.cpp | 331 +++++++++++++++++++++++++++++++++++++-- src/osgViewer/Viewer.cpp | 4 +- 2 files changed, 325 insertions(+), 10 deletions(-) diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 923d7e901..dba8a60ad 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -16,7 +16,10 @@ #include #include + #include +#include +#include #include #include @@ -709,8 +712,8 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); - osg::notify(osg::NOTICE)<<"Projector position = "<setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + if (intensityMap) + { + stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON); + } + osg::ref_ptr camera = new osg::Camera; camera->setGraphicsContext(gc.get()); camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); @@ -1051,10 +1066,308 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned } } +static osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius) +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + bool centerProjection = false; + + double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); + bool flip = false; + bool texcoord_flip = false; + + osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); + + + osg::notify(osg::INFO)<<"createParoramicSphericalDisplayDistortionMesh : Projector position = "<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); + + osg::GraphicsContext::ScreenIdentifier si; + si.readDISPLAY(); + + // displayNum has not been set so reset it to 0. + if (si.displayNum<0) si.displayNum = 0; + + si.screenNum = screenNum; + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); + texture->setInternalFormat(GL_RGB); + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + +#if 0 + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; + GLenum buffer = GL_FRONT; +#else + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; + GLenum buffer = GL_FRONT; +#endif + + // front face + { + osg::ref_ptr camera = new osg::Camera; + camera->setName("Front face camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture); + + addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); + } + + // distortion correction set up. + { + osg::Geode* geode = new osg::Geode(); + geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar)); + + // new we need to add the texture to the mesh, we do so by creating a + // StateSet to contain the Texture StateAttribute. + osg::StateSet* stateset = geode->getOrCreateStateSet(); + stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + + osg::TexMat* texmat = new osg::TexMat; + texmat->setScaleByTextureRectangleSize(true); + stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); + + if (intensityMap) + { + stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON); + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.1,0.1,1.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(false); + //camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(geode); + + camera->setName("DistortionCorrectionCamera"); + + addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } } diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index fa6a71c4b..996363426 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -77,7 +77,7 @@ Viewer::Viewer(osg::ArgumentParser& arguments) while (arguments.read("--window",x,y,width,height)) {} bool ss3d = false; - if ((ss3d=arguments.read("--3d-ss")) || arguments.read("--panoramic-ss")) + if ((ss3d=arguments.read("--3d-sd")) || arguments.read("--panoramic-sd")) { double radius = 1.0; while (arguments.read("--radius",radius)) {} @@ -94,10 +94,12 @@ Viewer::Viewer(osg::ArgumentParser& arguments) if (ss3d) { + setThreadingModel(SingleThreaded); setUpViewFor3DSphericalDisplay(radius, collar, screenNum, intensityMap.get()); } else { + setThreadingModel(SingleThreaded); setUpViewForPanoramicSphericalDisplay(radius, collar, screenNum, intensityMap.get()); } }