- Timestamp:
- Jun 15, 2012, 9:14:07 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.