Added support for intensityMap and fix naming of --panoramic-sd and --3d-sd command line arguments
This commit is contained in:
parent
501b3241c6
commit
d743eb2d95
@ -16,7 +16,10 @@
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osg/TextureCubeMap>
|
||||
#include <osg/TextureRectangle>
|
||||
#include <osg/TexMat>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgUtil/IntersectionVisitor>
|
||||
@ -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 = "<<projector<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"distance = "<<distance<<std::endl;
|
||||
osg::notify(osg::INFO)<<"create3DSphericalDisplayDistortionMesh : Projector position = "<<projector<<std::endl;
|
||||
osg::notify(osg::INFO)<<"create3DSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl;
|
||||
|
||||
|
||||
// create the quad to visualize.
|
||||
@ -729,7 +732,8 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
int noSteps = 50;
|
||||
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
||||
osg::Vec3Array* texcoords = new osg::Vec3Array;
|
||||
osg::Vec3Array* texcoords0 = new osg::Vec3Array;
|
||||
osg::Vec2Array* texcoords1 = new osg::Vec2Array;
|
||||
osg::Vec4Array* colors = new osg::Vec4Array;
|
||||
|
||||
osg::Vec3 bottom = origin;
|
||||
@ -756,6 +760,8 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
|
||||
phi *= 2.0;
|
||||
|
||||
if (theta<0.0) theta += 2.0*osg::PI;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
||||
|
||||
@ -765,7 +771,8 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
|
||||
vertices->push_back(cursor);
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
texcoords->push_back(texcoord);
|
||||
texcoords0->push_back(texcoord);
|
||||
texcoords1->push_back( osg::Vec2(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2) );
|
||||
|
||||
cursor += dx;
|
||||
}
|
||||
@ -783,6 +790,7 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
double theta = atan2(-delta.y(), delta.x());
|
||||
double phi = osg::PI_2 * delta.length() / screenRadius;
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
if (theta<0.0) theta += 2.0*osg::PI;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
||||
|
||||
@ -798,7 +806,8 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
|
||||
vertices->push_back(cursor);
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
texcoords->push_back(texcoord);
|
||||
texcoords0->push_back(texcoord);
|
||||
texcoords1->push_back( osg::Vec2(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2) );
|
||||
|
||||
cursor += dx;
|
||||
}
|
||||
@ -812,7 +821,8 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
geometry->setColorArray(colors);
|
||||
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
geometry->setTexCoordArray(0,texcoords);
|
||||
geometry->setTexCoordArray(0,texcoords0);
|
||||
geometry->setTexCoordArray(1,texcoords1);
|
||||
|
||||
for(i=0;i<noSteps-1;++i)
|
||||
{
|
||||
@ -830,7 +840,7 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
|
||||
void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned int screenNum, osg::Image* intensityMap)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"View::setUpViewFor3DSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
||||
osg::notify(osg::INFO)<<"View::setUpViewFor3DSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
@ -1018,6 +1028,11 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
stateset->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<osg::Camera> 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 = "<<projector<<std::endl;
|
||||
osg::notify(osg::INFO)<<"createParoramicSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl;
|
||||
|
||||
|
||||
// create the quad to visualize.
|
||||
osg::Geometry* geometry = new osg::Geometry();
|
||||
|
||||
geometry->setSupportsDisplayList(false);
|
||||
|
||||
osg::Vec3 xAxis(widthVector);
|
||||
float width = widthVector.length();
|
||||
xAxis /= width;
|
||||
|
||||
osg::Vec3 yAxis(heightVector);
|
||||
float height = heightVector.length();
|
||||
yAxis /= height;
|
||||
|
||||
int noSteps = 160;
|
||||
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
||||
osg::Vec2Array* texcoords0 = new osg::Vec2Array;
|
||||
osg::Vec2Array* texcoords1 = new osg::Vec2Array;
|
||||
osg::Vec4Array* colors = new osg::Vec4Array;
|
||||
|
||||
osg::Vec3 bottom = origin;
|
||||
osg::Vec3 dx = xAxis*(width/((float)(noSteps-2)));
|
||||
osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
|
||||
|
||||
osg::Vec3 top = origin + yAxis*height;
|
||||
|
||||
osg::Vec3d screenCenter = origin + widthVector*0.5f + heightVector*0.5f;
|
||||
float screenRadius = heightVector.length() * 0.5f;
|
||||
|
||||
double rotation = 0.0;
|
||||
|
||||
osg::Vec3 cursor = bottom;
|
||||
int i,j;
|
||||
|
||||
int midSteps = noSteps/2;
|
||||
|
||||
for(i=0;i<midSteps;++i)
|
||||
{
|
||||
osg::Vec3 cursor = bottom+dy*(float)i;
|
||||
for(j=0;j<midSteps;++j)
|
||||
{
|
||||
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
||||
double theta = atan2(delta.x(), -delta.y());
|
||||
theta += 2*osg::PI;
|
||||
|
||||
double phi = osg::PI_2 * delta.length() / screenRadius;
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
|
||||
double f = distance * sin(phi);
|
||||
double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f);
|
||||
double l = e * cos(phi);
|
||||
double h = e * sin(phi);
|
||||
double gamma = atan2(h, l-distance);
|
||||
|
||||
osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0-gamma/osg::PI);
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl;
|
||||
|
||||
if (flip)
|
||||
vertices->push_back(osg::Vec3(cursor.x(), top.y()-(cursor.y()-origin.y()),cursor.z()));
|
||||
else
|
||||
vertices->push_back(cursor);
|
||||
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
texcoords0->push_back( texcoord_flip ? osg::Vec2(texcoord.x(), 1.0f - texcoord.y()) : texcoord);
|
||||
texcoords1->push_back( osg::Vec2(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2) );
|
||||
|
||||
if (j+1<midSteps) cursor += dx;
|
||||
}
|
||||
|
||||
for(;j<noSteps;++j)
|
||||
{
|
||||
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
||||
double theta = atan2(delta.x(), -delta.y());
|
||||
double phi = osg::PI_2 * delta.length() / screenRadius;
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
|
||||
double f = distance * sin(phi);
|
||||
double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f);
|
||||
double l = e * cos(phi);
|
||||
double h = e * sin(phi);
|
||||
double gamma = atan2(h, l-distance);
|
||||
|
||||
osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0-gamma/osg::PI);
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl;
|
||||
|
||||
if (flip)
|
||||
vertices->push_back(osg::Vec3(cursor.x(), top.y()-(cursor.y()-origin.y()),cursor.z()));
|
||||
else
|
||||
vertices->push_back(cursor);
|
||||
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
texcoords0->push_back( texcoord_flip ? osg::Vec2(texcoord.x(), 1.0f - texcoord.y()) : texcoord);
|
||||
texcoords1->push_back( osg::Vec2(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2) );
|
||||
|
||||
cursor += dx;
|
||||
}
|
||||
// osg::notify(osg::NOTICE)<<std::endl;
|
||||
}
|
||||
|
||||
for(;i<noSteps;++i)
|
||||
{
|
||||
osg::Vec3 cursor = bottom+dy*(float)i;
|
||||
for(j=0;j<noSteps;++j)
|
||||
{
|
||||
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
||||
double theta = atan2(delta.x(), -delta.y());
|
||||
if (theta<0.0) theta += 2*osg::PI;
|
||||
double phi = osg::PI_2 * delta.length() / screenRadius;
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
|
||||
double f = distance * sin(phi);
|
||||
double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f);
|
||||
double l = e * cos(phi);
|
||||
double h = e * sin(phi);
|
||||
double gamma = atan2(h, l-distance);
|
||||
|
||||
osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0-gamma/osg::PI);
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl;
|
||||
|
||||
if (flip)
|
||||
vertices->push_back(osg::Vec3(cursor.x(), top.y()-(cursor.y()-origin.y()),cursor.z()));
|
||||
else
|
||||
vertices->push_back(cursor);
|
||||
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
texcoords0->push_back( texcoord_flip ? osg::Vec2(texcoord.x(), 1.0f - texcoord.y()) : texcoord);
|
||||
texcoords1->push_back( osg::Vec2(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2) );
|
||||
|
||||
cursor += dx;
|
||||
}
|
||||
|
||||
// osg::notify(osg::NOTICE)<<std::endl;
|
||||
}
|
||||
|
||||
// pass the created vertex array to the points geometry object.
|
||||
geometry->setVertexArray(vertices);
|
||||
|
||||
geometry->setColorArray(colors);
|
||||
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
geometry->setTexCoordArray(0,texcoords0);
|
||||
geometry->setTexCoordArray(1,texcoords1);
|
||||
|
||||
for(i=0;i<noSteps-1;++i)
|
||||
{
|
||||
osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP);
|
||||
for(j=0;j<noSteps;++j)
|
||||
{
|
||||
elements->push_back(j+(i+1)*noSteps);
|
||||
elements->push_back(j+(i)*noSteps);
|
||||
}
|
||||
geometry->addPrimitiveSet(elements);
|
||||
}
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void View::setUpViewForPanoramicSphericalDisplay(double radius, double collar, unsigned int screenNum, osg::Image* intensityMap)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"View::setUpViewForPanoramicSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
||||
setUpViewOnSingleScreen(screenNum);
|
||||
osg::notify(osg::INFO)<<"View::setUpViewForPanoramicSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
||||
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->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<osg::GraphicsContext::Traits> 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<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
if (!gc)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int tex_width = width;
|
||||
int tex_height = height;
|
||||
|
||||
int camera_width = tex_width;
|
||||
int camera_height = tex_height;
|
||||
|
||||
osg::TextureRectangle* texture = new osg::TextureRectangle;
|
||||
|
||||
texture->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<osg::Camera> 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<osg::Camera> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user