Ignore:
Timestamp:
Apr 22, 2012, 4:51:35 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
6 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
  • experimental/distortionNG/DistortionSet.cpp

    r360 r361  
    4141
    4242        _distortionInternals = new osg::Switch();
     43
    4344}
    4445
  • experimental/distortionNG/DistortionSet.h

    r360 r361  
    6161        osg::Switch* getDistortionInternals()   { return _distortionInternals; }
    6262
    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; }
    6467
    6568
     
    113116        osg::observer_ptr<osg::Camera> _camera; // is used to pass the distortion cam from osgViewers setupDistortion() method to the manipulator.
    114117        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
    115121};
    116122
  • experimental/distortionNG/distortionNG.vcproj

    r355 r361  
    375375                </Filter>
    376376                <File
    377                         RelativePath=".\shader.frag"
     377                        RelativePath=".\shaderIntensityMap.frag"
    378378                        >
    379379                </File>
    380380                <File
    381                         RelativePath=".\shader.vert"
     381                        RelativePath=".\shaderIntensityMapVis.frag"
    382382                        >
    383383                </File>
  • experimental/distortionNG/extViewer.cpp

    r360 r361  
    4141        // Add help for command-line options here
    4242    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       
    4671}
    4772
     
    236261
    237262        addSlave(camera.get(), _distortionSet->getProjectionOffset(), _distortionSet->getViewOffset() );
     263
    238264    }
    239265
     
    332358    stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitIntensityMap(), intensityMapTexture, osg::StateAttribute::ON);
    333359
    334         // create shaders for blending
     360        // create shader for blending
    335361        osg::Program* IntensityMapProgram = new osg::Program;
    336362        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 );
    343370                stateset->addUniform( new osg::Uniform("sceneTexture", (int)_distortionSet->getTexUnitScene()) );
    344371                stateset->addUniform( new osg::Uniform("intensityMapTexture", (int)_distortionSet->getTexUnitIntensityMap()) );
  • experimental/distortionNG/main.cpp

    r360 r361  
    5656        viewer.setUpViewForManualDistortion(_distortionSet, 0);
    5757   
    58         //viewer.setUpIntensityMapBlending("intensitymap.png");
    5958
    6059        // set up the camera manipulators.
     
    8887    // add the state manipulator
    8988    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
    90 
     89        //viewer.addEventHandler( new osgGA::StateSetManipulator);
     90       
    9191    // add the stats handler
    9292    viewer.addEventHandler(new osgViewer::StatsHandler);
     
    118118                if(!rootnode)
    119119                {
    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;
    121121                        return 1;
    122122                }
    123123    }
    124         viewer.setSceneData( rootnode );
    125        
     124
    126125        // run the viewers main loop
    127126        return viewer.run();
     
    150149 * modul                                                                Funktionen / Description
    151150 *
    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|x
    153  *
     151 * [postponed] plugin .dist                             load / Save distContainers                                      loads and saves via serializers the distortion container from/to file.
     152 *  
    154153 *
    155154 * [done] Distortion Container                                  Beinhaltet die folgenden Distortion Details:
     
    174173 * distortionManipulator                                abgeleitet von osgGA::GUIEventHandler
    175174 *                                                                              Grundfunktionen:
    176  *                                                      [done|.|.]      - Key to Show Distortion Mesh / Intensity Map / none
     175 *                                                      [done        - Key to Show Distortion Mesh / Intensity Map / none
    177176 *                                                                              - Key to Save distortion Container  - via plugin
    178177 *                                                      [.]             - Key to toggle MANUAL mode between blending und distortion setup
     
    199198 * speichern des containers in ein .dist file
    200199 * Laden des Containers.
    201  * osgviewer setup fit machen: simple distortion ( nur rows, colums und optional blendmap ist angegeben
    202  * shaderwechsel funktioniert, so dass die reine blendmap angezeigt werden kann.
    203200 * reset distortion funktioniert.
    204201 * statesetmanipulator muss auf die scene, nicht auf mesh losgehen.
Note: See TracChangeset for help on using the changeset viewer.