From 199c5f2b47eb1f8e5a2d20e60f07e97cd95a6ba6 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Mon, 1 Mar 2021 03:59:21 +0100 Subject: geo_alignedbox_5 was failing with AVX enabled, due to storing `Vector4d` in a `std::vector` without using an aligned allocator. Got rid of using `std::vector` and simplified the code. Avoid leading `_` --- test/geo_alignedbox.cpp | 127 +++++++++++++++++------------------------------- 1 file changed, 45 insertions(+), 82 deletions(-) (limited to 'test') diff --git a/test/geo_alignedbox.cpp b/test/geo_alignedbox.cpp index 7ce640d81..7b1684f29 100644 --- a/test/geo_alignedbox.cpp +++ b/test/geo_alignedbox.cpp @@ -10,7 +10,6 @@ #include "main.h" #include -#include using namespace std; // NOTE the following workaround was needed on some 32 bits builds to kill extra precision of x87 registers. @@ -26,7 +25,7 @@ void kill_extra_precision(T& /* x */) { } -template void alignedbox(const BoxType& _box) +template void alignedbox(const BoxType& box) { /* this test covers the following files: AlignedBox.h @@ -36,7 +35,7 @@ template void alignedbox(const BoxType& _box) typedef typename ScalarTraits::Real RealScalar; typedef Matrix VectorType; - const Index dim = _box.dim(); + const Index dim = box.dim(); VectorType p0 = VectorType::Random(dim); VectorType p1 = VectorType::Random(dim); @@ -87,18 +86,18 @@ template void alignedbox(const BoxType& _box) } -template void alignedboxTranslatable(const BoxType& _box) +template void alignedboxTranslatable(const BoxType& box) { typedef typename BoxType::Scalar Scalar; typedef Matrix VectorType; typedef Transform IsometryTransform; typedef Transform AffineTransform; - alignedbox(_box); + alignedbox(box); const VectorType Ones = VectorType::Ones(); const VectorType UnitX = VectorType::UnitX(); - const Index dim = _box.dim(); + const Index dim = box.dim(); // box((-1, -1, -1), (1, 1, 1)) BoxType a(-Ones, Ones); @@ -175,33 +174,33 @@ template void alignedboxTranslatable(const BoxType& _box) } template -Rotation rotate2D(Scalar _angle) { - return Rotation2D(_angle); +Rotation rotate2D(Scalar angle) { + return Rotation2D(angle); } template -Rotation rotate2DIntegral(typename NumTraits::NonInteger _angle) { +Rotation rotate2DIntegral(typename NumTraits::NonInteger angle) { typedef typename NumTraits::NonInteger NonInteger; - return Rotation2D(_angle).toRotationMatrix(). + return Rotation2D(angle).toRotationMatrix(). template cast(); } template -Rotation rotate3DZAxis(Scalar _angle) { - return AngleAxis(_angle, Matrix(0, 0, 1)); +Rotation rotate3DZAxis(Scalar angle) { + return AngleAxis(angle, Matrix(0, 0, 1)); } template -Rotation rotate3DZAxisIntegral(typename NumTraits::NonInteger _angle) { +Rotation rotate3DZAxisIntegral(typename NumTraits::NonInteger angle) { typedef typename NumTraits::NonInteger NonInteger; - return AngleAxis(_angle, Matrix(0, 0, 1)). + return AngleAxis(angle, Matrix(0, 0, 1)). toRotationMatrix().template cast(); } template -Rotation rotate4DZWAxis(Scalar _angle) { +Rotation rotate4DZWAxis(Scalar angle) { Rotation result = Matrix::Identity(); - result.block(0, 0, 3, 3) = rotate3DZAxis(_angle).toRotationMatrix(); + result.block(0, 0, 3, 3) = rotate3DZAxis(angle).toRotationMatrix(); return result; } @@ -221,38 +220,22 @@ MatrixType randomRotationMatrix() } template -std::vector > boxGetCorners(const Matrix& _min, const Matrix& _max, int dim = Dim) +Matrix boxGetCorners(const Matrix& min_, const Matrix& max_) { - std::vector > result; - if (dim == 1) + Matrix result; + for(Index i=0; i<(1< > shorter = boxGetCorners(_min, _max, dim - 1); - for (size_t i = 0; i < shorter.size(); ++i) - { - Matrix vec = shorter[i]; - - Matrix vec1 = _min; - vec1.block(Dim - dim, 0, dim - 1, 1) = vec.block(Dim - dim, 0, dim - 1, 1); - result.push_back(vec1); - - Matrix vec2 = _max; - vec2.block(Dim - dim, 0, dim - 1, 1) = vec.block(Dim - dim, 0, dim - 1, 1); - result.push_back(vec2); - } + for(Index j=0; j void alignedboxRotatable( - const BoxType& _box, - Rotation (*_rotate)(typename NumTraits::NonInteger /*_angle*/)) + const BoxType& box, + Rotation (*rotate)(typename NumTraits::NonInteger /*_angle*/)) { - alignedboxTranslatable(_box); + alignedboxTranslatable(box); typedef typename BoxType::Scalar Scalar; typedef typename NumTraits::NonInteger NonInteger; @@ -285,7 +268,7 @@ template void alignedboxRotatable( IsometryTransform tf2 = IsometryTransform::Identity(); // for some weird reason the following statement has to be put separate from // the following rotate call, otherwise precision problems arise... - Rotation rot = _rotate(NonInteger(EIGEN_PI)); + Rotation rot = rotate(NonInteger(EIGEN_PI)); tf2.rotate(rot); c.transform(tf2); @@ -295,7 +278,7 @@ template void alignedboxRotatable( VERIFY_IS_APPROX((c.min)(), UnitX - UnitZ * Scalar(2)); VERIFY_IS_APPROX((c.max)(), UnitX * Scalar(3) + UnitY * Scalar(2)); - rot = _rotate(NonInteger(EIGEN_PI / 2)); + rot = rotate(NonInteger(EIGEN_PI / 2)); tf2.setIdentity(); tf2.rotate(rot); @@ -319,18 +302,20 @@ template void alignedboxRotatable( } template void alignedboxNonIntegralRotatable( - const BoxType& _box, - Rotation (*_rotate)(typename NumTraits::NonInteger /*_angle*/)) + const BoxType& box, + Rotation (*rotate)(typename NumTraits::NonInteger /*_angle*/)) { - alignedboxRotatable(_box, _rotate); + alignedboxRotatable(box, rotate); typedef typename BoxType::Scalar Scalar; typedef typename NumTraits::NonInteger NonInteger; - typedef Matrix VectorType; - typedef Transform IsometryTransform; - typedef Transform AffineTransform; + enum { Dim = BoxType::AmbientDimAtCompileTime }; + typedef Matrix VectorType; + typedef Matrix CornersType; + typedef Transform IsometryTransform; + typedef Transform AffineTransform; - const Index dim = _box.dim(); + const Index dim = box.dim(); const VectorType Zero = VectorType::Zero(); const VectorType Ones = VectorType::Ones(); @@ -347,7 +332,7 @@ template void alignedboxNonIntegralRotatabl VectorType cornerTL = (c.max)(); cornerTL[0] = cornerBL[0]; NonInteger angle = NonInteger(EIGEN_PI/3); - Rotation rot = _rotate(angle); + Rotation rot = rotate(angle); IsometryTransform tf2; tf2.setIdentity(); tf2.rotate(rot); @@ -393,8 +378,7 @@ template void alignedboxNonIntegralRotatabl c = BoxType(minCorner, maxCorner); - std::vector corners = boxGetCorners(minCorner, maxCorner); - const size_t numCorners = corners.size(); + CornersType corners = boxGetCorners(minCorner, maxCorner); typename AffineTransform::LinearMatrixType rotation = randomRotationMatrix(); @@ -404,20 +388,10 @@ template void alignedboxNonIntegralRotatabl tf2.translate(VectorType::Random()); c.transform(tf2); - for (size_t corner = 0; corner < numCorners; ++corner) - corners[corner] = tf2 * corners[corner]; + corners = tf2 * corners; - for (Index d = 0; d < dim; ++d) - { - minCorner[d] = corners[0][d]; - maxCorner[d] = corners[0][d]; - - for (size_t corner = 0; corner < numCorners; ++corner) - { - minCorner[d] = (min)(minCorner[d], corners[corner][d]); - maxCorner[d] = (max)(maxCorner[d], corners[corner][d]); - } - } + minCorner = corners.rowwise().minCoeff(); + maxCorner = corners.rowwise().maxCoeff(); VERIFY_IS_APPROX((c.min)(), minCorner); VERIFY_IS_APPROX((c.max)(), maxCorner); @@ -434,28 +408,17 @@ template void alignedboxNonIntegralRotatabl c = BoxType(minCorner, maxCorner); - std::vector corners = boxGetCorners(minCorner, maxCorner); - const size_t numCorners = corners.size(); + CornersType corners = boxGetCorners(minCorner, maxCorner); AffineTransform atf = AffineTransform::Identity(); atf.linearExt() = AffineTransform::LinearPart::Random(); atf.translate(VectorType::Random()); c.transform(atf); - for (size_t corner = 0; corner < numCorners; ++corner) - corners[corner] = atf * corners[corner]; + corners = atf * corners; - for (Index d = 0; d < dim; ++d) - { - minCorner[d] = corners[0][d]; - maxCorner[d] = corners[0][d]; - - for (size_t corner = 0; corner < numCorners; ++corner) - { - minCorner[d] = (min)(minCorner[d], corners[corner][d]); - maxCorner[d] = (max)(maxCorner[d], corners[corner][d]); - } - } + minCorner = corners.rowwise().minCoeff(); + maxCorner = corners.rowwise().maxCoeff(); VERIFY_IS_APPROX((c.min)(), minCorner); VERIFY_IS_APPROX((c.max)(), maxCorner); @@ -463,13 +426,13 @@ template void alignedboxNonIntegralRotatabl } template -void alignedboxCastTests(const BoxType& _box) +void alignedboxCastTests(const BoxType& box) { // casting typedef typename BoxType::Scalar Scalar; typedef Matrix VectorType; - const Index dim = _box.dim(); + const Index dim = box.dim(); VectorType p0 = VectorType::Random(dim); VectorType p1 = VectorType::Random(dim); -- cgit v1.2.3