10 #ifndef EIGEN_HOMOGENEOUS_H
11 #define EIGEN_HOMOGENEOUS_H
34 template<
typename MatrixType,
int Direction>
35 struct traits<Homogeneous<
MatrixType,Direction> >
38 typedef typename traits<MatrixType>::StorageKind StorageKind;
39 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
40 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
42 RowsPlusOne = (MatrixType::RowsAtCompileTime !=
Dynamic) ?
43 int(MatrixType::RowsAtCompileTime) + 1 :
Dynamic,
44 ColsPlusOne = (MatrixType::ColsAtCompileTime !=
Dynamic) ?
45 int(MatrixType::ColsAtCompileTime) + 1 :
Dynamic,
46 RowsAtCompileTime = Direction==
Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
47 ColsAtCompileTime = Direction==
Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
48 MaxRowsAtCompileTime = RowsAtCompileTime,
49 MaxColsAtCompileTime = ColsAtCompileTime,
51 Flags = ColsAtCompileTime==1 ? (TmpFlags & ~
RowMajorBit)
57 template<
typename MatrixType,
typename Lhs>
struct homogeneous_left_product_impl;
58 template<
typename MatrixType,
typename Rhs>
struct homogeneous_right_product_impl;
62 template<
typename MatrixType,
int Direction_>
class Homogeneous
63 :
public MatrixBase<Homogeneous<MatrixType,Direction_> >, internal::no_assignment_operator
84 template<
typename Rhs>
92 template<
typename Lhs>
friend
100 template<
typename Scalar,
int Dim,
int Mode,
int Options>
friend
108 template<
typename Func>
132 template<
typename Derived>
150 template<
typename ExpressionType,
int Direction>
174 template<
typename Derived>
180 ColsAtCompileTime==1?
size()-1:1,
181 ColsAtCompileTime==1?1:
size()-1) / coeff(
size()-1);
198 template<
typename ExpressionType,
int Direction>
206 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
207 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1>
219 template<
typename MatrixOrTransformType>
220 struct take_matrix_for_product
222 typedef MatrixOrTransformType type;
226 template<
typename Scalar,
int Dim,
int Mode,
int Options>
227 struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
229 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
230 typedef std::add_const_t<typename TransformType::ConstAffinePart> type;
234 template<
typename Scalar,
int Dim,
int Options>
235 struct take_matrix_for_product<Transform<Scalar, Dim,
Projective, Options> >
237 typedef Transform<Scalar, Dim, Projective, Options> TransformType;
242 template<
typename MatrixType,
typename Lhs>
245 typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
246 typedef remove_all_t<MatrixType> MatrixTypeCleaned;
247 typedef remove_all_t<LhsMatrixType> LhsMatrixTypeCleaned;
248 typedef typename make_proper_matrix_type<
249 typename traits<MatrixTypeCleaned>::Scalar,
250 LhsMatrixTypeCleaned::RowsAtCompileTime,
251 MatrixTypeCleaned::ColsAtCompileTime,
252 MatrixTypeCleaned::PlainObject::Options,
253 LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
254 MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
257 template<
typename MatrixType,
typename Lhs>
259 :
public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
261 typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
262 typedef remove_all_t<LhsMatrixType> LhsMatrixTypeCleaned;
263 typedef remove_all_t<typename LhsMatrixTypeCleaned::Nested> LhsMatrixTypeNested;
265 : m_lhs(take_matrix_for_product<Lhs>::run(lhs)),
277 dst = Block<
const LhsMatrixTypeNested,
278 LhsMatrixTypeNested::RowsAtCompileTime,
279 LhsMatrixTypeNested::ColsAtCompileTime==
Dynamic?
Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1>
280 (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs;
281 dst += m_lhs.col(m_lhs.cols()-1).rowwise()
282 .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
285 typename LhsMatrixTypeCleaned::Nested m_lhs;
286 typename MatrixType::Nested m_rhs;
289 template<
typename MatrixType,
typename Rhs>
292 typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar,
293 MatrixType::RowsAtCompileTime,
294 Rhs::ColsAtCompileTime,
295 MatrixType::PlainObject::Options,
296 MatrixType::MaxRowsAtCompileTime,
297 Rhs::MaxColsAtCompileTime>::type ReturnType;
300 template<
typename MatrixType,
typename Rhs>
302 :
public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
304 typedef remove_all_t<typename Rhs::Nested> RhsNested;
306 : m_lhs(lhs), m_rhs(rhs)
315 dst = m_lhs * Block<
const RhsNested,
316 RhsNested::RowsAtCompileTime==
Dynamic?
Dynamic:RhsNested::RowsAtCompileTime-1,
317 RhsNested::ColsAtCompileTime>
318 (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols());
319 dst += m_rhs.row(m_rhs.rows()-1).colwise()
320 .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
323 typename MatrixType::Nested m_lhs;
324 typename Rhs::Nested m_rhs;
327 template<
typename ArgType,
int Direction>
328 struct evaluator_traits<Homogeneous<ArgType,Direction> >
330 typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
331 typedef HomogeneousShape Shape;
334 template<>
struct AssignmentKind<DenseShape,HomogeneousShape> {
typedef Dense2Dense Kind; };
337 template<
typename ArgType,
int Direction>
338 struct unary_evaluator<Homogeneous<ArgType,Direction>, IndexBased>
339 : evaluator<typename Homogeneous<ArgType,Direction>::PlainObject >
341 typedef Homogeneous<ArgType,Direction> XprType;
342 typedef typename XprType::PlainObject PlainObject;
343 typedef evaluator<PlainObject> Base;
348 internal::construct_at<Base>(
this, m_temp);
356 template<
typename DstXprType,
typename ArgType,
typename Scalar>
357 struct Assignment<DstXprType, Homogeneous<ArgType,
Vertical>,
internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
359 typedef Homogeneous<ArgType,Vertical> SrcXprType;
360 EIGEN_DEVICE_FUNC static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<Scalar,typename ArgType::Scalar> &)
362 Index dstRows = src.rows();
363 Index dstCols = src.cols();
364 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
365 dst.resize(dstRows, dstCols);
367 dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
368 dst.row(dst.rows()-1).setOnes();
373 template<
typename DstXprType,
typename ArgType,
typename Scalar>
374 struct Assignment<DstXprType, Homogeneous<ArgType,
Horizontal>,
internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
376 typedef Homogeneous<ArgType,Horizontal> SrcXprType;
377 EIGEN_DEVICE_FUNC static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<Scalar,typename ArgType::Scalar> &)
379 Index dstRows = src.rows();
380 Index dstCols = src.cols();
381 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
382 dst.resize(dstRows, dstCols);
384 dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();
385 dst.col(dst.cols()-1).setOnes();
389 template<
typename LhsArg,
typename Rhs,
int ProductTag>
390 struct generic_product_impl<Homogeneous<LhsArg,
Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag>
392 template<
typename Dest>
393 EIGEN_DEVICE_FUNC static void evalTo(Dest& dst,
const Homogeneous<LhsArg,Horizontal>& lhs,
const Rhs& rhs)
395 homogeneous_right_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst);
399 template<
typename Lhs,
typename Rhs>
400 struct homogeneous_right_product_refactoring_helper
403 Dim = Lhs::ColsAtCompileTime,
404 Rows = Lhs::RowsAtCompileTime
407 typedef std::remove_const_t<LinearBlockConst> LinearBlock;
408 typedef typename Rhs::ConstRowXpr ConstantColumn;
409 typedef Replicate<const ConstantColumn,Rows,1> ConstantBlock;
410 typedef Product<Lhs,LinearBlock,LazyProduct> LinearProduct;
411 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>,
const LinearProduct,
const ConstantBlock> Xpr;
414 template<
typename Lhs,
typename Rhs,
int ProductTag>
416 :
public evaluator<typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs>::Xpr>
419 typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs> helper;
420 typedef typename helper::ConstantBlock ConstantBlock;
421 typedef typename helper::Xpr RefactoredXpr;
422 typedef evaluator<RefactoredXpr>
Base;
425 :
Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template
topRows<helper::Dim>(xpr.lhs().nestedExpression().
cols()) )
426 + ConstantBlock(xpr.rhs().
row(xpr.rhs().
rows()-1),xpr.lhs().
rows(), 1) )
430 template<
typename Lhs,
typename RhsArg,
int ProductTag>
431 struct generic_product_impl<Lhs, Homogeneous<RhsArg,
Vertical>, DenseShape, HomogeneousShape, ProductTag>
433 template<
typename Dest>
434 EIGEN_DEVICE_FUNC static void evalTo(Dest& dst,
const Lhs& lhs,
const Homogeneous<RhsArg,Vertical>& rhs)
436 homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst);
442 template<
typename Lhs,
typename RhsArg,
int ProductTag>
443 struct generic_product_impl<Lhs, Homogeneous<RhsArg,
Vertical>, TriangularShape, HomogeneousShape, ProductTag>
445 template<
typename Dest>
446 static void evalTo(Dest& dst,
const Lhs& lhs,
const Homogeneous<RhsArg,Vertical>& rhs)
448 dst.noalias() = lhs * rhs.eval();
452 template<
typename Lhs,
typename Rhs>
453 struct homogeneous_left_product_refactoring_helper
456 Dim = Rhs::RowsAtCompileTime,
457 Cols = Rhs::ColsAtCompileTime
460 typedef std::remove_const_t<LinearBlockConst> LinearBlock;
461 typedef typename Lhs::ConstColXpr ConstantColumn;
462 typedef Replicate<const ConstantColumn,1,Cols> ConstantBlock;
463 typedef Product<LinearBlock,Rhs,LazyProduct> LinearProduct;
464 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>,
const LinearProduct,
const ConstantBlock> Xpr;
467 template<
typename Lhs,
typename Rhs,
int ProductTag>
468 struct product_evaluator<Product<Lhs, Rhs,
LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
469 :
public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression>::Xpr>
471 typedef Product<Lhs, Rhs, LazyProduct> XprType;
472 typedef homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression> helper;
473 typedef typename helper::ConstantBlock ConstantBlock;
474 typedef typename helper::Xpr RefactoredXpr;
475 typedef evaluator<RefactoredXpr> Base;
478 : Base( xpr.lhs().template
leftCols<helper::Dim>(xpr.rhs().nestedExpression().
rows()) .lazyProduct( xpr.rhs().nestedExpression() )
479 + ConstantBlock(xpr.lhs().
col(xpr.lhs().
cols()-1),1,xpr.rhs().
cols()) )
483 template<
typename Scalar,
int Dim,
int Mode,
int Options,
typename RhsArg,
int ProductTag>
484 struct generic_product_impl<Transform<Scalar,Dim,Mode,Options>, Homogeneous<RhsArg,
Vertical>, DenseShape, HomogeneousShape, ProductTag>
486 typedef Transform<Scalar,Dim,Mode,Options> TransformType;
487 template<
typename Dest>
488 EIGEN_DEVICE_FUNC static void evalTo(Dest& dst,
const TransformType& lhs,
const Homogeneous<RhsArg,Vertical>& rhs)
490 homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, TransformType>(lhs, rhs.nestedExpression()).evalTo(dst);
494 template<
typename ExpressionType,
int S
ide,
bool Transposed>
495 struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
496 :
public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
NRowsBlockXpr<... >::Type topRows(NRowsType n)
RowXpr row(Index i)
This is the const version of row(). */.
NColsBlockXpr<... >::Type leftCols(NColsType n)
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_DEVICE_FUNC
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Matrix< float, 1, Dynamic > MatrixType
Expression of a fixed-size or dynamic-size block.
Generic expression where a coefficient-wise binary operator is applied to two expressions.
internal::traits< Homogeneous< MatrixType, Direction_ > >::Scalar Scalar
Expression of one (or a set of) homogeneous vector(s)
internal::result_of< Func(Scalar, Scalar)>::type redux(const Func &func) const
const Product< Homogeneous, Rhs > operator*(const MatrixBase< Rhs > &rhs) const
const NestedExpression & nestedExpression() const
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
MatrixBase< Homogeneous > Base
MatrixType NestedExpression
MatrixType::Nested m_matrix
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Base class for all dense matrices, vectors, and expressions.
MatrixBase< Homogeneous< MatrixType, Direction_ > > & matrix()
The matrix class, also used for vectors and row-vectors.
Expression of the product of two arbitrary matrices or vectors.
Expression of the multiple replication of a matrix or vector.
const HNormalizedReturnType hnormalized() const
column or row-wise homogeneous normalization
const HNormalizedReturnType hnormalized() const
homogeneous normalization
HomogeneousReturnType homogeneous() const
HomogeneousReturnType homogeneous() const
const unsigned int RowMajorBit
const unsigned int HereditaryBits
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.