[344] | 1 | #ifndef OSGVIEWER_DistortionSet |
---|
| 2 | #define OSGVIEWER_DistortionSet 1 |
---|
| 3 | |
---|
| 4 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2012 Torben Dannhauer |
---|
| 5 | * |
---|
| 6 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 7 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 8 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 9 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 10 | * |
---|
| 11 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 12 | * You have to aquire licenses for all used proprietary modules. |
---|
| 13 | * |
---|
| 14 | * This library is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * OpenSceneGraph Public License for more details. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <osg/Object> |
---|
| 21 | #include <osg/Image> |
---|
| 22 | #include <osg/Matrixd> |
---|
[353] | 23 | #include <osg/Camera> |
---|
| 24 | #include <osg/Switch> |
---|
[360] | 25 | #include <osg/Shader> |
---|
[374] | 26 | #include <osg/Geometry> |
---|
[344] | 27 | |
---|
| 28 | namespace osgViewer { |
---|
| 29 | |
---|
| 30 | class DistortionSet : public osg::Object |
---|
| 31 | { |
---|
| 32 | public: |
---|
[357] | 33 | enum DistortionInternals { |
---|
| 34 | MESH = 0, |
---|
| 35 | HIGHLIGHTER = 1, |
---|
| 36 | HUD = 2 |
---|
| 37 | }; |
---|
| 38 | |
---|
[344] | 39 | META_Object(osgViewer,DistortionSet); // Required for serializer |
---|
| 40 | |
---|
| 41 | DistortionSet(const osgViewer::DistortionSet& ds, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): // Required for serializer |
---|
| 42 | _distortionMeshRows(ds._distortionMeshRows), |
---|
| 43 | _distortionMeshColumns(ds._distortionMeshColumns), |
---|
| 44 | //osg::PrimitiveSet::Mode _MeshType |
---|
| 45 | _intensityMap(ds._intensityMap), |
---|
| 46 | _texUnitScene(ds._texUnitScene), |
---|
| 47 | _texUnitIntensityMap(ds._texUnitIntensityMap), |
---|
| 48 | _viewOffset(ds._viewOffset), |
---|
[350] | 49 | _projectionOffset(ds._projectionOffset), |
---|
| 50 | _showIntesityMapMapOnly(ds._showIntesityMapMapOnly){} |
---|
[344] | 51 | |
---|
| 52 | DistortionSet(); |
---|
| 53 | virtual ~DistortionSet(); |
---|
| 54 | |
---|
[350] | 55 | // Working access |
---|
[383] | 56 | bool isDirty(){return(_meshDirty || _matrixDirty);} |
---|
| 57 | void dirtyMesh(){_meshDirty = true;} |
---|
| 58 | void dirtyMatrix(){_matrixDirty = true;} |
---|
| 59 | void clearDirtyStatus() { _meshDirty = false; _matrixDirty = false;} |
---|
| 60 | |
---|
[407] | 61 | void setDistortionMeshDimensions(int rows, int cols, bool enforceMeshRebuild=false); |
---|
[379] | 62 | |
---|
[350] | 63 | osg::Image* getIntensityMap() { return _intensityMap; } // Also for manipulating the intensity map |
---|
| 64 | bool& getShowIntensityMapOnlyAsRef() { return _showIntesityMapMapOnly;} |
---|
| 65 | |
---|
[398] | 66 | void setSceneCamera(osg::Camera* camera) { _sceneCamera = camera;} |
---|
| 67 | osg::Camera* getSceneCamera() { return _sceneCamera.get(); } |
---|
[350] | 68 | |
---|
[398] | 69 | void setDistortionCamera(osg::Camera* camera) { _distortionCamera = camera;} |
---|
| 70 | osg::Camera* getDistortionCamera() { return _distortionCamera.get(); } |
---|
| 71 | |
---|
[353] | 72 | osg::Switch* getDistortionInternals() { return _distortionInternals; } |
---|
[350] | 73 | |
---|
[361] | 74 | osg::Shader* getShaderIntensityMap() { return shaderIntensityMap; } |
---|
| 75 | void setShaderIntensityMap(osg::Shader* shader) { shaderIntensityMap = shader; } |
---|
| 76 | osg::Shader* getShaderIntensityMapVis() { return shaderIntensityMapVis; } |
---|
| 77 | void setShaderIntensityMapVis(osg::Shader* shader) { shaderIntensityMapVis = shader; } |
---|
[353] | 78 | |
---|
[408] | 79 | osg::Matrixd& getProjectionOffset() { return _projectionOffset; } |
---|
[353] | 80 | |
---|
[360] | 81 | |
---|
[408] | 82 | |
---|
[350] | 83 | // Serializer Access |
---|
[344] | 84 | void setDistortionMeshRows(int distortionMeshRows) { _distortionMeshRows = distortionMeshRows; } |
---|
[345] | 85 | int getDistortionMeshRows() const { return _distortionMeshRows; } |
---|
[344] | 86 | |
---|
| 87 | void setDistortionMeshColumns(int distortionMeshColumns) { _distortionMeshColumns = distortionMeshColumns; } |
---|
[345] | 88 | int getDistortionMeshColumns() const { return _distortionMeshColumns; } |
---|
[344] | 89 | |
---|
[383] | 90 | void setDistortionMesh(osg::Vec4Array* distortionMesh) { _distortionMesh = distortionMesh; } |
---|
| 91 | const osg::Vec4Array* getDistortionMesh() const { return _distortionMesh; } |
---|
[374] | 92 | |
---|
[345] | 93 | void setMeshType(GLenum meshType) { _meshType = meshType; } |
---|
| 94 | inline GLenum getMeshType() const { return _meshType; } |
---|
| 95 | |
---|
[344] | 96 | void setIntensityMap(osg::Image* intensityMap) { _intensityMap = intensityMap; } |
---|
[350] | 97 | const osg::Image* getIntensityMap() const { return _intensityMap; } |
---|
[344] | 98 | |
---|
[350] | 99 | |
---|
[344] | 100 | void setTexUnitScene(unsigned int texUnitScene) { _texUnitScene = texUnitScene; } |
---|
[345] | 101 | unsigned int getTexUnitScene() const { return _texUnitScene; } |
---|
[344] | 102 | |
---|
| 103 | void setTexUnitIntensityMap(unsigned int texUnitIntensityMap) { _texUnitIntensityMap = texUnitIntensityMap; } |
---|
[345] | 104 | unsigned int getTexUnitIntensityMap() const { return _texUnitIntensityMap; } |
---|
[344] | 105 | |
---|
| 106 | void setViewOffset(const osg::Matrixd& viewOffset) { _viewOffset = viewOffset; } |
---|
[345] | 107 | const osg::Matrixd& getViewOffset() const { return _viewOffset; } |
---|
[344] | 108 | |
---|
| 109 | void setProjectionOffset(const osg::Matrixd& projectionOffset) { _projectionOffset = projectionOffset; } |
---|
[345] | 110 | const osg::Matrixd& getProjectionOffset() const { return _projectionOffset; } |
---|
[344] | 111 | |
---|
[350] | 112 | void setShowIntensityMapOnly(bool show) {_showIntesityMapMapOnly = show;} |
---|
| 113 | bool getShowIntensityMapOnly() const { return _showIntesityMapMapOnly;} |
---|
| 114 | |
---|
| 115 | |
---|
[344] | 116 | private: |
---|
[383] | 117 | // Blendmap has no dirty flag because changes of the intensityMap is directly effective. |
---|
| 118 | bool _meshDirty; |
---|
| 119 | bool _matrixDirty; |
---|
| 120 | |
---|
[344] | 121 | int _distortionMeshRows; |
---|
| 122 | int _distortionMeshColumns; |
---|
[383] | 123 | osg::ref_ptr<osg::Vec4Array> _distortionMesh; // x,y = vertex coordinates, z,t=textureCoordinates |
---|
[345] | 124 | GLenum _meshType; |
---|
[344] | 125 | |
---|
| 126 | osg::ref_ptr<osg::Image> _intensityMap; |
---|
| 127 | unsigned int _texUnitScene; |
---|
| 128 | unsigned int _texUnitIntensityMap; |
---|
| 129 | |
---|
| 130 | osg::Matrixd _viewOffset; |
---|
| 131 | osg::Matrixd _projectionOffset; |
---|
| 132 | |
---|
[374] | 133 | // Interconnect-Pointer to allow access between distortion elements (osgViewer) and the distortion manipulator. |
---|
| 134 | // These variable are therefor not saved/restored by the serializer but populated on runtime. |
---|
[350] | 135 | bool _showIntesityMapMapOnly; // Intensity Blending is done by a frag shader. To control it on runtime, the uniform must be bound to a central variable. |
---|
[398] | 136 | osg::observer_ptr<osg::Camera> _sceneCamera; // us used to pass the scene camera to the manipulator to allow matrix changes of the camera |
---|
| 137 | osg::observer_ptr<osg::Camera> _distortionCamera; // is used to pass the distortion cam from osgViewers setupDistortion() method to the manipulator. |
---|
[357] | 138 | osg::ref_ptr<osg::Switch> _distortionInternals; // definition: child #0 = mesh, #1 = highlighter, #2 HUD |
---|
[361] | 139 | |
---|
| 140 | osg::ref_ptr<osg::Shader> shaderIntensityMap; // used in 99%, it provides active intensity map blending |
---|
| 141 | osg::ref_ptr<osg::Shader> shaderIntensityMapVis; // only used during setup process, this shaders discards the fragment color and only displays the intensitymapcolor to visualize the blendmap |
---|
[344] | 142 | }; |
---|
| 143 | |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | #endif |
---|