source: experimental/distortionNG/main.cpp @ 353

Last change on this file since 353 was 353, checked in by Torben Dannhauer, 12 years ago

DistortionManipulator? is working (alpha stadium)

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