source: experimental/distortionNG/main.cpp @ 352

Last change on this file since 352 was 352, checked in by Torben Dannhauer, 12 years ago
File size: 9.1 KB
Line 
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
19#include "extViewer.h"
20#include "distortionNG.h"
21
22#include <osg/ArgumentParser>
23#include <osg/PolygonOffset>
24
25#include <osgDB/ReadFile>
26
27#include <osgViewer/Viewer>
28#include <osgViewer/ViewerEventHandlers>
29
30#include <osgGA/TrackballManipulator>
31#include <osgGA/FlightManipulator>
32#include <osgGA/DriveManipulator>
33#include <osgGA/KeySwitchMatrixManipulator>
34#include <osgGA/StateSetManipulator>
35#include <osgGA/AnimationPathManipulator>
36#include <osgGA/TerrainManipulator>
37
38#include "DistortionManipulator.h"
39
40int main(int argc, char** argv)
41{
42    osg::ArgumentParser arguments(&argc, argv);
43
44    // construct the viewer.
45    extViewer viewer(arguments);
46
47        osg::Image* intMap = osgDB::readImageFile("intensitymap.png");
48        if (!intMap)
49        {
50                osg::notify(osg::WARN) << "Couldn't find intensity map, quiting." << std::endl;
51                return -1;
52        } 
53        // Create DistortionSet
54        osg::ref_ptr<osgViewer::DistortionSet> _distortionSet = new osgViewer::DistortionSet();
55        _distortionSet->setIntensityMap( intMap );
56        _distortionSet->setDistortionMeshRows( 20 );
57        _distortionSet->setDistortionMeshColumns( 20 );
58       
59        viewer.setUpViewForManualDistortion(_distortionSet, 0);
60   
61       
62
63        // set up the camera manipulators.
64    {
65        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
66
67        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
68        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
69        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
70        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
71
72        std::string pathfile;
73        char keyForAnimationPath = '5';
74        while (arguments.read("-p",pathfile))
75        {
76            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
77            if (apm || !apm->valid()) 
78            {
79                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
80                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
81                keyswitchManipulator->selectMatrixManipulator(num);
82                ++keyForAnimationPath;
83            }
84        }
85
86        viewer.setCameraManipulator( keyswitchManipulator.get() );
87    }
88
89        // Add the distortion manipulator
90        osgViewer::DistortionManipulator* distManip = new osgViewer::DistortionManipulator();
91        distManip->setDistortionSet(_distortionSet);
92        viewer.addEventHandler(distManip);
93
94    // add the state manipulator
95    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
96
97    // add the stats handler
98    viewer.addEventHandler(new osgViewer::StatsHandler);
99
100    // add the record camera path handler
101    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
102
103    // add the window size toggle handler
104    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
105
106        // add the thread model handler
107    viewer.addEventHandler(new osgViewer::ThreadingHandler);
108
109    // add the help handler
110    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
111
112    // add the LOD Scale handler
113    viewer.addEventHandler(new osgViewer::LODScaleHandler);
114
115    // add the screen capture handler
116    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
117
118    // load the nodes from the commandline arguments.
119    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
120
121    if (!rootnode)
122    {
123                rootnode = osgDB::readNodeFile("cow.osgt");
124                if(!rootnode)
125                {
126                        osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;
127                        return 1;
128                }
129    }
130        viewer.setSceneData( rootnode );
131       
132        // run the viewers main loop
133        return viewer.run();
134}
135
136/*
137ToDo:
138
139The intersection works and the selector highlighter is set and displayed correctly.
140Next steps:
141 * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode.
142 * catch up dragging values and translate them in the correct coordinate frame.
143 * apply dragging values:
144 *      a) either on the texture coordinate while the grid is constant,
145 *  b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!)
146 *
147 
148
149 *
150 * Layout vom Distortion System
151 *
152 * Das distortion System unterstützt Verzerrungen, die pro Kanal jeweils nur eine camera verwenden.
153 * 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)
154 *
155 *
156 * modul                                                                Funktionen / Description
157 *
158 * [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
159 *
160 *
161 * [done] Distortion Container                                  Beinhaltet die folgenden Distortion Details:
162 *                                                                              - Blendmap (osgImage)
163 *                                                                              - Mesh Dimensions (rows, columns)
164 *                                                                              - Mesh Type (GLenum QUAD_STRIP, ...)
165 *                                                                              - textureUnit for Scene RTT (z.B.: 0)
166 *                                                                              - textureUnit for blendmap (z.B.: 1)
167 *                                                                              - screenNum
168 *                                                                              - slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist identity)
169 *                                                                              - slaveCam viewOffset   (wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset)
170 *                                                                             
171 *                                                                              need to add setter/getter as well as the serializer macros.
172 *                                                                             
173 *                                                                              Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der COntainer vom Vierwer verwaltet werden.
174 *
175 * osgViewer                                                    load and apply distortion (apply via setupDistortion(...)
176 *                                                                              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.
177 *                                                                              setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
178 *
179 *
180 * distortionManipulator                                abgeleitet von osgGA::GUIEventHandler
181 *                                                                              Grundfunktionen:
182 *                                                      [done]          - Key to Show Distortion Mesh / Intensity Map / none
183 *                                                                              - Key to Save distortion Container  - via plugin
184 *                                                      [done]          - Key to toggle MANUAL mode between blending und distortion setup
185 *                                                      [done]          - Key to toggle distortion setup:
186 *                                                                                              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)
187 *                                                                                              MANUAL distortion/blending modification via mouse Selection and drag'n'drop
188 *                                                                                              DELEGATED distortion/blending modification by calling a foreign class or calling a subclassed function
189 *                                                      [done]          - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates.
190 *                                                                              - Key to reset Distortion.
191 *                                                      [done]          - Key to reset Blending.
192 *                                                                             
193 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
194 *                                                                                      DISABLED: ignorieren
195 *                                                                                      MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren
196 *                                                                                      DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird:
197 *                                                                                                                              subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container)
198 *                                                                                     
199 *                                                                              Vertex Highlighter für die manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist.
200 *                                                                     
201 *
202 *
203 *
204*/
Note: See TracBrowser for help on using the repository browser.