source: experimental/distortionNG/DistortionSet.cpp @ 398

Last change on this file since 398 was 398, checked in by Torben Dannhauer, 12 years ago
File size: 3.6 KB
Line 
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
22using namespace osgViewer;
23
24DistortionSet::DistortionSet()
25{
26        _meshDirty = false;
27        _matrixDirty = false;
28
29        _distortionMeshRows = 2;
30        _distortionMeshColumns = 2;
31        _distortionMesh = new osg::Vec4Array();
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;
41
42        _sceneCamera = NULL;
43        _distortionCamera = NULL;
44        _distortionInternals = NULL;
45
46        _distortionInternals = new osg::Switch();
47
48}
49
50DistortionSet::~DistortionSet()
51{
52}
53
54void DistortionSet::setDistortionMeshDimensions(int rows, int cols)
55{
56        _distortionMeshRows = rows;
57        _distortionMeshColumns = cols;
58
59        if(_distortionMesh->size() != _distortionMeshRows * _distortionMeshColumns)     // If dimensions differ: discard current mesh and create a new one
60        {
61                _distortionMesh = new osg::Vec4Array(_distortionMeshRows * _distortionMeshColumns);
62                for(int row=0;row<_distortionMeshRows;row++)
63                {
64                        for(int col=0;col<_distortionMeshColumns;col++)
65                        {
66                                float x=col/_distortionMeshColumns;     // Vertex X
67                                float y=row/_distortionMeshRows;        // Vertex Y
68                                float z=col/_distortionMeshColumns;     // TexCoord X
69                                float w=row/_distortionMeshRows;        // TexCoord Y
70
71                                _distortionMesh->at(row*_distortionMeshColumns+col).set(x,y,z,w);
72                        }
73                }
74        }
75}
76
77
78REGISTER_OBJECT_WRAPPER( osgViewer_DistortionSet,                  // The unique wrapper name
79                         new osgViewer::DistortionSet,             // The proto
80                         osgViewer::DistortionSet,                 // The class typename
81                         "osg::Object osgViewer::DistortionSet" )  // The inheritance relations
82{
83    // Serializers for different members
84        ADD_INT_SERIALIZER( DistortionMeshRows, 1 );    //int _distortionMeshRows;
85        ADD_INT_SERIALIZER( DistortionMeshColumns, 1 ); //int _distortionMeshColumns;
86        ADD_OBJECT_SERIALIZER( DistortionMesh, osg::Vec4Array, NULL );  // x,y = vertex coordinates, z,t=textureCoordinates, Werte sind normalisiert auf 0-1
87
88    ADD_GLENUM_SERIALIZER( MeshType, GLenum, GL_QUAD_STRIP );  //osg::PrimitiveSet::Mode _MeshType
89       
90        ADD_IMAGE_SERIALIZER( IntensityMap, osg::Image, NULL );  //osg::ref_ptr<osg::Image> _intensityMap;
91
92        ADD_UINT_SERIALIZER( TexUnitScene, 0 ); //unsigned int _texUnitScene;
93        ADD_UINT_SERIALIZER( TexUnitIntensityMap, 1 );  //unsigned int _texUnitIntensityMap;
94
95        ADD_MATRIX_SERIALIZER( ViewOffset, osg::Matrix() );     //osg::Matrix _viewOffset;
96        ADD_MATRIX_SERIALIZER( ProjectionOffset, osg::Matrix() );       //osg::Matrix _projectionOffset;
97
98        ADD_BOOL_SERIALIZER( ShowIntensityMapOnly, false );     //bool _showIntesityMapMapOnly
99}
Note: See TracBrowser for help on using the repository browser.