Changeset 361 for experimental/distortionNG
- Timestamp:
- Apr 22, 2012, 4:51:35 PM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/DistortionManipulator.cpp
r358 r361 23 23 #include <osg/PolygonMode> 24 24 25 #include <osgDB/Registry> 26 #include <osgDB/ReaderWriter> 27 #include <osgDB/WriteFile> 28 25 29 using namespace osg; 26 30 using namespace osgViewer; … … 42 46 _camera = 0; 43 47 //_distortionMesh(distortionMesh) 48 49 // Create Shader to vizualize intensitymap during blending setup. 50 osg::Shader* sh = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shaderIntensityMapVis.frag" ); 51 sh->setName("shaderIntensityMapVis"); 52 ds->setShaderIntensityMapVis( sh ); 44 53 } 45 54 … … 96 105 { 97 106 OSG_ALWAYS<<"mouse click!"<<std::endl; 98 if ( activeSetupMode == MANUAL /*&& ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL*/ && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )107 if ( activeSetupMode == MANUAL /*&& ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL*/ && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) 99 108 { 100 109 osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa); … … 210 219 { 211 220 OSG_ALWAYS<<"KEY_KP_8 : todo: Save DistortionContainer"<<std::endl; 221 222 223 224 // Configure Compression and instantiate read/write-options 225 bool asAscii_ = true; 226 bool compressionEnabled = false; 227 228 std::string readOptionString = ""; 229 std::string writeOptionString = ""; 230 if(asAscii_) 231 { 232 readOptionString = "Ascii"; 233 writeOptionString = "Ascii"; 234 } 235 if (compressionEnabled) 236 writeOptionString+=" Compressor=zlib"; 237 238 osg::ref_ptr<osgDB::Options> readOptions = new osgDB::Options( readOptionString.c_str() ); 239 osg::ref_ptr<osgDB::Options> writeOptions = new osgDB::Options( writeOptionString.c_str() ); 240 241 //// Get ReaderWriter 242 //osg::ref_ptr<osgDB::ReaderWriter> rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb"); 243 244 //// Writing node to stream 245 //std::stringstream myOstream; 246 //if ( rw ) 247 //{ 248 // osgDB::ReaderWriter::WriteResult wr = rw->writeObject( *_distortionSet, myOstream, writeOptions ); 249 // if (wr.success() ) 250 // { 251 // OSG_ALWAYS<<"write node success"<<std::endl; 252 // } 253 // else 254 // { 255 // OSG_ALWAYS<<"write node failed"<<std::endl; 256 // } 257 //} 258 259 if( osgDB::writeObjectFile(*_distortionSet, "test.osgt", writeOptions) ) 260 { 261 OSG_ALWAYS<<"write node success"<<std::endl; 262 } 263 else 264 { 265 OSG_ALWAYS<<"write node failed"<<std::endl; 266 } 267 268 269 270 271 272 273 274 275 276 277 278 279 212 280 return(true); 213 281 } … … 277 345 { 278 346 polyModeObj = new osg::PolygonMode; 279 stateset->setAttribute(polyModeObj );347 stateset->setAttribute(polyModeObj, osg::StateAttribute::PROTECTED|osg::StateAttribute::ON); 280 348 } 281 349 … … 289 357 void DistortionManipulator::showIntensityMap(bool show) 290 358 { 291 OSG_ALWAYS<<"ToDo: showIntensityMap(bool) is now "<<show<<std::endl; 292 293 if(_distortionSet.valid()) 294 _distortionSet->setShowIntensityMapOnly(show); 359 if(_distortionSet.valid()) 360 { 361 osg::StateSet* stateset = _distortionSet->getDistortionInternals()->getChild(DistortionSet::MESH)->getOrCreateStateSet(); 362 osg::Program* program = static_cast<osg::Program*>(stateset->getAttribute(::osg::StateAttribute::PROGRAM)); 363 364 if(show) 365 { 366 program->removeShader( _distortionSet->getShaderIntensityMap() ); 367 program->addShader( _distortionSet->getShaderIntensityMapVis() ); 368 } 369 else 370 { 371 program->removeShader( _distortionSet->getShaderIntensityMapVis() ); 372 program->addShader( _distortionSet->getShaderIntensityMap() ); 373 } 374 } 295 375 } 296 376 -
experimental/distortionNG/DistortionSet.cpp
r360 r361 41 41 42 42 _distortionInternals = new osg::Switch(); 43 43 44 } 44 45 -
experimental/distortionNG/DistortionSet.h
r360 r361 61 61 osg::Switch* getDistortionInternals() { return _distortionInternals; } 62 62 63 63 osg::Shader* getShaderIntensityMap() { return shaderIntensityMap; } 64 void setShaderIntensityMap(osg::Shader* shader) { shaderIntensityMap = shader; } 65 osg::Shader* getShaderIntensityMapVis() { return shaderIntensityMapVis; } 66 void setShaderIntensityMapVis(osg::Shader* shader) { shaderIntensityMapVis = shader; } 64 67 65 68 … … 113 116 osg::observer_ptr<osg::Camera> _camera; // is used to pass the distortion cam from osgViewers setupDistortion() method to the manipulator. 114 117 osg::ref_ptr<osg::Switch> _distortionInternals; // definition: child #0 = mesh, #1 = highlighter, #2 HUD 118 119 osg::ref_ptr<osg::Shader> shaderIntensityMap; // used in 99%, it provides active intensity map blending 120 osg::ref_ptr<osg::Shader> shaderIntensityMapVis; // only used during setup process, this shaders discards the fragment color and only displays the intensitymapcolor to visualize the blendmap 115 121 }; 116 122 -
experimental/distortionNG/distortionNG.vcproj
r355 r361 375 375 </Filter> 376 376 <File 377 RelativePath=".\shader .frag"377 RelativePath=".\shaderIntensityMap.frag" 378 378 > 379 379 </File> 380 380 <File 381 RelativePath=".\shader .vert"381 RelativePath=".\shaderIntensityMapVis.frag" 382 382 > 383 383 </File> -
experimental/distortionNG/extViewer.cpp
r360 r361 41 41 // Add help for command-line options here 42 42 arguments.getApplicationUsage()->addCommandLineOption("--distort","load distortion file and set up geometrical distortion for viewer. This includes blending"); 43 arguments.getApplicationUsage()->addCommandLineOption("--blend","Set up viewer vor simple blending CullDrawThreadPerContext threading model for viewer."); 44 45 osgDB::Registry::instance()->addFileExtensionAlias("dist", "osgt"); 43 arguments.getApplicationUsage()->addCommandLineOption("--blend","Set up viewer for simple intensity map blending."); 44 45 std::string distortionSetFilename = ""; 46 std::string intensityMapFilename = ""; 47 while( arguments.read("--blend",intensityMapFilename) ) {} 48 while( arguments.read("--distort",distortionSetFilename) ) {} 49 50 if( !intensityMapFilename.empty() ) 51 { 52 OSG_ALWAYS<<"Pure blendmap setup with : "<<intensityMapFilename<<std::endl; 53 setUpIntensityMapBlending(intensityMapFilename); 54 } 55 else if( !distortionSetFilename.empty() ) 56 { 57 OSG_ALWAYS<<"Set up distortion by loaded distortionSet: "<<distortionSetFilename<<std::endl; 58 59 osg::Object* distSet = osgDB::readObjectFile( distortionSetFilename ); 60 if( distSet != NULL ) 61 { 62 OSG_ALWAYS<<"read distortionSet success"<<std::endl; 63 setUpViewForManualDistortion(static_cast<osgViewer::DistortionSet*>(distSet)); 64 } 65 else 66 { 67 OSG_ALWAYS<<"read distortionSet failed"<<std::endl; 68 } 69 } 70 46 71 } 47 72 … … 236 261 237 262 addSlave(camera.get(), _distortionSet->getProjectionOffset(), _distortionSet->getViewOffset() ); 263 238 264 } 239 265 … … 332 358 stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitIntensityMap(), intensityMapTexture, osg::StateAttribute::ON); 333 359 334 // create shader sfor blending360 // create shader for blending 335 361 osg::Program* IntensityMapProgram = new osg::Program; 336 362 IntensityMapProgram->setName( "intensityMapBlending" ); 337 osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" ); 338 fShader->setName("intensityMapFragShader"); 339 340 if ( fShader ) 341 { 342 IntensityMapProgram->addShader( fShader ); 363 osg::Shader* shaderIntensityMap = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shaderIntensityMap.frag" ); 364 shaderIntensityMap->setName("shaderIntensityMap"); 365 _distortionSet->setShaderIntensityMap( shaderIntensityMap ); 366 367 if ( shaderIntensityMap ) 368 { 369 IntensityMapProgram->addShader( shaderIntensityMap ); 343 370 stateset->addUniform( new osg::Uniform("sceneTexture", (int)_distortionSet->getTexUnitScene()) ); 344 371 stateset->addUniform( new osg::Uniform("intensityMapTexture", (int)_distortionSet->getTexUnitIntensityMap()) ); -
experimental/distortionNG/main.cpp
r360 r361 56 56 viewer.setUpViewForManualDistortion(_distortionSet, 0); 57 57 58 //viewer.setUpIntensityMapBlending("intensitymap.png");59 58 60 59 // set up the camera manipulators. … … 88 87 // add the state manipulator 89 88 viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 90 89 //viewer.addEventHandler( new osgGA::StateSetManipulator); 90 91 91 // add the stats handler 92 92 viewer.addEventHandler(new osgViewer::StatsHandler); … … 118 118 if(!rootnode) 119 119 { 120 osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;120 OSG_WARN<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; 121 121 return 1; 122 122 } 123 123 } 124 viewer.setSceneData( rootnode ); 125 124 126 125 // run the viewers main loop 127 126 return viewer.run(); … … 150 149 * modul Funktionen / Description 151 150 * 152 * [postponed] plugin .dist load / Save distContainers loads and saves via serializers the distortion container from/to file. Can potentially be replaced by a simple extension alias to osgt|b|x153 * 151 * [postponed] plugin .dist load / Save distContainers loads and saves via serializers the distortion container from/to file. 152 * 154 153 * 155 154 * [done] Distortion Container Beinhaltet die folgenden Distortion Details: … … 174 173 * distortionManipulator abgeleitet von osgGA::GUIEventHandler 175 174 * Grundfunktionen: 176 * [done |.|.]- Key to Show Distortion Mesh / Intensity Map / none175 * [done] - Key to Show Distortion Mesh / Intensity Map / none 177 176 * - Key to Save distortion Container - via plugin 178 177 * [.] - Key to toggle MANUAL mode between blending und distortion setup … … 199 198 * speichern des containers in ein .dist file 200 199 * Laden des Containers. 201 * osgviewer setup fit machen: simple distortion ( nur rows, colums und optional blendmap ist angegeben202 * shaderwechsel funktioniert, so dass die reine blendmap angezeigt werden kann.203 200 * reset distortion funktioniert. 204 201 * statesetmanipulator muss auf die scene, nicht auf mesh losgehen.
Note: See TracChangeset
for help on using the changeset viewer.