00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __VCGLIB_AABBBINARYTREEINDEX_H
00042 #define __VCGLIB_AABBBINARYTREEINDEX_H
00043
00044
00045 #include <vcg/space/index/base.h>
00046 #include <vcg/space/index/aabb_binary_tree/base.h>
00047 #include <vcg/space/index/aabb_binary_tree/closest.h>
00048 #include <vcg/space/index/aabb_binary_tree/frustum_cull.h>
00049 #include <vcg/space/index/aabb_binary_tree/kclosest.h>
00050 #include <vcg/space/index/aabb_binary_tree/ray.h>
00051 #include <wrap/utils.h>
00052
00053
00054
00055 namespace vcg {
00056
00057 template <class OBJTYPE, class SCALARTYPE, class NODEAUXDATA = EmptyClass>
00058 class AABBBinaryTreeIndex : public SpatialIndex<OBJTYPE, SCALARTYPE> {
00059 public:
00060 typedef AABBBinaryTreeIndex<OBJTYPE, SCALARTYPE, NODEAUXDATA> ClassType;
00061 typedef OBJTYPE ObjType;
00062 typedef SCALARTYPE ScalarType;
00063 typedef NODEAUXDATA NodeAuxData;
00064 typedef ObjType * ObjPtr;
00065 typedef Point3<ScalarType> CoordType;
00066 typedef AABBBinaryTree<ObjType, ScalarType, NodeAuxData> TreeType;
00067
00068 inline TreeType & Tree(void) {
00069 return (this->tree);
00070 }
00071
00072 inline const TreeType & Tree(void) const {
00073 return (this->tree);
00074 }
00075
00076 template <class OBJITER>
00077 inline void Set(const OBJITER & _oBegin, const OBJITER & _oEnd) {
00078 GetPointerFunctor getPtr;
00079 GetBox3Functor getBox;
00080 GetBarycenter3Functor getBarycenter;
00081
00082
00083
00084 const unsigned int maxObjectsPerLeaf = 10;
00085 const ScalarType leafBoxMaxVolume = ((ScalarType)0);
00086 const bool useVariance = true;
00087
00088 (void)(this->tree.Set(_oBegin, _oEnd, getPtr, getBox, getBarycenter, maxObjectsPerLeaf, leafBoxMaxVolume, useVariance));
00089 }
00090
00091 template <class OBJITERATOR, class OBJITERATORPTRFUNCT, class OBJBOXFUNCT, class OBJBARYCENTERFUNCT>
00092 inline bool Set(const OBJITERATOR & _oBegin, const OBJITERATOR & _oEnd, OBJITERATORPTRFUNCT & _objPtr, OBJBOXFUNCT & _objBox, OBJBARYCENTERFUNCT & _objBarycenter, const unsigned int _maxElemsPerLeaf = 1, const ScalarType & _leafBoxMaxVolume = ((ScalarType)0), const bool _useVariance = true) {
00093 return (this->tree.Set(_oBegin, _oEnd, _objPtr, _objBox, _objBarycenter, _maxElemsPerLeaf, _leafBoxMaxVolume, _useVariance));
00094 }
00095
00096 template <class OBJPOINTDISTFUNCTOR, class OBJMARKER>
00097 inline ObjPtr GetClosest(
00098 OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker,
00099 const typename OBJPOINTDISTFUNCTOR::QueryType & _p, const ScalarType & _maxDist,
00100 ScalarType & _minDist, CoordType & _closestPt) {
00101 (void)_marker;
00102 return (AABBBinaryTreeClosest<TreeType>::Closest(this->tree, _getPointDistance, _p, _maxDist, _minDist, _closestPt));
00103 }
00104
00105 template <class OBJPOINTDISTFUNCTOR, class OBJMARKER, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
00106 inline unsigned int GetKClosest(
00107 OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker, const unsigned int _k, const CoordType & _p, const ScalarType & _maxDist,
00108 OBJPTRCONTAINER & _objectPtrs, DISTCONTAINER & _distances, POINTCONTAINER & _points) {
00109 (void)_marker;
00110 return (AABBBinaryTreeKClosest<TreeType>::KClosest(this->tree, _getPointDistance, _k, _p, _maxDist, _objectPtrs, _distances, _points));
00111 }
00112
00113 template <class OBJRAYISECTFUNCTOR, class OBJMARKER>
00114 inline ObjPtr DoRay(OBJRAYISECTFUNCTOR & _rayIntersector, OBJMARKER & _marker, const Ray3<ScalarType> & _ray, const ScalarType & _maxDist, ScalarType & _t) {
00115 (void)_marker;
00116 return (AABBBinaryTreeRay<TreeType>::Ray(this->tree, _rayIntersector, _ray, _maxDist, _t));
00117 }
00118
00119 inline void InitializeFrustumCull(void) {
00120 (void)(AABBBinaryTreeFrustumCull<TreeType>::Initialize(this->tree));
00121 }
00122
00123 inline void FrustumCull(const Plane3<ScalarType> _frustumPlanes[6], const unsigned int _minNodeObjectsCount) {
00124 (void)(AABBBinaryTreeFrustumCull<TreeType>::FrustumCull(this->tree, _frustumPlanes, _minNodeObjectsCount));
00125 }
00126
00127 protected:
00128 TreeType tree;
00129
00130 };
00131
00132 }
00133
00134 #endif // #ifndef __VCGLIB_AABBBINARYTREEINDEX_H