source: experimental/distortionNG/main.cpp @ 356

Last change on this file since 356 was 356, checked in by Torben Dannhauer, 12 years ago
File size: 9.0 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
60        // set up the camera manipulators.
61    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
62
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() );
67
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()) 
74        {
75            unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
76            keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
77            keyswitchManipulator->selectMatrixManipulator(num);
78            ++keyForAnimationPath;
79        }
80    }
81
82        // Add keyswitch manipulator for multiple scene controls-
83    viewer.setCameraManipulator( keyswitchManipulator.get() );
84
85        // Add the distortion manipulator
86        viewer.addEventHandler(new osgViewer::DistortionManipulator(_distortionSet));
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    {
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                }
123    }
124        viewer.setSceneData( rootnode );
125       
126        // run the viewers main loop
127        return viewer.run();
128}
129
130/*
131ToDo:
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!)
140 *
141 
142
143 *
144 * Layout vom Distortion System
145 *
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)
148 *
149 *
150 * modul                                                                Funktionen / Description
151 *
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
153 *
154 *
155 * [done] Distortion Container                                  Beinhaltet die folgenden Distortion Details:
156 *                                                                              - Blendmap (osgImage)
157 *                                                                              - Mesh Dimensions (rows, columns)
158 *                                                                              - Mesh Type (GLenum QUAD_STRIP, ...)
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.
166 *                                                                             
167 *                                                                              Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der COntainer vom Vierwer verwaltet werden.
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:
176 *                                                      [.]             - Key to Show Distortion Mesh / Intensity Map / none
177 *                                                                              - Key to Save distortion Container  - via plugin
178 *                                                      [.]             - Key to toggle MANUAL mode between blending und distortion setup
179 *                                                      [done]          - Key to toggle distortion setup:
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
183 *                                                      [done]          - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates.
184 *                                                                              - Key to reset Distortion.
185 *                                                      [done]          - Key to reset Blending.
186 *                                                      [done]          - Key to Show/Hide distortion HUD
187 *                                                                             
188 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
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:
192 *                                                                                                                              subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container)
193 *                                                                                     
194 *                                                                              Vertex Highlighter für die manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist.
195 *                                                                     
196 *
197 *
198 *
199*/
Note: See TracBrowser for help on using the repository browser.