/* -*-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 "DistortionSet.h" #include #include #include using namespace osgViewer; DistortionSet::DistortionSet() { _meshDirty = false; _matrixDirty = false; _distortionMeshRows = 2; _distortionMeshColumns = 2; _distortionMesh = new osg::Vec4Array(); _intensityMap = NULL; _texUnitScene = 0; _texUnitIntensityMap = 1; _viewOffset = osg::Matrixd::identity(); _projectionOffset = osg::Matrixd::identity(); _showIntesityMapMapOnly = false; _sceneCamera = NULL; _distortionCamera = NULL; _distortionInternals = NULL; _distortionInternals = new osg::Switch(); } DistortionSet::~DistortionSet() { } void DistortionSet::setDistortionMeshDimensions(int rows, int cols) { _distortionMeshRows = rows; _distortionMeshColumns = cols; if(_distortionMesh->size() != _distortionMeshRows * _distortionMeshColumns) // If dimensions differ: discard current mesh and create a new one { _distortionMesh = new osg::Vec4Array(_distortionMeshRows * _distortionMeshColumns); for(int row=0;row<_distortionMeshRows;row++) { for(int col=0;col<_distortionMeshColumns;col++) { float x=col/_distortionMeshColumns; // Vertex X float y=row/_distortionMeshRows; // Vertex Y float z=col/_distortionMeshColumns; // TexCoord X float w=row/_distortionMeshRows; // TexCoord Y _distortionMesh->at(row*_distortionMeshColumns+col).set(x,y,z,w); } } } } REGISTER_OBJECT_WRAPPER( osgViewer_DistortionSet, // The unique wrapper name new osgViewer::DistortionSet, // The proto osgViewer::DistortionSet, // The class typename "osg::Object osgViewer::DistortionSet" ) // The inheritance relations { // Serializers for different members ADD_INT_SERIALIZER( DistortionMeshRows, 1 ); //int _distortionMeshRows; ADD_INT_SERIALIZER( DistortionMeshColumns, 1 ); //int _distortionMeshColumns; ADD_OBJECT_SERIALIZER( DistortionMesh, osg::Vec4Array, NULL ); // x,y = vertex coordinates, z,t=textureCoordinates, Werte sind normalisiert auf 0-1 ADD_GLENUM_SERIALIZER( MeshType, GLenum, GL_QUAD_STRIP ); //osg::PrimitiveSet::Mode _MeshType ADD_IMAGE_SERIALIZER( IntensityMap, osg::Image, NULL ); //osg::ref_ptr _intensityMap; ADD_UINT_SERIALIZER( TexUnitScene, 0 ); //unsigned int _texUnitScene; ADD_UINT_SERIALIZER( TexUnitIntensityMap, 1 ); //unsigned int _texUnitIntensityMap; ADD_MATRIX_SERIALIZER( ViewOffset, osg::Matrix() ); //osg::Matrix _viewOffset; ADD_MATRIX_SERIALIZER( ProjectionOffset, osg::Matrix() ); //osg::Matrix _projectionOffset; ADD_BOOL_SERIALIZER( ShowIntensityMapOnly, false ); //bool _showIntesityMapMapOnly }