source: experimental/distortionNG/DistortionSet.h @ 386

Last change on this file since 386 was 383, checked in by Torben Dannhauer, 12 years ago
File size: 5.8 KB
Line 
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>
23#include <osg/Camera>
24#include <osg/Switch>
25#include <osg/Shader>
26#include <osg/Geometry>
27
28namespace osgViewer {
29
30class DistortionSet : public osg::Object
31{
32public:
33        enum DistortionInternals {
34                MESH = 0,
35                HIGHLIGHTER = 1,
36                HUD = 2
37        };
38
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),
49                _projectionOffset(ds._projectionOffset),
50                _showIntesityMapMapOnly(ds._showIntesityMapMapOnly){}
51
52        DistortionSet();
53        virtual ~DistortionSet();
54
55        // Working access
56        bool isDirty(){return(_meshDirty || _matrixDirty);}
57        void dirtyMesh(){_meshDirty = true;}
58        void dirtyMatrix(){_matrixDirty = true;}
59        void clearDirtyStatus() { _meshDirty = false; _matrixDirty = false;}
60       
61        void setDistortionMeshDimensions(int rows, int cols);
62
63        osg::Image* getIntensityMap()  { return _intensityMap; }        // Also for manipulating the intensity map
64        bool& getShowIntensityMapOnlyAsRef()    { return _showIntesityMapMapOnly;}
65
66        void setDistortionCamera(osg::Camera* camera)   { _camera = camera;}
67        osg::Camera* getDistortionCamera()      { return _camera.get(); }
68
69        osg::Switch* getDistortionInternals()   { return _distortionInternals; }
70
71        osg::Shader* getShaderIntensityMap()    { return shaderIntensityMap; }
72        void setShaderIntensityMap(osg::Shader* shader) { shaderIntensityMap = shader; }
73        osg::Shader* getShaderIntensityMapVis() { return shaderIntensityMapVis; }
74        void setShaderIntensityMapVis(osg::Shader* shader)      { shaderIntensityMapVis = shader; }
75
76
77
78        // Serializer Access
79        void setDistortionMeshRows(int distortionMeshRows)              { _distortionMeshRows = distortionMeshRows; }
80        int getDistortionMeshRows() const       { return _distortionMeshRows; }
81
82        void setDistortionMeshColumns(int distortionMeshColumns)                { _distortionMeshColumns = distortionMeshColumns; }
83        int getDistortionMeshColumns() const    { return _distortionMeshColumns; }
84
85        void setDistortionMesh(osg::Vec4Array* distortionMesh)  { _distortionMesh = distortionMesh; }
86        const osg::Vec4Array* getDistortionMesh() const { return _distortionMesh; }
87
88        void setMeshType(GLenum meshType) { _meshType = meshType; }
89    inline GLenum getMeshType() const { return _meshType; }
90
91        void setIntensityMap(osg::Image* intensityMap)          { _intensityMap = intensityMap; }
92        const osg::Image* getIntensityMap() const       { return _intensityMap; }
93
94
95        void setTexUnitScene(unsigned int texUnitScene)         { _texUnitScene = texUnitScene; }
96        unsigned int getTexUnitScene() const    { return _texUnitScene; }
97
98        void setTexUnitIntensityMap(unsigned int texUnitIntensityMap)   { _texUnitIntensityMap = texUnitIntensityMap; }
99        unsigned int getTexUnitIntensityMap() const     { return _texUnitIntensityMap; }
100
101        void setViewOffset(const osg::Matrixd& viewOffset)      { _viewOffset = viewOffset; }
102        const osg::Matrixd& getViewOffset() const       { return _viewOffset; }
103
104        void setProjectionOffset(const osg::Matrixd& projectionOffset)          { _projectionOffset = projectionOffset; }
105        const osg::Matrixd& getProjectionOffset() const { return _projectionOffset; }
106
107        void setShowIntensityMapOnly(bool show) {_showIntesityMapMapOnly = show;}
108        bool getShowIntensityMapOnly() const    { return _showIntesityMapMapOnly;}
109
110
111private:
112        // Blendmap has no dirty flag because changes of the intensityMap is directly effective.
113        bool _meshDirty;
114        bool _matrixDirty;
115
116        int _distortionMeshRows;
117        int _distortionMeshColumns;
118        osg::ref_ptr<osg::Vec4Array> _distortionMesh;   // x,y = vertex coordinates, z,t=textureCoordinates
119        GLenum _meshType;
120       
121        osg::ref_ptr<osg::Image> _intensityMap;
122        unsigned int _texUnitScene;
123        unsigned int _texUnitIntensityMap;
124
125        osg::Matrixd _viewOffset;
126        osg::Matrixd _projectionOffset;
127
128        // Interconnect-Pointer to allow access between distortion elements (osgViewer) and the distortion manipulator.
129        // These variable are therefor not saved/restored by the serializer but populated on runtime.
130        bool _showIntesityMapMapOnly;   // Intensity Blending is done by a frag shader. To control it on runtime, the uniform must be bound to a central variable.
131        osg::observer_ptr<osg::Camera> _camera; // is used to pass the distortion cam from osgViewers setupDistortion() method to the manipulator.
132        osg::ref_ptr<osg::Switch> _distortionInternals; // definition: child #0 = mesh, #1 = highlighter, #2 HUD
133
134        osg::ref_ptr<osg::Shader> shaderIntensityMap;   // used in 99%, it provides active intensity map blending
135        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
136};
137
138}
139
140
141#endif
Note: See TracBrowser for help on using the repository browser.