source: experimental/distortionNG/main.cpp @ 350

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