Changeset 350
- Timestamp:
- Apr 21, 2012, 4:53:52 PM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/DistortionManipulator.cpp
r349 r350 141 141 142 142 143 OSG_ALWAYS<<"KEY_KP_7 : activeVisualizationMode is now "<<activeVisualizationMode<<std::endl ;143 OSG_ALWAYS<<"KEY_KP_7 : activeVisualizationMode is now "<<activeVisualizationMode<<std::endl<<std::endl; 144 144 return(true); 145 145 } … … 225 225 { 226 226 OSG_ALWAYS<<"ToDo: showIntensityMap(bool) is now "<<show<<std::endl; 227 } 227 228 if(_distortionSet.valid()) 229 _distortionSet->setShowIntensityMapOnly(show); 230 } -
experimental/distortionNG/DistortionSet.cpp
r345 r350 24 24 DistortionSet::DistortionSet() 25 25 { 26 _distortionMeshRows = 1; 27 _distortionMeshColumns = 1; 28 //GLenum _meshType; 29 30 _intensityMap = NULL; 31 _texUnitScene = 0; 32 _texUnitIntensityMap = 1; 33 34 _viewOffset = osg::Matrixd::identity(); 35 _projectionOffset = osg::Matrixd::identity(); 36 37 _showIntesityMapMapOnly = false; 26 38 } 27 39 … … 49 61 ADD_MATRIX_SERIALIZER( ViewOffset, osg::Matrix() ); //osg::Matrix _viewOffset; 50 62 ADD_MATRIX_SERIALIZER( ProjectionOffset, osg::Matrix() ); //osg::Matrix _projectionOffset; 63 64 ADD_BOOL_SERIALIZER( ShowIntensityMapOnly, false ); //bool _showIntesityMapMapOnly 51 65 } -
experimental/distortionNG/DistortionSet.h
r349 r350 37 37 _texUnitIntensityMap(ds._texUnitIntensityMap), 38 38 _viewOffset(ds._viewOffset), 39 _projectionOffset(ds._projectionOffset){} 39 _projectionOffset(ds._projectionOffset), 40 _showIntesityMapMapOnly(ds._showIntesityMapMapOnly){} 40 41 41 42 DistortionSet(); 42 43 virtual ~DistortionSet(); 43 44 45 // Working access 46 osg::Image* getIntensityMap() { return _intensityMap; } // Also for manipulating the intensity map 47 bool& getShowIntensityMapOnlyAsRef() { return _showIntesityMapMapOnly;} 48 49 50 51 // Serializer Access 44 52 void setDistortionMeshRows(int distortionMeshRows) { _distortionMeshRows = distortionMeshRows; } 45 53 int getDistortionMeshRows() const { return _distortionMeshRows; } … … 52 60 53 61 void setIntensityMap(osg::Image* intensityMap) { _intensityMap = intensityMap; } 54 const osg::Image* getIntensityMap() const { return _intensityMap; } // for serializers55 osg::Image* getIntensityMap() { return _intensityMap; } // for manipulating the intensity map 62 const osg::Image* getIntensityMap() const { return _intensityMap; } 63 56 64 57 65 void setTexUnitScene(unsigned int texUnitScene) { _texUnitScene = texUnitScene; } … … 67 75 const osg::Matrixd& getProjectionOffset() const { return _projectionOffset; } 68 76 77 void setShowIntensityMapOnly(bool show) {_showIntesityMapMapOnly = show;} 78 bool getShowIntensityMapOnly() const { return _showIntesityMapMapOnly;} 79 80 69 81 private: 70 82 int _distortionMeshRows; … … 79 91 osg::Matrixd _projectionOffset; 80 92 81 93 bool _showIntesityMapMapOnly; // Intensity Blending is done by a frag shader. To control it on runtime, the uniform must be bound to a central variable. 82 94 }; 83 95 -
experimental/distortionNG/extViewer.cpp
r349 r350 57 57 } 58 58 59 //static osg::Texture2D* loadTexture( const std::string& fileName )60 //{61 // std::string foundFileName = osgDB::findDataFile(fileName);62 // if (foundFileName.length() != 0 )63 // {64 // // load distortion map texture file65 // osg::Image* image = osgDB::readImageFile(foundFileName);66 // if (image)67 // {68 // osg::Texture2D* texture = new osg::Texture2D;69 // texture->setImage(image);70 // texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);71 // texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);72 // texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);73 // texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);74 // return texture;75 // }76 // }77 //78 // OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;79 //80 // return NULL;81 //}82 83 //static osg::TextureRectangle* loadTextureRect( const std::string& fileName )84 //{85 // std::string foundFileName = osgDB::findDataFile(fileName);86 // if (foundFileName.length() != 0 )87 // {88 // // load distortion map texture file89 // osg::Image* image = osgDB::readImageFile(foundFileName);90 // if (image)91 // {92 // osg::TextureRectangle* texture = new osg::TextureRectangle;93 // texture->setImage(image);94 // texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);95 // texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);96 // texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);97 // texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);98 // return texture;99 // }100 // }101 //102 // OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;103 //104 // return NULL;105 //}106 107 59 static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, osg::Image* intensityMap, bool applyIntensityMapAsColours, const osg::Matrix& projectorMatrix) 108 60 { … … 199 151 } 200 152 153 201 154 void extViewer::setUpViewForManualDistortion(unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix) 202 155 { 203 OSG_INFO<<"View::setUpViewForManualDistortion(sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl; 156 OSG_INFO<<"View::setUpViewForManualDistortion(sn="<<screenNum<<")"<<std::endl; 157 158 // Create DistortionSet 159 _distortionSet = new osgViewer::DistortionSet(); 160 _distortionSet->setIntensityMap( intensityMap ); 161 _distortionSet->setDistortionMeshRows( 20 ); 162 _distortionSet->setDistortionMeshColumns( 20 ); 163 164 165 204 166 205 167 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); … … 233 195 traits->sharedContext = 0; 234 196 235 bool applyIntensityMapAsColours = false;236 237 197 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 238 198 if (!gc) … … 302 262 // StateSet to contain the Texture StateAttribute. 303 263 osg::StateSet* stateset = geode->getOrCreateStateSet(); 304 stateset->setTextureAttributeAndModes( 0, sceneTexture,osg::StateAttribute::ON);264 stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitScene(), sceneTexture,osg::StateAttribute::ON); 305 265 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 306 266 … … 309 269 stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); 310 270 311 // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1 312 if (!applyIntensityMapAsColours && intensityMap) 313 setUpIntensityMapBlending(stateset, intensityMap, screenNum, 0, 1); 314 315 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, intensityMap, applyIntensityMapAsColours, projectorMatrix); 271 setUpIntensityMapBlending(_distortionSet, stateset, screenNum); 272 273 osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, _distortionSet->getIntensityMap(), false, projectorMatrix); 316 274 geode->addDrawable(distortionMesh); 317 275 … … 347 305 camera->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) ); 348 306 349 // Create DistortionSet350 _distortionSet = new osgViewer::DistortionSet();351 _distortionSet->setIntensityMap( intensityMap );352 353 354 307 // Add the distortionHandler 355 308 osgViewer::DistortionManipulator* distManip = new osgViewer::DistortionManipulator(); … … 364 317 } 365 318 366 void extViewer::setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit) 367 { 368 if(stateset == NULL || intensityMap == NULL) 319 void extViewer::setUpIntensityMapBlending(osgViewer::DistortionSet* distSet, osg::StateSet* stateset, unsigned int screenNum) 320 { 321 osg::Image* intensityMap = _distortionSet->getIntensityMap(); 322 if(intensityMap == NULL) return; 323 324 if(stateset == NULL) 369 325 { 370 326 OSG_NOTICE<<"Error, no intensityMap or stateset for intensityMapBlending specified."<<std::endl; … … 400 356 intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); 401 357 402 stateset->setTextureAttributeAndModes( intensityMapTextureUnit, intensityMapTexture, osg::StateAttribute::ON);358 stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitIntensityMap(), intensityMapTexture, osg::StateAttribute::ON); 403 359 404 360 // create shaders for blending … … 411 367 { 412 368 distortProgram->addShader( fShader ); 413 stateset->addUniform( new osg::Uniform("sceneTexture", rttSceneTextureUnit) ); 414 stateset->addUniform( new osg::Uniform("intensityMapTexture", intensityMapTextureUnit) ); 369 //stateset->addUniform( new osg::Uniform("sceneTexture", _distortionSet->getTexUnitScene()) ); 370 //stateset->addUniform( new osg::Uniform("intensityMapTexture", _distortionSet->getTexUnitIntensityMap()) ); 371 stateset->addUniform( new osg::Uniform("sceneTexture", 0 ) ); 372 stateset->addUniform( new osg::Uniform("intensityMapTexture", 1 ) ); 415 373 stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON); 416 374 } 417 375 } 376 377 void extViewer::setUpIntensityMapBlending(std::string intensityMap) 378 { 379 // Try to load intensityMap 380 osg::Image* intMap = osgDB::readImageFile(intensityMap); 381 if (!intMap) 382 { 383 osg::notify(osg::WARN) << "Quitting, couldn't find intensity map: " << intensityMap << std::endl; 384 return; 385 } 386 387 // Create DistortionSet 388 _distortionSet = new osgViewer::DistortionSet(); 389 _distortionSet->setIntensityMap( intMap ); 390 _distortionSet->setDistortionMeshRows( 1 ); 391 _distortionSet->setDistortionMeshColumns( 1 ); 392 _distortionSet->setTexUnitScene( 0 ); 393 _distortionSet->setTexUnitIntensityMap( 1 ); 394 395 // Todo: call setupDistortion/Blendung to perform the blending 396 } -
experimental/distortionNG/extViewer.h
r349 r350 23 23 #include "DistortionSet.h" 24 24 25 #include <string> 25 26 26 27 class extViewer : public osgViewer::Viewer … … 38 39 void setUpViewForManualDistortion(unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); 39 40 40 void setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum=0, int rttSceneTextureUnit=0, int intensityMapTextureUnit=1); 41 void setUpIntensityMapBlending(osgViewer::DistortionSet* distSet, osg::StateSet* stateset, unsigned int screenNum=0); 42 void setUpIntensityMapBlending(std::string intensityMap); 41 43 42 44 osgViewer::DistortionSet* getDistortionSet() {return _distortionSet;} -
experimental/distortionNG/main.cpp
r349 r350 136 136 * Layout vom Distortion System 137 137 * 138 * Das distortion systme unterstüzt verzerrungen ,die pro kanal auhcnur eine camera verwenden.139 * Verzerrungen, die das Bild je Kanal aus mehreren Cams zusammensetzen um Views>=180° zu erreichen werden nicht unterstützt da hierfür dasCamera Setup nötig wäre, welches nicht im distortion-Container gespeichert wird (Sonderfall, zu speziell für das Dist-Framework)138 * Das distortion System unterstützt Verzerrungen, die pro Kanal jeweils nur eine camera verwenden. 139 * Verzerrungen, die das Bild je Kanal aus mehreren Cams zusammensetzen um Views>=180° zu erreichen werden nicht unterstützt da hierfür ein Camera Setup nötig wäre, welches nicht im distortion-Container gespeichert wird (Sonderfall, zu speziell für das Dist-Framework) 140 140 * 141 141 * … … 156 156 * 157 157 * need to add setter/getter as well as the serializer macros. 158 * 158 * 159 * Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der COntainer vom Vierwer verwaltet werden. 159 160 * 160 161 * osgViewer load and apply distortion (apply via setupDistortion(...)
Note: See TracChangeset
for help on using the changeset viewer.