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