[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 | #include "distortionNG.h" |
---|
| 21 | |
---|
[307] | 22 | #include <osg/ArgumentParser> |
---|
[309] | 23 | #include <osg/PolygonOffset> |
---|
| 24 | |
---|
[307] | 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 | int main(int argc, char** argv) |
---|
| 38 | { |
---|
| 39 | osg::ArgumentParser arguments(&argc, argv); |
---|
| 40 | |
---|
| 41 | // construct the viewer. |
---|
[311] | 42 | extViewer viewer(arguments); |
---|
[307] | 43 | |
---|
[342] | 44 | osg::Image* intMap = osgDB::readImageFile("intensitymap.png"); |
---|
[331] | 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. |
---|
[307] | 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 | { |
---|
[309] | 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 | } |
---|
[325] | 116 | } |
---|
[327] | 117 | viewer.setSceneData( rootnode ); |
---|
[309] | 118 | |
---|
| 119 | // run the viewers main loop |
---|
| 120 | return viewer.run(); |
---|
[329] | 121 | } |
---|
| 122 | |
---|
| 123 | /* |
---|
| 124 | ToDo: |
---|
[340] | 125 | |
---|
| 126 | The intersection works and the selector highlighter is set and displayed correctly. |
---|
| 127 | Next steps: |
---|
| 128 | * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode. |
---|
| 129 | * catch up dragging values and translate them in the correct coordinate frame. |
---|
| 130 | * apply dragging values: |
---|
| 131 | * a) either on the texture coordinate while the grid is constant, |
---|
| 132 | * b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!) |
---|
[329] | 133 | * |
---|
[340] | 134 | |
---|
[329] | 135 | |
---|
[342] | 136 | * |
---|
| 137 | * Layout vom Distortion System |
---|
| 138 | * |
---|
| 139 | * Das distortion systme unterstüzt verzerrungen ,die pro kanal auhc nur eine camera verwenden. |
---|
| 140 | * 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) |
---|
| 141 | * |
---|
| 142 | * |
---|
| 143 | * modul Funktionen / Description |
---|
| 144 | * |
---|
| 145 | * plugin .dist load / Save distContainers loads and saves via serializers the distortion container from/to file. |
---|
| 146 | * |
---|
| 147 | * |
---|
| 148 | * Distortion Container Beinhaltet die folgenden Distortion Details: |
---|
| 149 | * - Blendmap (osgImage) |
---|
| 150 | * - Mesh Dimensions (rows, columns) |
---|
| 151 | * - Mesh Type (osg::PrimitiveSet::QUAD_STRIP, ...) |
---|
| 152 | * - textureUnit for Scene RTT (z.B.: 0) |
---|
| 153 | * - textureUnit for blendmap (z.B.: 1) |
---|
| 154 | * - screenNum |
---|
| 155 | * - slaveCam projectionOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, meist identity) |
---|
| 156 | * - slaveCam viewOffset (wird mit der vom master multipliziert und auf die slave cam angewendet, verwendet für translation und rotation offset) |
---|
| 157 | * |
---|
| 158 | * need to add setter/getter as well as the serializer macros. |
---|
| 159 | * |
---|
| 160 | * |
---|
| 161 | * osgViewer load and apply distortion (apply via setupDistortion(...) |
---|
| 162 | * 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. |
---|
| 163 | * setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit) |
---|
| 164 | * |
---|
| 165 | * |
---|
| 166 | * distortionManipulator abgeleitet von osgGA::GUIEventHandler |
---|
| 167 | * Grundfunktionen: |
---|
[343] | 168 | * - Key to Show/Hide Distortion Mesh |
---|
| 169 | * - Key to Show/Hide Intensity Map |
---|
| 170 | * - Key to Save distortion Container - via plugin |
---|
| 171 | * - Key to toggle MANUAL mode between blending und distortion setup |
---|
| 172 | * - Key to toggle distortion setup: |
---|
| 173 | * 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) |
---|
| 174 | * MANUAL distortion/blending modification via mouse Selection and drag'n'drop |
---|
| 175 | * DELEGATED distortion/blending modification by calling a foreign class or calling a subclassed function |
---|
| 176 | * - Key to control if mouse drags affects mesh coordinates or rttScene texture coordinates. Default: Mesh coordinates. |
---|
[342] | 177 | * - Key to reset Distortion. |
---|
[343] | 178 | * - Key to reset Blending. |
---|
[342] | 179 | * |
---|
| 180 | * Die Funktion handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ): |
---|
| 181 | * DISABLED: ignorieren |
---|
| 182 | * MANUAL : auf mouse selection und drags horchen und auf Distortion Anwenden. bei keys die obigen funktionen realisieren |
---|
| 183 | * DELEGATED : beim typ FRAME die Distortion zur Veränderung stellen indem der Pointer an die bearbeitende Funktion übergeben wird: |
---|
| 184 | * subsclassed function aufrufen bzw foreignClass->delegateDistortionSetup(distContainer& container) |
---|
| 185 | * |
---|
[343] | 186 | * Vertex Highlighter für die manuelle Verzerrung soll nur eingeblendet werden wenn der Betriebsmodus MANUAL ist. |
---|
| 187 | * |
---|
[342] | 188 | * |
---|
| 189 | * |
---|
| 190 | * |
---|
[329] | 191 | */ |
---|