OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OperationArrayFunctor.h
Go to the documentation of this file.
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 
24 namespace osgUtil {
25 
26 template <class T>
27 class 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 
61 {
62  template <typename ArrayType>
63  void process(ArrayType & array)
64  {
65  typedef typename ArrayType::ElementDataType ElementDataType;
66 
67  ElementDataType 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 
84 };
86 
88 {
89  template <typename ArrayType>
90  void process(ArrayType & array)
91  {
92  typedef typename ArrayType::ElementDataType ElementDataType;
93 
94  ElementDataType 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 
111 };
113 
114 } // end osgUtil namespace
115 
116 #endif // ** OPERATIONARRAYFUNCTOR ** //
virtual void apply(osg::Vec4ubArray &array)
virtual void apply(osg::Vec3Array &array)
virtual void apply(osg::Vec4sArray &array)
void process(ArrayType &array)
virtual void apply(osg::Vec3bArray &array)
virtual void apply(osg::Vec2bArray &array)
virtual void apply(osg::Vec4bArray &array)
virtual void apply(osg::Vec2Array &array)
OperationArrayFunctor< MultiplyRangeOperator > MultiplyRangeFunctor
virtual void apply(osg::Vec2dArray &array)
virtual void apply(osg::Vec4dArray &array)
virtual void apply(osg::Vec2sArray &array)
virtual void apply(osg::Vec4Array &array)
virtual void apply(osg::Vec3sArray &array)
virtual void apply(osg::Array &)
virtual void apply(osg::Vec3dArray &array)
static void convert(InType &in, OutType &out)
Definition: ConvertVec.h:24
Shader generator framework.
Definition: RenderInfo.h:20
OperationArrayFunctor< AddRangeOperator > AddRangeFunctor