11 #include <Eigen/Geometry> 28 template<
typename BoxType>
void alignedbox(
const BoxType& box)
38 const Index dim = box.dim();
40 VectorType
p0 = VectorType::Random(dim);
41 VectorType
p1 = VectorType::Random(dim);
43 p1 = VectorType::Random(dim); }
44 RealScalar s1 = internal::random<RealScalar>(0,1);
47 BoxType
b1(VectorType::Random(dim),VectorType::Random(dim));
56 VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1));
57 VERIFY(b0.contains(b0.center()));
66 BoxType box1(VectorType::Random(dim));
67 box1.extend(VectorType::Random(dim));
68 BoxType box2(VectorType::Random(dim));
69 box2.extend(VectorType::Random(dim));
71 VERIFY(box1.intersects(box2) == !box1.intersection(box2).isEmpty());
74 BoxType *bp0 =
new BoxType(dim);
75 BoxType *bp1 =
new BoxType(dim);
81 for(
int i=0;
i<10; ++
i )
83 VectorType r = b0.sample();
98 const VectorType Ones = VectorType::Ones();
99 const VectorType UnitX = VectorType::UnitX();
100 const Index dim = box.dim();
103 BoxType
a(-Ones, Ones);
108 VectorType translate = Ones;
110 b.translate(translate);
119 IsometryTransform tf = IsometryTransform::Identity();
120 tf.translation() = -translate;
122 BoxType
c = b.transformed(tf);
136 AffineTransform atf = AffineTransform::Identity();
144 atf = AffineTransform::Identity();
153 BoxType transformedC = c.transformed(IsometryTransform::Identity());
156 for (
size_t i = 0;
i < 10; ++
i)
158 VectorType minCorner;
159 VectorType maxCorner;
162 minCorner[
d] = internal::random<Scalar>(-10,10);
163 maxCorner[
d] = minCorner[
d] + internal::random<Scalar>(0, 10);
166 c = BoxType(minCorner, maxCorner);
168 translate = VectorType::Random();
169 c.translate(translate);
176 template<
typename Scalar,
typename Rotation>
181 template<
typename Scalar,
typename Rotation>
185 template cast<Scalar>();
188 template<
typename Scalar,
typename Rotation>
193 template<
typename Scalar,
typename Rotation>
200 template<
typename Scalar,
typename Rotation>
203 result.block(0, 0, 3, 3) = rotate3DZAxis<Scalar, AngleAxisd>(angle).
toRotationMatrix();
207 template <
typename MatrixType>
213 const MatrixType q = rand.householderQr().householderQ();
217 diag(MatrixType::RowsAtCompileTime - 1, MatrixType::ColsAtCompileTime - 1) = det;
222 template <
typename Scalar,
int Dim>
246 const VectorType Zero = VectorType::Zero();
247 const VectorType Ones = VectorType::Ones();
248 const VectorType UnitX = VectorType::UnitX();
249 const VectorType UnitY = VectorType::UnitY();
251 const VectorType UnitZ = Ones - UnitX - UnitY;
255 BoxType
a(-Ones, Ones);
261 VectorType minPoint = -2 * Ones;
263 VectorType maxPoint = Zero;
265 BoxType
c(minPoint, maxPoint);
268 IsometryTransform tf2 = IsometryTransform::Identity();
293 AffineTransform atf = AffineTransform::Identity();
294 atf.linearExt()(0, 1) =
Scalar(1);
295 c = BoxType(-Ones, Ones);
312 enum { Dim = BoxType::AmbientDimAtCompileTime };
318 const Index dim = box.dim();
319 const VectorType Zero = VectorType::Zero();
320 const VectorType Ones = VectorType::Ones();
322 VectorType minPoint = -2 * Ones;
324 VectorType maxPoint = Zero;
326 BoxType
c(minPoint, maxPoint);
329 VectorType cornerBL = (c.min)();
330 VectorType cornerTR = (c.max)();
331 VectorType cornerBR = (c.min)(); cornerBR[0] = cornerTR[0];
332 VectorType cornerTL = (c.max)(); cornerTL[0] = cornerBL[0];
334 NonInteger angle = NonInteger(
EIGEN_PI/3);
336 IsometryTransform tf2;
343 cornerBL = tf2 * cornerBL;
344 cornerBR = tf2 * cornerBR;
345 cornerTL = tf2 * cornerTL;
346 cornerTR = tf2 * cornerTR;
348 VectorType minCorner = Ones *
Scalar(-2);
349 VectorType maxCorner = Zero;
350 minCorner[0] = (
min)((
min)(cornerBL[0], cornerBR[0]), (
min)(cornerTL[0], cornerTR[0]));
351 maxCorner[0] = (
max)((
max)(cornerBL[0], cornerBR[0]), (
max)(cornerTL[0], cornerTR[0]));
352 minCorner[1] = (
min)((
min)(cornerBL[1], cornerBR[1]), (
min)(cornerTL[1], cornerTR[1]));
353 maxCorner[1] = (
max)((
max)(cornerBL[1], cornerBR[1]), (
max)(cornerTL[1], cornerTR[1]));
361 VectorType minCornerValue = Ones *
Scalar(-2);
362 VectorType maxCornerValue = Zero;
366 maxCornerValue[1] =
Scalar(3 *
cos(angle));
371 for (
size_t i = 0;
i < 10; ++
i)
375 minCorner[
d] = internal::random<Scalar>(-10,10);
376 maxCorner[
d] = minCorner[
d] + internal::random<Scalar>(0, 10);
379 c = BoxType(minCorner, maxCorner);
383 typename AffineTransform::LinearMatrixType
rotation =
384 randomRotationMatrix<typename AffineTransform::LinearMatrixType>();
388 tf2.translate(VectorType::Random());
393 minCorner = corners.rowwise().minCoeff();
394 maxCorner = corners.rowwise().maxCoeff();
401 for (
size_t i = 0;
i < 10; ++
i)
405 minCorner[
d] = internal::random<Scalar>(-10,10);
406 maxCorner[
d] = minCorner[
d] + internal::random<Scalar>(0, 10);
409 c = BoxType(minCorner, maxCorner);
413 AffineTransform atf = AffineTransform::Identity();
414 atf.linearExt() = AffineTransform::LinearPart::Random();
415 atf.translate(VectorType::Random());
420 minCorner = corners.rowwise().minCoeff();
421 maxCorner = corners.rowwise().maxCoeff();
428 template<
typename BoxType>
435 const Index dim = box.dim();
437 VectorType
p0 = VectorType::Random(dim);
438 VectorType
p1 = VectorType::Random(dim);
445 const int Dim = BoxType::AmbientDimAtCompileTime;
456 Vector2f
m; m << -1.0f, -2.0f;
457 Vector2f
M; M << 1.0f, 5.0f;
459 typedef AlignedBox2f BoxType;
462 Vector2f sides = M-
m;
474 Vector2f bottomRight; bottomRight << M[0], m[1];
475 Vector2f
topLeft; topLeft << m[0], M[1];
483 Vector3i
m; m << -1, -2, 0;
484 Vector3i
M; M << 1, 5, 3;
486 typedef AlignedBox3i BoxType;
489 Vector3i sides = M-
m;
500 Vector3i bottomRightFloor; bottomRightFloor << M[0], m[1], m[2];
501 Vector3i topLeftFloor; topLeftFloor << m[0], M[1], m[2];
502 VERIFY_IS_APPROX( bottomRightFloor, box.corner( BoxType::BottomRightFloor ) );
524 CALL_SUBTEST_10( (alignedboxRotatable<AlignedBox2i, Matrix2i>(AlignedBox2i(), &rotate2DIntegral<int, Matrix2i>)) );
525 CALL_SUBTEST_11( (alignedboxRotatable<AlignedBox3i, Matrix3i>(AlignedBox3i(), &rotate3DZAxisIntegral<int, Matrix3i>)) );
void alignedboxRotatable(const BoxType &box, Rotation(*rotate)(typename NumTraits< typename BoxType::Scalar >::NonInteger))
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
#define CALL_SUBTEST_12(FUNC)
void alignedboxCastTests(const BoxType &box)
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf > svd(m, ComputeThinU|ComputeThinV)
#define CALL_SUBTEST_9(FUNC)
#define CALL_SUBTEST_6(FUNC)
#define CALL_SUBTEST_4(FUNC)
Matrix< RealScalar, Dynamic, Dynamic > M
Jet< T, N > cos(const Jet< T, N > &f)
Rotation rotate2DIntegral(typename NumTraits< Scalar >::NonInteger angle)
void alignedbox(const BoxType &box)
Matrix diag(const std::vector< Matrix > &Hs)
#define CALL_SUBTEST_13(FUNC)
#define CALL_SUBTEST_3(FUNC)
void determinant(const MatrixType &m)
const MatrixUType & matrixU() const
#define CALL_SUBTEST_7(FUNC)
#define CALL_SUBTEST_11(FUNC)
Jet< T, N > sin(const Jet< T, N > &f)
void alignedboxTranslatable(const BoxType &box)
Rotation rotate2D(Scalar angle)
#define CALL_SUBTEST_14(FUNC)
#define CALL_SUBTEST_10(FUNC)
#define EIGEN_DONT_INLINE
EIGEN_DEVICE_FUNC const AtanReturnType atan() const
#define VERIFY_IS_APPROX(a, b)
#define CALL_SUBTEST_1(FUNC)
Rotation rotate3DZAxis(Scalar angle)
static EIGEN_DEVICE_FUNC Matrix< Scalar, 2, 2 > toRotationMatrix(const Scalar &s)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
P rotate(const T &r, const P &pt)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
#define CALL_SUBTEST_8(FUNC)
void alignedboxNonIntegralRotatable(const BoxType &box, Rotation(*rotate)(typename NumTraits< typename BoxType::Scalar >::NonInteger))
EIGEN_DEVICE_FUNC const Scalar & q
EIGEN_DECLARE_TEST(geo_alignedbox)
Rotation rotate3DZAxisIntegral(typename NumTraits< Scalar >::NonInteger angle)
GTSAM_EXPORT Matrix3 topLeft(const SO4 &Q, OptionalJacobian< 9, 6 > H)
NumTraits< Scalar >::Real RealScalar
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
Represents a rotation/orientation in a 2 dimensional space.
#define CALL_SUBTEST_5(FUNC)
Two-sided Jacobi SVD decomposition of a rectangular matrix.
MatrixType randomRotationMatrix()
void corners(const MatrixType &m)
const MatrixVType & matrixV() const
#define CALL_SUBTEST_2(FUNC)
Jet< T, N > sqrt(const Jet< T, N > &f)
Matrix< Scalar, Dim,(1<< Dim)> boxGetCorners(const Matrix< Scalar, Dim, 1 > &min_, const Matrix< Scalar, Dim, 1 > &max_)
EIGEN_DONT_INLINE void kill_extra_precision(T &)
Point3 rotate(const Point3 &p, OptionalJacobian< 3, 3 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
The matrix class, also used for vectors and row-vectors.
Rot3 rotation(const Pose3 &pose, OptionalJacobian< 3, 6 > H)
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Rotation rotate4DZWAxis(Scalar angle)