Changeset 331
- Timestamp:
- Mar 11, 2012, 9:45:19 AM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/distortionNG.cpp
r329 r331 124 124 _highlighter->dirtyBound(); 125 125 } 126 127 /* 128 Grundsätzliche Gedanken Schritte: 129 Die Verzerrung kann auf zwei Arten realisiert werden 130 - Verzerrung der Textur-Koordinaten aus der RTT-Szene 131 - Verzerrung des Meshes im Verzerrungs-Rendern 132 Die IntensityMap muss über das fertige verzerrte Bild gelegt werden. 133 134 135 136 */ -
experimental/distortionNG/extViewer.cpp
r329 r331 30 30 { 31 31 32 } 33 34 static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, osg::Image* intensityMap, const osg::Matrix& projectorMatrix) 35 { 36 // Create Quad to render on 37 osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; 38 39 geom->setUseDisplayList( false ); 40 41 osg::Vec3 xAxis(widthVector); 42 float width = widthVector.length(); 43 xAxis /= width; 44 45 osg::Vec3 yAxis(heightVector); 46 float height = heightVector.length(); 47 yAxis /= height; 48 49 osg::Vec3 dx = xAxis*(width/((float)(columns-1))); 50 osg::Vec3 dy = yAxis*(height/((float)(rows-1))); 51 52 53 // Create vertices and coordinates 54 osg::Vec3Array* vertices = new osg::Vec3Array; 55 osg::Vec2Array* texcoords0 = new osg::Vec2Array; 56 osg::Vec2Array* texcoords1 = intensityMap==0 ? new osg::Vec2Array : 0; 57 osg::Vec4Array* colors = new osg::Vec4Array; 58 59 geom->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); 60 61 for ( unsigned int row=0; row<rows; row++ ) 62 { 63 for ( unsigned int col=0; col<columns; col++ ) 64 { 65 // Create coordinates of the mesh node (geometry). 66 vertices->push_back( origin+dy*row+dx*col ); 67 68 // Create tex coordinates 69 osg::Vec2 texcoord = osg::Vec2((float)col/(float)(columns-1), (float)row/(float)(rows-1)); 70 71 // Set Coordinates for RTT-Texture (scene rendering) 72 texcoords0->push_back( texcoord ); 73 74 // Set Color of the mesh node 75 if (intensityMap) 76 { 77 colors->push_back(intensityMap->getColor(texcoord)); 78 } 79 else 80 { 81 colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 82 } 83 84 // Set coordinates for second texcoords array (if applyIntensityMapAsColours==true) 85 if (texcoords1) texcoords1->push_back( texcoord ); 86 } 87 } 88 89 // Pass the created vertex array to the points geometry object. 90 geom->setUseVertexBufferObjects( true ); 91 geom->setVertexArray(vertices); 92 93 geom->setColorArray(colors); 94 geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); 95 96 geom->setTexCoordArray(0,texcoords0); 97 if (texcoords1) geom->setTexCoordArray(1,texcoords1); 98 99 // osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); 100 // geometry->addPrimitiveSet(elements); 101 102 for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips. 103 { 104 osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(GL_QUAD_STRIP, columns*2); // columns*2 = number of involved vertices for this strip. 105 for ( unsigned int col=0; col<columns; col++ ) 106 { 107 (*de)[col*2 + 0] = row*columns + col; 108 (*de)[col*2 + 1] = (row+1)*columns + col; 109 } 110 geom->addPrimitiveSet( de.get() ); 111 } 112 113 return geom.release(); 32 114 } 33 115 … … 66 148 traits->sharedContext = 0; 67 149 68 bool applyIntensityMapAsColours = true;150 bool applyIntensityMapAsColours = false; 69 151 70 152 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); … … 132 214 { 133 215 osg::Geode* geode = new osg::Geode(); 134 //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), 1, 0.45, 0, projectorMatrix));135 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, projectorMatrix);216 //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), 1, 0.45, intensityMap, projectorMatrix)); 217 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, intensityMap, projectorMatrix); 136 218 geode->addDrawable(distortionMesh); 137 219 138 // new we need to add the texture to the mesh, we do so by creating a220 // new we need to add the scene texture to the mesh, we do so by creating a 139 221 // StateSet to contain the Texture StateAttribute. 140 222 osg::StateSet* stateset = geode->getOrCreateStateSet(); … … 189 271 } 190 272 } 191 192 osg::Geometry* extViewer::createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, const osg::Matrix& projectorMatrix)193 {194 // Create Quad to render on195 osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;196 197 geom->setUseDisplayList( false );198 199 osg::Vec3 xAxis(widthVector);200 float width = widthVector.length();201 xAxis /= width;202 203 osg::Vec3 yAxis(heightVector);204 float height = heightVector.length();205 yAxis /= height;206 207 osg::Vec3 dx = xAxis*(width/((float)(columns-1)));208 osg::Vec3 dy = yAxis*(height/((float)(rows-1)));209 210 211 // Create vertices and coordinates212 osg::Vec3Array* vertices = new osg::Vec3Array;213 osg::Vec2Array* texcoords0 = new osg::Vec2Array;214 //osg::Vec2Array* texcoords1 = intensityMap==0 ? new osg::Vec2Array : 0;215 osg::Vec4Array* colors = new osg::Vec4Array;216 217 geom->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);218 219 for ( unsigned int row=0; row<rows; row++ )220 {221 for ( unsigned int col=0; col<columns; col++ )222 {223 vertices->push_back( origin+dy*row+dx*col ); // geometry224 osg::Vec2 texcoord = osg::Vec2((float)col/(float)(columns-1), (float)row/(float)(rows-1));225 texcoords0->push_back( texcoord );226 227 // if (intensityMap)228 // {229 // colors->push_back(intensityMap->getColor(texcoord1));230 // }231 // else232 // {233 colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));234 // if (texcoords1) texcoords1->push_back( texcoord1 );235 // }236 237 }238 }239 240 // Pass the created vertex array to the points geometry object.241 geom->setUseVertexBufferObjects( true );242 geom->setVertexArray(vertices);243 244 geom->setColorArray(colors);245 geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);246 247 geom->setTexCoordArray(0,texcoords0);248 //if (texcoords1) geometry->setTexCoordArray(1,texcoords1);249 250 // osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES);251 // geometry->addPrimitiveSet(elements);252 253 for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips.254 {255 osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(GL_QUAD_STRIP, columns*2); // columns*2 = number of involved vertices for this strip.256 for ( unsigned int col=0; col<columns; col++ )257 {258 (*de)[col*2 + 0] = row*columns + col;259 (*de)[col*2 + 1] = (row+1)*columns + col;260 }261 geom->addPrimitiveSet( de.get() );262 }263 264 return geom.release();265 } -
experimental/distortionNG/extViewer.h
r328 r331 15 15 /** Convenience method for projection on curved screens using a slave camera rendering scene and a second camera doing distortion correction to present on a nonplaner display.*/ 16 16 void setUpViewForManualDistortion(unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); 17 18 static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, const osg::Matrix& projectorMatrix);19 17 }; -
experimental/distortionNG/main.cpp
r329 r331 41 41 // construct the viewer. 42 42 extViewer viewer(arguments); 43 viewer.setUpViewForManualDistortion();44 //viewer.setUpViewFor3DSphericalDisplay();45 43 46 // set up the camera manipulators. 44 osg::Image* intMap = osgDB::readImageFile("intensitymap.png"); 45 if (!intMap) 46 { 47 osg::notify(osg::WARN) << "Couldn't find intensity map, quiting." << std::endl; 48 return -1; 49 } 50 51 viewer.setUpViewForManualDistortion(0, intMap); 52 //viewer.setUpViewForPanoramicSphericalDisplay(1, 0, 0, intMap); 53 54 // set up the camera manipulators. 47 55 { 48 56 osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
Note: See TracChangeset
for help on using the changeset viewer.