root/OpenSceneGraph/trunk/include/osgUtil/OperationArrayFunctor @ 13041

Revision 13041, 4.1 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is 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 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_OPERATIONARRAYFUNCTOR
15#define OSGUTIL_OPERATIONARRAYFUNCTOR 1
16
17
18#include <osg/Array>
19#include <osgUtil/ConvertVec>
20
21// ** template ArrayVisitor to handle all method in one template.
22// **  Only use when process done on each array could be templated
23
24namespace osgUtil {
25
26template <class T>
27class OperationArrayFunctor : public osg::ArrayVisitor, public T
28{
29    public:
30
31        virtual void apply(osg::Array&) {}
32//        virtual void apply(osg::ByteArray& array) { T::process<osg::ByteArray>(array); }
33//        virtual void apply(osg::ShortArray& array) { T::process(array); }
34//        virtual void apply(osg::IntArray& array) { T::process<osg::IntArray>(array); }
35//        virtual void apply(osg::UByteArray& array) { T::process<osg::UByteArray>(array); }
36//        virtual void apply(osg::UShortArray& array) { T::process<osg::UShortArray>(array); }
37//        virtual void apply(osg::UIntArray& array) { T::process<osg::UIntArray>(array); }
38//        virtual void apply(osg::FloatArray& array) { T::process<osg::FloatArray>(array); }
39//        virtual void apply(osg::DoubleArray& array) { T::process<osg::DoubleArray>(array); }
40
41        virtual void apply(osg::Vec2Array & array) { T::process(array); }
42        virtual void apply(osg::Vec3Array& array) { T::process(array); }
43        virtual void apply(osg::Vec4Array& array) { T::process(array); }
44
45        virtual void apply(osg::Vec4ubArray& array) { T::process(array); }
46
47        virtual void apply(osg::Vec2bArray& array) { T::process(array); }
48        virtual void apply(osg::Vec3bArray& array) { T::process(array); }
49        virtual void apply(osg::Vec4bArray& array) { T::process(array); }
50
51        virtual void apply(osg::Vec2sArray& array) { T::process(array); }
52        virtual void apply(osg::Vec3sArray& array) { T::process(array); }
53        virtual void apply(osg::Vec4sArray& array) { T::process(array); }
54
55        virtual void apply(osg::Vec2dArray& array) { T::process(array); }
56        virtual void apply(osg::Vec3dArray& array) { T::process(array); }
57        virtual void apply(osg::Vec4dArray& array) { T::process(array); }
58};
59
60struct AddRangeOperator
61{
62    template <typename ArrayType>
63    void process(ArrayType & array)
64    {
65        typedef typename ArrayType::ElementDataType ElementDataType;
66
67        ElementDataType convertedVector;
68        osgUtil::ConvertVec<osg::Vec3d, ElementDataType>::convert(_vector, convertedVector);
69
70        typename ArrayType::iterator it = array.begin();
71        std::advance(it, _begin);
72
73        typename ArrayType::iterator end = it;
74        std::advance(end, _count);
75
76        for (; it < end; ++it)
77            (*it) += convertedVector;
78    }
79
80    unsigned int _begin;
81    unsigned int _count;
82
83    osg::Vec3d _vector;
84};
85typedef OperationArrayFunctor<AddRangeOperator> AddRangeFunctor;
86
87struct MultiplyRangeOperator
88{
89    template <typename ArrayType>
90    void process(ArrayType & array)
91    {
92        typedef typename ArrayType::ElementDataType ElementDataType;
93
94        ElementDataType convertedVector;
95        osgUtil::ConvertVec<osg::Vec3d, ElementDataType>::convert(_vector, convertedVector);
96
97        typename ArrayType::iterator it = array.begin();
98        std::advance(it, _begin);
99
100        typename ArrayType::iterator end = it;
101        std::advance(end, _count);
102
103        for (; it < end; ++it)
104            (*it) *= convertedVector;
105    }
106
107    unsigned int _begin;
108    unsigned int _count;
109
110    osg::Vec3d _vector;
111};
112typedef OperationArrayFunctor<MultiplyRangeOperator> MultiplyRangeFunctor;
113
114} // end osgUtil namespace
115
116#endif // ** OPERATIONARRAYFUNCTOR ** //
Note: See TracBrowser for help on using the browser.