source: experimental/distortionNG/DistortionSet.h @ 365

Last change on this file since 365 was 361, checked in by Torben Dannhauer, 13 years ago
File size: 5.2 KB
RevLine 
[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>
[344]26
27namespace osgViewer {
28
29class DistortionSet : public osg::Object
30{
31public:
[357]32        enum DistortionInternals {
33                MESH = 0,
34                HIGHLIGHTER = 1,
35                HUD = 2
36        };
37
[344]38        META_Object(osgViewer,DistortionSet);   // Required for serializer
39
40        DistortionSet(const osgViewer::DistortionSet& ds, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): // Required for serializer
41                _distortionMeshRows(ds._distortionMeshRows),
42                _distortionMeshColumns(ds._distortionMeshColumns),
43                //osg::PrimitiveSet::Mode _MeshType
44                _intensityMap(ds._intensityMap),
45                _texUnitScene(ds._texUnitScene),
46                _texUnitIntensityMap(ds._texUnitIntensityMap),
47                _viewOffset(ds._viewOffset),
[350]48                _projectionOffset(ds._projectionOffset),
49                _showIntesityMapMapOnly(ds._showIntesityMapMapOnly){}
[344]50
51        DistortionSet();
52        virtual ~DistortionSet();
53
[350]54        // Working access
55        osg::Image* getIntensityMap()  { return _intensityMap; }        // Also for manipulating the intensity map
56        bool& getShowIntensityMapOnlyAsRef()    { return _showIntesityMapMapOnly;}
57
[353]58        void setDistortionCamera(osg::Camera* camera)   { _camera = camera;}
59        osg::Camera* getDistortionCamera()      { return _camera.get(); }
[350]60
[353]61        osg::Switch* getDistortionInternals()   { return _distortionInternals; }
[350]62
[361]63        osg::Shader* getShaderIntensityMap()    { return shaderIntensityMap; }
64        void setShaderIntensityMap(osg::Shader* shader) { shaderIntensityMap = shader; }
65        osg::Shader* getShaderIntensityMapVis() { return shaderIntensityMapVis; }
66        void setShaderIntensityMapVis(osg::Shader* shader)      { shaderIntensityMapVis = shader; }
[353]67
68
[360]69
[350]70        // Serializer Access
[344]71        void setDistortionMeshRows(int distortionMeshRows)              { _distortionMeshRows = distortionMeshRows; }
[345]72        int getDistortionMeshRows() const       { return _distortionMeshRows; }
[344]73
74        void setDistortionMeshColumns(int distortionMeshColumns)                { _distortionMeshColumns = distortionMeshColumns; }
[345]75        int getDistortionMeshColumns() const    { return _distortionMeshColumns; }
[344]76
[345]77        void setMeshType(GLenum meshType) { _meshType = meshType; }
78    inline GLenum getMeshType() const { return _meshType; }
79
[344]80        void setIntensityMap(osg::Image* intensityMap)          { _intensityMap = intensityMap; }
[350]81        const osg::Image* getIntensityMap() const       { return _intensityMap; }
[344]82
[350]83
[344]84        void setTexUnitScene(unsigned int texUnitScene)         { _texUnitScene = texUnitScene; }
[345]85        unsigned int getTexUnitScene() const    { return _texUnitScene; }
[344]86
87        void setTexUnitIntensityMap(unsigned int texUnitIntensityMap)   { _texUnitIntensityMap = texUnitIntensityMap; }
[345]88        unsigned int getTexUnitIntensityMap() const     { return _texUnitIntensityMap; }
[344]89
90        void setViewOffset(const osg::Matrixd& viewOffset)      { _viewOffset = viewOffset; }
[345]91        const osg::Matrixd& getViewOffset() const       { return _viewOffset; }
[344]92
93        void setProjectionOffset(const osg::Matrixd& projectionOffset)          { _projectionOffset = projectionOffset; }
[345]94        const osg::Matrixd& getProjectionOffset() const { return _projectionOffset; }
[344]95
[350]96        void setShowIntensityMapOnly(bool show) {_showIntesityMapMapOnly = show;}
97        bool getShowIntensityMapOnly() const    { return _showIntesityMapMapOnly;}
98
99
[344]100private:
101        int _distortionMeshRows;
102        int _distortionMeshColumns;
[345]103        GLenum _meshType;
[344]104       
105        osg::ref_ptr<osg::Image> _intensityMap;
106        unsigned int _texUnitScene;
107        unsigned int _texUnitIntensityMap;
108
109        osg::Matrixd _viewOffset;
110        osg::Matrixd _projectionOffset;
111
[350]112        bool _showIntesityMapMapOnly;   // Intensity Blending is done by a frag shader. To control it on runtime, the uniform must be bound to a central variable.
[353]113
114        // Interconnect-Pointer to allow acces between distortion elements (osgViewer) and the distortion manipulator.
115        // These variable are therefor not saved/restored by the serializer but populated on runtime.
116        osg::observer_ptr<osg::Camera> _camera; // is used to pass the distortion cam from osgViewers setupDistortion() method to the manipulator.
[357]117        osg::ref_ptr<osg::Switch> _distortionInternals; // definition: child #0 = mesh, #1 = highlighter, #2 HUD
[361]118
119        osg::ref_ptr<osg::Shader> shaderIntensityMap;   // used in 99%, it provides active intensity map blending
120        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]121};
122
123}
124
125
126#endif
Note: See TracBrowser for help on using the repository browser.