Changeset 394


Ignore:
Timestamp:
Jun 30, 2012, 8:56:16 PM (7 years ago)
Author:
Torben Dannhauer
Message:

vertex- and texcoord warping works now :)

Location:
experimental/distortionNG
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionSetupStrategy.h

    r377 r394  
    3737        virtual void delegateDistortionSetup(osgViewer::DistortionSet* distortionSet)=0;
    3838
    39         enum distortionType { VERTEXDISTORTION, TEXCOORDDISTORTION, COMBINEDDISTORTION, UNDEFINED};
    40 
    4139protected:
    4240
  • experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp

    r393 r394  
    2828        _blendmapFilename = "";
    2929        _frustumFilename = "";
    30         _vertexDistortionFilename = "";
    31         _texCoordDistortionFilename = "";
    32         _distortionType = DistortionSetupStrategy::UNDEFINED;
     30        _distortionFilename = "";
    3331
    3432        _distortionInitialized=false;
     
    4038}
    4139
    42 void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)
    43 {
    44         _distortionType = type;
     40void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles(std::string distortionFile, std::string blendmapFile, std::string frustumFile)
     41{
    4542        _blendmapFilename = blendmapFile;
    4643        _frustumFilename = frustumFile;
    47         _vertexDistortionFilename = vertexDistortionFile;
    48         _texCoordDistortionFilename = texCoordDistortionFile;
     44        _distortionFilename = distortionFile;
    4945}
    5046
     
    168164}
    169165
    170 int DistortionSetupStrategyProjectSyntropy::readMeshPointsFromCSVFile(std::string filePath, osg::Vec2Array* tmpMesh)
     166int DistortionSetupStrategyProjectSyntropy::readMeshPointsFromCSVFile(std::string filePath, osg::Vec4Array* tmpMesh)
    171167{
    172168        int numValues=6;
     
    211207
    212208                                // Store values into array
    213                                 tmpMesh->push_back(osg::Vec2(values[0], values[1]));
     209                                tmpMesh->push_back(osg::Vec4(values[0], values[1], values[2], values[3]));
    214210                        }
    215211                }
     
    233229        }
    234230
    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;
     231        if(      _blendmapFilename.empty() || _frustumFilename.empty() ||  _distortionFilename.empty() )
     232        {
     233                OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames correctly!"<<std::endl;
    243234                return;
    244235        }
     
    348339                        //*******************************************************************************************//
    349340                        //***    MESH WARPING                                                                                                                                     ***//
    350                         //***    Both Vertex Warping and Texcoord Warping is supported. Although there might      ***//
     341                        //***    Both Vertex Warping and Texcoord Warping is supported.
     342                        //***    The input file contains . Although there might      ***//
    351343                        //***    be a preferred version for osgvisual, both options should be implemented in osg  ***//
    352344                        //*******************************************************************************************//
    353345
    354346                        // Exctract mesh dimensions from file and pass them to the container.
    355                         // If soley texCoordDistortion is used, _texCoordDistortionFilename is used to determine the dimensions, otherwise _vertexDistortionFilename
     347
    356348                        int distortionMeshRows=0, distortionMeshColumns=0;
    357                         readMeshDimensionsFromCSVFile(_distortionType==DistortionSetupStrategy::TEXCOORDDISTORTION?_texCoordDistortionFilename:_vertexDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
     349                        readMeshDimensionsFromCSVFile(_distortionFilename, &distortionMeshRows, &distortionMeshColumns);
    358350
    359351                        distortionSet->setDistortionMeshRows(distortionMeshRows);
    360352                        distortionSet->setDistortionMeshColumns(distortionMeshColumns);
    361353
    362                         // If vertex- and texCoord distortion is combined: Ensure both files have the same dimensions
    363                         if(_distortionType==DistortionSetupStrategy::COMBINEDDISTORTION)
    364                         {
    365                                 int texCoordRows=0, texCoordColumns=0;
    366                                 readMeshDimensionsFromCSVFile(_texCoordDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
    367                                 if(distortionMeshRows!=texCoordRows || distortionMeshColumns!=texCoordColumns)
    368                                 {
    369                                         OSG_ALWAYS<<"The mesh dimensions of the vertex- and textureCoordinate-file differ!"<<std::endl;
    370                                         return;
    371                                 }
    372                         }
    373 
    374354                        // Read in the mesh arrays
    375                         osg::Vec2Array* vertexMeshVec2 = new osg::Vec2Array;
    376                         osg::Vec2Array* texCoordMeshVec2 = new osg::Vec2Array;
    377                         osg::Vec4Array* distortionMesh = new osg::Vec4Array(distortionMeshRows*distortionMeshColumns);
    378                        
    379                         if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION))
    380                         {
    381                                 readMeshPointsFromCSVFile(_vertexDistortionFilename, vertexMeshVec2);
    382                         }
    383 
    384                         if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION))
    385                         {
    386                                 readMeshPointsFromCSVFile(_texCoordDistortionFilename, texCoordMeshVec2);
    387                         }
    388 
    389                         // Transfer the read values into the combinedArray
    390                         for(int row=0;row<distortionMeshRows;row++)
    391                         {
    392                                 for(int col=0;col<distortionMeshColumns;col++)
    393                                 {
    394                                         float x=(float)col/(float)(distortionMeshColumns-1);    // Vertex X
    395                                         float y=(float)row/(float)(distortionMeshRows-1);               // Vertex Y
    396                                         float z=(float)col/(float)(distortionMeshColumns-1);    // TexCoord X
    397                                         float w=(float)row/(float)(distortionMeshRows-1);               // TexCoord Y
    398 
    399                                         if(_distortionType==VERTEXDISTORTION || _distortionType==COMBINEDDISTORTION)
    400                                         {
    401                                                 x = vertexMeshVec2->at(row*distortionMeshColumns + col).x();
    402                                                 y = vertexMeshVec2->at(row*distortionMeshColumns + col).y();
    403                                         }
    404                                         if(_distortionType==TEXCOORDDISTORTION || _distortionType==COMBINEDDISTORTION)
    405                                         {
    406                                                 z = texCoordMeshVec2->at(row*distortionMeshColumns + col).x();
    407                                                 w = texCoordMeshVec2->at(row*distortionMeshColumns + col).y();
    408                                         }
    409 
    410                                         distortionMesh->at(row*distortionMeshColumns+col).set(x,y,z,w);
    411                                 }
    412                         }
     355                        osg::Vec4Array* distortionMesh = new osg::Vec4Array;
     356                        readMeshPointsFromCSVFile(_distortionFilename, distortionMesh);
    413357
    414358#if 1
     
    421365
    422366                        distortionSet->setDistortionMesh(distortionMesh);
    423                         //distortionSet->setDistortionMeshColumns(distortionMeshColumns);
    424                         //distortionSet->setDistortionMeshRows(distortionMeshRows);
    425367                        distortionSet->setDistortionMeshDimensions(distortionMeshRows, distortionMeshColumns);
    426368                }
  • experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.h

    r383 r394  
    3535        ~DistortionSetupStrategyProjectSyntropy();
    3636        void delegateDistortionSetup(osgViewer::DistortionSet* distortionSet);
    37         void setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type);
     37        void setDistortionInputFiles(std::string distortionFile, std::string blendmapFile, std::string frustumFile);
    3838private:
    3939        //Functions related to CSV-File-Reading
    4040        int readFrustumFromCSVFile(std::string filePath, int numValues, float* frustumValues);
    4141        int readMeshDimensionsFromCSVFile(std::string filePath, int* meshRows, int* meshColumns);
    42         int readMeshPointsFromCSVFile(std::string filePath, osg::Vec2Array* tmpMesh);
     42        int readMeshPointsFromCSVFile(std::string filePath, osg::Vec4Array* tmpMesh);
    4343
    4444        bool _distortionInitialized;                            //Is Distortion already initialized?
    45         DistortionSetupStrategy::distortionType _distortionType; //might be VERTEXDISTORTION, TEXCOORDDISTORTION, COMBINEDDISTORTION or UNDEFINED...
    4645        std::string _blendmapFilename;
    4746        std::string _frustumFilename;
    48         std::string _vertexDistortionFilename;
    49         std::string _texCoordDistortionFilename;
    50 
     47        std::string _distortionFilename;
    5148};
  • experimental/distortionNG/extViewer.cpp

    r392 r394  
    100100    osg::Vec3 dy = yAxis*(height/((float)(rows-1)));
    101101
    102 
    103102        // Create vertices and coordinates
    104103        osg::Vec3Array* vertices = new osg::Vec3Array;
     
    112111                for ( unsigned int col=0; col<columns; col++ )
    113112                {
     113                        osg::Vec3 vertex = origin+dy*row+dx*col;
     114
    114115                        // Create coordinates of the mesh node (geometry).
    115                         vertices->push_back( origin+dy*row+dx*col );
    116 
    117                         // Create tex coordinates
    118                         osg::Vec2 texcoord = osg::Vec2((float)col/(float)(columns-1), (float)row/(float)(rows-1));
     116                        vertices->push_back( vertex );
    119117
    120118                        // Set Coordinates for RTT-Texture (scene rendering)
    121                         texcoords0->push_back( texcoord );
     119                        texcoords0->push_back( osg::Vec2( vertex.x(), vertex.y()) );
    122120
    123121                        // Set Color of the mesh node
  • experimental/distortionNG/main.cpp

    r393 r394  
    9696        DistortionSetupStrategyProjectSyntropy* psStrategy = new DistortionSetupStrategyProjectSyntropy();
    9797        psStrategy->setDistortionInputFiles( "./resources/ProjectSyntropy/Vertices/warpmap_1.csv",
    98                                                                                 "./resources/ProjectSyntropy/TexCoords/warpmap_1.csv",
     98                                                                                //"./resources/ProjectSyntropy/TexCoords/warpmap_1.csv",
    9999                                                                                "./resources/ProjectSyntropy/blending_1.bmp",
    100                                                                                 "./resources/ProjectSyntropy/Vertices/frustum_1.csv",
    101                                                                                 DistortionSetupStrategy::TEXCOORDDISTORTION );
     100                                                                                "./resources/ProjectSyntropy/Vertices/frustum_1.csv" );
    102101        distortionManip->setDistortionSetupStrategy( psStrategy );
    103102        viewer.addEventHandler(distortionManip);
Note: See TracChangeset for help on using the changeset viewer.