Hyperplane.h
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 #ifndef EIGEN_HYPERPLANE_H
12 #define EIGEN_HYPERPLANE_H
13 
14 namespace Eigen {
15 
33 template <typename _Scalar, int _AmbientDim, int _Options>
34 class Hyperplane
35 {
36 public:
37  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==Dynamic ? Dynamic : _AmbientDim+1)
38  enum {
39  AmbientDimAtCompileTime = _AmbientDim,
40  Options = _Options
41  };
42  typedef _Scalar Scalar;
44  typedef Eigen::Index Index;
47  ? Dynamic
51 
54 
55  template<int OtherOptions>
57  : m_coeffs(other.coeffs())
58  {}
59 
62  EIGEN_DEVICE_FUNC inline explicit Hyperplane(Index _dim) : m_coeffs(_dim+1) {}
63 
68  : m_coeffs(n.size()+1)
69  {
70  normal() = n;
71  offset() = -n.dot(e);
72  }
73 
79  : m_coeffs(n.size()+1)
80  {
81  normal() = n;
82  offset() = d;
83  }
84 
89  {
90  Hyperplane result(p0.size());
91  result.normal() = (p1 - p0).unitOrthogonal();
92  result.offset() = -p0.dot(result.normal());
93  return result;
94  }
95 
99  EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1, const VectorType& p2)
100  {
102  Hyperplane result(p0.size());
103  VectorType v0(p2 - p0), v1(p1 - p0);
104  result.normal() = v0.cross(v1);
105  RealScalar norm = result.normal().norm();
106  if(norm <= v0.norm() * v1.norm() * NumTraits<RealScalar>::epsilon())
107  {
108  Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
110  result.normal() = svd.matrixV().col(2);
111  }
112  else
113  result.normal() /= norm;
114  result.offset() = -p0.dot(result.normal());
115  return result;
116  }
117 
122  // FIXME to be consistent with the rest this could be implemented as a static Through function ??
124  {
125  normal() = parametrized.direction().unitOrthogonal();
126  offset() = -parametrized.origin().dot(normal());
127  }
128 
130 
133 
136  {
137  m_coeffs /= normal().norm();
138  }
139 
143  EIGEN_DEVICE_FUNC inline Scalar signedDistance(const VectorType& p) const { return normal().dot(p) + offset(); }
144 
149 
152  EIGEN_DEVICE_FUNC inline VectorType projection(const VectorType& p) const { return p - signedDistance(p) * normal(); }
153 
158 
163 
167  EIGEN_DEVICE_FUNC inline const Scalar& offset() const { return m_coeffs.coeff(dim()); }
168 
171  EIGEN_DEVICE_FUNC inline Scalar& offset() { return m_coeffs(dim()); }
172 
176  EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; }
177 
182 
190  {
192  Scalar det = coeffs().coeff(0) * other.coeffs().coeff(1) - coeffs().coeff(1) * other.coeffs().coeff(0);
193  // since the line equations ax+by=c are normalized with a^2+b^2=1, the following tests
194  // whether the two lines are approximately parallel.
196  { // special case where the two lines are approximately parallel. Pick any point on the first line.
197  if(numext::abs(coeffs().coeff(1))>numext::abs(coeffs().coeff(0)))
198  return VectorType(coeffs().coeff(1), -coeffs().coeff(2)/coeffs().coeff(1)-coeffs().coeff(0));
199  else
200  return VectorType(-coeffs().coeff(2)/coeffs().coeff(0)-coeffs().coeff(1), coeffs().coeff(0));
201  }
202  else
203  { // general case
204  Scalar invdet = Scalar(1) / det;
205  return VectorType(invdet*(coeffs().coeff(1)*other.coeffs().coeff(2)-other.coeffs().coeff(1)*coeffs().coeff(2)),
206  invdet*(other.coeffs().coeff(0)*coeffs().coeff(2)-coeffs().coeff(0)*other.coeffs().coeff(2)));
207  }
208  }
209 
216  template<typename XprType>
218  {
219  if (traits==Affine)
220  {
221  normal() = mat.inverse().transpose() * normal();
222  m_coeffs /= normal().norm();
223  }
224  else if (traits==Isometry)
225  normal() = mat * normal();
226  else
227  {
228  eigen_assert(0 && "invalid traits value in Hyperplane::transform()");
229  }
230  return *this;
231  }
232 
240  template<int TrOptions>
242  TransformTraits traits = Affine)
243  {
244  transform(t.linear(), traits);
245  offset() -= normal().dot(t.translation());
246  return *this;
247  }
248 
254  template<typename NewScalarType>
257  {
258  return typename internal::cast_return_type<Hyperplane,
260  }
261 
263  template<typename OtherScalarType,int OtherOptions>
265  { m_coeffs = other.coeffs().template cast<Scalar>(); }
266 
271  template<int OtherOptions>
273  { return m_coeffs.isApprox(other.m_coeffs, prec); }
274 
275 protected:
276 
278 };
279 
280 } // end namespace Eigen
281 
282 #endif // EIGEN_HYPERPLANE_H
Eigen::Hyperplane::m_coeffs
Coefficients m_coeffs
Definition: Hyperplane.h:277
Eigen::Hyperplane::transform
EIGEN_DEVICE_FUNC Hyperplane & transform(const Transform< Scalar, AmbientDimAtCompileTime, Affine, TrOptions > &t, TransformTraits traits=Affine)
Definition: Hyperplane.h:241
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane(const VectorType &n, const Scalar &d)
Definition: Hyperplane.h:78
Eigen::Hyperplane::transform
EIGEN_DEVICE_FUNC Hyperplane & transform(const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
Definition: Hyperplane.h:217
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::Hyperplane::Scalar
_Scalar Scalar
Definition: Hyperplane.h:42
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::cast_return_type
Definition: XprHelper.h:509
Eigen::Hyperplane::absDistance
EIGEN_DEVICE_FUNC Scalar absDistance(const VectorType &p) const
Definition: Hyperplane.h:148
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane()
Definition: Hyperplane.h:53
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Eigen::ComputeFullV
@ ComputeFullV
Definition: Constants.h:397
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::Transform
Represents an homogeneous transformation in a N dimensional space.
Definition: ForwardDeclarations.h:294
Eigen::Hyperplane::offset
EIGEN_DEVICE_FUNC Scalar & offset()
Definition: Hyperplane.h:171
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
d
static const double d[K][N]
Definition: igam.h:11
Eigen::Hyperplane::~Hyperplane
EIGEN_DEVICE_FUNC ~Hyperplane()
Definition: Hyperplane.h:129
v0
static const double v0
Definition: testCal3DFisheye.cpp:31
Eigen::Affine
@ Affine
Definition: Constants.h:460
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::Hyperplane::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: Hyperplane.h:43
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane(const ParametrizedLine< Scalar, AmbientDimAtCompileTime > &parametrized)
Definition: Hyperplane.h:123
Eigen::Hyperplane::offset
const EIGEN_DEVICE_FUNC Scalar & offset() const
Definition: Hyperplane.h:167
Eigen::Hyperplane::coeffs
const EIGEN_DEVICE_FUNC Coefficients & coeffs() const
Definition: Hyperplane.h:176
Eigen::ParametrizedLine::direction
const EIGEN_DEVICE_FUNC VectorType & direction() const
Definition: ParametrizedLine.h:76
type
Definition: pytypes.h:1525
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Eigen::internal::isMuchSmallerThan
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: Eigen/src/Core/MathFunctions.h:1940
Eigen::Hyperplane::Through
static EIGEN_DEVICE_FUNC Hyperplane Through(const VectorType &p0, const VectorType &p1)
Definition: Hyperplane.h:88
result
Values result
Definition: OdometryOptimize.cpp:8
svd
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf > svd(m, ComputeThinU|ComputeThinV)
Eigen::Hyperplane::NormalReturnType
Block< Coefficients, AmbientDimAtCompileTime, 1 > NormalReturnType
Definition: Hyperplane.h:49
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane(const VectorType &n, const VectorType &e)
Definition: Hyperplane.h:67
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::Hyperplane::AmbientDimAtCompileTime
@ AmbientDimAtCompileTime
Definition: Hyperplane.h:39
n
int n
Definition: BiCGSTAB_simple.cpp:1
simple::p2
static Point3 p2
Definition: testInitializePose3.cpp:51
Eigen::Hyperplane::Options
@ Options
Definition: Hyperplane.h:40
Eigen::Hyperplane::normalize
EIGEN_DEVICE_FUNC void normalize(void)
Definition: Hyperplane.h:135
Eigen::Isometry
@ Isometry
Definition: Constants.h:457
Eigen::TransformTraits
TransformTraits
Definition: Constants.h:455
Eigen::Hyperplane::ConstNormalReturnType
const typedef Block< const Coefficients, AmbientDimAtCompileTime, 1 > ConstNormalReturnType
Definition: Hyperplane.h:50
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::Hyperplane::isApprox
EIGEN_DEVICE_FUNC bool isApprox(const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Hyperplane.h:272
Eigen::Hyperplane
A hyperplane.
Definition: ForwardDeclarations.h:296
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
Eigen::Hyperplane::Coefficients
Matrix< Scalar, Index(AmbientDimAtCompileTime)==Dynamic ? Dynamic :Index(AmbientDimAtCompileTime)+1, 1, Options > Coefficients
Definition: Hyperplane.h:48
Eigen::Hyperplane::intersection
EIGEN_DEVICE_FUNC VectorType intersection(const Hyperplane &other) const
Definition: Hyperplane.h:189
Eigen::ParametrizedLine
A parametrized line.
Definition: ForwardDeclarations.h:295
p1
Vector3f p1
Definition: MatrixBase_all.cpp:2
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:157
Eigen::JacobiSVD
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: ForwardDeclarations.h:278
Eigen::Hyperplane::VectorType
Matrix< Scalar, AmbientDimAtCompileTime, 1 > VectorType
Definition: Hyperplane.h:45
Eigen::Hyperplane::projection
EIGEN_DEVICE_FUNC VectorType projection(const VectorType &p) const
Definition: Hyperplane.h:152
Eigen::Hyperplane::dim
EIGEN_DEVICE_FUNC Index dim() const
Definition: Hyperplane.h:132
Eigen::Hyperplane::Through
static EIGEN_DEVICE_FUNC Hyperplane Through(const VectorType &p0, const VectorType &p1, const VectorType &p2)
Definition: Hyperplane.h:99
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane(const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other)
Definition: Hyperplane.h:56
Eigen::Hyperplane::coeffs
EIGEN_DEVICE_FUNC Coefficients & coeffs()
Definition: Hyperplane.h:181
p0
Vector3f p0
Definition: MatrixBase_all.cpp:2
Eigen::Hyperplane::normal
EIGEN_DEVICE_FUNC NormalReturnType normal()
Definition: Hyperplane.h:162
p
float * p
Definition: Tutorial_Map_using.cpp:9
Eigen::PlainObjectBase::coeff
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:152
Eigen::Hyperplane::normal
EIGEN_DEVICE_FUNC ConstNormalReturnType normal() const
Definition: Hyperplane.h:157
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane(Index _dim)
Definition: Hyperplane.h:62
Eigen::Hyperplane::Hyperplane
EIGEN_DEVICE_FUNC Hyperplane(const Hyperplane< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &other)
Definition: Hyperplane.h:264
Eigen::Matrix< Scalar, AmbientDimAtCompileTime, 1 >
Eigen::numext::abs
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
Definition: Eigen/src/Core/MathFunctions.h:1511
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::Hyperplane::signedDistance
EIGEN_DEVICE_FUNC Scalar signedDistance(const VectorType &p) const
Definition: Hyperplane.h:143
Eigen::Hyperplane::cast
EIGEN_DEVICE_FUNC internal::cast_return_type< Hyperplane, Hyperplane< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast() const
Definition: Hyperplane.h:256
align_3::t
Point2 t(10, 10)
Eigen::Hyperplane::Index
Eigen::Index Index
Definition: Hyperplane.h:44
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Definition: Memory.h:842
v1
Vector v1
Definition: testSerializationBase.cpp:38
Eigen::ParametrizedLine::origin
const EIGEN_DEVICE_FUNC VectorType & origin() const
Definition: ParametrizedLine.h:73
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:26