source: experimental/distortionNG/main.cpp @ 413

Last change on this file since 413 was 413, checked in by friedmann, 12 years ago

Uploadtest

File size: 12.5 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//TEST
20
21#include "extViewer.h"
22
23#include <osg/ArgumentParser>
24#include <osg/PolygonOffset>
25
26#include <osgDB/ReadFile>
27#include <osgDB/WriteFile>      // Testweise zum dist plugin verifizieren
28
29#include <osgViewer/Viewer>
30#include <osgViewer/ViewerEventHandlers>
31
32#include <osgGA/TrackballManipulator>
33#include <osgGA/FlightManipulator>
34#include <osgGA/DriveManipulator>
35#include <osgGA/KeySwitchMatrixManipulator>
36#include <osgGA/StateSetManipulator>
37#include <osgGA/AnimationPathManipulator>
38#include <osgGA/TerrainManipulator>
39
40#include "DistortionManipulator.h"
41#include "DistortionSetupStrategyProjectSyntropy.h"
42#include "DistortionSetupStrategyProjectionDesigner.h"
43
44int main(int argc, char** argv)
45{
46    osg::ArgumentParser arguments(&argc, argv);
47
48    // construct the viewer.
49    extViewer viewer(arguments);
50
51        osg::Image* intMap = osgDB::readImageFile("intensitymap.png");
52        if (!intMap)
53                osg::notify(osg::WARN) << "Couldn't find intensity map, skip intensityMap setup." << std::endl;
54
55        // Create DistortionSet
56        osg::ref_ptr<osgViewer::DistortionSet> _distortionSet = new osgViewer::DistortionSet();
57        _distortionSet->setIntensityMap( intMap );
58        _distortionSet->setDistortionMeshDimensions(20, 30);
59       
60
61// ---- test plugin read / write
62        //osgDB::writeObjectFile( *_distortionSet, "distortionset.dist" );
63        //_distortionSet = NULL;
64        //_distortionSet = dynamic_cast<osgViewer::DistortionSet*>( osgDB::readObjectFile( "distortionset.dist" ) );
65// ------------ Test ende -----------
66
67       
68        viewer.setUpViewForManualDistortion(_distortionSet, 0);
69   
70
71        // set up the camera manipulators.
72    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
73
74    keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
75    keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
76    keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
77    keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
78
79    std::string pathfile;
80    char keyForAnimationPath = '5';
81    while (arguments.read("-p",pathfile))
82    {
83        osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
84        if (apm || !apm->valid()) 
85        {
86            unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
87            keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
88            keyswitchManipulator->selectMatrixManipulator(num);
89            ++keyForAnimationPath;
90        }
91    }
92
93        // Add keyswitch manipulator for multiple scene controls-
94    viewer.setCameraManipulator( keyswitchManipulator.get() );
95
96        // Add the distortion manipulator
97        osgViewer::DistortionManipulator* distortionManip = new osgViewer::DistortionManipulator(&viewer, _distortionSet);
98
99        DistortionSetupStrategyProjectSyntropy* psStrategy = new DistortionSetupStrategyProjectSyntropy();
100        psStrategy->setDistortionInputFiles( "./resources/ProjectSyntropy/example2/warpmap_1.csv",
101                                                                                "./resources/ProjectSyntropy/example2/blending_1.bmp",
102                                                                                "./resources/ProjectSyntropy/example2/frustum_1.csv" );
103
104        //LF UPDATE
105        DistortionSetupStrategyProjectionDesigner* pdStrategy = new DistortionSetupStrategyProjectionDesigner();
106        pdStrategy->setDistortionInputFiles( "./resources/ProjectionDesigner/example1/distort_center.bmp",
107                                                                                "./resources/ProjectionDesigner/example1/blend_center.bmp",
108                                                                                "./resources/ProjectionDesigner/example1/view_center.cfg" );
109
110
111        //Decide on DistortionSetupStrategy
112        //distortionManip->setDistortionSetupStrategy( psStrategy );
113        distortionManip->setDistortionSetupStrategy( pdStrategy );
114        viewer.addEventHandler(distortionManip);
115
116    // add the state manipulator
117    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
118       
119    // add the stats handler
120    viewer.addEventHandler(new osgViewer::StatsHandler);
121
122    // add the record camera path handler
123    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
124
125    // add the window size toggle handler
126    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
127
128        // add the thread model handler
129    viewer.addEventHandler(new osgViewer::ThreadingHandler);
130
131    // add the help handler
132    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
133
134    // add the LOD Scale handler
135    viewer.addEventHandler(new osgViewer::LODScaleHandler);
136
137    // add the screen capture handler
138    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
139
140    // load the nodes from the commandline arguments.
141    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
142        osgDB::Registry::instance()->getDataFilePathList().push_front("./resources/");
143        osgDB::Registry::instance()->getDataFilePathList().push_front("H:/AllInOnDB");
144
145    if (!rootnode)
146    {
147                rootnode = osgDB::readNodeFile("./resources/TestSphere/sphere_500.obj");
148                if(!rootnode)
149                {
150                        OSG_WARN<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;
151                        return 1;
152                }
153    }
154        viewer.setSceneData( rootnode );
155
156        // run the viewers main loop
157        return viewer.run();
158}
159
160/*
161ToDo:
162
163The intersection works and the selector highlighter is set and displayed correctly.
164Next steps:
165 * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode.
166 * catch up dragging values and translate them in the correct coordinate frame.
167 * apply dragging values:
168 *      a) either on the texture coordinate while the grid is constant,
169 *  b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!)
170 *
171 
172
173 *
174 * Layout vom Distortion System
175 *
176 * Das distortion System unterstützt Verzerrungen, die pro Kanal jeweils nur eine camera verwenden.
177 * 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)
178 *
179 *
180 * modul                                                                Funktionen / Description
181 *
182 * [] plugin .dist                      [done]          load / Save distContainers                                      loads and saves via serializers the distortion container from/to file.
183 *                                                                                                                                                                      Ensures the Coordinates are normalized before saving the container.
184 *                                                                              Load:
185 *                                                      [done]          * use ReaderWriterOSG2 to load container
186 *                                                                              * invoke osgViewer::setUpViewForManualDistortion(distSet, screenNum, projectorMatrix) to set up distortion
187 *                                                                              Save:
188 *                                                                              * check if container is normalized. if not, copy and normalize container
189 *                                                      [done]          * use ReaderWriterOSG2 to save container
190 * 
191 *
192 * [done] Distortion Container                  Der Container wird immer normalisiert gespeichert, alle Koordinaten (Mesh+TexCoords) werden im Range [0-1]angespeichert.
193 *                                                                              Er beinhaltet die folgenden Distortion Details:
194 *                                                                              - Blendmap (osgImage)
195 *                                                                              - Mesh Dimensions (rows, columns)
196 *                                                                              - Mesh Type (GLenum QUAD_STRIP, ...)
197 *                                                                              - Mesh Coordinates [0-1]
198 *                                                                              - Texture Coordinates [0-1]
199 *                                                                              - textureUnit for Scene RTT (z.B.: 0)
200 *                                                                              - textureUnit for blendmap (z.B.: 1)
201 *                                                                              - screenNum
202 *                                                                              - slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist Identity)
203 *                                                                              - slaveCam viewOffset   (wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset)
204 *                                                                             
205 *                                                      []                      Todo: get set methode für das Mesh implementieren.
206 *                                                                             
207 *                                                                              Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der Container vom Viewer verwaltet werden. der manipulator greift darauf zu, das plugin kann container entgegen nehmen oder zurückgeben, hat aber keinen direkten kontakt zur container instanz von osgViewer
208 *
209 * osgViewer                                                    im construtor (anfangs ersatzweise in der main.cpp) : -dist <distFile> => load and apply distortion [via setUpViewForManualDistortion(std::string distFile)]
210 *                                                                              setUpIntensityMapBlending(string filepath, int rrtTexUnit=1, int scenTexUnit=0):        Simple function providing a file path, and optionally the texUnits to use.
211 *                                                                                                                                                                                                                                                      Will invoke the more detailed funtion (below) for setup.
212 *                                                                              setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit)
213 *                                                                              setUpViewForManualDistortion(osgViewer::DistortionSet* distSet, unsigned int screenNum, const osg::Matrixd& projectorMatrix)
214 *                                                                              setUpViewForManualDistortion(std::string distFile, unsigned int screenNum, const osg::Matrixd& projectorMatrix) is invoked by -dist <distFile>, reads distSet via osgDB::readObjectFile(), calls setUpViewForManualDistortion(osgViewer::DistortionSet* distSet, unsigned int screenNum, const osg::Matrixd& projectorMatrix) to setup the distortion.
215 *
216 * distortionManipulator                                abgeleitet von osgGA::GUIEventHandler
217 *                                                                              Grundfunktionen:
218 *                                                      [done]          - Key to Show Distortion Mesh / Intensity Map / none
219 *                                                      [done]          - Key to Save distortion Container  - via osgDB::writeObjectFile(const osg::Object& object, const std::string& filename, const Options* options). osgDB & registry determines and loads the approriate plugin bythe file ending (.dist).
220 *                                                      [.]                     - Key to toggle MANUAL mode between blending und distortion setup
221 *                                                      [done]          - Key to toggle distortion setup:
222 *                                                                                              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)
223 *                                                                                              MANUAL distortion/blending modification via mouse Selection and drag'n'drop
224 *                                                                                              DELEGATED distortion/blending modification by calling a foreign class or calling a subclassed function
225 *                                                      [done]          - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates.
226 *                                                      [done]          - Key to reset Distortion.
227 *                                                      [done]          - Key to reset Blending.
228 *                                                      [done]          - Key to Show/Hide distortion HUD
229 *                                                                             
230 *                                                                              Die Funktion  handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ):
231 *                                                      [done]                  DISABLED: ignorieren
232 *                                                      [.]                             MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren
233 *                                                      [.]                             DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird:
234 *                                                                                                                              subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container)
235 *                                                                                     
236 *                                                      [done]                  Vertex Highlighter für die manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist.
237 *                                                                     
238 *
239 * direct to do:
240 *
241 * Plugin fertigstellen
242 * extViewer::setUpViewForManualDistortion(std::string distFile)
243 * Load Funktion vom osgViewer (ersatzweise Anfangs in der main.cpp) fertigstellen : -dist <distFile> weiterreichen and extViewer::setUpViewForManualDistortion(std::string distFile)
244 * Laden des Containers.
245 * Anwenden der manuellen distortion auf die Meshknoten oder die texturekoordinaten
246 *
247 *
248*/
Note: See TracBrowser for help on using the repository browser.