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 
28  VectorType p0 = VectorType::Random(dim);
29  VectorType p1 = VectorType::Random(dim);
30 
31  VectorType d0 = VectorType::Random(dim).normalized();
32 
33  LineType l0(p0, d0);
34 
35  Scalar s0 = internal::random<Scalar>();
36  Scalar s1 = abs(internal::random<Scalar>());
37 
38  VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0), RealScalar(1) );
39  VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0+s0*d0), RealScalar(1) );
40  VERIFY_IS_APPROX( (l0.projection(p1)-p1).norm(), l0.distance(p1) );
41  VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(l0.projection(p1)), RealScalar(1) );
42  VERIFY_IS_APPROX( Scalar(l0.distance((p0+s0*d0) + d0.unitOrthogonal() * s1)), s1 );
43 
44  // casting
45  const int Dim = LineType::AmbientDimAtCompileTime;
46  typedef typename GetDifferentType<Scalar>::type OtherScalar;
47  ParametrizedLine<OtherScalar,Dim> hp1f = l0.template cast<OtherScalar>();
48  VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),l0);
49  ParametrizedLine<Scalar,Dim> hp1d = l0.template cast<Scalar>();
50  VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),l0);
51 
52  // intersections
53  VectorType p2 = VectorType::Random(dim);
54  VectorType n2 = VectorType::Random(dim).normalized();
55  HyperplaneType hp(p2,n2);
56  Scalar t = l0.intersectionParameter(hp);
57  VectorType pi = l0.pointAt(t);
58  VERIFY_IS_MUCH_SMALLER_THAN(hp.signedDistance(pi), RealScalar(1));
59  VERIFY_IS_MUCH_SMALLER_THAN(l0.distance(pi), RealScalar(1));
60  VERIFY_IS_APPROX(l0.intersectionPoint(hp), pi);
61 }
62 
63 template<typename Scalar> void parametrizedline_alignment()
64 {
67 
68  EIGEN_ALIGN_MAX Scalar array1[16];
69  EIGEN_ALIGN_MAX Scalar array2[16];
70  EIGEN_ALIGN_MAX Scalar array3[16+1];
71  Scalar* array3u = array3+1;
72 
73  Line4a *p1 = ::new(reinterpret_cast<void*>(array1)) Line4a;
74  Line4u *p2 = ::new(reinterpret_cast<void*>(array2)) Line4u;
75  Line4u *p3 = ::new(reinterpret_cast<void*>(array3u)) Line4u;
76 
77  p1->origin().setRandom();
78  p1->direction().setRandom();
79  *p2 = *p1;
80  *p3 = *p1;
81 
82  VERIFY_IS_APPROX(p1->origin(), p2->origin());
83  VERIFY_IS_APPROX(p1->origin(), p3->origin());
84  VERIFY_IS_APPROX(p1->direction(), p2->direction());
85  VERIFY_IS_APPROX(p1->direction(), p3->direction());
86 
87  #if defined(EIGEN_VECTORIZE) && EIGEN_MAX_STATIC_ALIGN_BYTES>0
88  if(internal::packet_traits<Scalar>::Vectorizable && internal::packet_traits<Scalar>::size<=4)
89  VERIFY_RAISES_ASSERT((::new(reinterpret_cast<void*>(array3u)) Line4a));
90  #endif
91 }
92 
94 {
95  for(int i = 0; i < g_repeat; i++) {
96  CALL_SUBTEST_1( parametrizedline(ParametrizedLine<float,2>()) );
97  CALL_SUBTEST_2( parametrizedline(ParametrizedLine<float,3>()) );
98  CALL_SUBTEST_2( parametrizedline_alignment<float>() );
99  CALL_SUBTEST_3( parametrizedline(ParametrizedLine<double,4>()) );
100  CALL_SUBTEST_3( parametrizedline_alignment<double>() );
101  CALL_SUBTEST_4( parametrizedline(ParametrizedLine<std::complex<double>,5>()) );
102  }
103 }
SCALAR Scalar
Definition: bench_gemm.cpp:33
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:285
void parametrizedline_alignment()
static Point3 p3
Vector3f p1
Vector3f p0
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
#define VERIFY_IS_APPROX(a, b)
void test_geo_parametrizedline()
void parametrizedline(const LineType &_line)
static int g_repeat
Definition: main.h:144
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:34
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
Definition: main.h:335
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2201
#define EIGEN_ALIGN_MAX
Definition: Macros.h:757
static Point3 p2
The matrix class, also used for vectors and row-vectors.
#define abs(x)
Definition: datatypes.h:17
friend const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
Definition: mpreal.h:2201
A parametrized line.
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:07