source: experimental/distortionNG/main.cpp @ 362

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