Changeset 361 for experimental/distortionNG/DistortionManipulator.cpp
- Timestamp:
- Apr 22, 2012, 4:51:35 PM (12 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.