diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-04-23 11:33:36 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-04-23 11:33:36 +0000 |
commit | acb32c69d4e8a78763400ac045b7e06930348fe9 (patch) | |
tree | 0f48303571d5f3a1d39827eb82dffafd34a66324 /unsupported | |
parent | c7bb7436f9107f96d32c229313bb3f72a85fbf21 (diff) |
* update BVH to explicitely use aligned_allocator
* fix warning in StdVector
Diffstat (limited to 'unsupported')
-rw-r--r-- | unsupported/Eigen/src/BVH/KdBVH.h | 28 | ||||
-rw-r--r-- | unsupported/test/BVH.cpp | 18 |
2 files changed, 28 insertions, 18 deletions
diff --git a/unsupported/Eigen/src/BVH/KdBVH.h b/unsupported/Eigen/src/BVH/KdBVH.h index 4b681925c..124ad66b5 100644 --- a/unsupported/Eigen/src/BVH/KdBVH.h +++ b/unsupported/Eigen/src/BVH/KdBVH.h @@ -40,18 +40,18 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Dim) //these templates help the tree initializer get the bounding boxes either from a provided //iterator range or using ei_bounding_box in a unified way -template<typename Object, typename Volume, typename BoxIter> +template<typename ObjectList, typename VolumeList, typename BoxIter> struct ei_get_boxes_helper { - void operator()(const std::vector<Object> &objects, BoxIter boxBegin, BoxIter boxEnd, std::vector<Volume> &outBoxes) + void operator()(const ObjectList &objects, BoxIter boxBegin, BoxIter boxEnd, VolumeList &outBoxes) { outBoxes.insert(outBoxes.end(), boxBegin, boxEnd); ei_assert(outBoxes.size() == objects.size()); } }; -template<typename Object, typename Volume> -struct ei_get_boxes_helper<Object, Volume, int> { - void operator()(const std::vector<Object> &objects, int, int, std::vector<Volume> &outBoxes) +template<typename ObjectList, typename VolumeList> +struct ei_get_boxes_helper<ObjectList, VolumeList, int> { + void operator()(const ObjectList &objects, int, int, VolumeList &outBoxes) { outBoxes.reserve(objects.size()); for(int i = 0; i < (int)objects.size(); ++i) @@ -78,8 +78,10 @@ template<typename _Scalar, int _Dim, typename _Object> class KdBVH public: enum { Dim = _Dim }; typedef _Object Object; + typedef std::vector<Object, aligned_allocator<Object> > ObjectList; typedef _Scalar Scalar; typedef AlignedBox<Scalar, Dim> Volume; + typedef std::vector<Volume, aligned_allocator<Volume> > VolumeList; typedef int Index; typedef const int *VolumeIterator; //the iterators are just pointers into the tree's vectors typedef const Object *ObjectIterator; @@ -110,10 +112,11 @@ public: if(n < 2) return; //if we have at most one object, we don't need any internal nodes - std::vector<Volume> objBoxes; - std::vector<VIPair> objCenters; + VolumeList objBoxes; + VIPairList objCenters; - ei_get_boxes_helper<Object, Volume, BIter>()(objects, boxBegin, boxEnd, objBoxes); //compute the bounding boxes depending on BIter type + //compute the bounding boxes depending on BIter type + ei_get_boxes_helper<ObjectList, VolumeList, BIter>()(objects, boxBegin, boxEnd, objBoxes); objCenters.reserve(n); boxes.reserve(n - 1); @@ -124,7 +127,7 @@ public: build(objCenters, 0, n, objBoxes, 0); //the recursive part of the algorithm - std::vector<Object> tmp(n); + ObjectList tmp(n); tmp.swap(objects); for(int i = 0; i < n; ++i) objects[i] = tmp[objCenters[i].second]; @@ -174,6 +177,7 @@ public: private: typedef ei_vector_int_pair<Scalar, Dim> VIPair; + typedef std::vector<VIPair, aligned_allocator<VIPair> > VIPairList; typedef Matrix<Scalar, Dim, 1> VectorType; struct VectorComparator //compares vectors, or, more specificall, VIPairs along a particular dimension { @@ -185,7 +189,7 @@ private: //Build the part of the tree between objects[from] and objects[to] (not including objects[to]). //This routine partitions the objCenters in [from, to) along the dimension dim, recursively constructs //the two halves, and adds their parent node. TODO: a cache-friendlier layout - void build(std::vector<VIPair> &objCenters, int from, int to, const std::vector<Volume> &objBoxes, int dim) + void build(VIPairList &objCenters, int from, int to, const VolumeList &objBoxes, int dim) { ei_assert(to - from > 1); if(to - from == 2) { @@ -218,8 +222,8 @@ private: } std::vector<int> children; //children of x are children[2x] and children[2x+1], indices bigger than boxes.size() index into objects. - std::vector<Volume> boxes; - std::vector<Object> objects; + VolumeList boxes; + ObjectList objects; }; #endif //KDBVH_H_INCLUDED diff --git a/unsupported/test/BVH.cpp b/unsupported/test/BVH.cpp index 445489eef..879daacc2 100644 --- a/unsupported/test/BVH.cpp +++ b/unsupported/test/BVH.cpp @@ -42,10 +42,12 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(double, Dim) double radius; }; + template<int Dim> AlignedBox<double, Dim> ei_bounding_box(const Matrix<double, Dim, 1> &v) { return AlignedBox<double, Dim>(v); } template<int Dim> AlignedBox<double, Dim> ei_bounding_box(const Ball<Dim> &b) { return AlignedBox<double, Dim>(b.center.cwise() - b.radius, b.center.cwise() + b.radius); } + template<int Dim> struct BallPointStuff //this class provides functions to be both an intersector and a minimizer, both for a ball and a point and for two trees { @@ -97,16 +99,19 @@ struct BallPointStuff //this class provides functions to be both an intersector int count; }; + template<int Dim> struct TreeTest { typedef Matrix<double, Dim, 1> VectorType; + typedef std::vector<VectorType, aligned_allocator<VectorType> > VectorTypeList; typedef Ball<Dim> BallType; + typedef std::vector<BallType, aligned_allocator<BallType> > BallTypeList; typedef AlignedBox<double, Dim> BoxType; void testIntersect1() { - std::vector<BallType> b; + BallTypeList b; for(int i = 0; i < 500; ++i) { b.push_back(BallType(VectorType::Random(), 0.5 * ei_random(0., 1.))); } @@ -125,7 +130,7 @@ struct TreeTest void testMinimize1() { - std::vector<BallType> b; + BallTypeList b; for(int i = 0; i < 500; ++i) { b.push_back(BallType(VectorType::Random(), 0.01 * ei_random(0., 1.))); } @@ -146,8 +151,8 @@ struct TreeTest void testIntersect2() { - std::vector<BallType> b; - std::vector<VectorType> v; + BallTypeList b; + VectorTypeList v; for(int i = 0; i < 50; ++i) { b.push_back(BallType(VectorType::Random(), 0.5 * ei_random(0., 1.))); @@ -171,8 +176,8 @@ struct TreeTest void testMinimize2() { - std::vector<BallType> b; - std::vector<VectorType> v; + BallTypeList b; + VectorTypeList v; for(int i = 0; i < 50; ++i) { b.push_back(BallType(VectorType::Random(), 1e-7 + 1e-6 * ei_random(0., 1.))); @@ -197,6 +202,7 @@ struct TreeTest } }; + void test_BVH() { for(int i = 0; i < g_repeat; i++) { |