Ignore:
Timestamp:
Apr 22, 2012, 4:51:35 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r358 r361  
    2323#include <osg/PolygonMode>
    2424
     25#include <osgDB/Registry>
     26#include <osgDB/ReaderWriter>
     27#include <osgDB/WriteFile>
     28
    2529using namespace osg;
    2630using namespace osgViewer;
     
    4246        _camera = 0;
    4347        //_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 );
    4453}
    4554
     
    96105                {
    97106                        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 )
    99108                        {
    100109                                osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa);
     
    210219                        {
    211220                                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
    212280                                return(true);
    213281                        }
     
    277345    {
    278346        polyModeObj = new osg::PolygonMode;
    279         stateset->setAttribute(polyModeObj);
     347        stateset->setAttribute(polyModeObj, osg::StateAttribute::PROTECTED|osg::StateAttribute::ON);
    280348    }
    281349 
     
    289357void DistortionManipulator::showIntensityMap(bool show)
    290358{
    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        }
    295375}
    296376
Note: See TracChangeset for help on using the changeset viewer.