Changeset 349


Ignore:
Timestamp:
Apr 21, 2012, 1:33:14 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r348 r349  
    3131        activeManualSetupMode = DISTORTION;
    3232        activeVisualizationMode = NONE;
     33
     34        _distortionSet = NULL;
    3335}
    3436
     
    5052bool DistortionManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv)
    5153{
    52         osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa);
    53                 if ( viewer )
    54                 {
    55                         //osg::notify(osg::ALWAYS)<<"viewer!"<<std::endl;
    56                 }
     54        //osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa);
     55        //if ( viewer && !_distortionSet.isValid())
     56        //{
     57        //      OSG_ALWAYS<<"Fetching valid DistortionSet!"<<std::endl;
     58        //      _distortionSet = viewer->getDistortionSet();
     59        //}
    5760
    5861        switch(ea.getEventType())
     
    6164        case(osgGA::GUIEventAdapter::DRAG):
    6265                {
    63                         osg::notify(osg::ALWAYS)<<"DRAG!"<<std::endl;
     66                        OSG_ALWAYS<<"DRAG!"<<std::endl;
    6467                        break;
    6568                }
     
    6871                        if(ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
    6972                        {
    70                                 osg::notify(osg::ALWAYS)<<"mouse click left!"<<std::endl;
     73                                OSG_ALWAYS<<"mouse click left!"<<std::endl;
    7174                        }
    7275                        break;
     
    9497                                }
    9598
    96                                 osg::notify(osg::ALWAYS)<<"KEY_KP_4 : Setup Mode now "<<activeSetupMode<<std::endl;
     99                                OSG_ALWAYS<<"KEY_KP_4 : Setup Mode now "<<activeSetupMode<<std::endl;
    97100                                return(true);
    98101                        }
     
    101104
    102105                                activeManualSetupMode = (activeManualSetupMode==DISTORTION?BLENDING:DISTORTION);
    103                                 osg::notify(osg::ALWAYS)<<"KEY_KP_5 : activeManualSetupMode is now "<<activeManualSetupMode<<std::endl;
     106                                OSG_ALWAYS<<"KEY_KP_5 : activeManualSetupMode is now "<<activeManualSetupMode<<std::endl;
    104107                                return(true);
    105108                        }
     
    107110                        {
    108111                                activeDistortionMode = (activeDistortionMode==MESH?TEXCOORDINATES:MESH);
    109                                 osg::notify(osg::ALWAYS)<<"KEY_KP_6 : activeDistortionMode is now "<<activeDistortionMode<<std::endl;
     112                                OSG_ALWAYS<<"KEY_KP_6 : activeDistortionMode is now "<<activeDistortionMode<<std::endl;
    110113                                return(true);
    111114                        }
     
    114117                                switch(activeVisualizationMode)
    115118                                {       
    116                                         case DISTORTION_MESH : activeVisualizationMode = INTENSITY_MAP; break;
    117                                         case INTENSITY_MAP : activeVisualizationMode = NONE; break;
    118                                         case NONE : activeVisualizationMode = DISTORTION_MESH; break;
     119                                        case DISTORTION_MESH :
     120                                        {
     121                                                activeVisualizationMode = INTENSITY_MAP;
     122                                                showDistortionMesh(true);
     123                                                showIntensityMap(false);
     124                                                break;
     125                                        }
     126                                        case INTENSITY_MAP :
     127                                        {
     128                                                activeVisualizationMode = NONE;
     129                                                showDistortionMesh(false);
     130                                                showIntensityMap(true);
     131                                                break;
     132                                        }
     133                                        case NONE :
     134                                        {
     135                                                activeVisualizationMode = DISTORTION_MESH;
     136                                                showDistortionMesh(false);
     137                                                showIntensityMap(false);
     138                                                break;
     139                                        }
    119140                                }
    120                                 osg::notify(osg::ALWAYS)<<"KEY_KP_7 : activeVisualizationMode is now "<<activeVisualizationMode<<std::endl;
     141
     142
     143                                OSG_ALWAYS<<"KEY_KP_7 : activeVisualizationMode is now "<<activeVisualizationMode<<std::endl;
    121144                                return(true);
    122145                        }
    123146                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Up)     // KP 8: Save distortion set     via plugin
    124147                        {
    125                                 osg::notify(osg::ALWAYS)<<"KEY_KP_8 : todo: Save DistortionContainer"<<std::endl;
     148                                OSG_ALWAYS<<"KEY_KP_8 : todo: Save DistortionContainer"<<std::endl;
    126149                                return(true);
    127150                        }
     
    133156                case(osgGA::GUIEventAdapter::FRAME):
    134157                {
    135                         //osg::notify(osg::ALWAYS)<<"FRAME!"<<std::endl;
     158                        //OSG_ALWAYS<<"FRAME!"<<std::endl;
    136159                        break;
    137160                }
    138161        case (osgGA::GUIEventAdapter::RESIZE):  // todo: adapt distortion mesh to new screen size
    139162                {
    140                         osg::notify(osg::ALWAYS)<<"RESIZE!"<<std::endl;
     163                        OSG_ALWAYS<<"RESIZE!"<<std::endl;
    141164                        break;
    142165                }
     
    150173void DistortionManipulator::resetIntensityMap()
    151174{
    152         osg::notify(osg::ALWAYS)<<"ToDo: resetIntensityMap()"<<std::endl;
     175        if(!_distortionSet.valid())
     176                return;
     177
     178        osg::ref_ptr<osg::Image> image = _distortionSet->getIntensityMap();
     179
     180        OSG_ALWAYS<<"Reseting IntensityMap Blending."<<std::endl;
     181
     182        if (!image->isDataContiguous())
     183        {
     184                OSG_WARN<<"Warning: DistortionManipulator does not support working with non contiguous imagery as blendmaps!"<<std::endl;
     185                return;
     186        }
     187
     188        // Fill intensity map with 255
     189        unsigned char* dataPtr = image->data();
     190        for(unsigned int i=0;i<image->getTotalSizeInBytes();i++)
     191        {
     192                *dataPtr++ = 255;
     193        }
     194        image->dirty();
    153195}
    154196
    155197void DistortionManipulator::resetDistortion()
    156198{
    157         osg::notify(osg::ALWAYS)<<"ToDo: resetDistortion()"<<std::endl;
    158 }
     199        if(!_distortionSet.valid())
     200                return;
     201
     202        OSG_ALWAYS<<"ToDo: resetDistortion()"<<std::endl;
     203}
     204
     205void DistortionManipulator::showDistortionMesh(bool show)
     206{
     207        OSG_ALWAYS<<"ToDo: showDistortionMesh(bool) is now "<<show<<std::endl;
     208
     209        // Todo: Stateset muss das von der MeshGeode sein.
     210
     211   /* osg::PolygonMode* polyModeObj = dynamic_cast<osg::PolygonMode*>(_stateset->getAttribute(osg::StateAttribute::POLYGONMODE));
     212    if (!polyModeObj)
     213    {
     214        polyModeObj = new osg::PolygonMode;
     215        _stateset->setAttribute(polyModeObj);
     216    }
     217 
     218        if(show)
     219                polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
     220        else
     221                polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::FILL);*/
     222}
     223
     224void DistortionManipulator::showIntensityMap(bool show)
     225{
     226                OSG_ALWAYS<<"ToDo: showIntensityMap(bool) is now "<<show<<std::endl;
     227}
  • experimental/distortionNG/DistortionManipulator.h

    r348 r349  
    2020#define OSGGA_DISTORTION_MANIPULATOR 1
    2121
    22 #include<osgGA/GUIEventHandler>
     22#include <osgGA/GUIEventHandler>
     23#include<osg/Referenced>
     24#include "DistortionSet.h"
    2325
    2426
     
    5456    virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv);
    5557
     58        void setDistortionSet(DistortionSet* ds) {_distortionSet = ds;}
     59
    5660private:
    5761        void resetIntensityMap();
    5862        void resetDistortion();
     63        void showDistortionMesh(bool show);
     64        void showIntensityMap(bool show);
    5965
    6066        SetupMode activeSetupMode;
     
    6268        ManualSetupMode activeManualSetupMode;
    6369        VisualizationMode activeVisualizationMode;
     70
     71        osg::ref_ptr<DistortionSet> _distortionSet;
    6472};
    6573
  • experimental/distortionNG/DistortionSet.h

    r345 r349  
    5252
    5353        void setIntensityMap(osg::Image* intensityMap)          { _intensityMap = intensityMap; }
    54         const osg::Image* getIntensityMap() const       { return _intensityMap; }
     54        const osg::Image* getIntensityMap() const       { return _intensityMap; }       // for serializers
     55        osg::Image* getIntensityMap()  { return _intensityMap; }        // for manipulating the intensity map
    5556
    5657        void setTexUnitScene(unsigned int texUnitScene)         { _texUnitScene = texUnitScene; }
  • experimental/distortionNG/extViewer.cpp

    r346 r349  
    347347                camera->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
    348348
     349                // Create DistortionSet
     350                _distortionSet = new osgViewer::DistortionSet();
     351                _distortionSet->setIntensityMap( intensityMap );
     352
     353
    349354                // Add the distortionHandler
    350                 addEventHandler(new osgViewer::DistortionManipulator);
     355                osgViewer::DistortionManipulator* distManip = new osgViewer::DistortionManipulator();
     356                distManip->setDistortionSet(_distortionSet);
     357                addEventHandler(distManip);
    351358
    352359
  • experimental/distortionNG/extViewer.h

    r346 r349  
    1919*/
    2020
     21#include <osgViewer/Viewer>
     22#include<osg/Referenced>
     23#include "DistortionSet.h"
    2124
    22 #include<osgViewer/Viewer>
    2325
    2426class extViewer : public osgViewer::Viewer
     
    3739
    3840                void setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum=0, int rttSceneTextureUnit=0, int intensityMapTextureUnit=1);
     41
     42                osgViewer::DistortionSet* getDistortionSet()    {return _distortionSet;}
     43                void setDistortionSet(osgViewer::DistortionSet* ds) {_distortionSet = ds;}
     44
     45private:
     46                osg::ref_ptr<osgViewer::DistortionSet> _distortionSet;
    3947};
  • experimental/distortionNG/main.cpp

    r348 r349  
    174174 *                                                      [done]          - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates.
    175175 *                                                                              - Key to reset Distortion.
    176  *                                                                              - Key to reset Blending.
     176 *                                                      [done]          - Key to reset Blending.
    177177 *                                                                             
    178178 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
Note: See TracChangeset for help on using the changeset viewer.