10 #ifndef EIGEN_HOMOGENEOUS_H
11 #define EIGEN_HOMOGENEOUS_H
32 template<
typename MatrixType,
int Direction>
33 struct 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
56 template<
typename MatrixType,
typename Lhs>
struct homogeneous_left_product_impl;
57 template<
typename MatrixType,
typename Rhs>
struct homogeneous_right_product_impl;
61 template<
typename MatrixType,
int _Direction>
class Homogeneous
62 : internal::no_assignment_operator,
public MatrixBase<Homogeneous<MatrixType,_Direction> >
66 enum { Direction = _Direction };
68 typedef MatrixBase<Homogeneous> Base;
69 EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous)
71 inline Homogeneous(const MatrixType& matrix)
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())
81 || (
int(Direction)==
Horizontal && col==m_matrix.cols()))
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> >
104 operator* (
const Transform<Scalar,Dim,Mode,Options>& lhs,
const Homogeneous& rhs)
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;
125 template<
typename Derived>
126 inline typename MatrixBase<Derived>::HomogeneousReturnType
129 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
141 template<
typename ExpressionType,
int Direction>
145 return _expression();
156 template<
typename Derived>
160 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
162 ColsAtCompileTime==1?size()-1:1,
163 ColsAtCompileTime==1?1:size()-1) / coeff(size()-1);
174 template<
typename ExpressionType,
int Direction>
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>
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));
195 template<
typename MatrixOrTransformType>
196 struct take_matrix_for_product
198 typedef MatrixOrTransformType type;
199 static const type& run(
const type &x) {
return x; }
202 template<
typename Scalar,
int Dim,
int Mode,
int Options>
203 struct 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(); }
210 template<
typename Scalar,
int Dim,
int Options>
211 struct 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(); }
218 template<
typename MatrixType,
typename Lhs>
219 struct 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;
233 template<
typename MatrixType,
typename Lhs>
234 struct 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;
264 template<
typename MatrixType,
typename Rhs>
265 struct 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;
275 template<
typename MatrixType,
typename Rhs>
276 struct 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;
307 #endif // EIGEN_HOMOGENEOUS_H
Definition: Constants.h:398
RowXpr row(Index i)
Definition: DenseBase.h:750
Homogeneous< ExpressionType, Direction > homogeneous() const
Definition: Homogeneous.h:143
const int Dynamic
Definition: Constants.h:21
ColXpr col(Index i)
Definition: DenseBase.h:733
Definition: Constants.h:212
const HNormalizedReturnType hnormalized() const
Definition: Homogeneous.h:176
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:107
const HNormalizedReturnType hnormalized() const
Definition: Homogeneous.h:158
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:62
Definition: Constants.h:209
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
HomogeneousReturnType homogeneous() const
Definition: Homogeneous.h:127
const unsigned int RowMajorBit
Definition: Constants.h:53
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
Expression of one (or a set of) homogeneous vector(s)
Definition: ForwardDeclarations.h:268