#ifndef OSGVIEWER_DistortionSet #define OSGVIEWER_DistortionSet 1 /* -*-c++-*- osgVisual - Copyright (C) 2009-2012 Torben Dannhauer * * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. * You have to aquire licenses for all used proprietary modules. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include namespace osgViewer { class DistortionSet : public osg::Object { public: enum DistortionInternals { MESH = 0, HIGHLIGHTER = 1, HUD = 2 }; META_Object(osgViewer,DistortionSet); // Required for serializer DistortionSet(const osgViewer::DistortionSet& ds, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): // Required for serializer _distortionMeshRows(ds._distortionMeshRows), _distortionMeshColumns(ds._distortionMeshColumns), //osg::PrimitiveSet::Mode _MeshType _intensityMap(ds._intensityMap), _texUnitScene(ds._texUnitScene), _texUnitIntensityMap(ds._texUnitIntensityMap), _viewOffset(ds._viewOffset), _projectionOffset(ds._projectionOffset), _showIntesityMapMapOnly(ds._showIntesityMapMapOnly){} DistortionSet(); virtual ~DistortionSet(); // Working access bool isDirty(){return(_meshDirty || _matrixDirty);} void dirtyMesh(){_meshDirty = true;} void dirtyMatrix(){_matrixDirty = true;} void clearDirtyStatus() { _meshDirty = false; _matrixDirty = false;} void setDistortionMeshDimensions(int rows, int cols); osg::Image* getIntensityMap() { return _intensityMap; } // Also for manipulating the intensity map bool& getShowIntensityMapOnlyAsRef() { return _showIntesityMapMapOnly;} void setSceneCamera(osg::Camera* camera) { _sceneCamera = camera;} osg::Camera* getSceneCamera() { return _sceneCamera.get(); } void setDistortionCamera(osg::Camera* camera) { _distortionCamera = camera;} osg::Camera* getDistortionCamera() { return _distortionCamera.get(); } osg::Switch* getDistortionInternals() { return _distortionInternals; } osg::Shader* getShaderIntensityMap() { return shaderIntensityMap; } void setShaderIntensityMap(osg::Shader* shader) { shaderIntensityMap = shader; } osg::Shader* getShaderIntensityMapVis() { return shaderIntensityMapVis; } void setShaderIntensityMapVis(osg::Shader* shader) { shaderIntensityMapVis = shader; } // Serializer Access void setDistortionMeshRows(int distortionMeshRows) { _distortionMeshRows = distortionMeshRows; } int getDistortionMeshRows() const { return _distortionMeshRows; } void setDistortionMeshColumns(int distortionMeshColumns) { _distortionMeshColumns = distortionMeshColumns; } int getDistortionMeshColumns() const { return _distortionMeshColumns; } void setDistortionMesh(osg::Vec4Array* distortionMesh) { _distortionMesh = distortionMesh; } const osg::Vec4Array* getDistortionMesh() const { return _distortionMesh; } void setMeshType(GLenum meshType) { _meshType = meshType; } inline GLenum getMeshType() const { return _meshType; } void setIntensityMap(osg::Image* intensityMap) { _intensityMap = intensityMap; } const osg::Image* getIntensityMap() const { return _intensityMap; } void setTexUnitScene(unsigned int texUnitScene) { _texUnitScene = texUnitScene; } unsigned int getTexUnitScene() const { return _texUnitScene; } void setTexUnitIntensityMap(unsigned int texUnitIntensityMap) { _texUnitIntensityMap = texUnitIntensityMap; } unsigned int getTexUnitIntensityMap() const { return _texUnitIntensityMap; } void setViewOffset(const osg::Matrixd& viewOffset) { _viewOffset = viewOffset; } const osg::Matrixd& getViewOffset() const { return _viewOffset; } void setProjectionOffset(const osg::Matrixd& projectionOffset) { _projectionOffset = projectionOffset; } const osg::Matrixd& getProjectionOffset() const { return _projectionOffset; } void setShowIntensityMapOnly(bool show) {_showIntesityMapMapOnly = show;} bool getShowIntensityMapOnly() const { return _showIntesityMapMapOnly;} private: // Blendmap has no dirty flag because changes of the intensityMap is directly effective. bool _meshDirty; bool _matrixDirty; int _distortionMeshRows; int _distortionMeshColumns; osg::ref_ptr _distortionMesh; // x,y = vertex coordinates, z,t=textureCoordinates GLenum _meshType; osg::ref_ptr _intensityMap; unsigned int _texUnitScene; unsigned int _texUnitIntensityMap; osg::Matrixd _viewOffset; osg::Matrixd _projectionOffset; // Interconnect-Pointer to allow access between distortion elements (osgViewer) and the distortion manipulator. // These variable are therefor not saved/restored by the serializer but populated on runtime. bool _showIntesityMapMapOnly; // Intensity Blending is done by a frag shader. To control it on runtime, the uniform must be bound to a central variable. osg::observer_ptr _sceneCamera; // us used to pass the scene camera to the manipulator to allow matrix changes of the camera osg::observer_ptr _distortionCamera; // is used to pass the distortion cam from osgViewers setupDistortion() method to the manipulator. osg::ref_ptr _distortionInternals; // definition: child #0 = mesh, #1 = highlighter, #2 HUD osg::ref_ptr shaderIntensityMap; // used in 99%, it provides active intensity map blending osg::ref_ptr shaderIntensityMapVis; // only used during setup process, this shaders discards the fragment color and only displays the intensitymapcolor to visualize the blendmap }; } #endif