Changeset 383 for experimental
- Timestamp:
- Jun 15, 2012, 9:14:07 PM (12 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/DistortionSet.cpp
r379 r383 24 24 DistortionSet::DistortionSet() 25 25 { 26 _dirty = false; 26 _meshDirty = false; 27 _matrixDirty = false; 27 28 28 29 _distortionMeshRows = 2; 29 30 _distortionMeshColumns = 2; 30 //GLenum _meshType;31 _distortionMesh = new osg::Vec4Array(); 31 32 32 33 _intensityMap = NULL; … … 50 51 } 51 52 52 void DistortionSet::setDistortionMesh (osg::Geometry*)53 void DistortionSet::setDistortionMeshDimensions(int rows, int cols) 53 54 { 54 // todo: denormalisieren und mesh dann an seine passenden Platz vom Switch packen. 55 _distortionMeshRows = rows; 56 _distortionMeshColumns = cols; 57 58 if(_distortionMesh->size() != _distortionMeshRows * _distortionMeshRows) // If dimensions differ: discard current mesh and createa new one 59 { 60 _distortionMesh = new osg::Vec4Array(_distortionMeshRows * _distortionMeshRows); 61 for(int row=0;row<_distortionMeshRows;row++) 62 { 63 for(int col=0;col<_distortionMeshColumns;col++) 64 { 65 float x=col/_distortionMeshColumns; // Vertex X 66 float y=row/_distortionMeshRows; // Vertex Y 67 float z=col/_distortionMeshColumns; // TexCoord X 68 float w=row/_distortionMeshRows; // TexCoord Y 69 70 _distortionMesh->at(row*_distortionMeshColumns+col).set(x,y,z,w); 71 } 72 } 73 } 55 74 } 56 75 57 const osg::Geometry* DistortionSet::getDistortionMesh() const58 {59 // Todo: Normalisieren und dann zurückgeben60 return NULL;61 }62 76 63 77 REGISTER_OBJECT_WRAPPER( osgViewer_DistortionSet, // The unique wrapper name … … 69 83 ADD_INT_SERIALIZER( DistortionMeshRows, 1 ); //int _distortionMeshRows; 70 84 ADD_INT_SERIALIZER( DistortionMeshColumns, 1 ); //int _distortionMeshColumns; 71 ADD_OBJECT_SERIALIZER( DistortionMesh, osg:: Geometry, NULL ); // Normalisiertes Mesh85 ADD_OBJECT_SERIALIZER( DistortionMesh, osg::Vec4Array, NULL ); // x,y = vertex coordinates, z,t=textureCoordinates, Werte sind normalisiert auf 0-1 72 86 73 87 ADD_GLENUM_SERIALIZER( MeshType, GLenum, GL_QUAD_STRIP ); //osg::PrimitiveSet::Mode _MeshType -
experimental/distortionNG/DistortionSet.h
r379 r383 54 54 55 55 // Working access 56 bool isDirty(){return(_dirty);} 57 void dirty(){_dirty=true;} 56 bool isDirty(){return(_meshDirty || _matrixDirty);} 57 void dirtyMesh(){_meshDirty = true;} 58 void dirtyMatrix(){_matrixDirty = true;} 59 void clearDirtyStatus() { _meshDirty = false; _matrixDirty = false;} 60 61 void setDistortionMeshDimensions(int rows, int cols); 58 62 59 63 osg::Image* getIntensityMap() { return _intensityMap; } // Also for manipulating the intensity map … … 79 83 int getDistortionMeshColumns() const { return _distortionMeshColumns; } 80 84 81 void setDistortionMesh(osg:: Geometry*);82 const osg:: Geometry* getDistortionMesh() const;85 void setDistortionMesh(osg::Vec4Array* distortionMesh) { _distortionMesh = distortionMesh; } 86 const osg::Vec4Array* getDistortionMesh() const { return _distortionMesh; } 83 87 84 88 void setMeshType(GLenum meshType) { _meshType = meshType; } … … 106 110 107 111 private: 108 bool _dirty; 112 // Blendmap has no dirty flag because changes of the intensityMap is directly effective. 113 bool _meshDirty; 114 bool _matrixDirty; 115 109 116 int _distortionMeshRows; 110 117 int _distortionMeshColumns; 118 osg::ref_ptr<osg::Vec4Array> _distortionMesh; // x,y = vertex coordinates, z,t=textureCoordinates 111 119 GLenum _meshType; 112 120 -
experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp
r382 r383 28 28 _blendmapFilename = ""; 29 29 _frustumFilename = ""; 30 _distortionFilename = ""; 30 _vertexDistortionFilename = ""; 31 _texCoordDistortionFilename = ""; 31 32 _distortionType = DistortionSetupStrategy::UNDEFINED; 32 33 … … 39 40 } 40 41 41 void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string distortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)42 void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type) 42 43 { 43 44 _distortionType = type; 44 45 _blendmapFilename = blendmapFile; 45 46 _frustumFilename = frustumFile; 46 _distortionFilename = distortionFile; 47 _vertexDistortionFilename = vertexDistortionFile; 48 _texCoordDistortionFilename = texCoordDistortionFile; 47 49 } 48 50 … … 231 233 } 232 234 233 if( _distortionType == DistortionSetupStrategy::UNDEFINED || _blendmapFilename.empty() || _frustumFilename.empty() || _distortionFilename.empty() ) 234 { 235 OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames and distortion type!"<<std::endl; 235 if( _distortionType == DistortionSetupStrategy::UNDEFINED 236 || _blendmapFilename.empty() 237 || _frustumFilename.empty() 238 || ( _vertexDistortionFilename.empty() && _distortionType == DistortionSetupStrategy::VERTEXDISTORTION ) 239 || ( _texCoordDistortionFilename.empty() && _distortionType == DistortionSetupStrategy::TEXCOORDDISTORTION ) 240 ) 241 { 242 OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames and distortion type correctly!"<<std::endl; 236 243 return; 237 244 } … … 242 249 { 243 250 _distortionInitialized=true; 244 distortionSet->dirty(); 251 distortionSet->dirtyMesh(); 252 distortionSet->dirtyMatrix(); 253 245 254 246 255 // ******************** // … … 317 326 //*******************************************************************************************// 318 327 319 #if 1328 #if 0 320 329 osg::Vec3Array* vertices = (osg::Vec3Array*) distortionMeshGeometry->getVertexArray(); 321 330 osg::Vec2Array* texcoords0 = (osg::Vec2Array*) distortionMeshGeometry->getTexCoordArray(0); … … 338 347 //*******************************************************************************************// 339 348 340 // Exctract mesh dimensions from file and pass them to the container 349 // Exctract mesh dimensions from file and pass them to the container. 350 // If soley texCoordDistortion is used, _texCoordDistortionFilename is used to determine the dimensions, otherwise _vertexDistortionFilename 341 351 int distortionMeshRows=0, distortionMeshColumns=0; 342 readMeshDimensionsFromCSVFile(_distortion Filename, &distortionMeshRows, &distortionMeshColumns);352 readMeshDimensionsFromCSVFile(_distortionType==DistortionSetupStrategy::TEXCOORDDISTORTION?_texCoordDistortionFilename:_vertexDistortionFilename, &distortionMeshRows, &distortionMeshColumns); 343 353 344 354 distortionSet->setDistortionMeshRows(distortionMeshRows); 345 355 distortionSet->setDistortionMeshColumns(distortionMeshColumns); 346 356 347 osg::Vec2Array* tmpMeshVec2 = new osg::Vec2Array; 348 osg::Vec3Array* vertexMeshVec3 = new osg::Vec3Array; 349 350 readMeshPointsFromCSVFile(_distortionFilename, tmpMeshVec2); 357 // If vertex- and texCoord distortion is combined: Ensure both files have the same dimensions 358 if(_distortionType==DistortionSetupStrategy::COMBINEDDISTORTION) 359 { 360 int texCoordRows=0, texCoordColumns=0; 361 readMeshDimensionsFromCSVFile(_texCoordDistortionFilename, &distortionMeshRows, &distortionMeshColumns); 362 if(distortionMeshRows!=texCoordRows || distortionMeshColumns!=texCoordColumns) 363 { 364 OSG_ALWAYS<<"The mesh dimensions of the vertex- and textureCoordinate-distortion differ!"<<std::endl; 365 return; 366 } 367 } 368 369 // Read in the mesh arrays 370 osg::Vec2Array* vertexMeshVec2 = new osg::Vec2Array; 371 osg::Vec2Array* texCoordMeshVec2 = new osg::Vec2Array; 372 osg::Vec4Array* distortionMesh = new osg::Vec4Array(distortionMeshRows*distortionMeshColumns); 373 374 if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION)) 375 { 376 readMeshPointsFromCSVFile(_vertexDistortionFilename, vertexMeshVec2); 377 } 351 378 352 379 if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION)) 353 380 { 354 distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray(0,tmpMeshVec2); 355 } 356 357 if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION)) 358 { 359 for(unsigned int i=0;i<tmpMeshVec2->size();i++) 360 { 361 // Scale vector with the screen resolution 362 osg::Vec3 tmpVec = osg::Vec3( tmpMeshVec2->at(i).x()*width, 363 tmpMeshVec2->at(i).y()*height, 364 0.0 ); 365 vertexMeshVec3->push_back( tmpVec ); 366 } 367 distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setVertexArray(vertexMeshVec3); 368 369 } 381 readMeshPointsFromCSVFile(_texCoordDistortionFilename, texCoordMeshVec2); 382 } 383 384 // Transfer the read values into the combinedArray 385 for(int row=0;row<distortionMeshRows;row++) 386 { 387 for(int col=0;col<distortionMeshColumns;col++) 388 { 389 float x=col/distortionMeshColumns; // Vertex X 390 float y=row/distortionMeshRows; // Vertex Y 391 float z=col/distortionMeshColumns; // TexCoord X 392 float w=row/distortionMeshRows; // TexCoord Y 393 if(_distortionType==VERTEXDISTORTION || _distortionType==COMBINEDDISTORTION) 394 { 395 x = vertexMeshVec2->at(row*col).x(); 396 y = vertexMeshVec2->at(row*col).y(); 397 } 398 if(_distortionType==TEXCOORDDISTORTION || _distortionType==COMBINEDDISTORTION) 399 { 400 z = texCoordMeshVec2->at(row*col).x(); 401 w = texCoordMeshVec2->at(row*col).y(); 402 } 403 404 distortionMesh->at(row*distortionMeshColumns+col).set(x,y,z,w); 405 } 406 } 407 408 distortionSet->setDistortionMesh(distortionMesh); 409 distortionSet->setDistortionMeshColumns(distortionMeshColumns); 410 distortionSet->setDistortionMeshRows(distortionMeshRows); 411 412 // apply new settings 413 //if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION)) 414 //{ 415 // distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray(0,tmpMeshVec2); 416 //} 417 418 //if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION)) 419 //{ 420 // OSG_ALWAYS<<"New mesh ---------------------------"<<std::endl; 421 // for(unsigned int i=0;i<tmpMeshVec2->size();i++) 422 // { 423 // // Scale vector with the screen resolution 424 // osg::Vec3 tmpVec = osg::Vec3( tmpMeshVec2->at(i).x()*width, 425 // tmpMeshVec2->at(i).y()*height, 426 // 0.0 ); 427 // vertexMeshVec3->push_back( tmpVec ); 428 // OSG_ALWAYS<<"X:"<<tmpVec.x()<<" Y:"<<tmpVec.y()<<" Z:"<<tmpVec.z()<<std::endl; 429 // } 430 // OSG_ALWAYS<<"tmpMeshVec2 size:"<<tmpMeshVec2->size()<<std::endl; 431 // distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setVertexArray(vertexMeshVec3); 432 // distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray 433 // distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->dirtyDisplayList(); 434 //} 370 435 } 371 436 } -
experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.h
r382 r383 35 35 ~DistortionSetupStrategyProjectSyntropy(); 36 36 void delegateDistortionSetup(osgViewer::DistortionSet* distortionSet); 37 void setDistortionInputFiles( std::string distortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type);37 void setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type); 38 38 private: 39 39 //Functions related to CSV-File-Reading … … 46 46 std::string _blendmapFilename; 47 47 std::string _frustumFilename; 48 std::string _distortionFilename; 48 std::string _vertexDistortionFilename; 49 std::string _texCoordDistortionFilename; 49 50 50 51 }; -
experimental/distortionNG/main.cpp
r380 r383 53 53 osg::ref_ptr<osgViewer::DistortionSet> _distortionSet = new osgViewer::DistortionSet(); 54 54 _distortionSet->setIntensityMap( intMap ); 55 _distortionSet->setDistortionMeshRows( 20 ); 56 _distortionSet->setDistortionMeshColumns( 20 ); 57 55 _distortionSet->setDistortionMeshDimensions(20, 20); 56 58 57 59 58 // ---- test plugin read / write … … 96 95 97 96 DistortionSetupStrategyProjectSyntropy* psStrategy = new DistortionSetupStrategyProjectSyntropy(); 98 psStrategy->setDistortionInputFiles( "./resources/ProjectSyntropy/Vertices/warpmap_1.csv", 97 psStrategy->setDistortionInputFiles( "./resources/ProjectSyntropy/Vertices/warpmap_2.csv", 98 "./resources/ProjectSyntropy/TexCoords/warpmap_2.csv", 99 99 "./resources/ProjectSyntropy/blending_1.bmp", 100 100 "./resources/ProjectSyntropy/Vertices/frustum_1.csv",
Note: See TracChangeset
for help on using the changeset viewer.