Changeset 376
- Timestamp:
- Jun 13, 2012, 9:18:04 PM (12 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/DistortionSetupStrategy.h
r372 r376 37 37 virtual void delegateDistortionSetup(osgViewer::DistortionSet* distortionSet)=0; 38 38 39 enum distortionType { VERTEXDISTORTION, TEXCOORDDISTORTION, COMBINEDDISTORTION}; 40 39 41 protected: 40 42 -
experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp
r372 r376 17 17 */ 18 18 19 #include <osgDB/ReadFile> 20 #include <osg/Vec3d> 21 #include <osgDB/fstream> 22 19 23 #include "DistortionSetupStrategyProjectSyntropy.h" 20 24 21 25 DistortionSetupStrategyProjectSyntropy::DistortionSetupStrategyProjectSyntropy() 22 26 { 27 _switchDistortionTypeVortexToTexcoords=false; 28 29 _intensityMapFilename="./resources/ProjectSyntropy/blending_1.bmp"; 30 31 _frustumVortexDistortionFilename="./resources/ProjectSyntropy/Vertices/frustum_1.csv"; 32 _frustumTexcoordDistortionFilename="./resources/ProjectSyntropy/TexCoords/frustum_1.csv"; 33 34 _meshVortexDistortionFilename="./resources/ProjectSyntropy/Vertices/warpmap_1.csv"; 35 _meshTexcoordDistortionFilename="./resources/ProjectSyntropy/TexCoords/warpmap_1.csv"; 36 37 38 _distortionInitialized=false; 23 39 } 24 40 … … 26 42 { 27 43 } 44 45 void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string distortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type) 46 { 47 48 } 49 50 int DistortionSetupStrategyProjectSyntropy::readFrustumFromCSVFile(std::string filePath, int numValues, float* frustumValues) 51 { 52 int numSeparator=0; 53 std::string line, valueString; 54 char separator=';'; 55 size_t valueStart, valueEnd; 56 57 osgDB::ifstream inputFile (const_cast<char*>(filePath.c_str())); 58 59 for (int i=0;i<numValues; i++) frustumValues[i]=0.0; 60 61 if (inputFile.is_open()) 62 { 63 inputFile.clear(); 64 inputFile.seekg (0, std::ios::beg); 65 66 while (!inputFile.eof()) 67 { 68 getline (inputFile,line); 69 70 if((line.size()>0) && (line.find('x')==std::string::npos)) 71 {new osg::Vec2Array; 72 numSeparator=0; 73 for (size_t numLineChar=0; numLineChar < line.length(); numLineChar++) 74 { 75 if(line.at(numLineChar)==separator) numSeparator++; 76 } 77 if(numSeparator!=numValues-1) //Number of Entries per Line is not correct 78 { 79 OSG_ALWAYS<< "Inconsistency in file " << filePath << " detected. Please check this file." <<std::endl; 80 return 1; 81 } 82 valueStart=0; 83 valueEnd=0; 84 for (int j=0;j<numValues; j++) 85 { 86 if(j!=numValues-1) 87 { 88 if((valueEnd=line.find(separator,valueStart))!=std::string::npos) 89 { 90 valueString=line.substr(valueStart,valueEnd-valueStart); 91 valueStart=valueEnd+1; 92 } 93 } 94 else valueString=line.substr(valueStart,line.size()); 95 96 frustumValues[j]=atof(const_cast<char*>(valueString.c_str())); 97 } 98 99 } 100 101 } 102 inputFile.close(); 103 } 104 else //File couldn't be loaded 105 { 106 OSG_ALWAYS<< "Unable to open " << filePath << std::endl; 107 return 1; 108 } 109 return 0; 110 } 111 112 int DistortionSetupStrategyProjectSyntropy::readMeshDimensionsFromCSVFile(std::string filePath, int* meshRows, int* meshColumns) 113 { 114 int tempRows=0, tempCols=0, numSeparator=0, numValues=6; 115 std::string line, valueString; 116 char separator=';'; 117 size_t valueStart, valueEnd; 118 119 osgDB::ifstream inputFile (const_cast<char*>(filePath.c_str())); 120 121 if (inputFile.is_open()) 122 { 123 inputFile.clear(); 124 inputFile.seekg (0, std::ios::beg); 125 126 while (!inputFile.eof()) 127 { 128 getline (inputFile,line); 129 130 if((line.size()>0) && (line.find('x')==std::string::npos)) 131 { 132 numSeparator=0; 133 for (size_t numLineChar=0; numLineChar < line.length(); numLineChar++) 134 { 135 if(line.at(numLineChar)==separator) numSeparator++; 136 } 137 if(numSeparator!=numValues-1) //Number of Entries per Line is not correct 138 { 139 OSG_ALWAYS<< "Inconsistency in file " << filePath << " detected. Please check this file." <<std::endl; 140 return 1; 141 } 142 //Get number of rows of the distortion grid, last valid line of input file contains actual value 143 valueStart=line.rfind(separator,line.size()); 144 valueString=line.substr(valueStart+1,line.size()-valueStart-1); 145 tempRows=atoi(const_cast<char*>(valueString.c_str())); 146 if(tempRows>*meshRows) *meshRows=tempRows; 147 148 //Get number of columns of the distortion grid, last valid line of input file contains actual value 149 valueEnd=valueStart-1; 150 valueStart=line.rfind(separator,valueEnd); 151 valueString=line.substr(valueStart+1,valueEnd-valueStart); 152 tempCols=atoi(const_cast<char*>(valueString.c_str())); 153 if(tempCols>*meshColumns) *meshColumns=tempCols; 154 } 155 156 } 157 inputFile.close(); 158 } 159 else //File couldn't be loaded 160 { 161 OSG_ALWAYS<< "Unable to open " << filePath << std::endl; 162 return 1; 163 } 164 165 *meshColumns+=1; 166 *meshRows+=1; 167 168 return 0; 169 } 170 171 int DistortionSetupStrategyProjectSyntropy::readMeshPointsFromCSVFile(std::string filePath, osg::Vec2Array* meshPointsVec2, osg::Vec3Array* meshPointsVec3, int displayWidth, int displayHeight) 172 { 173 174 int numValues=6; 175 std::string line, valueString; 176 char separator=';'; 177 float* values = new float[numValues]; 178 size_t valueStart, valueEnd; 179 osg::Vec2 tempVec2; 180 osg::Vec3 tempVec3; 181 182 osgDB::ifstream inputFile (const_cast<char*>(filePath.c_str())); 183 184 if (inputFile.is_open()) 185 { 186 inputFile.clear(); 187 inputFile.seekg (0, std::ios::beg); 188 189 while (!inputFile.eof()) 190 { 191 getline (inputFile,line); 192 193 if((line.size()>0) && (line.find('x')==std::string::npos)) 194 { 195 for (int i=0;i<numValues; i++) values[i]=0.0; 196 197 valueStart=0; 198 valueEnd=0; 199 for (int j=0;j<numValues; j++) 200 { 201 if(j!=numValues-1) 202 { 203 if((valueEnd=line.find(separator,valueStart))!=std::string::npos) 204 { 205 valueString=line.substr(valueStart,valueEnd-valueStart); 206 valueStart=valueEnd+1; 207 } 208 } 209 else valueString=line.substr(valueStart,line.size()); 210 211 values[j]=atof(const_cast<char*>(valueString.c_str())); 212 } 213 214 // Insertion of Values U and V (corresponding to values[2],values[3] in a temporary Array 215 // which is returned and merged into distortionSet later 216 if(_switchDistortionTypeVortexToTexcoords) 217 { 218 tempVec2.set(values[2],values[3]); 219 meshPointsVec2->push_back(tempVec2); 220 } 221 else 222 { 223 tempVec3.set(values[2]*displayWidth,values[3]*displayHeight,0.0); 224 meshPointsVec3->push_back(tempVec3); 225 } 226 } 227 228 } 229 inputFile.close(); 230 } 231 else 232 { 233 OSG_ALWAYS<< "Unable to open " << filePath << std::endl; 234 return 1; 235 } 236 237 return 0; 238 } 239 240 241 242 243 28 244 29 245 void DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup(osgViewer::DistortionSet* distortionSet) … … 35 251 } 36 252 37 OSG_ALWAYS<<"drin"<<std::endl; 38 39 /* Todo: In diese Klasse das Einlesen und übertragen der Project Syntropy Dateien packen: 40 * 41 * 1. Blendmap einlesen, auf Screensize skalieren und in den distortioncontainer übertragen 42 * 2. Frustum CSV auslesen und die Werte in ViewMatrix und Projectionmatrix übertragen 43 * 3. Meshkoordinaten aus CSV einlesen und in DistortionSet übertragen 44 * 45 */ 46 } 253 //OSG_ALWAYS<<"drin"<<std::endl; 254 255 if (_distortionInitialized==false) 256 { 257 258 // ******************** // 259 // *** IntensityMap *** // 260 // ******************** // 261 262 osg::Image* intensityMap=NULL; 263 intensityMap=osgDB::readImageFile(_intensityMapFilename); 264 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 265 if (!wsi) 266 { 267 OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; 268 return; 269 } 270 271 osg::GraphicsContext::ScreenIdentifier si; 272 si.readDISPLAY(); 273 274 if (si.displayNum<0) si.displayNum = 0; 275 276 si.screenNum = 0; //Fixed value, may be replaced later 277 278 unsigned int width=0, height=0; 279 wsi->getScreenResolution(si, width, height); 280 281 if(intensityMap->s()!=width || intensityMap->t()!=height) 282 intensityMap->scaleImage(width, height, intensityMap->r()); 283 284 distortionSet->setIntensityMap(intensityMap); 285 286 // ******************************* // 287 // *** Frustum and View Offset *** // 288 // ******************************* // 289 290 //....Read Files and set parameters 291 int numFrustumValues=16; 292 float* frustumValues = new float[numFrustumValues]; 293 double zNear=0.1, zFar=100.0; 294 295 if(_switchDistortionTypeVortexToTexcoords) readFrustumFromCSVFile(_frustumTexcoordDistortionFilename, numFrustumValues, frustumValues); 296 else readFrustumFromCSVFile(_frustumVortexDistortionFilename, numFrustumValues, frustumValues); 297 298 osg::Matrixd viewOffset=osg::Matrixd(); 299 osg::Matrixd projectionOffset=osg::Matrixd(); 300 301 // View Offset Parameters: x, y, z, heading, pitch, bank 302 // Translational Parameters are defines in millimeters (->Correction required?!) 303 // Coordinate System / Directions may be looked up in "Koordinatensystem.png", trans/rot order confirmed bei PS 304 viewOffset = osg::Matrixd::translate(frustumValues[0],frustumValues[1],frustumValues[2]); 305 viewOffset*= osg::Matrixd::rotate(osg::inDegrees(frustumValues[3]), 0.0,0.0,1.0); //Heading 306 viewOffset*= osg::Matrixd::rotate(osg::inDegrees(frustumValues[4]), 1.0,0.0,0.0); //Pitch 307 viewOffset*= osg::Matrixd::rotate(osg::inDegrees(frustumValues[5]), 0.0,1.0,0.0); //Bank 308 309 //Frustum Parameters: Left, Right, Bottom, Top, zNear, zFar 310 projectionOffset.makeFrustum(osg::inDegrees(frustumValues[6]), osg::inDegrees(frustumValues[7]), osg::inDegrees(frustumValues[8]), osg::inDegrees(frustumValues[9]), zNear, zFar); 311 312 distortionSet->setViewOffset(viewOffset); 313 distortionSet->setProjectionOffset(projectionOffset); 314 315 // ******************************* // 316 // ******* Distortion Mesh ******* // 317 // ******************************* // 318 319 osg::Geometry* distortionMeshGeometry = distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry(); 320 if(distortionMeshGeometry) 321 { 322 //*******************************************************************************************// 323 //*** PRINT VERTEXARRAY/TEXCOORDARRAY for Debug Purposes ***// 324 //*** both Arrays are listed in "HorizontalLine-after-HorizontalLine" order, ***// 325 //*** sorted from topleft (0,0,0 vertices; 0,0 texcoords) to bottomright ***// 326 //*** (1920,1080,0 vertices; 1,1 texcoords) ***// 327 //*******************************************************************************************// 328 329 if(0) 330 { 331 osg::Vec3Array* vertices = (osg::Vec3Array*) distortionMeshGeometry->getVertexArray(); 332 osg::Vec2Array* texcoords0 = (osg::Vec2Array*) distortionMeshGeometry->getTexCoordArray(0); 333 334 for (osg::Vec3Array::iterator it = vertices->begin(); it != vertices->end(); ++it) 335 { 336 OSG_ALWAYS<<"Vertice "<<(*it).x()<<" "<<(*it).y()<<" "<<(*it).z()<<std::endl; 337 } 338 339 for (osg::Vec2Array::iterator it = texcoords0->begin(); it != texcoords0->end(); ++it) 340 { 341 OSG_ALWAYS<<"Texcoord "<<(*it).x()<<" "<<(*it).y()<<std::endl; 342 } 343 } 344 345 //*******************************************************************************************// 346 //*** MESH WARPING ***// 347 //*** Both Vertex Warping and Texcoord Warping is supported. Although there might ***// 348 //*** be a preferred version for osgvisual, both options should be implemented in osg ***// 349 //*******************************************************************************************// 350 351 352 int distortionMeshRows=0, distortionMeshColumns=0; 353 if(_switchDistortionTypeVortexToTexcoords) readMeshDimensionsFromCSVFile(_meshTexcoordDistortionFilename, &distortionMeshRows, &distortionMeshColumns); 354 else readMeshDimensionsFromCSVFile(_meshVortexDistortionFilename, &distortionMeshRows, &distortionMeshColumns); 355 356 distortionSet->setDistortionMeshRows(distortionMeshRows); 357 distortionSet->setDistortionMeshColumns(distortionMeshColumns); 358 359 360 361 osg::Vec2Array* distortionMeshVec2 = new osg::Vec2Array; 362 osg::Vec3Array* distortionMeshVec3 = new osg::Vec3Array; 363 364 if(_switchDistortionTypeVortexToTexcoords) 365 { 366 readMeshPointsFromCSVFile(_meshTexcoordDistortionFilename, distortionMeshVec2, distortionMeshVec3, width, height); 367 distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray(0,distortionMeshVec2); 368 } 369 else 370 { 371 readMeshPointsFromCSVFile(_meshVortexDistortionFilename, distortionMeshVec2, distortionMeshVec3, width, height); 372 distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setVertexArray(distortionMeshVec3); 373 374 } 375 376 } 377 378 _distortionInitialized=true; 379 380 381 } 382 383 } -
experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.h
r372 r376 19 19 #pragma once 20 20 21 #include " distortionsetupstrategy.h"21 #include "DistortionSetupStrategy.h" 22 22 23 24 /** 25 * \brief "Project Syntropy" Setup Strategy reads setup files of http://www.project-syntropy.de/ and configures the distortion accordingly. 26 * 27 * @author Torben Dannhauer 28 * @date Jun 2012 29 */ 23 30 class DistortionSetupStrategyProjectSyntropy : 24 31 public DistortionSetupStrategy … … 28 35 ~DistortionSetupStrategyProjectSyntropy(); 29 36 void delegateDistortionSetup(osgViewer::DistortionSet* distortionSet); 37 void setDistortionInputFiles( std::string distortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type); 38 private: 39 //Functions related to CSV-File-Reading 40 int readFrustumFromCSVFile(std::string filePath, int numValues, float* frustumValues); 41 int readMeshDimensionsFromCSVFile(std::string filePath, int* meshRows, int* meshColumns); 42 int readMeshPointsFromCSVFile(std::string filePath, osg::Vec2Array* meshPointsVec2, osg::Vec3Array* meshPointsVec3); 43 int readMeshPointsFromCSVFile(std::string filePath, osg::Vec2Array* meshPointsVec2, osg::Vec3Array* meshPointsVec3, int displayWidth, int displayHeight); 44 45 bool _distortionInitialized; //Is Distortion already initialized? 46 bool _switchDistortionTypeVortexToTexcoords; //Indicates if Texcoord- (true) or Vortexdistortion (false) is selected 47 48 //Paths of Blending/Warping related Files 49 std::string _intensityMapFilename; 50 51 std::string _frustumVortexDistortionFilename; 52 std::string _frustumTexcoordDistortionFilename; 53 54 std::string _meshVortexDistortionFilename; 55 std::string _meshTexcoordDistortionFilename; 30 56 }; -
experimental/distortionNG/main.cpp
r374 r376 94 94 // Add the distortion manipulator 95 95 osgViewer::DistortionManipulator* distortionManip = new osgViewer::DistortionManipulator(_distortionSet); 96 distortionManip->setDistortionSetupStrategy( new DistortionSetupStrategyProjectSyntropy() ); 96 97 DistortionSetupStrategyProjectSyntropy* psStrategy = new DistortionSetupStrategyProjectSyntropy(); 98 psStrategy->setDistortionInputFiles( "./resources/ProjectSyntropy/Vertices/warpmap_1.csv", 99 "./resources/ProjectSyntropy/blending_1.bmp", 100 "./resources/ProjectSyntropy/Vertices/frustum_1.csv", 101 DistortionSetupStrategy::VERTEXDISTORTION ); 102 distortionManip->setDistortionSetupStrategy( psStrategy ); 97 103 viewer.addEventHandler(distortionManip); 98 104
Note: See TracChangeset
for help on using the changeset viewer.