From David Callu, various classes in support of VirtualPlanetBuilder
This commit is contained in:
139
include/osgUtil/ConvertVec
Normal file
139
include/osgUtil/ConvertVec
Normal file
@@ -0,0 +1,139 @@
|
||||
/* -*-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_CONVERTVEC
|
||||
#define OSGUTIL_CONVERTVEC 1
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
template <typename InType, typename OutType,
|
||||
unsigned int InSize = InType::num_components,
|
||||
unsigned int OutSize = OutType::num_components>
|
||||
struct ConvertVec
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 2, 2>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 2, 3>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()),
|
||||
static_cast<typename OutType::value_type>(0.0));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 2, 4>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()),
|
||||
static_cast<typename OutType::value_type>(0.0),
|
||||
static_cast<typename OutType::value_type>(1.0));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 3, 2>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 3, 3>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()),
|
||||
static_cast<typename OutType::value_type>(in.z()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 3, 4>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()),
|
||||
static_cast<typename OutType::value_type>(in.z()),
|
||||
static_cast<typename OutType::value_type>(1.0));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 4, 2>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()/in.w()),
|
||||
static_cast<typename OutType::value_type>(in.y()/in.w()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 4, 3>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()/in.w()),
|
||||
static_cast<typename OutType::value_type>(in.y()/in.w()),
|
||||
static_cast<typename OutType::value_type>(in.z()/in.w()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
struct ConvertVec<InType, OutType, 4, 4>
|
||||
{
|
||||
static void convert(InType & in, OutType & out)
|
||||
{
|
||||
out.set(static_cast<typename OutType::value_type>(in.x()),
|
||||
static_cast<typename OutType::value_type>(in.y()),
|
||||
static_cast<typename OutType::value_type>(in.z()),
|
||||
static_cast<typename OutType::value_type>(in.w()));
|
||||
}
|
||||
};
|
||||
|
||||
} // end of osg namespace
|
||||
|
||||
#endif // ** OSG_CONVERTVEC ** //
|
||||
210
include/osgUtil/EdgeCollector
Normal file
210
include/osgUtil/EdgeCollector
Normal file
@@ -0,0 +1,210 @@
|
||||
/* -*-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_EDGECOLLECTOR
|
||||
#define OSGUTIL_EDGECOLLECTOR 1
|
||||
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
struct dereference_less
|
||||
{
|
||||
template<class T, class U>
|
||||
inline bool operator() (const T& lhs,const U& rhs) const
|
||||
{
|
||||
return *lhs < *rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
bool dereference_check_less(const T& lhs,const T& rhs)
|
||||
{
|
||||
if (lhs==rhs) return false;
|
||||
if (!lhs) return true;
|
||||
if (!rhs) return false;
|
||||
return *lhs < *rhs;
|
||||
}
|
||||
|
||||
struct dereference_clear
|
||||
{
|
||||
template<class T>
|
||||
inline void operator() (const T& t)
|
||||
{
|
||||
T& non_const_t = const_cast<T&>(t);
|
||||
non_const_t->clear();
|
||||
}
|
||||
};
|
||||
|
||||
class EdgeCollector
|
||||
{
|
||||
public:
|
||||
|
||||
struct Triangle;
|
||||
struct Edge;
|
||||
struct Edgeloop;
|
||||
struct Point;
|
||||
|
||||
|
||||
|
||||
typedef std::list<osg::ref_ptr<osg::UIntArray> > IndexArrayList;
|
||||
|
||||
~EdgeCollector();
|
||||
|
||||
void setGeometry(osg::Geometry* geometry);
|
||||
osg::Geometry* getGeometry() { return _geometry; }
|
||||
|
||||
unsigned int getNumOfTriangles() { return _triangleSet.size(); }
|
||||
|
||||
typedef std::set<osg::ref_ptr<Edge>,dereference_less > EdgeSet;
|
||||
typedef std::vector<osg::ref_ptr<Edge> > EdgeList;
|
||||
typedef std::list< osg::ref_ptr<Edgeloop> > EdgeloopList;
|
||||
typedef std::set< osg::ref_ptr<Point>,dereference_less > PointSet;
|
||||
typedef std::vector< osg::ref_ptr<Point> > PointList;
|
||||
typedef std::list< osg::ref_ptr<Triangle> > TriangleList;
|
||||
typedef std::set< osg::ref_ptr<Triangle> > TriangleSet;
|
||||
typedef std::map< osg::ref_ptr<Triangle>, unsigned int, dereference_less > TriangleMap;
|
||||
|
||||
struct Point : public osg::Referenced
|
||||
{
|
||||
Point(): _protected(false), _index(0) {}
|
||||
|
||||
bool _protected;
|
||||
|
||||
unsigned int _index;
|
||||
|
||||
osg::Vec3 _vertex;
|
||||
TriangleSet _triangles;
|
||||
|
||||
void clear() { _triangles.clear(); }
|
||||
|
||||
bool operator < ( const Point& rhs) const { return _vertex < rhs._vertex; }
|
||||
|
||||
bool isBoundaryPoint() const;
|
||||
};
|
||||
|
||||
struct Edge : public osg::Referenced
|
||||
{
|
||||
void clear();
|
||||
|
||||
osg::ref_ptr<Point> _p1;
|
||||
osg::ref_ptr<Point> _p2;
|
||||
|
||||
osg::ref_ptr<Point> _op1;
|
||||
osg::ref_ptr<Point> _op2;
|
||||
|
||||
TriangleSet _triangles;
|
||||
|
||||
|
||||
bool operator < ( const Edge& rhs) const;
|
||||
|
||||
bool operator == ( const Edge& rhs) const;
|
||||
|
||||
bool operator != ( const Edge& rhs) const;
|
||||
|
||||
void setOrderedPoints(Point* p1, Point* p2);
|
||||
|
||||
void addTriangle(Triangle* triangle) { _triangles.insert(triangle); }
|
||||
|
||||
bool isBoundaryEdge() const { return _triangles.size()<=1; }
|
||||
|
||||
bool isAdjacentToBoundary() const { return isBoundaryEdge() || _p1->isBoundaryPoint() || _p2->isBoundaryPoint(); }
|
||||
|
||||
bool endConnected(const Edge& rhs) const { return (_op2 == rhs._op1); }
|
||||
|
||||
bool beginConnected(const Edge& rhs) const { return (_op1 == rhs._op2); }
|
||||
};
|
||||
|
||||
struct Triangle : public osg::Referenced
|
||||
{
|
||||
Triangle() {}
|
||||
|
||||
void clear();
|
||||
|
||||
inline bool operator < (const Triangle& rhs) const;
|
||||
|
||||
|
||||
void setOrderedPoints(Point* p1, Point* p2, Point* p3);
|
||||
|
||||
float distance(const osg::Vec3& vertex) const { return _plane.distance(vertex); }
|
||||
|
||||
bool isBoundaryTriangle() const
|
||||
{ return (_e1->isBoundaryEdge() || _e2->isBoundaryEdge() || _e3->isBoundaryEdge()); }
|
||||
|
||||
|
||||
osg::ref_ptr<Point> _p1;
|
||||
osg::ref_ptr<Point> _p2;
|
||||
osg::ref_ptr<Point> _p3;
|
||||
|
||||
osg::ref_ptr<Point> _op1;
|
||||
osg::ref_ptr<Point> _op2;
|
||||
osg::ref_ptr<Point> _op3;
|
||||
|
||||
osg::ref_ptr<Edge> _e1;
|
||||
osg::ref_ptr<Edge> _e2;
|
||||
osg::ref_ptr<Edge> _e3;
|
||||
|
||||
osg::Plane _plane;
|
||||
};
|
||||
|
||||
class Edgeloop : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
typedef std::vector<osg::ref_ptr<Edge> > EdgeList;
|
||||
|
||||
bool isClosed() { return (_edgeList.back()->endConnected(*_edgeList.front().get())); }
|
||||
|
||||
osg::UIntArray * toIndexArray() const;
|
||||
|
||||
EdgeList _edgeList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Triangle* addTriangle(unsigned int p1, unsigned int p2, unsigned int p3);
|
||||
Triangle* addTriangle(Point* p1, Point* p2, Point* p3);
|
||||
|
||||
Edge* addEdge(Triangle* triangle, Point* p1, Point* p2);
|
||||
|
||||
Point* addPoint(Triangle* triangle, unsigned int p1) { return addPoint(triangle,_originalPointList[p1].get()); }
|
||||
Point* addPoint(Triangle* triangle, Point* point);
|
||||
|
||||
void getBoundaryEdgeList(EdgeList & el);
|
||||
bool extractBoundaryEdgeloop(EdgeList & el, Edgeloop & edgeloop);
|
||||
bool extractBoundaryEdgeloopList(EdgeList & el, EdgeloopList & edgeloopList);
|
||||
|
||||
void getEdgeloopIndexList(IndexArrayList & ial);
|
||||
|
||||
//protected:
|
||||
|
||||
osg::Geometry* _geometry;
|
||||
|
||||
EdgeSet _edgeSet;
|
||||
TriangleSet _triangleSet;
|
||||
PointSet _pointSet;
|
||||
PointList _originalPointList;
|
||||
|
||||
};
|
||||
|
||||
} // end of osgUtil namespace
|
||||
|
||||
#endif // ** OSGUTIL_EDGECOLLECTOR ** //
|
||||
103
include/osgUtil/OperationArrayFunctor
Normal file
103
include/osgUtil/OperationArrayFunctor
Normal file
@@ -0,0 +1,103 @@
|
||||
#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::Vec3, 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::Vec3 _vector;
|
||||
};
|
||||
typedef OperationArrayFunctor<AddRangeOperator> AddRangeFunctor;
|
||||
|
||||
struct MultiplyRangeOperator
|
||||
{
|
||||
template <typename ArrayType>
|
||||
void process(ArrayType & array)
|
||||
{
|
||||
typedef typename ArrayType::ElementDataType ElementDataType;
|
||||
|
||||
ElementDataType convertedVector;
|
||||
osgUtil::ConvertVec<osg::Vec3, 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::Vec3 _vector;
|
||||
};
|
||||
typedef OperationArrayFunctor<MultiplyRangeOperator> MultiplyRangeFunctor;
|
||||
|
||||
} // end osgUtil namespace
|
||||
|
||||
#endif // ** OPERATIONARRAYFUNCTOR ** //
|
||||
77
include/osgUtil/ReversePrimitiveFunctor
Normal file
77
include/osgUtil/ReversePrimitiveFunctor
Normal file
@@ -0,0 +1,77 @@
|
||||
/* -*-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_REVERSEPRIMITIVEFUNCTOR
|
||||
#define OSGUTIL_REVERSEPRIMITIVEFUNCTOR 1
|
||||
|
||||
#include <osg/PrimitiveSet>
|
||||
#include <osg/Notify>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
|
||||
class ReversePrimitiveFunctor : public osg::PrimitiveIndexFunctor
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~ReversePrimitiveFunctor() {}
|
||||
|
||||
osg::PrimitiveSet * getReversedPrimitiveSet() { return _reversedPrimitiveSet.get(); }
|
||||
|
||||
virtual void setVertexArray(unsigned int /*count*/,const osg::Vec2* /*vertices*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void setVertexArray(unsigned int /*count*/,const osg::Vec3* /*vertices*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void setVertexArray(unsigned int /*count*/,const osg::Vec4* /*vertices*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void setVertexArray(unsigned int /*count*/,const osg::Vec2d* /*vertices*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void setVertexArray(unsigned int /*count*/,const osg::Vec3d* /*vertices*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void setVertexArray(unsigned int /*count*/,const osg::Vec4d* /*vertices*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void drawArrays(GLenum /*mode*/,GLint /*first*/,GLsizei /*count*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices);
|
||||
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices);
|
||||
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices);
|
||||
|
||||
|
||||
/// Mimics the OpenGL \c glBegin() function.
|
||||
virtual void begin(GLenum /*mode*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void vertex(unsigned int /*pos*/)
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
virtual void end()
|
||||
{ osg::notify(osg::WARN) << "ReversePrimitiveFunctor : not implemented " << std::endl; }
|
||||
|
||||
|
||||
osg::ref_ptr<osg::PrimitiveSet> _reversedPrimitiveSet;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // end osgUtil namespace
|
||||
|
||||
#endif // ** OSGUTIL_REVERSEFACEVISITOR ** //
|
||||
Reference in New Issue
Block a user