10#ifndef EIGEN_HOMOGENEOUS_H
11#define EIGEN_HOMOGENEOUS_H
32template<
typename MatrixType,
int Direction>
33struct traits<Homogeneous<MatrixType,Direction> >
36 typedef typename traits<MatrixType>::StorageKind StorageKind;
37 typedef typename nested<MatrixType>::type MatrixTypeNested;
38 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
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)
52 CoeffReadCost = _MatrixTypeNested::CoeffReadCost
56template<
typename MatrixType,
typename Lhs>
struct homogeneous_left_product_impl;
57template<
typename MatrixType,
typename Rhs>
struct homogeneous_right_product_impl;
61template<
typename MatrixType,
int _Direction>
class Homogeneous
62 :
public MatrixBase<Homogeneous<MatrixType,_Direction> >
66 enum { Direction = _Direction };
68 typedef MatrixBase<Homogeneous> Base;
69 EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous)
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); }
80 if( (
int(Direction)==
Vertical &&
row==m_matrix.rows())
83 return m_matrix.coeff(
row,
col);
86 template<
typename Rhs>
87 inline const internal::homogeneous_right_product_impl<Homogeneous,Rhs>
88 operator* (
const MatrixBase<Rhs>& rhs)
const
91 return internal::homogeneous_right_product_impl<Homogeneous,Rhs>(m_matrix,rhs.derived());
94 template<
typename Lhs>
friend
95 inline const internal::homogeneous_left_product_impl<Homogeneous,Lhs>
96 operator* (
const MatrixBase<Lhs>& lhs,
const Homogeneous& rhs)
98 eigen_assert(
int(Direction)==
Vertical);
99 return internal::homogeneous_left_product_impl<Homogeneous,Lhs>(lhs.derived(),rhs.m_matrix);
102 template<
typename Scalar,
int Dim,
int Mode,
int Options>
friend
103 inline const internal::homogeneous_left_product_impl<Homogeneous,Transform<Scalar,Dim,Mode,Options> >
106 eigen_assert(
int(Direction)==
Vertical);
107 return internal::homogeneous_left_product_impl<Homogeneous,Transform<Scalar,Dim,Mode,Options> >(lhs,rhs.m_matrix);
111 typename MatrixType::Nested m_matrix;
125template<
typename Derived>
126inline typename MatrixBase<Derived>::HomogeneousReturnType
129 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
141template<
typename ExpressionType,
int Direction>
145 return _expression();
156template<
typename Derived>
157inline const typename MatrixBase<Derived>::HNormalizedReturnType
160 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
161 return ConstStartMinusOne(derived(),0,0,
174template<
typename ExpressionType,
int Direction>
175inline const typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType
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));
195template<
typename MatrixOrTransformType>
196struct take_matrix_for_product
198 typedef MatrixOrTransformType type;
199 static const type& run(
const type &x) {
return x; }
202template<
typename Scalar,
int Dim,
int Mode,
int Options>
203struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
205 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
206 typedef typename internal::add_const<typename TransformType::ConstAffinePart>::type type;
207 static type run (
const TransformType& x) {
return x.affine(); }
210template<
typename Scalar,
int Dim,
int Options>
211struct take_matrix_for_product<Transform<Scalar, Dim,
Projective, Options> >
213 typedef Transform<Scalar, Dim, Projective, Options> TransformType;
214 typedef typename TransformType::MatrixType type;
215 static const type& run (
const TransformType& x) {
return x.matrix(); }
218template<
typename MatrixType,
typename Lhs>
219struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>,Lhs> >
221 typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
222 typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
223 typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
224 typedef typename make_proper_matrix_type<
225 typename traits<MatrixTypeCleaned>::Scalar,
226 LhsMatrixTypeCleaned::RowsAtCompileTime,
227 MatrixTypeCleaned::ColsAtCompileTime,
228 MatrixTypeCleaned::PlainObject::Options,
229 LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
230 MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
233template<
typename MatrixType,
typename Lhs>
234struct homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>,Lhs>
235 :
public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
237 typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
238 typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
239 typedef typename remove_all<typename LhsMatrixTypeCleaned::Nested>::type LhsMatrixTypeNested;
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)),
246 inline Index rows()
const {
return m_lhs.rows(); }
247 inline Index cols()
const {
return m_rhs.cols(); }
249 template<
typename Dest>
void evalTo(Dest& dst)
const
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());
260 typename LhsMatrixTypeCleaned::Nested m_lhs;
261 typename MatrixType::Nested m_rhs;
264template<
typename MatrixType,
typename Rhs>
265struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>,Rhs> >
267 typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar,
268 MatrixType::RowsAtCompileTime,
269 Rhs::ColsAtCompileTime,
270 MatrixType::PlainObject::Options,
271 MatrixType::MaxRowsAtCompileTime,
272 Rhs::MaxColsAtCompileTime>::type ReturnType;
275template<
typename MatrixType,
typename Rhs>
276struct homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>,Rhs>
277 :
public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
279 typedef typename remove_all<typename Rhs::Nested>::type RhsNested;
280 typedef typename MatrixType::Index Index;
281 homogeneous_right_product_impl(
const MatrixType& lhs,
const Rhs& rhs)
282 : m_lhs(lhs), m_rhs(rhs)
285 inline Index rows()
const {
return m_lhs.rows(); }
286 inline Index cols()
const {
return m_rhs.cols(); }
288 template<
typename Dest>
void evalTo(Dest& dst)
const
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());
299 typename MatrixType::Nested m_lhs;
300 typename Rhs::Nested m_rhs;
internal::traits< Homogeneous< MatrixType, _Direction > >::Index Index
Definition DenseBase.h:51
ColXpr col(Index i)
Definition DenseBase.h:553
RowXpr row(Index i)
Definition DenseBase.h:570
@ ColsAtCompileTime
Definition DenseBase.h:98
Expression of one (or a set of) homogeneous vector(s)
Definition Homogeneous.h:63
const HNormalizedReturnType hnormalized() const
Definition Homogeneous.h:158
HomogeneousReturnType homogeneous() const
Definition Homogeneous.h:127
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:64
Homogeneous< ExpressionType, Direction > homogeneous() const
Definition Homogeneous.h:143
const HNormalizedReturnType hnormalized() const
Definition Homogeneous.h:176
@ Projective
Definition Constants.h:391
@ Vertical
Definition Constants.h:204
@ Horizontal
Definition Constants.h:207
const unsigned int RowMajorBit
Definition Constants.h:48