geo_parametrizedline.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #include "main.h"
12 #include <Eigen/Geometry>
13 #include <Eigen/LU>
14 #include <Eigen/QR>
15 
16 template<typename LineType> void parametrizedline(const LineType& _line)
17 {
18  /* this test covers the following files:
19  ParametrizedLine.h
20  */
21  using std::abs;
22  const Index dim = _line.dim();
23  typedef typename LineType::Scalar Scalar;
24  typedef typename NumTraits<Scalar>::Real RealScalar;
27  typedef Matrix<Scalar, HyperplaneType::AmbientDimAtCompileTime,
28  HyperplaneType::AmbientDimAtCompileTime> MatrixType;
29 
30  VectorType p0 = VectorType::Random(dim);
31  VectorType p1 = VectorType::Random(dim);
32 
33  VectorType d0 = VectorType::Random(dim).normalized();
34 
35  LineType l0(p0, d0);
36 
37  Scalar s0 = internal::random<Scalar>();
38  Scalar s1 = abs(internal::random<Scalar>());
39 
41  VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0+s0*d0), RealScalar(1) );
42  VERIFY_IS_APPROX( (l0.projection(p1)-p1).norm(), l0.distance(p1) );
43  VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(l0.projection(p1)), RealScalar(1) );
44  VERIFY_IS_APPROX( Scalar(l0.distance((p0+s0*d0) + d0.unitOrthogonal() * s1)), s1 );
45 
46  // casting
47  const int Dim = LineType::AmbientDimAtCompileTime;
48  typedef typename GetDifferentType<Scalar>::type OtherScalar;
49  ParametrizedLine<OtherScalar,Dim> hp1f = l0.template cast<OtherScalar>();
50  VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),l0);
51  ParametrizedLine<Scalar,Dim> hp1d = l0.template cast<Scalar>();
52  VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),l0);
53 
54  // intersections
55  VectorType p2 = VectorType::Random(dim);
56  VectorType n2 = VectorType::Random(dim).normalized();
57  HyperplaneType hp(p2,n2);
58  Scalar t = l0.intersectionParameter(hp);
59  VectorType pi = l0.pointAt(t);
60  VERIFY_IS_MUCH_SMALLER_THAN(hp.signedDistance(pi), RealScalar(1));
61  VERIFY_IS_MUCH_SMALLER_THAN(l0.distance(pi), RealScalar(1));
62  VERIFY_IS_APPROX(l0.intersectionPoint(hp), pi);
63 
64  // transform
66  {
67  MatrixType rot = MatrixType::Random(dim,dim).householderQr().householderQ();
70 
71  while(scaling.diagonal().cwiseAbs().minCoeff()<RealScalar(1e-4)) scaling.diagonal() = VectorType::Random();
72 
73  LineType l1 = l0;
74  VectorType p3 = l0.pointAt(Scalar(1));
75  VERIFY_IS_MUCH_SMALLER_THAN( l1.transform(rot).distance(rot * p3), Scalar(1) );
76  l1 = l0;
77  VERIFY_IS_MUCH_SMALLER_THAN( l1.transform(rot,Isometry).distance(rot * p3), Scalar(1) );
78  l1 = l0;
79  VERIFY_IS_MUCH_SMALLER_THAN( l1.transform(rot*scaling).distance((rot*scaling) * p3), Scalar(1) );
80  l1 = l0;
81  VERIFY_IS_MUCH_SMALLER_THAN( l1.transform(rot*scaling*translation)
82  .distance((rot*scaling*translation) * p3), Scalar(1) );
83  l1 = l0;
85  .distance((rot*translation) * p3), Scalar(1) );
86  }
87 
88 }
89 
90 template<typename Scalar> void parametrizedline_alignment()
91 {
94 
95  EIGEN_ALIGN_MAX Scalar array1[16];
96  EIGEN_ALIGN_MAX Scalar array2[16];
97  EIGEN_ALIGN_MAX Scalar array3[16+1];
98  Scalar* array3u = array3+1;
99 
100  Line4a *p1 = ::new(reinterpret_cast<void*>(array1)) Line4a;
101  Line4u *p2 = ::new(reinterpret_cast<void*>(array2)) Line4u;
102  Line4u *p3 = ::new(reinterpret_cast<void*>(array3u)) Line4u;
103 
104  p1->origin().setRandom();
105  p1->direction().setRandom();
106  *p2 = *p1;
107  *p3 = *p1;
108 
109  VERIFY_IS_APPROX(p1->origin(), p2->origin());
110  VERIFY_IS_APPROX(p1->origin(), p3->origin());
111  VERIFY_IS_APPROX(p1->direction(), p2->direction());
112  VERIFY_IS_APPROX(p1->direction(), p3->direction());
113 }
114 
115 EIGEN_DECLARE_TEST(geo_parametrizedline)
116 {
117  for(int i = 0; i < g_repeat; i++) {
120  CALL_SUBTEST_2( parametrizedline_alignment<float>() );
122  CALL_SUBTEST_3( parametrizedline_alignment<double>() );
123  CALL_SUBTEST_4( parametrizedline(ParametrizedLine<std::complex<double>,5>()) );
124  }
125 }
VERIFY_IS_MUCH_SMALLER_THAN
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
Definition: main.h:390
Eigen::DiagonalMatrix
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:140
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(geo_parametrizedline)
Definition: geo_parametrizedline.cpp:115
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
parametrizedline
void parametrizedline(const LineType &_line)
Definition: geo_parametrizedline.cpp:16
l0
static Symbol l0('L', 0)
rot
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
Definition: level1_real_impl.h:79
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
EIGEN_ALIGN_MAX
#define EIGEN_ALIGN_MAX
Definition: ConfigureVectorization.h:157
simple::p2
static Point3 p2
Definition: testInitializePose3.cpp:51
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
Eigen::DiagonalMatrix::diagonal
const EIGEN_DEVICE_FUNC DiagonalVectorType & diagonal() const
Definition: DiagonalMatrix.h:160
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
benchmark.n2
n2
Definition: benchmark.py:85
Eigen::Isometry
@ Isometry
Definition: Constants.h:457
Eigen::Hyperplane
A hyperplane.
Definition: ForwardDeclarations.h:296
simple::p3
static Point3 p3
Definition: testInitializePose3.cpp:53
Eigen::g_repeat
static int g_repeat
Definition: main.h:169
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
Eigen::ParametrizedLine
A parametrized line.
Definition: ForwardDeclarations.h:295
p1
Vector3f p1
Definition: MatrixBase_all.cpp:2
parametrizedline_alignment
void parametrizedline_alignment()
Definition: geo_parametrizedline.cpp:90
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:47
main.h
gtsam::internal::translation
Point3 translation(const Pose3 &pose, OptionalJacobian< 3, 6 > H)
Definition: slam/expressions.h:84
p0
Vector3f p0
Definition: MatrixBase_all.cpp:2
l1
gtsam::Key l1
Definition: testLinearContainerFactor.cpp:24
Eigen::Translation
Represents a translation transformation.
Definition: ForwardDeclarations.h:291
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
abs
#define abs(x)
Definition: datatypes.h:17
GetDifferentType
Definition: main.h:725
VectorType
Definition: FFTW.cpp:65
align_3::t
Point2 t(10, 10)
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:21