source: experimental/distortionNG/main.cpp @ 342

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

first draft of the complete distortion framework.

File size: 9.2 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        //viewer.setUpViewForPanoramicSphericalDisplay(1, 0, 0, intMap);
53   
54        // set up the camera manipulators.
55    {
56        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
57
58        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
59        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
60        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
61        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
62
63        std::string pathfile;
64        char keyForAnimationPath = '5';
65        while (arguments.read("-p",pathfile))
66        {
67            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
68            if (apm || !apm->valid()) 
69            {
70                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
71                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
72                keyswitchManipulator->selectMatrixManipulator(num);
73                ++keyForAnimationPath;
74            }
75        }
76
77        viewer.setCameraManipulator( keyswitchManipulator.get() );
78    }
79
80
81    // add the state manipulator
82    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
83
84    // add the stats handler
85    viewer.addEventHandler(new osgViewer::StatsHandler);
86
87    // add the record camera path handler
88    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
89
90    // add the window size toggle handler
91    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
92
93        // add the thread model handler
94    viewer.addEventHandler(new osgViewer::ThreadingHandler);
95
96    // add the help handler
97    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
98
99    // add the LOD Scale handler
100    viewer.addEventHandler(new osgViewer::LODScaleHandler);
101
102    // add the screen capture handler
103    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
104
105    // load the nodes from the commandline arguments.
106    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
107
108    if (!rootnode)
109    {
110                rootnode = osgDB::readNodeFile("cow.osgt");
111                if(!rootnode)
112                {
113                        osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;
114                        return 1;
115                }
116    }
117        viewer.setSceneData( rootnode );
118
119        //osg::ref_ptr<osg::Geode> geode = new osg::Geode;
120        //geode->addDrawable( extViewer::createMesh(16, 9) );
121        //geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
122        //geode->getOrCreateStateSet()->setAttributeAndModes( new osg::PolygonOffset(1.0f, 1.0f) );
123
124        //osg::ref_ptr<distortionHandler> selector = new distortionHandler( viewer.getCamera() );
125
126        //osg::ref_ptr<osg::Group> root = new osg::Group;
127        //root->addChild( geode.get() );
128        //root->addChild( selector->createVertexHighlighter() );
129        //viewer.addEventHandler( selector.get() );
130        //viewer.setSceneData( root.get() );
131
132        // Avoid that the highlighter is culled away
133        //osg::CullSettings::CullingMode mode = viewer.getCamera()->getCullingMode();
134        //viewer.getCamera()->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
135       
136        // run the viewers main loop
137        return viewer.run();
138}
139
140/*
141ToDo:
142
143The intersection works and the selector highlighter is set and displayed correctly.
144Next steps:
145 * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode.
146 * catch up dragging values and translate them in the correct coordinate frame.
147 * apply dragging values:
148 *      a) either on the texture coordinate while the grid is constant,
149 *  b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!)
150 *
151 
152
153 *
154 * Layout vom Distortion System
155 *
156 * Das distortion systme unterstüzt verzerrungen ,die pro kanal auhc nur eine camera verwenden.
157 * Verzerrungen, die das Bild je Kanal aus mehreren Cams zusammensetzen um Views>=180° zu erreichen werden nicht unterstützt da hierfür das Camera Setup nötig wäre, welches nicht im distortion-Container gespeichert wird (Sonderfall, zu speziell für das Dist-Framework)
158 *
159 *
160 * modul                                                                Funktionen / Description
161 *
162 * plugin .dist                                                 load / Save distContainers                                      loads and saves via serializers the distortion container from/to file.
163 *
164 *
165 * Distortion Container                                 Beinhaltet die folgenden Distortion Details:
166 *                                                                              - Blendmap (osgImage)
167 *                                                                              - Mesh Dimensions (rows, columns)
168 *                                                                              - Mesh Type (osg::PrimitiveSet::QUAD_STRIP, ...)
169 *                                                                              - textureUnit for Scene RTT (z.B.: 0)
170 *                                                                              - textureUnit for blendmap (z.B.: 1)
171 *                                                                              - screenNum
172 *                                                                              - slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist identity)
173 *                                                                              - slaveCam viewOffset   (wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset)
174 *                                                                             
175 *                                                                              need to add setter/getter as well as the serializer macros.
176 *
177 *
178 * osgViewer                                                    load and apply distortion (apply via setupDistortion(...)
179 *                                                                              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.
180 *                                                                              setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
181 *
182 *
183 * distortionManipulator                                abgeleitet von osgGA::GUIEventHandler
184 *                                                                              Grundfunktionen:
185 *                                                                              - Key for Show/Hide Distortion Mesh
186 *                                                                              - Key for Save distortion Handler  - via plugin
187 *                                                                              - Key for toggle distortion setup:
188 *                                                                                              DISABLED distortion 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 beeinflussen)
189 *                                                                                              MANUAL distortion modification via mouse Selection and drag'n'drop
190 *                                                                                              DELEGATED via calling a foreign class or calling a subclassed function
191 *                                                                              - Key to control if mouse drags affects mesh coordinates or texture coordinates. Default: Mesh coordinates.
192 *                                                                              - Key to reset Distortion.
193 *                                                                             
194 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
195 *                                                                                      DISABLED: ignorieren
196 *                                                                                      MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren
197 *                                                                                      DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird:
198 *                                                                                                                              subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container)
199 *                                                                                     
200 *                                                                              Vertex Highlighter für die Manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist.
201 *
202 *                                                                             
203 * blending Manipulator                                 abgeleitet von osgGA::GUIEventHandler
204 *                                                                              Grundfunktionen:
205 *
206 *                                                                              - To Do
207 *                                                                             
208 *
209 *
210 *
211*/
Note: See TracBrowser for help on using the repository browser.