25 #ifndef EIGEN_HOMOGENEOUS_H
26 #define EIGEN_HOMOGENEOUS_H
47 template<
typename MatrixType,
int Direction>
48 struct traits<Homogeneous<MatrixType,Direction> >
52 typedef typename nested<MatrixType>::type MatrixTypeNested;
53 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
55 RowsPlusOne = (MatrixType::RowsAtCompileTime !=
Dynamic) ?
56 int(MatrixType::RowsAtCompileTime) + 1 :
Dynamic,
57 ColsPlusOne = (MatrixType::ColsAtCompileTime !=
Dynamic) ?
58 int(MatrixType::ColsAtCompileTime) + 1 :
Dynamic,
59 RowsAtCompileTime = Direction==
Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
60 ColsAtCompileTime = Direction==
Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
61 MaxRowsAtCompileTime = RowsAtCompileTime,
62 MaxColsAtCompileTime = ColsAtCompileTime,
64 Flags = ColsAtCompileTime==1 ? (TmpFlags & ~
RowMajorBit)
67 CoeffReadCost = _MatrixTypeNested::CoeffReadCost
71 template<
typename MatrixType,
typename Lhs>
struct homogeneous_left_product_impl;
72 template<
typename MatrixType,
typename Rhs>
struct homogeneous_right_product_impl;
76 template<
typename MatrixType,
int _Direction>
class Homogeneous
77 :
public MatrixBase<Homogeneous<MatrixType,_Direction> >
101 template<
typename Rhs>
102 inline const internal::homogeneous_right_product_impl<Homogeneous,Rhs>
106 return internal::homogeneous_right_product_impl<Homogeneous,Rhs>(
m_matrix,rhs.derived());
109 template<
typename Lhs>
friend
110 inline const internal::homogeneous_left_product_impl<Homogeneous,Lhs>
114 return internal::homogeneous_left_product_impl<Homogeneous,Lhs>(lhs.derived(),rhs.
m_matrix);
117 template<
typename Scalar,
int Dim,
int Mode,
int Options>
friend
118 inline const internal::homogeneous_left_product_impl<Homogeneous,Transform<Scalar,Dim,Mode,Options> >
122 return internal::homogeneous_left_product_impl<Homogeneous,Transform<Scalar,Dim,Mode,Options> >(lhs,rhs.
m_matrix);
140 template<
typename Derived>
156 template<
typename ExpressionType,
int Direction>
160 return _expression();
171 template<
typename Derived>
177 ColsAtCompileTime==1?size()-1:1,
178 ColsAtCompileTime==1?1:size()-1) / coeff(size()-1);
189 template<
typename ExpressionType,
int Direction>
194 Direction==
Vertical ? _expression().rows()-1 : _expression().rows(),
195 Direction==
Horizontal ? _expression().cols()-1 : _expression().cols()).cwiseQuotient(
197 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
198 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1>
200 Direction==
Vertical ? _expression().rows()-1:0,
201 Direction==
Horizontal ? _expression().cols()-1:0,
202 Direction==
Vertical ? 1 : _expression().rows(),
203 Direction==
Horizontal ? 1 : _expression().cols()),
204 Direction==
Vertical ? _expression().rows()-1 : 1,
205 Direction==
Horizontal ? _expression().cols()-1 : 1));
210 template<
typename MatrixOrTransformType>
211 struct take_matrix_for_product
213 typedef MatrixOrTransformType type;
214 static const type& run(
const type &x) {
return x; }
217 template<
typename Scalar,
int Dim,
int Mode,
int Options>
218 struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
220 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
221 typedef typename internal::add_const<typename TransformType::ConstAffinePart>::type type;
222 static type run (
const TransformType& x) {
return x.affine(); }
225 template<
typename Scalar,
int Dim,
int Options>
226 struct take_matrix_for_product<Transform<Scalar, Dim,
Projective, Options> >
228 typedef Transform<Scalar, Dim, Projective, Options> TransformType;
229 typedef typename TransformType::MatrixType type;
230 static const type& run (
const TransformType& x) {
return x.matrix(); }
233 template<
typename MatrixType,
typename Lhs>
234 struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>,Lhs> >
236 typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
237 typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
238 typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
239 typedef typename make_proper_matrix_type<
241 LhsMatrixTypeCleaned::RowsAtCompileTime,
242 MatrixTypeCleaned::ColsAtCompileTime,
243 MatrixTypeCleaned::PlainObject::Options,
244 LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
245 MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
248 template<
typename MatrixType,
typename Lhs>
249 struct homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>,Lhs>
250 :
public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
253 typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
254 typedef typename remove_all<typename LhsMatrixTypeCleaned::Nested>::type LhsMatrixTypeNested;
255 typedef typename MatrixType::Index Index;
256 homogeneous_left_product_impl(
const Lhs& lhs,
const MatrixType& rhs)
257 : m_lhs(take_matrix_for_product<Lhs>::run(lhs)),
261 inline Index rows()
const {
return m_lhs.rows(); }
262 inline Index cols()
const {
return m_rhs.cols(); }
264 template<
typename Dest>
void evalTo(Dest& dst)
const
267 dst = Block<
const LhsMatrixTypeNested,
268 LhsMatrixTypeNested::RowsAtCompileTime,
269 LhsMatrixTypeNested::ColsAtCompileTime==
Dynamic?
Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1>
270 (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs;
271 dst += m_lhs.col(m_lhs.cols()-1).rowwise()
272 .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
275 typename LhsMatrixTypeCleaned::Nested m_lhs;
276 typename MatrixType::Nested m_rhs;
279 template<
typename MatrixType,
typename Rhs>
280 struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>,Rhs> >
282 typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar,
283 MatrixType::RowsAtCompileTime,
284 Rhs::ColsAtCompileTime,
285 MatrixType::PlainObject::Options,
286 MatrixType::MaxRowsAtCompileTime,
287 Rhs::MaxColsAtCompileTime>::type ReturnType;
290 template<
typename MatrixType,
typename Rhs>
291 struct homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>,Rhs>
292 :
public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
294 typedef typename remove_all<typename Rhs::Nested>::type RhsNested;
295 typedef typename MatrixType::Index Index;
296 homogeneous_right_product_impl(
const MatrixType& lhs,
const Rhs& rhs)
297 : m_lhs(lhs), m_rhs(rhs)
300 inline Index rows()
const {
return m_lhs.rows(); }
301 inline Index cols()
const {
return m_rhs.cols(); }
303 template<
typename Dest>
void evalTo(Dest& dst)
const
306 dst = m_lhs * Block<
const RhsNested,
307 RhsNested::RowsAtCompileTime==
Dynamic?
Dynamic:RhsNested::RowsAtCompileTime-1,
308 RhsNested::ColsAtCompileTime>
309 (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols());
310 dst += m_rhs.row(m_rhs.rows()-1).colwise()
311 .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
314 typename MatrixType::Nested m_lhs;
315 typename Rhs::Nested m_rhs;
322 #endif // EIGEN_HOMOGENEOUS_H