[307] | 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 | |
---|
[310] | 19 | #include "extViewer.h" |
---|
[309] | 20 | |
---|
[307] | 21 | #include <osg/ArgumentParser> |
---|
[309] | 22 | #include <osg/PolygonOffset> |
---|
| 23 | |
---|
[307] | 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> |
---|
[352] | 36 | |
---|
| 37 | #include "DistortionManipulator.h" |
---|
| 38 | |
---|
[307] | 39 | int main(int argc, char** argv) |
---|
| 40 | { |
---|
| 41 | osg::ArgumentParser arguments(&argc, argv); |
---|
| 42 | |
---|
| 43 | // construct the viewer. |
---|
[311] | 44 | extViewer viewer(arguments); |
---|
[307] | 45 | |
---|
[342] | 46 | osg::Image* intMap = osgDB::readImageFile("intensitymap.png"); |
---|
[331] | 47 | if (!intMap) |
---|
[353] | 48 | osg::notify(osg::WARN) << "Couldn't find intensity map, skip intensityMap setup." << std::endl; |
---|
| 49 | |
---|
[352] | 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 | |
---|
[331] | 58 | |
---|
| 59 | // set up the camera manipulators. |
---|
[353] | 60 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
---|
[307] | 61 | |
---|
[353] | 62 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
---|
| 63 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
---|
| 64 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
---|
| 65 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
---|
[307] | 66 | |
---|
[353] | 67 | std::string pathfile; |
---|
| 68 | char keyForAnimationPath = '5'; |
---|
| 69 | while (arguments.read("-p",pathfile)) |
---|
| 70 | { |
---|
| 71 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
---|
| 72 | if (apm || !apm->valid()) |
---|
[307] | 73 | { |
---|
[353] | 74 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
---|
| 75 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
---|
| 76 | keyswitchManipulator->selectMatrixManipulator(num); |
---|
| 77 | ++keyForAnimationPath; |
---|
[307] | 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
[353] | 81 | // Add keyswitch manipulator for multiple scene controls- |
---|
| 82 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
---|
| 83 | |
---|
[352] | 84 | // Add the distortion manipulator |
---|
[353] | 85 | viewer.addEventHandler(new osgViewer::DistortionManipulator(_distortionSet)); |
---|
[307] | 86 | |
---|
| 87 | // add the state manipulator |
---|
| 88 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
---|
[361] | 89 | //viewer.addEventHandler( new osgGA::StateSetManipulator); |
---|
| 90 | |
---|
[307] | 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 | { |
---|
[309] | 117 | rootnode = osgDB::readNodeFile("cow.osgt"); |
---|
| 118 | if(!rootnode) |
---|
| 119 | { |
---|
[361] | 120 | OSG_WARN<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
---|
[309] | 121 | return 1; |
---|
| 122 | } |
---|
[325] | 123 | } |
---|
[361] | 124 | |
---|
[309] | 125 | // run the viewers main loop |
---|
| 126 | return viewer.run(); |
---|
[329] | 127 | } |
---|
| 128 | |
---|
| 129 | /* |
---|
| 130 | ToDo: |
---|
[340] | 131 | |
---|
| 132 | The intersection works and the selector highlighter is set and displayed correctly. |
---|
| 133 | Next steps: |
---|
| 134 | * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode. |
---|
| 135 | * catch up dragging values and translate them in the correct coordinate frame. |
---|
| 136 | * apply dragging values: |
---|
| 137 | * a) either on the texture coordinate while the grid is constant, |
---|
| 138 | * b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!) |
---|
[329] | 139 | * |
---|
[340] | 140 | |
---|
[329] | 141 | |
---|
[342] | 142 | * |
---|
| 143 | * Layout vom Distortion System |
---|
| 144 | * |
---|
[350] | 145 | * Das distortion System unterstützt Verzerrungen, die pro Kanal jeweils nur eine camera verwenden. |
---|
| 146 | * 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) |
---|
[342] | 147 | * |
---|
| 148 | * |
---|
| 149 | * modul Funktionen / Description |
---|
| 150 | * |
---|
[361] | 151 | * [postponed] plugin .dist load / Save distContainers loads and saves via serializers the distortion container from/to file. |
---|
| 152 | * |
---|
[342] | 153 | * |
---|
[345] | 154 | * [done] Distortion Container Beinhaltet die folgenden Distortion Details: |
---|
[342] | 155 | * - Blendmap (osgImage) |
---|
| 156 | * - Mesh Dimensions (rows, columns) |
---|
[345] | 157 | * - Mesh Type (GLenum QUAD_STRIP, ...) |
---|
[342] | 158 | * - textureUnit for Scene RTT (z.B.: 0) |
---|
| 159 | * - textureUnit for blendmap (z.B.: 1) |
---|
| 160 | * - screenNum |
---|
| 161 | * - slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist identity) |
---|
| 162 | * - slaveCam viewOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset) |
---|
| 163 | * |
---|
| 164 | * need to add setter/getter as well as the serializer macros. |
---|
[350] | 165 | * |
---|
| 166 | * Besitz: Da osgViewer distSets ohne Manipulationsmöglichkeit konsumieren können soll, muss der COntainer vom Vierwer verwaltet werden. |
---|
[342] | 167 | * |
---|
| 168 | * osgViewer load and apply distortion (apply via setupDistortion(...) |
---|
| 169 | * 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. |
---|
| 170 | * setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit) |
---|
| 171 | * |
---|
| 172 | * |
---|
| 173 | * distortionManipulator abgeleitet von osgGA::GUIEventHandler |
---|
| 174 | * Grundfunktionen: |
---|
[361] | 175 | * [done] - Key to Show Distortion Mesh / Intensity Map / none |
---|
[343] | 176 | * - Key to Save distortion Container - via plugin |
---|
[356] | 177 | * [.] - Key to toggle MANUAL mode between blending und distortion setup |
---|
[348] | 178 | * [done] - Key to toggle distortion setup: |
---|
[343] | 179 | * 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) |
---|
| 180 | * MANUAL distortion/blending modification via mouse Selection and drag'n'drop |
---|
| 181 | * DELEGATED distortion/blending modification by calling a foreign class or calling a subclassed function |
---|
[348] | 182 | * [done] - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates. |
---|
[342] | 183 | * - Key to reset Distortion. |
---|
[349] | 184 | * [done] - Key to reset Blending. |
---|
[356] | 185 | * [done] - Key to Show/Hide distortion HUD |
---|
[342] | 186 | * |
---|
| 187 | * Die Funktion handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ): |
---|
[356] | 188 | * [done] DISABLED: ignorieren |
---|
| 189 | * [.] MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren |
---|
| 190 | * [.] DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird: |
---|
[342] | 191 | * subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container) |
---|
| 192 | * |
---|
[357] | 193 | * [done] Vertex Highlighter für die manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist. |
---|
[343] | 194 | * |
---|
[342] | 195 | * |
---|
[360] | 196 | * direct to do: |
---|
[342] | 197 | * |
---|
[360] | 198 | * speichern des containers in ein .dist file |
---|
| 199 | * Laden des Containers. |
---|
| 200 | * reset distortion funktioniert. |
---|
| 201 | * statesetmanipulator muss auf die scene, nicht auf mesh losgehen. |
---|
[342] | 202 | * |
---|
[360] | 203 | * Anwenden der distortion auf die Meshknoten oder die texturekoordinaten |
---|
| 204 | * |
---|
| 205 | * alternativ: |
---|
| 206 | * - umstellung der koordinaten auf [0-1] |
---|
| 207 | * - speichern der hieght und width im container so daß das mesh an andere Bildschirmgrößen angepasst werden kann. |
---|
| 208 | |
---|
| 209 | * |
---|
[329] | 210 | */ |
---|