[344] | 1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2012 Torben Dannhauer |
---|
| 2 | * |
---|
| 3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 7 | * |
---|
| 8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 9 | * You have to aquire licenses for all used proprietary modules. |
---|
| 10 | * |
---|
| 11 | * This library is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * OpenSceneGraph Public License for more details. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include "DistortionSet.h" |
---|
| 18 | #include <osgDB/ObjectWrapper> |
---|
| 19 | #include <osgDB/InputStream> |
---|
| 20 | #include <osgDB/OutputStream> |
---|
| 21 | |
---|
| 22 | using namespace osgViewer; |
---|
| 23 | |
---|
| 24 | DistortionSet::DistortionSet() |
---|
| 25 | { |
---|
[383] | 26 | _meshDirty = false; |
---|
| 27 | _matrixDirty = false; |
---|
[379] | 28 | |
---|
[407] | 29 | setDistortionMeshDimensions(2, 2); |
---|
[350] | 30 | |
---|
| 31 | _intensityMap = NULL; |
---|
| 32 | _texUnitScene = 0; |
---|
| 33 | _texUnitIntensityMap = 1; |
---|
| 34 | |
---|
| 35 | _viewOffset = osg::Matrixd::identity(); |
---|
| 36 | _projectionOffset = osg::Matrixd::identity(); |
---|
| 37 | |
---|
| 38 | _showIntesityMapMapOnly = false; |
---|
[353] | 39 | |
---|
[398] | 40 | _sceneCamera = NULL; |
---|
| 41 | _distortionCamera = NULL; |
---|
[353] | 42 | _distortionInternals = NULL; |
---|
| 43 | |
---|
| 44 | _distortionInternals = new osg::Switch(); |
---|
[361] | 45 | |
---|
[344] | 46 | } |
---|
| 47 | |
---|
| 48 | DistortionSet::~DistortionSet() |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
[407] | 52 | void DistortionSet::setDistortionMeshDimensions(int rows, int cols, bool enforceMeshRebuild) |
---|
[374] | 53 | { |
---|
[383] | 54 | _distortionMeshRows = rows; |
---|
| 55 | _distortionMeshColumns = cols; |
---|
[374] | 56 | |
---|
[407] | 57 | if(!_distortionMesh.valid() || enforceMeshRebuild || _distortionMesh->size() != _distortionMeshRows * _distortionMeshColumns) // If dimensions differ: discard current mesh and create a new one |
---|
[383] | 58 | { |
---|
[392] | 59 | _distortionMesh = new osg::Vec4Array(_distortionMeshRows * _distortionMeshColumns); |
---|
[383] | 60 | for(int row=0;row<_distortionMeshRows;row++) |
---|
| 61 | { |
---|
| 62 | for(int col=0;col<_distortionMeshColumns;col++) |
---|
| 63 | { |
---|
[407] | 64 | float x=col/(float)(_distortionMeshColumns-1); // Vertex X |
---|
| 65 | float y=row/(float)(_distortionMeshRows-1); // Vertex Y |
---|
| 66 | float z=col/(float)(_distortionMeshColumns-1); // TexCoord X |
---|
| 67 | float w=row/(float)(_distortionMeshRows-1); // TexCoord Y |
---|
[383] | 68 | |
---|
| 69 | _distortionMesh->at(row*_distortionMeshColumns+col).set(x,y,z,w); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
[374] | 73 | } |
---|
| 74 | |
---|
[383] | 75 | |
---|
[344] | 76 | REGISTER_OBJECT_WRAPPER( osgViewer_DistortionSet, // The unique wrapper name |
---|
| 77 | new osgViewer::DistortionSet, // The proto |
---|
| 78 | osgViewer::DistortionSet, // The class typename |
---|
| 79 | "osg::Object osgViewer::DistortionSet" ) // The inheritance relations |
---|
| 80 | { |
---|
| 81 | // Serializers for different members |
---|
| 82 | ADD_INT_SERIALIZER( DistortionMeshRows, 1 ); //int _distortionMeshRows; |
---|
| 83 | ADD_INT_SERIALIZER( DistortionMeshColumns, 1 ); //int _distortionMeshColumns; |
---|
[383] | 84 | ADD_OBJECT_SERIALIZER( DistortionMesh, osg::Vec4Array, NULL ); // x,y = vertex coordinates, z,t=textureCoordinates, Werte sind normalisiert auf 0-1 |
---|
[344] | 85 | |
---|
[345] | 86 | ADD_GLENUM_SERIALIZER( MeshType, GLenum, GL_QUAD_STRIP ); //osg::PrimitiveSet::Mode _MeshType |
---|
[344] | 87 | |
---|
[345] | 88 | ADD_IMAGE_SERIALIZER( IntensityMap, osg::Image, NULL ); //osg::ref_ptr<osg::Image> _intensityMap; |
---|
[344] | 89 | |
---|
| 90 | ADD_UINT_SERIALIZER( TexUnitScene, 0 ); //unsigned int _texUnitScene; |
---|
| 91 | ADD_UINT_SERIALIZER( TexUnitIntensityMap, 1 ); //unsigned int _texUnitIntensityMap; |
---|
| 92 | |
---|
| 93 | ADD_MATRIX_SERIALIZER( ViewOffset, osg::Matrix() ); //osg::Matrix _viewOffset; |
---|
| 94 | ADD_MATRIX_SERIALIZER( ProjectionOffset, osg::Matrix() ); //osg::Matrix _projectionOffset; |
---|
[350] | 95 | |
---|
| 96 | ADD_BOOL_SERIALIZER( ShowIntensityMapOnly, false ); //bool _showIntesityMapMapOnly |
---|
[344] | 97 | } |
---|