Ignore:
Timestamp:
Jun 15, 2012, 9:14:07 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp

    r382 r383  
    2828        _blendmapFilename = "";
    2929        _frustumFilename = "";
    30         _distortionFilename = "";
     30        _vertexDistortionFilename = "";
     31        _texCoordDistortionFilename = "";
    3132        _distortionType = DistortionSetupStrategy::UNDEFINED;
    3233
     
    3940}
    4041
    41 void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string distortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)
     42void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)
    4243{
    4344        _distortionType = type;
    4445        _blendmapFilename = blendmapFile;
    4546        _frustumFilename = frustumFile;
    46         _distortionFilename = distortionFile;
     47        _vertexDistortionFilename = vertexDistortionFile;
     48        _texCoordDistortionFilename = texCoordDistortionFile;
    4749}
    4850
     
    231233        }
    232234
    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;
    236243                return;
    237244        }
     
    242249        {
    243250                _distortionInitialized=true;
    244                 distortionSet->dirty();
     251                distortionSet->dirtyMesh();
     252                distortionSet->dirtyMatrix();
     253
    245254
    246255                // ******************** //
     
    317326                        //*******************************************************************************************//
    318327                       
    319 #if 1
     328#if 0
    320329                        osg::Vec3Array* vertices =  (osg::Vec3Array*) distortionMeshGeometry->getVertexArray();
    321330                        osg::Vec2Array* texcoords0 = (osg::Vec2Array*) distortionMeshGeometry->getTexCoordArray(0);
     
    338347                        //*******************************************************************************************//
    339348
    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
    341351                        int distortionMeshRows=0, distortionMeshColumns=0;
    342                         readMeshDimensionsFromCSVFile(_distortionFilename, &distortionMeshRows, &distortionMeshColumns);
     352                        readMeshDimensionsFromCSVFile(_distortionType==DistortionSetupStrategy::TEXCOORDDISTORTION?_texCoordDistortionFilename:_vertexDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
    343353
    344354                        distortionSet->setDistortionMeshRows(distortionMeshRows);
    345355                        distortionSet->setDistortionMeshColumns(distortionMeshColumns);
    346356
    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                        }
    351378
    352379                        if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION))
    353380                        {
    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                        //}
    370435                }
    371436        }
Note: See TracChangeset for help on using the changeset viewer.