Changeset 350


Ignore:
Timestamp:
Apr 21, 2012, 4:53:52 PM (7 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r349 r350  
    141141
    142142
    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;
    144144                                return(true);
    145145                        }
     
    225225{
    226226                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  
    2424DistortionSet::DistortionSet()
    2525{
     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;
    2638}
    2739
     
    4961        ADD_MATRIX_SERIALIZER( ViewOffset, osg::Matrix() );     //osg::Matrix _viewOffset;
    5062        ADD_MATRIX_SERIALIZER( ProjectionOffset, osg::Matrix() );       //osg::Matrix _projectionOffset;
     63
     64        ADD_BOOL_SERIALIZER( ShowIntensityMapOnly, false );     //bool _showIntesityMapMapOnly
    5165}
  • experimental/distortionNG/DistortionSet.h

    r349 r350  
    3737                _texUnitIntensityMap(ds._texUnitIntensityMap),
    3838                _viewOffset(ds._viewOffset),
    39                 _projectionOffset(ds._projectionOffset){}
     39                _projectionOffset(ds._projectionOffset),
     40                _showIntesityMapMapOnly(ds._showIntesityMapMapOnly){}
    4041
    4142        DistortionSet();
    4243        virtual ~DistortionSet();
    4344
     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
    4452        void setDistortionMeshRows(int distortionMeshRows)              { _distortionMeshRows = distortionMeshRows; }
    4553        int getDistortionMeshRows() const       { return _distortionMeshRows; }
     
    5260
    5361        void setIntensityMap(osg::Image* intensityMap)          { _intensityMap = intensityMap; }
    54         const osg::Image* getIntensityMap() const       { return _intensityMap; }       // for serializers
    55         osg::Image* getIntensityMap()  { return _intensityMap; }        // for manipulating the intensity map
     62        const osg::Image* getIntensityMap() const       { return _intensityMap; }
     63
    5664
    5765        void setTexUnitScene(unsigned int texUnitScene)         { _texUnitScene = texUnitScene; }
     
    6775        const osg::Matrixd& getProjectionOffset() const { return _projectionOffset; }
    6876
     77        void setShowIntensityMapOnly(bool show) {_showIntesityMapMapOnly = show;}
     78        bool getShowIntensityMapOnly() const    { return _showIntesityMapMapOnly;}
     79
     80
    6981private:
    7082        int _distortionMeshRows;
     
    7991        osg::Matrixd _projectionOffset;
    8092
    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.
    8294};
    8395
  • experimental/distortionNG/extViewer.cpp

    r349 r350  
    5757}
    5858
    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 file
    65 //        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 file
    89 //        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 
    10759static 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)
    10860{
     
    199151}
    200152
     153
    201154void extViewer::setUpViewForManualDistortion(unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix)
    202155{
    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
    204166
    205167    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
     
    233195    traits->sharedContext = 0;
    234196
    235         bool applyIntensityMapAsColours = false;
    236 
    237197        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
    238198    if (!gc)
     
    302262        // StateSet to contain the Texture StateAttribute.
    303263            osg::StateSet* stateset = geode->getOrCreateStateSet();
    304         stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON);
     264        stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitScene(), sceneTexture,osg::StateAttribute::ON);
    305265        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    306266
     
    309269        stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
    310270
    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);
    316274                geode->addDrawable(distortionMesh);
    317275
     
    347305                camera->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
    348306
    349                 // Create DistortionSet
    350                 _distortionSet = new osgViewer::DistortionSet();
    351                 _distortionSet->setIntensityMap( intensityMap );
    352 
    353 
    354307                // Add the distortionHandler
    355308                osgViewer::DistortionManipulator* distManip = new osgViewer::DistortionManipulator();
     
    364317}
    365318
    366 void extViewer::setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
    367 {
    368         if(stateset == NULL || intensityMap == NULL)
     319void 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)
    369325        {
    370326                OSG_NOTICE<<"Error, no intensityMap or stateset for intensityMapBlending specified."<<std::endl;
     
    400356        intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
    401357
    402     stateset->setTextureAttributeAndModes(intensityMapTextureUnit, intensityMapTexture, osg::StateAttribute::ON);
     358    stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitIntensityMap(), intensityMapTexture, osg::StateAttribute::ON);
    403359
    404360        // create shaders for blending
     
    411367        {
    412368                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 ) );
    415373                stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON);
    416374        }
    417375}
     376
     377void 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  
    2323#include "DistortionSet.h"
    2424
     25#include <string>
    2526
    2627class extViewer : public osgViewer::Viewer
     
    3839        void setUpViewForManualDistortion(unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
    3940
    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);
    4143
    4244                osgViewer::DistortionSet* getDistortionSet()    {return _distortionSet;}
  • experimental/distortionNG/main.cpp

    r349 r350  
    136136 * Layout vom Distortion System
    137137 *
    138  * Das distortion systme unterstüzt verzerrungen ,die pro kanal auhc 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 das Camera 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)
    140140 *
    141141 *
     
    156156 *                                                                             
    157157 *                                                                              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.
    159160 *
    160161 * osgViewer                                                    load and apply distortion (apply via setupDistortion(...)
Note: See TracChangeset for help on using the changeset viewer.