[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 | |
---|
[360] | 29 | _distortionMeshRows = 2; |
---|
| 30 | _distortionMeshColumns = 2; |
---|
[383] | 31 | _distortionMesh = new osg::Vec4Array(); |
---|
[350] | 32 | |
---|
| 33 | _intensityMap = NULL; |
---|
| 34 | _texUnitScene = 0; |
---|
| 35 | _texUnitIntensityMap = 1; |
---|
| 36 | |
---|
| 37 | _viewOffset = osg::Matrixd::identity(); |
---|
| 38 | _projectionOffset = osg::Matrixd::identity(); |
---|
| 39 | |
---|
| 40 | _showIntesityMapMapOnly = false; |
---|
[353] | 41 | |
---|
| 42 | _camera = NULL; |
---|
| 43 | _distortionInternals = NULL; |
---|
| 44 | |
---|
| 45 | _distortionInternals = new osg::Switch(); |
---|
[361] | 46 | |
---|
[344] | 47 | } |
---|
| 48 | |
---|
| 49 | DistortionSet::~DistortionSet() |
---|
| 50 | { |
---|
| 51 | } |
---|
| 52 | |
---|
[383] | 53 | void DistortionSet::setDistortionMeshDimensions(int rows, int cols) |
---|
[374] | 54 | { |
---|
[383] | 55 | _distortionMeshRows = rows; |
---|
| 56 | _distortionMeshColumns = cols; |
---|
[374] | 57 | |
---|
[383] | 58 | if(_distortionMesh->size() != _distortionMeshRows * _distortionMeshRows) // If dimensions differ: discard current mesh and createa new one |
---|
| 59 | { |
---|
| 60 | _distortionMesh = new osg::Vec4Array(_distortionMeshRows * _distortionMeshRows); |
---|
| 61 | for(int row=0;row<_distortionMeshRows;row++) |
---|
| 62 | { |
---|
| 63 | for(int col=0;col<_distortionMeshColumns;col++) |
---|
| 64 | { |
---|
| 65 | float x=col/_distortionMeshColumns; // Vertex X |
---|
| 66 | float y=row/_distortionMeshRows; // Vertex Y |
---|
| 67 | float z=col/_distortionMeshColumns; // TexCoord X |
---|
| 68 | float w=row/_distortionMeshRows; // TexCoord Y |
---|
| 69 | |
---|
| 70 | _distortionMesh->at(row*_distortionMeshColumns+col).set(x,y,z,w); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|
[374] | 74 | } |
---|
| 75 | |
---|
[383] | 76 | |
---|
[344] | 77 | REGISTER_OBJECT_WRAPPER( osgViewer_DistortionSet, // The unique wrapper name |
---|
| 78 | new osgViewer::DistortionSet, // The proto |
---|
| 79 | osgViewer::DistortionSet, // The class typename |
---|
| 80 | "osg::Object osgViewer::DistortionSet" ) // The inheritance relations |
---|
| 81 | { |
---|
| 82 | // Serializers for different members |
---|
| 83 | ADD_INT_SERIALIZER( DistortionMeshRows, 1 ); //int _distortionMeshRows; |
---|
| 84 | ADD_INT_SERIALIZER( DistortionMeshColumns, 1 ); //int _distortionMeshColumns; |
---|
[383] | 85 | ADD_OBJECT_SERIALIZER( DistortionMesh, osg::Vec4Array, NULL ); // x,y = vertex coordinates, z,t=textureCoordinates, Werte sind normalisiert auf 0-1 |
---|
[344] | 86 | |
---|
[345] | 87 | ADD_GLENUM_SERIALIZER( MeshType, GLenum, GL_QUAD_STRIP ); //osg::PrimitiveSet::Mode _MeshType |
---|
[344] | 88 | |
---|
[345] | 89 | ADD_IMAGE_SERIALIZER( IntensityMap, osg::Image, NULL ); //osg::ref_ptr<osg::Image> _intensityMap; |
---|
[344] | 90 | |
---|
| 91 | ADD_UINT_SERIALIZER( TexUnitScene, 0 ); //unsigned int _texUnitScene; |
---|
| 92 | ADD_UINT_SERIALIZER( TexUnitIntensityMap, 1 ); //unsigned int _texUnitIntensityMap; |
---|
| 93 | |
---|
| 94 | ADD_MATRIX_SERIALIZER( ViewOffset, osg::Matrix() ); //osg::Matrix _viewOffset; |
---|
| 95 | ADD_MATRIX_SERIALIZER( ProjectionOffset, osg::Matrix() ); //osg::Matrix _projectionOffset; |
---|
[350] | 96 | |
---|
| 97 | ADD_BOOL_SERIALIZER( ShowIntensityMapOnly, false ); //bool _showIntesityMapMapOnly |
---|
[344] | 98 | } |
---|