Changeset 356 for experimental


Ignore:
Timestamp:
Apr 21, 2012, 11:11:37 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r355 r356  
    3737       
    3838        createVertexHighlighter();
     39        createHUD();
    3940
    4041        _camera = 0;
     
    4849void DistortionManipulator::getUsage(osg::ApplicationUsage& usage) const
    4950{
    50     usage.addKeyboardMouseBinding("Keypad 7","Show distortion mesh / intensity map / none.");
    51         usage.addKeyboardMouseBinding("Keypad 8","Save distortion set.");       // via plugin
     51        usage.addKeyboardMouseBinding("Keypad 0","Show/Hide distortion HUD.");
     52        usage.addKeyboardMouseBinding("Keypad 1","Reset distortion.");
     53        usage.addKeyboardMouseBinding("Keypad 2","Reset intensity blending.");
    5254        usage.addKeyboardMouseBinding("Keypad 4","Toggles Setup Mode between DISABLED, MANUAL & DELEGATED.");
    5355        usage.addKeyboardMouseBinding("Keypad 5","MANUAL Mode: Toggle between blending & distortion setup.");
    54         usage.addKeyboardMouseBinding("Keypad 6","MANUAL Mode: Toggle if distortion drags affect mesh or rtt texture coordinates.");    // Defaults to Mesh
    55         usage.addKeyboardMouseBinding("Keypad 1","Reset distortion.");
    56         usage.addKeyboardMouseBinding("Keypad 2","Reset intensity blending.");
     56    usage.addKeyboardMouseBinding("Keypad 6","MANUAL Mode: Toggle if distortion drags affect mesh or rtt texture coordinates.");        // Defaults to Mesh
     57        usage.addKeyboardMouseBinding("Keypad 7","Show distortion mesh / intensity map / none.");
     58        usage.addKeyboardMouseBinding("Keypad 8","Save distortion set.");       // via plugin
    5759}
    5860
     
    8486                {
    8587                        OSG_ALWAYS<<"mouse click!"<<std::endl;
    86                         if ( activeSetupMode == MANUAL && ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
     88                        if ( activeSetupMode == MANUAL /*&& ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL*/ && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
    8789                        {
    8890                                osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa);
     
    107109        case(osgGA::GUIEventAdapter::KEYDOWN):
    108110                {
     111                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Insert) // KP 0: Show/Hide HUD   // definition: child #0 = mesh, #1 = highlighter, #2 HUD
     112                        {
     113                                bool oldValue = _distortionSet->getDistortionInternals()->getValue(2);
     114                                _distortionSet->getDistortionInternals()->setValue(2, !oldValue);
     115                                return(true);
     116                        }
    109117                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_End)    // KP 1: reset distortion
    110118                        {
     
    124132                                        {
    125133                                                activeSetupMode = MANUAL;
    126                                                 OSG_ALWAYS<<"SetupMode MANUAL activated"<<std::endl;
    127                                                 _distortionSet->getDistortionInternals()->setValue(1, true); // per definition #0 = mesh, #1 = highlighter
     134                                                OSG_NOTICE<<"SetupMode MANUAL activated"<<std::endl;
     135                                                _distortionSet->getDistortionInternals()->setValue(1, true); // definition: child #0 = mesh, #1 = highlighter, #2 HUD
    128136                                                break;
    129137                                        }
     
    131139                                        {
    132140                                                activeSetupMode = DELEGATED;
    133                                                 _distortionSet->getDistortionInternals()->setValue(1, false); // per definition #0 = mesh, #1 = highlighter
    134                                                 OSG_ALWAYS<<"SetupMode DELEGATED activated"<<std::endl;
     141                                                _distortionSet->getDistortionInternals()->setValue(1, false); // definition: child #0 = mesh, #1 = highlighter, #2 HUD
     142                                                OSG_NOTICE<<"SetupMode DELEGATED activated"<<std::endl;
    135143                                                break;
    136144                                        }
     
    138146                                        {
    139147                                                activeSetupMode = DISABLED;
    140                                                 _distortionSet->getDistortionInternals()->setValue(1, false); // per definition #0 = mesh, #1 = highlighter
    141                                                 OSG_ALWAYS<<"SetupMode DISABLED activated"<<std::endl;
     148                                                _distortionSet->getDistortionInternals()->setValue(1, false); // definition: child #0 = mesh, #1 = highlighter, #2 HUD
     149                                                OSG_NOTICE<<"SetupMode DISABLED activated"<<std::endl;
    142150                                                break;
    143151                                        }
    144152                                }
    145 
     153                                updateHUD();
    146154                                return(true);
    147155                        }
     
    150158
    151159                                activeManualSetupMode = (activeManualSetupMode==DISTORTION?BLENDING:DISTORTION);
    152                                 OSG_ALWAYS<<"KEY_KP_5 : activeManualSetupMode is now "<<activeManualSetupMode<<std::endl;
     160                                updateHUD();
    153161                                return(true);
    154162                        }
     
    156164                        {
    157165                                activeDistortionMode = (activeDistortionMode==MESH?TEXCOORDINATES:MESH);
    158                                 OSG_ALWAYS<<"KEY_KP_6 : activeDistortionMode is now "<<activeDistortionMode<<std::endl;
     166                                updateHUD();
    159167                                return(true);
    160168                        }
     
    186194                                }
    187195
    188 
    189                                 OSG_ALWAYS<<"KEY_KP_7 : activeVisualizationMode is now "<<activeVisualizationMode<<std::endl<<std::endl;
     196                                updateHUD();
    190197                                return(true);
    191198                        }
     
    196203                        }
    197204                       
    198 
    199205                        return false;   // Event ignored
    200206                }
     
    202208                case(osgGA::GUIEventAdapter::FRAME):
    203209                {
    204                         //OSG_ALWAYS<<"FRAME!"<<std::endl;
     210                        if ( activeSetupMode == DELEGATED)
     211                        {
     212                                OSG_ALWAYS<<"Todo: Calling delegated class!"<<std::endl;
     213                        }
    205214                        break;
    206215                }
     
    297306        geode->setCullingActive(false); // disable the culling for the selector, otherwise the selector is culled away on the edge.
    298307
    299         _distortionSet->getDistortionInternals()->addChild(geode, false);
     308        _distortionSet->getDistortionInternals()->addChild(geode, false);       //  = child #1  :definition: child #0 = mesh, #1 = highlighter, #2 HUD
     309}
     310
     311void DistortionManipulator::createHUD()
     312{
     313        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
     314       
     315        osg::StateSet* stateSet = geode->getOrCreateStateSet();
     316        stateSet->setRenderBinDetails( 99, "RenderBin");
     317        // disable depth test to ensure that it is always drawn.
     318        stateSet->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
     319        stateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
     320
     321        // Add Text:
     322        osg::Vec3 position(20.0f,120.0f,0.0f);
     323        osg::Vec3 delta(0.0f,-25.0f,0.0f);
     324        std::string timesFont("fonts/arial.ttf");
     325        {
     326                osg::ref_ptr<osgText::Text> textHeader = new osgText::Text;
     327                textHeader->setText("Distortion Setup:");
     328                textHeader->setFont(timesFont);
     329                textHeader->setPosition(position);
     330                textHeader->setCharacterSize(21);
     331                textHeader->setDataVariance(osg::Object::STATIC);
     332                geode->addDrawable( textHeader );
     333
     334                position += delta;
     335
     336                hudSetupMode = new osgText::Text;
     337                hudSetupMode->setFont(timesFont);
     338                hudSetupMode->setPosition(position);
     339                hudSetupMode->setCharacterSize(21);
     340                hudSetupMode->setDataVariance(osg::Object::DYNAMIC);
     341                geode->addDrawable( hudSetupMode );
     342
     343                position += delta;
     344
     345                hudDistortionMode = new osgText::Text;
     346                hudDistortionMode->setFont(timesFont);
     347                hudDistortionMode->setPosition(position);
     348                hudDistortionMode->setCharacterSize(21);
     349                hudDistortionMode->setDataVariance(osg::Object::DYNAMIC);
     350                geode->addDrawable( hudDistortionMode );
     351
     352                position += delta;
     353
     354                hudManualSetupMode = new osgText::Text;
     355                hudManualSetupMode->setFont(timesFont);
     356                hudManualSetupMode->setPosition(position);
     357                hudManualSetupMode->setCharacterSize(21);
     358                hudManualSetupMode->setDataVariance(osg::Object::DYNAMIC);
     359                geode->addDrawable( hudManualSetupMode );
     360
     361                position += delta;
     362
     363                hudVisualizationMode = new osgText::Text;
     364                hudVisualizationMode->setFont(timesFont);
     365                hudVisualizationMode->setPosition(position);
     366                hudVisualizationMode->setCharacterSize(21);
     367                hudVisualizationMode->setDataVariance(osg::Object::DYNAMIC);
     368                geode->addDrawable( hudVisualizationMode );
     369        }
     370       
     371        updateHUD();
     372        _distortionSet->getDistortionInternals()->addChild(geode, false);       //  = child #2  :definition: child #0 = mesh, #1 = highlighter, #2 HUD
     373}
     374
     375void DistortionManipulator::updateHUD()
     376{
     377        switch(activeSetupMode)
     378        {
     379                case DISABLED : hudSetupMode->setText("Setup Mode : DISABLED"); break;
     380                case MANUAL : hudSetupMode->setText("Setup Mode : MANUAL"); break;
     381                case DELEGATED : hudSetupMode->setText("Setup Mode : DELEGATED"); break;
     382                default: hudSetupMode->setText("");
     383        };
     384        switch(activeDistortionMode)
     385        {
     386                case MESH : hudDistortionMode->setText("Distortion Mode : MESH"); break;
     387                case TEXCOORDINATES : hudDistortionMode->setText("Distortion Mode : TEXCOORDINATES"); break;
     388                default: hudDistortionMode->setText("");
     389        };
     390        switch(activeManualSetupMode)
     391        {
     392                case DISTORTION : hudManualSetupMode->setText("Manual Setup Mode : DISTORTION"); break;
     393                case BLENDING : hudManualSetupMode->setText("Manual Setup Mode : BLENDING"); break;
     394                default: hudManualSetupMode->setText("");
     395        };
     396        switch(activeVisualizationMode)
     397        {
     398                case DISTORTION_MESH : hudVisualizationMode->setText("Visualization Mode : DISTORTION_MESH"); break;
     399                case INTENSITY_MAP : hudVisualizationMode->setText("Visualization Mode : INTENSITY_MAP"); break;
     400                case NONE : hudVisualizationMode->setText("Visualization Mode : NONE"); break;
     401                default: hudVisualizationMode->setText("");
     402        };
    300403}
    301404
  • experimental/distortionNG/DistortionManipulator.h

    r353 r356  
    2626#include <osgUtil/IntersectionVisitor>
    2727#include <osgUtil/LineSegmentIntersector>
     28#include <osgText/Text>
    2829
    2930#include "DistortionSet.h"
     
    7475        void computeSelectedVertex( osgUtil::LineSegmentIntersector::Intersection& result );
    7576        void createVertexHighlighter();
     77        void createHUD();
     78        void updateHUD();
    7679
    7780        SetupMode activeSetupMode;
     
    8790        osg::Geometry* _distortionMesh;
    8891        const osg::Vec4 _highlightColor;
     92
     93        // HUD
     94        osg::ref_ptr<osgText::Text> hudSetupMode;
     95        osg::ref_ptr<osgText::Text> hudDistortionMode;
     96        osg::ref_ptr<osgText::Text> hudManualSetupMode;
     97        osg::ref_ptr<osgText::Text> hudVisualizationMode;
    8998};
    9099
  • experimental/distortionNG/main.cpp

    r353 r356  
    1818
    1919#include "extViewer.h"
    20 #include "distortionNG.h"
    2120
    2221#include <osg/ArgumentParser>
     
    175174 * distortionManipulator                                abgeleitet von osgGA::GUIEventHandler
    176175 *                                                                              Grundfunktionen:
    177  *                                                      [done]          - Key to Show Distortion Mesh / Intensity Map / none
     176 *                                                      [.]             - Key to Show Distortion Mesh / Intensity Map / none
    178177 *                                                                              - Key to Save distortion Container  - via plugin
    179  *                                                      [done]          - Key to toggle MANUAL mode between blending und distortion setup
     178 *                                                      [.]             - Key to toggle MANUAL mode between blending und distortion setup
    180179 *                                                      [done]          - Key to toggle distortion setup:
    181180 *                                                                                              DISABLED distortion/blending modifications are forbidden (ggfs. beim Verlassen von DISABLED ggf. auf singleThreaded wechseln und beim aktivieren von DISABLED wieder auf das alte threadingmodel. Alternativ  die data variance des meshes/Blendmap beeinflussen)
     
    185184 *                                                                              - Key to reset Distortion.
    186185 *                                                      [done]          - Key to reset Blending.
     186 *                                                      [done]          - Key to Show/Hide distortion HUD
    187187 *                                                                             
    188188 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
    189  *                                                                                      DISABLED: ignorieren
    190  *                                                                                      MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren
    191  *                                                                                      DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird:
     189 *                                                      [done]                  DISABLED: ignorieren
     190 *                                                      [.]                             MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren
     191 *                                                      [.]                             DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird:
    192192 *                                                                                                                              subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container)
    193193 *                                                                                     
Note: See TracChangeset for help on using the changeset viewer.