geo_hyperplane.cpp File Reference
#include "main.h"
#include <Eigen/Geometry>
#include <Eigen/LU>
#include <Eigen/QR>

Functions

template<typename HyperplaneType >
void hyperplane (const HyperplaneType &_plane)
 
template<typename Scalar >
void lines ()
 
template<typename Scalar >
void planes ()
 
template<typename Scalar >
void hyperplane_alignment ()
 
 EIGEN_DECLARE_TEST (geo_hyperplane)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( geo_hyperplane  )
171  {
172  for (int i = 0; i < g_repeat; i++) {
176  CALL_SUBTEST_2(hyperplane_alignment<float>());
178  CALL_SUBTEST_4(hyperplane(Hyperplane<std::complex<double>, 5>()));
179  CALL_SUBTEST_1(lines<float>());
180  CALL_SUBTEST_3(lines<double>());
181  CALL_SUBTEST_2(planes<float>());
182  CALL_SUBTEST_5(planes<double>());
183  }
184 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
A hyperplane.
Definition: Hyperplane.h:37
void hyperplane(const HyperplaneType &_plane)
Definition: geo_hyperplane.cpp:17
static int g_repeat
Definition: main.h:191
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, Eigen::g_repeat, hyperplane(), and i.

◆ hyperplane()

template<typename HyperplaneType >
void hyperplane ( const HyperplaneType &  _plane)
17  {
18  /* this test covers the following files:
19  Hyperplane.h
20  */
21  using std::abs;
22  const Index dim = _plane.dim();
23  enum { Options = HyperplaneType::Options };
24  typedef typename HyperplaneType::Scalar Scalar;
25  typedef typename HyperplaneType::RealScalar RealScalar;
28 
29  VectorType p0 = VectorType::Random(dim);
30  VectorType p1 = VectorType::Random(dim);
31 
32  VectorType n0 = VectorType::Random(dim).normalized();
33  VectorType n1 = VectorType::Random(dim).normalized();
34 
35  HyperplaneType pl0(n0, p0);
36  HyperplaneType pl1(n1, p1);
37  HyperplaneType pl2 = pl1;
38 
39  Scalar s0 = internal::random<Scalar>();
40  Scalar s1 = internal::random<Scalar>();
41 
42  VERIFY_IS_APPROX(n1.dot(n1), Scalar(1));
43 
44  VERIFY_IS_MUCH_SMALLER_THAN(pl0.absDistance(p0), Scalar(1));
45  if (numext::abs2(s0) > RealScalar(1e-6))
46  VERIFY_IS_APPROX(pl1.signedDistance(p1 + n1 * s0), s0);
47  else
48  VERIFY_IS_MUCH_SMALLER_THAN(abs(pl1.signedDistance(p1 + n1 * s0) - s0), Scalar(1));
49  VERIFY_IS_MUCH_SMALLER_THAN(pl1.signedDistance(pl1.projection(p0)), Scalar(1));
50  VERIFY_IS_MUCH_SMALLER_THAN(pl1.absDistance(p1 + pl1.normal().unitOrthogonal() * s1), Scalar(1));
51 
52  // transform
54  MatrixType rot = MatrixType::Random(dim, dim).householderQr().householderQ();
56  Translation<Scalar, HyperplaneType::AmbientDimAtCompileTime> translation(VectorType::Random());
57 
58  while (scaling.diagonal().cwiseAbs().minCoeff() < RealScalar(1e-4)) scaling.diagonal() = VectorType::Random();
59 
60  pl2 = pl1;
61  VERIFY_IS_MUCH_SMALLER_THAN(pl2.transform(rot).absDistance(rot * p1), Scalar(1));
62  pl2 = pl1;
63  VERIFY_IS_MUCH_SMALLER_THAN(pl2.transform(rot, Isometry).absDistance(rot * p1), Scalar(1));
64  pl2 = pl1;
65  VERIFY_IS_MUCH_SMALLER_THAN(pl2.transform(rot * scaling).absDistance((rot * scaling) * p1), Scalar(1));
66  VERIFY_IS_APPROX(pl2.normal().norm(), RealScalar(1));
67  pl2 = pl1;
69  pl2.transform(rot * scaling * translation).absDistance((rot * scaling * translation) * p1), Scalar(1));
70  VERIFY_IS_APPROX(pl2.normal().norm(), RealScalar(1));
71  pl2 = pl1;
72  VERIFY_IS_MUCH_SMALLER_THAN(pl2.transform(rot * translation, Isometry).absDistance((rot * translation) * p1),
73  Scalar(1));
74  VERIFY_IS_APPROX(pl2.normal().norm(), RealScalar(1));
75  }
76 
77  // casting
78  const int Dim = HyperplaneType::AmbientDimAtCompileTime;
79  typedef typename GetDifferentType<Scalar>::type OtherScalar;
80  Hyperplane<OtherScalar, Dim, Options> hp1f = pl1.template cast<OtherScalar>();
81  VERIFY_IS_APPROX(hp1f.template cast<Scalar>(), pl1);
82  Hyperplane<Scalar, Dim, Options> hp1d = pl1.template cast<Scalar>();
83  VERIFY_IS_APPROX(hp1d.template cast<Scalar>(), pl1);
84 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Vector3f p0
Definition: MatrixBase_all.cpp:2
Vector3f p1
Definition: MatrixBase_all.cpp:2
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:172
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Represents a translation transformation.
Definition: Translation.h:33
@ Isometry
Definition: Constants.h:455
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
EIGEN_BLAS_FUNC() rot(int *n, Scalar *px, int *incx, Scalar *py, int *incy, Scalar *pc, Scalar *ps)
Definition: level1_real_impl.h:88
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
Definition: main.h:371
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1102
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
static const unsigned Dim
Problem dimension.
Definition: two_d_tilted_square.cc:62
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: main.h:736
Definition: fft_test_shared.h:66

References abs(), Eigen::numext::abs2(), Eigen::DiagonalMatrix< Scalar_, SizeAtCompileTime, MaxSizeAtCompileTime >::diagonal(), Global_Variables::Dim, e(), Eigen::Isometry, p0, p1, rot(), VERIFY_IS_APPROX, and VERIFY_IS_MUCH_SMALLER_THAN.

Referenced by EIGEN_DECLARE_TEST(), Eigen::ParametrizedLine< Scalar_, AmbientDim_, Options_ >::intersection(), Eigen::ParametrizedLine< Scalar_, AmbientDim_, Options_ >::intersectionParameter(), Eigen::ParametrizedLine< Scalar_, AmbientDim_, Options_ >::intersectionPoint(), and Eigen::ParametrizedLine< Scalar_, AmbientDim_, Options_ >::ParametrizedLine().

◆ hyperplane_alignment()

template<typename Scalar >
void hyperplane_alignment ( )
150  {
151  typedef Hyperplane<Scalar, 3, AutoAlign> Plane3a;
152  typedef Hyperplane<Scalar, 3, DontAlign> Plane3u;
153 
154  EIGEN_ALIGN_MAX Scalar array1[4];
155  EIGEN_ALIGN_MAX Scalar array2[4];
156  EIGEN_ALIGN_MAX Scalar array3[4 + 1];
157  Scalar *array3u = array3 + 1;
158 
159  Plane3a *p1 = ::new (reinterpret_cast<void *>(array1)) Plane3a;
160  Plane3u *p2 = ::new (reinterpret_cast<void *>(array2)) Plane3u;
161  Plane3u *p3 = ::new (reinterpret_cast<void *>(array3u)) Plane3u;
162 
163  p1->coeffs().setRandom();
164  *p2 = *p1;
165  *p3 = *p1;
166 
167  VERIFY_IS_APPROX(p1->coeffs(), p2->coeffs());
168  VERIFY_IS_APPROX(p1->coeffs(), p3->coeffs());
169 }
#define EIGEN_ALIGN_MAX
Definition: ConfigureVectorization.h:146

References EIGEN_ALIGN_MAX, p1, and VERIFY_IS_APPROX.

◆ lines()

template<typename Scalar >
void lines ( )
87  {
88  using std::abs;
89  typedef Hyperplane<Scalar, 2> HLine;
90  typedef ParametrizedLine<Scalar, 2> PLine;
92  typedef Matrix<Scalar, 3, 1> CoeffsType;
93 
94  for (int i = 0; i < 10; i++) {
95  Vector center = Vector::Random();
96  Vector u = Vector::Random();
97  Vector v = Vector::Random();
98  Scalar a = internal::random<Scalar>();
99  while (abs(a - 1) < Scalar(1e-4)) a = internal::random<Scalar>();
100  while (u.norm() < Scalar(1e-4)) u = Vector::Random();
101  while (v.norm() < Scalar(1e-4)) v = Vector::Random();
102 
103  HLine line_u = HLine::Through(center + u, center + a * u);
104  HLine line_v = HLine::Through(center + v, center + a * v);
105 
106  // the line equations should be normalized so that a^2+b^2=1
107  VERIFY_IS_APPROX(line_u.normal().norm(), Scalar(1));
108  VERIFY_IS_APPROX(line_v.normal().norm(), Scalar(1));
109 
110  Vector result = line_u.intersection(line_v);
111 
112  // the lines should intersect at the point we called "center"
113  if (abs(a - 1) > Scalar(1e-2) && abs(v.normalized().dot(u.normalized())) < Scalar(0.9))
114  VERIFY_IS_APPROX(result, center);
115 
116  // check conversions between two types of lines
117  PLine pl(line_u); // gcc 3.3 will crash if we don't name this variable.
118  HLine line_u2(pl);
119  CoeffsType converted_coeffs = line_u2.coeffs();
120  if (line_u2.normal().dot(line_u.normal()) < Scalar(0)) converted_coeffs = -line_u2.coeffs();
121  VERIFY(line_u.coeffs().isApprox(converted_coeffs));
122  }
123 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
A parametrized line.
Definition: ParametrizedLine.h:33
Matrix< Type, Size, 1 > Vector
\cpp11 SizeƗ1 vector of type Type.
Definition: Eigen/Eigen/src/Core/Matrix.h:515
const Scalar * a
Definition: level2_cplx_impl.h:32
#define VERIFY(a)
Definition: main.h:362

References a, abs(), e(), i, v, VERIFY, and VERIFY_IS_APPROX.

◆ planes()

template<typename Scalar >
void planes ( )
126  {
127  using std::abs;
128  typedef Hyperplane<Scalar, 3> Plane;
130 
131  for (int i = 0; i < 10; i++) {
132  Vector v0 = Vector::Random();
133  Vector v1(v0), v2(v0);
134  if (internal::random<double>(0, 1) > 0.25) v1 += Vector::Random();
135  if (internal::random<double>(0, 1) > 0.25)
136  v2 += v1 * std::pow(internal::random<Scalar>(0, 1), internal::random<int>(1, 16));
137  if (internal::random<double>(0, 1) > 0.25)
138  v2 += Vector::Random() * std::pow(internal::random<Scalar>(0, 1), internal::random<int>(1, 16));
139 
140  Plane p0 = Plane::Through(v0, v1, v2);
141 
142  VERIFY_IS_APPROX(p0.normal().norm(), Scalar(1));
143  VERIFY_IS_MUCH_SMALLER_THAN(p0.absDistance(v0), Scalar(1));
144  VERIFY_IS_MUCH_SMALLER_THAN(p0.absDistance(v1), Scalar(1));
145  VERIFY_IS_MUCH_SMALLER_THAN(p0.absDistance(v2), Scalar(1));
146  }
147 }
Map< RowVectorXf > v2(M2.data(), M2.size())
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625

References abs(), i, p0, Eigen::bfloat16_impl::pow(), v1(), v2(), VERIFY_IS_APPROX, and VERIFY_IS_MUCH_SMALLER_THAN.