source: experimental/distortionNG/main.cpp @ 360

Last change on this file since 360 was 360, checked in by Torben Dannhauer, 12 years ago
File size: 9.7 KB
RevLine 
[307]1/* osgVisual test. distortionNG, experimental.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
[310]19#include "extViewer.h"
[309]20
[307]21#include <osg/ArgumentParser>
[309]22#include <osg/PolygonOffset>
23
[307]24#include <osgDB/ReadFile>
25
26#include <osgViewer/Viewer>
27#include <osgViewer/ViewerEventHandlers>
28
29#include <osgGA/TrackballManipulator>
30#include <osgGA/FlightManipulator>
31#include <osgGA/DriveManipulator>
32#include <osgGA/KeySwitchMatrixManipulator>
33#include <osgGA/StateSetManipulator>
34#include <osgGA/AnimationPathManipulator>
35#include <osgGA/TerrainManipulator>
[352]36
37#include "DistortionManipulator.h"
38
[307]39int main(int argc, char** argv)
40{
41    osg::ArgumentParser arguments(&argc, argv);
42
43    // construct the viewer.
[311]44    extViewer viewer(arguments);
[307]45
[342]46        osg::Image* intMap = osgDB::readImageFile("intensitymap.png");
[331]47        if (!intMap)
[353]48                osg::notify(osg::WARN) << "Couldn't find intensity map, skip intensityMap setup." << std::endl;
49
[352]50        // Create DistortionSet
51        osg::ref_ptr<osgViewer::DistortionSet> _distortionSet = new osgViewer::DistortionSet();
52        _distortionSet->setIntensityMap( intMap );
53        _distortionSet->setDistortionMeshRows( 20 );
54        _distortionSet->setDistortionMeshColumns( 20 );
55       
56        viewer.setUpViewForManualDistortion(_distortionSet, 0);
57   
[360]58        //viewer.setUpIntensityMapBlending("intensitymap.png");
[331]59
60        // set up the camera manipulators.
[353]61    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
[307]62
[353]63    keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
64    keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
65    keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
66    keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
[307]67
[353]68    std::string pathfile;
69    char keyForAnimationPath = '5';
70    while (arguments.read("-p",pathfile))
71    {
72        osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
73        if (apm || !apm->valid()) 
[307]74        {
[353]75            unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
76            keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
77            keyswitchManipulator->selectMatrixManipulator(num);
78            ++keyForAnimationPath;
[307]79        }
80    }
81
[353]82        // Add keyswitch manipulator for multiple scene controls-
83    viewer.setCameraManipulator( keyswitchManipulator.get() );
84
[352]85        // Add the distortion manipulator
[353]86        viewer.addEventHandler(new osgViewer::DistortionManipulator(_distortionSet));
[307]87
88    // add the state manipulator
89    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
90
91    // add the stats handler
92    viewer.addEventHandler(new osgViewer::StatsHandler);
93
94    // add the record camera path handler
95    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
96
97    // add the window size toggle handler
98    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
99
100        // add the thread model handler
101    viewer.addEventHandler(new osgViewer::ThreadingHandler);
102
103    // add the help handler
104    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
105
106    // add the LOD Scale handler
107    viewer.addEventHandler(new osgViewer::LODScaleHandler);
108
109    // add the screen capture handler
110    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
111
112    // load the nodes from the commandline arguments.
113    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
114
115    if (!rootnode)
116    {
[309]117                rootnode = osgDB::readNodeFile("cow.osgt");
118                if(!rootnode)
119                {
120                        osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;
121                        return 1;
122                }
[325]123    }
[327]124        viewer.setSceneData( rootnode );
[309]125       
126        // run the viewers main loop
127        return viewer.run();
[329]128}
129
130/*
131ToDo:
[340]132
133The intersection works and the selector highlighter is set and displayed correctly.
134Next steps:
135 * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode.
136 * catch up dragging values and translate them in the correct coordinate frame.
137 * apply dragging values:
138 *      a) either on the texture coordinate while the grid is constant,
139 *  b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!)
[329]140 *
[340]141 
[329]142
[342]143 *
144 * Layout vom Distortion System
145 *
[350]146 * Das distortion System unterstützt Verzerrungen, die pro Kanal jeweils nur eine camera verwenden.
147 * 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)
[342]148 *
149 *
150 * modul                                                                Funktionen / Description
151 *
[345]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
[342]153 *
154 *
[345]155 * [done] Distortion Container                                  Beinhaltet die folgenden Distortion Details:
[342]156 *                                                                              - Blendmap (osgImage)
157 *                                                                              - Mesh Dimensions (rows, columns)
[345]158 *                                                                              - Mesh Type (GLenum QUAD_STRIP, ...)
[342]159 *                                                                              - textureUnit for Scene RTT (z.B.: 0)
160 *                                                                              - textureUnit for blendmap (z.B.: 1)
161 *                                                                              - screenNum
162 *                                                                              - slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist identity)
163 *                                                                              - slaveCam viewOffset   (wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset)
164 *                                                                             
165 *                                                                              need to add setter/getter as well as the serializer macros.
[350]166 *                                                                             
167 *                                                                              Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der COntainer vom Vierwer verwaltet werden.
[342]168 *
169 * osgViewer                                                    load and apply distortion (apply via setupDistortion(...)
170 *                                                                              setUpIntensityMapBlending(string filepath, int rrtTexUnit=1, int scenTexUnit=0): simple function providing a file path, and optionally the texUnits to use. Wil invoke the more detailed funtion for setup.
171 *                                                                              setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
172 *
173 *
174 * distortionManipulator                                abgeleitet von osgGA::GUIEventHandler
175 *                                                                              Grundfunktionen:
[359]176 *                                                      [done|.|.]      - Key to Show Distortion Mesh / Intensity Map / none
[343]177 *                                                                              - Key to Save distortion Container  - via plugin
[356]178 *                                                      [.]             - Key to toggle MANUAL mode between blending und distortion setup
[348]179 *                                                      [done]          - Key to toggle distortion setup:
[343]180 *                                                                                              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)
181 *                                                                                              MANUAL distortion/blending modification via mouse Selection and drag'n'drop
182 *                                                                                              DELEGATED distortion/blending modification by calling a foreign class or calling a subclassed function
[348]183 *                                                      [done]          - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates.
[342]184 *                                                                              - Key to reset Distortion.
[349]185 *                                                      [done]          - Key to reset Blending.
[356]186 *                                                      [done]          - Key to Show/Hide distortion HUD
[342]187 *                                                                             
188 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
[356]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:
[342]192 *                                                                                                                              subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container)
193 *                                                                                     
[357]194 *                                                      [done]                  Vertex Highlighter für die manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist.
[343]195 *                                                                     
[342]196 *
[360]197 * direct to do:
[342]198 *
[360]199 * speichern des containers in ein .dist file
200 * 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.
203 * reset distortion funktioniert.
204 * statesetmanipulator muss auf die scene, nicht auf mesh losgehen.
[342]205 *
[360]206 * Anwenden der distortion auf die Meshknoten oder die texturekoordinaten
207 *
208 * alternativ:
209 * - umstellung der koordinaten auf [0-1]
210 * - speichern der hieght und width im container so daß das mesh an andere Bildschirmgrößen angepasst werden kann.
211 
212 *
[329]213*/
Note: See TracBrowser for help on using the repository browser.