OperationArrayFunctor
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is 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.
*
* 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.
*/
#ifndef OSGUTIL_OPERATIONARRAYFUNCTOR
#define OSGUTIL_OPERATIONARRAYFUNCTOR 1
#include <osg/Array>
#include <osgUtil/ConvertVec>
// ** template ArrayVisitor to handle all method in one template.
// ** Only use when process done on each array could be templated
namespace osgUtil {
template <class T>
class OperationArrayFunctor : public osg::ArrayVisitor, public T
{
public:
virtual void apply(osg::Array&) {}
// virtual void apply(osg::ByteArray& array) { T::process<osg::ByteArray>(array); }
// virtual void apply(osg::ShortArray& array) { T::process(array); }
// virtual void apply(osg::IntArray& array) { T::process<osg::IntArray>(array); }
// virtual void apply(osg::UByteArray& array) { T::process<osg::UByteArray>(array); }
// virtual void apply(osg::UShortArray& array) { T::process<osg::UShortArray>(array); }
// virtual void apply(osg::UIntArray& array) { T::process<osg::UIntArray>(array); }
// virtual void apply(osg::FloatArray& array) { T::process<osg::FloatArray>(array); }
// virtual void apply(osg::DoubleArray& array) { T::process<osg::DoubleArray>(array); }
virtual void apply(osg::Vec2Array & array) { T::process(array); }
virtual void apply(osg::Vec3Array& array) { T::process(array); }
virtual void apply(osg::Vec4Array& array) { T::process(array); }
virtual void apply(osg::Vec4ubArray& array) { T::process(array); }
virtual void apply(osg::Vec2bArray& array) { T::process(array); }
virtual void apply(osg::Vec3bArray& array) { T::process(array); }
virtual void apply(osg::Vec4bArray& array) { T::process(array); }
virtual void apply(osg::Vec2sArray& array) { T::process(array); }
virtual void apply(osg::Vec3sArray& array) { T::process(array); }
virtual void apply(osg::Vec4sArray& array) { T::process(array); }
virtual void apply(osg::Vec2dArray& array) { T::process(array); }
virtual void apply(osg::Vec3dArray& array) { T::process(array); }
virtual void apply(osg::Vec4dArray& array) { T::process(array); }
};
struct AddRangeOperator
{
template <typename ArrayType>
void process(ArrayType & array)
{
typedef typename ArrayType::ElementDataType ElementDataType;
ElementDataType convertedVector;
osgUtil::ConvertVec<osg::Vec3d, ElementDataType>::convert(_vector, convertedVector);
typename ArrayType::iterator it = array.begin();
std::advance(it, _begin);
typename ArrayType::iterator end = it;
std::advance(end, _count);
for (; it < end; ++it)
(*it) += convertedVector;
}
unsigned int _begin;
unsigned int _count;
osg::Vec3d _vector;
};
typedef OperationArrayFunctor<AddRangeOperator> AddRangeFunctor;
struct MultiplyRangeOperator
{
template <typename ArrayType>
void process(ArrayType & array)
{
typedef typename ArrayType::ElementDataType ElementDataType;
ElementDataType convertedVector;
osgUtil::ConvertVec<osg::Vec3d, ElementDataType>::convert(_vector, convertedVector);
typename ArrayType::iterator it = array.begin();
std::advance(it, _begin);
typename ArrayType::iterator end = it;
std::advance(end, _count);
for (; it < end; ++it)
(*it) *= convertedVector;
}
unsigned int _begin;
unsigned int _count;
osg::Vec3d _vector;
};
typedef OperationArrayFunctor<MultiplyRangeOperator> MultiplyRangeFunctor;
} // end osgUtil namespace
#endif // ** OPERATIONARRAYFUNCTOR ** //
Array
ConvertVec
osgUtil::OperationArrayFunctor
Definition OperationArrayFunctor:28
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec4Array &array)
Definition OperationArrayFunctor:43
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec2bArray &array)
Definition OperationArrayFunctor:47
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec2dArray &array)
Definition OperationArrayFunctor:55
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Array &)
Definition OperationArrayFunctor:31
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec3dArray &array)
Definition OperationArrayFunctor:56
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec3bArray &array)
Definition OperationArrayFunctor:48
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec4sArray &array)
Definition OperationArrayFunctor:53
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec2sArray &array)
Definition OperationArrayFunctor:51
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec2Array &array)
Definition OperationArrayFunctor:41
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec4ubArray &array)
Definition OperationArrayFunctor:45
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec4dArray &array)
Definition OperationArrayFunctor:57
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec3sArray &array)
Definition OperationArrayFunctor:52
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec3Array &array)
Definition OperationArrayFunctor:42
osgUtil::OperationArrayFunctor::apply
virtual void apply(osg::Vec4bArray &array)
Definition OperationArrayFunctor:49
osg::ArrayVisitor
Definition Array:465
osg::Array
Definition Array:61
osg::Vec3d
Definition Vec3d:30
osgUtil
Definition NodeVisitor:25
osgUtil::AddRangeFunctor
OperationArrayFunctor< AddRangeOperator > AddRangeFunctor
Definition OperationArrayFunctor:85
osgUtil::MultiplyRangeFunctor
OperationArrayFunctor< MultiplyRangeOperator > MultiplyRangeFunctor
Definition OperationArrayFunctor:112
osg::Vec2Array
TemplateArray< Vec2, Array::Vec2ArrayType, 2, GL_FLOAT > Vec2Array
Definition Array:448
osg::Vec4Array
TemplateArray< Vec4, Array::Vec4ArrayType, 4, GL_FLOAT > Vec4Array
Definition Array:450
osg::Vec3bArray
TemplateArray< Vec3b, Array::Vec3bArrayType, 3, GL_BYTE > Vec3bArray
Definition Array:425
osg::Vec3dArray
TemplateArray< Vec3d, Array::Vec3dArrayType, 3, GL_DOUBLE > Vec3dArray
Definition Array:453
osg::Vec3Array
TemplateArray< Vec3, Array::Vec3ArrayType, 3, GL_FLOAT > Vec3Array
Definition Array:449
osg::Vec2bArray
TemplateArray< Vec2b, Array::Vec2bArrayType, 2, GL_BYTE > Vec2bArray
Definition Array:424
osg::Vec4dArray
TemplateArray< Vec4d, Array::Vec4dArrayType, 4, GL_DOUBLE > Vec4dArray
Definition Array:454
osg::Vec2sArray
TemplateArray< Vec2s, Array::Vec2sArrayType, 2, GL_SHORT > Vec2sArray
Definition Array:428
osg::Vec3sArray
TemplateArray< Vec3s, Array::Vec3sArrayType, 3, GL_SHORT > Vec3sArray
Definition Array:429
osg::Vec4bArray
TemplateArray< Vec4b, Array::Vec4bArrayType, 4, GL_BYTE > Vec4bArray
Definition Array:426
osg::Vec4sArray
TemplateArray< Vec4s, Array::Vec4sArrayType, 4, GL_SHORT > Vec4sArray
Definition Array:430
osg::Vec2dArray
TemplateArray< Vec2d, Array::Vec2dArrayType, 2, GL_DOUBLE > Vec2dArray
Definition Array:452
osg::Vec4ubArray
TemplateArray< Vec4ub, Array::Vec4ubArrayType, 4, GL_UNSIGNED_BYTE > Vec4ubArray
Definition Array:438
osgUtil::AddRangeOperator
Definition OperationArrayFunctor:61
osgUtil::AddRangeOperator::process
void process(ArrayType &array)
Definition OperationArrayFunctor:63
osgUtil::AddRangeOperator::_begin
unsigned int _begin
Definition OperationArrayFunctor:80
osgUtil::AddRangeOperator::_count
unsigned int _count
Definition OperationArrayFunctor:81
osgUtil::AddRangeOperator::_vector
osg::Vec3d _vector
Definition OperationArrayFunctor:83
osgUtil::ConvertVec::convert
static void convert(InType &in, OutType &out)
Definition ConvertVec:24
osgUtil::MultiplyRangeOperator
Definition OperationArrayFunctor:88
osgUtil::MultiplyRangeOperator::_vector
osg::Vec3d _vector
Definition OperationArrayFunctor:110
osgUtil::MultiplyRangeOperator::_begin
unsigned int _begin
Definition OperationArrayFunctor:107
osgUtil::MultiplyRangeOperator::_count
unsigned int _count
Definition OperationArrayFunctor:108
osgUtil::MultiplyRangeOperator::process
void process(ArrayType &array)
Definition OperationArrayFunctor:90