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