Homogeneous.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) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_HOMOGENEOUS_H
11 #define EIGEN_HOMOGENEOUS_H
12 
13 namespace Eigen {
14 
30 namespace internal {
31 
32 template<typename MatrixType,int Direction>
33 struct traits<Homogeneous<MatrixType,Direction> >
34  : traits<MatrixType>
35 {
39  enum {
40  RowsPlusOne = (MatrixType::RowsAtCompileTime != Dynamic) ?
41  int(MatrixType::RowsAtCompileTime) + 1 : Dynamic,
42  ColsPlusOne = (MatrixType::ColsAtCompileTime != Dynamic) ?
43  int(MatrixType::ColsAtCompileTime) + 1 : Dynamic,
44  RowsAtCompileTime = Direction==Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
45  ColsAtCompileTime = Direction==Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
46  MaxRowsAtCompileTime = RowsAtCompileTime,
47  MaxColsAtCompileTime = ColsAtCompileTime,
48  TmpFlags = _MatrixTypeNested::Flags & HereditaryBits,
49  Flags = ColsAtCompileTime==1 ? (TmpFlags & ~RowMajorBit)
50  : RowsAtCompileTime==1 ? (TmpFlags | RowMajorBit)
51  : TmpFlags,
52  CoeffReadCost = _MatrixTypeNested::CoeffReadCost
53  };
54 };
55 
56 template<typename MatrixType,typename Lhs> struct homogeneous_left_product_impl;
57 template<typename MatrixType,typename Rhs> struct homogeneous_right_product_impl;
58 
59 } // end namespace internal
60 
61 template<typename MatrixType,int _Direction> class Homogeneous
62  : internal::no_assignment_operator, public MatrixBase<Homogeneous<MatrixType,_Direction> >
63 {
64  public:
65 
66  enum { Direction = _Direction };
67 
70 
71  inline Homogeneous(const MatrixType& matrix)
72  : m_matrix(matrix)
73  {}
74 
75  inline Index rows() const { return m_matrix.rows() + (int(Direction)==Vertical ? 1 : 0); }
76  inline Index cols() const { return m_matrix.cols() + (int(Direction)==Horizontal ? 1 : 0); }
77 
78  inline Scalar coeff(Index row, Index col) const
79  {
80  if( (int(Direction)==Vertical && row==m_matrix.rows())
81  || (int(Direction)==Horizontal && col==m_matrix.cols()))
82  return 1;
83  return m_matrix.coeff(row, col);
84  }
85 
86  template<typename Rhs>
88  operator* (const MatrixBase<Rhs>& rhs) const
89  {
90  eigen_assert(int(Direction)==Horizontal);
91  return internal::homogeneous_right_product_impl<Homogeneous,Rhs>(m_matrix,rhs.derived());
92  }
93 
94  template<typename Lhs> friend
96  operator* (const MatrixBase<Lhs>& lhs, const Homogeneous& rhs)
97  {
98  eigen_assert(int(Direction)==Vertical);
100  }
101 
102  template<typename Scalar, int Dim, int Mode, int Options> friend
105  {
106  eigen_assert(int(Direction)==Vertical);
108  }
109 
110  protected:
111  typename MatrixType::Nested m_matrix;
112 };
113 
125 template<typename Derived>
128 {
130  return derived();
131 }
132 
141 template<typename ExpressionType, int Direction>
144 {
145  return _expression();
146 }
147 
156 template<typename Derived>
157 inline const typename MatrixBase<Derived>::HNormalizedReturnType
159 {
161  return ConstStartMinusOne(derived(),0,0,
162  ColsAtCompileTime==1?size()-1:1,
163  ColsAtCompileTime==1?1:size()-1) / coeff(size()-1);
164 }
165 
174 template<typename ExpressionType, int Direction>
177 {
178  return HNormalized_Block(_expression(),0,0,
179  Direction==Vertical ? _expression().rows()-1 : _expression().rows(),
180  Direction==Horizontal ? _expression().cols()-1 : _expression().cols()).cwiseQuotient(
182  Direction==Vertical ? HNormalized_SizeMinusOne : 1,
183  Direction==Horizontal ? HNormalized_SizeMinusOne : 1>
184  (HNormalized_Factors(_expression(),
185  Direction==Vertical ? _expression().rows()-1:0,
186  Direction==Horizontal ? _expression().cols()-1:0,
187  Direction==Vertical ? 1 : _expression().rows(),
188  Direction==Horizontal ? 1 : _expression().cols()),
189  Direction==Vertical ? _expression().rows()-1 : 1,
190  Direction==Horizontal ? _expression().cols()-1 : 1));
191 }
192 
193 namespace internal {
194 
195 template<typename MatrixOrTransformType>
197 {
198  typedef MatrixOrTransformType type;
199  static const type& run(const type &x) { return x; }
200 };
201 
202 template<typename Scalar, int Dim, int Mode,int Options>
203 struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
204 {
207  static type run (const TransformType& x) { return x.affine(); }
208 };
209 
210 template<typename Scalar, int Dim, int Options>
211 struct take_matrix_for_product<Transform<Scalar, Dim, Projective, Options> >
212 {
214  typedef typename TransformType::MatrixType type;
215  static const type& run (const TransformType& x) { return x.matrix(); }
216 };
217 
218 template<typename MatrixType,typename Lhs>
220 {
224  typedef typename make_proper_matrix_type<
226  LhsMatrixTypeCleaned::RowsAtCompileTime,
227  MatrixTypeCleaned::ColsAtCompileTime,
228  MatrixTypeCleaned::PlainObject::Options,
229  LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
230  MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
231 };
232 
233 template<typename MatrixType,typename Lhs>
235  : public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
236 {
240  typedef typename MatrixType::Index Index;
241  homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs)
242  : m_lhs(take_matrix_for_product<Lhs>::run(lhs)),
243  m_rhs(rhs)
244  {}
245 
246  inline Index rows() const { return m_lhs.rows(); }
247  inline Index cols() const { return m_rhs.cols(); }
248 
249  template<typename Dest> void evalTo(Dest& dst) const
250  {
251  // FIXME investigate how to allow lazy evaluation of this product when possible
252  dst = Block<const LhsMatrixTypeNested,
253  LhsMatrixTypeNested::RowsAtCompileTime,
254  LhsMatrixTypeNested::ColsAtCompileTime==Dynamic?Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1>
255  (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs;
256  dst += m_lhs.col(m_lhs.cols()-1).rowwise()
257  .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
258  }
259 
260  typename LhsMatrixTypeCleaned::Nested m_lhs;
261  typename MatrixType::Nested m_rhs;
262 };
263 
264 template<typename MatrixType,typename Rhs>
266 {
268  MatrixType::RowsAtCompileTime,
269  Rhs::ColsAtCompileTime,
270  MatrixType::PlainObject::Options,
271  MatrixType::MaxRowsAtCompileTime,
272  Rhs::MaxColsAtCompileTime>::type ReturnType;
273 };
274 
275 template<typename MatrixType,typename Rhs>
277  : public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
278 {
280  typedef typename MatrixType::Index Index;
281  homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs)
282  : m_lhs(lhs), m_rhs(rhs)
283  {}
284 
285  inline Index rows() const { return m_lhs.rows(); }
286  inline Index cols() const { return m_rhs.cols(); }
287 
288  template<typename Dest> void evalTo(Dest& dst) const
289  {
290  // FIXME investigate how to allow lazy evaluation of this product when possible
291  dst = m_lhs * Block<const RhsNested,
292  RhsNested::RowsAtCompileTime==Dynamic?Dynamic:RhsNested::RowsAtCompileTime-1,
293  RhsNested::ColsAtCompileTime>
294  (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols());
295  dst += m_rhs.row(m_rhs.rows()-1).colwise()
296  .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
297  }
298 
299  typename MatrixType::Nested m_lhs;
300  typename Rhs::Nested m_rhs;
301 };
302 
303 } // end namespace internal
304 
305 } // end namespace Eigen
306 
307 #endif // EIGEN_HOMOGENEOUS_H
Scalar coeff(Index row, Index col) const
Definition: Homogeneous.h:78
Index cols() const
Definition: Homogeneous.h:76
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
Expression of the transpose of a matrix.
Definition: Transpose.h:57
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Homogeneous.h:38
Definition: LDLT.h:16
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Pseudo expression providing partial reduction operations.
const unsigned int RowMajorBit
Definition: Constants.h:53
ConstAffinePart affine() const
const HNormalizedReturnType hnormalized() const
Definition: Homogeneous.h:158
Generic expression where a coefficient-wise binary operator is applied to two expressions.
const unsigned int HereditaryBits
Definition: Constants.h:152
make_proper_matrix_type< typename traits< MatrixType >::Scalar, MatrixType::RowsAtCompileTime, Rhs::ColsAtCompileTime, MatrixType::PlainObject::Options, MatrixType::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime >::type ReturnType
Definition: Homogeneous.h:272
remove_all< typename LhsMatrixTypeCleaned::Nested >::type LhsMatrixTypeNested
Definition: Homogeneous.h:239
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:62
Index rows() const
Definition: Homogeneous.h:75
const HNormalizedReturnType hnormalized() const
Definition: Homogeneous.h:176
static const type & run(const type &x)
Definition: Homogeneous.h:199
make_proper_matrix_type< typename traits< MatrixTypeCleaned >::Scalar, LhsMatrixTypeCleaned::RowsAtCompileTime, MatrixTypeCleaned::ColsAtCompileTime, MatrixTypeCleaned::PlainObject::Options, LhsMatrixTypeCleaned::MaxRowsAtCompileTime, MatrixTypeCleaned::MaxColsAtCompileTime >::type ReturnType
Definition: Homogeneous.h:230
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
const MatrixType & matrix() const
Expression of a fixed-size or dynamic-size block.
Definition: Core/Block.h:102
RowXpr row(Index i)
Definition: BlockMethods.h:725
internal::add_const< typename TransformType::ConstAffinePart >::type type
Definition: Homogeneous.h:206
const int Dynamic
Definition: Constants.h:21
ColXpr col(Index i)
Definition: BlockMethods.h:708
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
#define eigen_assert(x)
MatrixBase< Homogeneous > Base
Definition: Homogeneous.h:68
MatrixType::Nested m_matrix
Definition: Homogeneous.h:111
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:126
void run(ClassLoader *loader)
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Represents an homogeneous transformation in a N dimensional space.
Expression of one (or a set of) homogeneous vector(s)
Definition: Homogeneous.h:61


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:50