10#ifndef EIGEN_HOMOGENEOUS_H
11#define EIGEN_HOMOGENEOUS_H
14#include "./InternalHeaderCheck.h"
35template <
typename MatrixType,
int Direction>
36struct traits<Homogeneous<MatrixType, Direction> > : traits<MatrixType> {
37 typedef typename traits<MatrixType>::StorageKind StorageKind;
38 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
39 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
41 RowsPlusOne = (MatrixType::RowsAtCompileTime !=
Dynamic) ?
int(MatrixType::RowsAtCompileTime) + 1 :
Dynamic,
42 ColsPlusOne = (MatrixType::ColsAtCompileTime !=
Dynamic) ?
int(MatrixType::ColsAtCompileTime) + 1 :
Dynamic,
43 RowsAtCompileTime = Direction ==
Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
44 ColsAtCompileTime = Direction ==
Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
45 MaxRowsAtCompileTime = RowsAtCompileTime,
46 MaxColsAtCompileTime = ColsAtCompileTime,
47 TmpFlags = MatrixTypeNested_::Flags & HereditaryBits,
48 Flags = ColsAtCompileTime == 1 ? (TmpFlags & ~RowMajorBit)
54template <
typename MatrixType,
typename Lhs>
55struct homogeneous_left_product_impl;
56template <
typename MatrixType,
typename Rhs>
57struct homogeneous_right_product_impl;
61template <
typename MatrixType,
int Direction_>
64 typedef MatrixType NestedExpression;
65 enum { Direction = Direction_ };
70 EIGEN_DEVICE_FUNC
explicit inline Homogeneous(
const MatrixType& matrix) : m_matrix(matrix) {}
72 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index rows()
const EIGEN_NOEXCEPT {
73 return m_matrix.rows() + (int(Direction) ==
Vertical ? 1 : 0);
75 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index cols()
const EIGEN_NOEXCEPT {
76 return m_matrix.cols() + (int(Direction) ==
Horizontal ? 1 : 0);
79 EIGEN_DEVICE_FUNC
const NestedExpression& nestedExpression()
const {
return m_matrix; }
81 template <
typename Rhs>
87 template <
typename Lhs>
90 eigen_assert(
int(Direction) ==
Vertical);
94 template <
typename Scalar,
int Dim,
int Mode,
int Options>
97 eigen_assert(
int(Direction) ==
Vertical);
101 template <
typename Func>
102 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename internal::result_of<Func(
Scalar,
Scalar)>::type redux(
103 const Func& func)
const {
104 return func(m_matrix.redux(func),
Scalar(1));
108 typename MatrixType::Nested m_matrix;
125template <
typename Derived>
127 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
142template <
typename ExpressionType,
int Direction>
165template <
typename Derived>
168 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
170 ColsAtCompileTime == 1 ? 1 : size() - 1) /
189template <
typename ExpressionType,
int Direction>
193 Direction ==
Horizontal ? _expression().cols() - 1 : _expression().cols())
196 ? HNormalized_SizeMinusOne
198 Direction ==
Horizontal ? _expression().cols() - 1 : 0,
199 Direction ==
Vertical ? 1 : _expression().rows(),
200 Direction ==
Horizontal ? 1 : _expression().cols()),
201 Direction ==
Vertical ? _expression().rows() - 1 : 1,
202 Direction ==
Horizontal ? _expression().cols() - 1 : 1));
207template <
typename MatrixOrTransformType>
208struct take_matrix_for_product {
209 typedef MatrixOrTransformType type;
210 EIGEN_DEVICE_FUNC
static const type& run(
const type& x) {
return x; }
213template <
typename Scalar,
int Dim,
int Mode,
int Options>
214struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> > {
215 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
216 typedef std::add_const_t<typename TransformType::ConstAffinePart> type;
217 EIGEN_DEVICE_FUNC
static type run(
const TransformType& x) {
return x.affine(); }
220template <
typename Scalar,
int Dim,
int Options>
221struct take_matrix_for_product<Transform<Scalar, Dim,
Projective, Options> > {
222 typedef Transform<Scalar, Dim, Projective, Options> TransformType;
223 typedef typename TransformType::MatrixType type;
224 EIGEN_DEVICE_FUNC
static const type& run(
const TransformType& x) {
return x.matrix(); }
227template <
typename MatrixType,
typename Lhs>
228struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>, Lhs> > {
229 typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
230 typedef remove_all_t<MatrixType> MatrixTypeCleaned;
231 typedef remove_all_t<LhsMatrixType> LhsMatrixTypeCleaned;
232 typedef typename make_proper_matrix_type<
233 typename traits<MatrixTypeCleaned>::Scalar, LhsMatrixTypeCleaned::RowsAtCompileTime,
234 MatrixTypeCleaned::ColsAtCompileTime, MatrixTypeCleaned::PlainObject::Options,
235 LhsMatrixTypeCleaned::MaxRowsAtCompileTime, MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
238template <
typename MatrixType,
typename Lhs>
239struct homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>, Lhs>
240 :
public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType, Vertical>, Lhs> > {
241 typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
242 typedef remove_all_t<LhsMatrixType> LhsMatrixTypeCleaned;
243 typedef remove_all_t<typename LhsMatrixTypeCleaned::Nested> LhsMatrixTypeNested;
244 EIGEN_DEVICE_FUNC homogeneous_left_product_impl(
const Lhs& lhs,
const MatrixType& rhs)
245 : m_lhs(take_matrix_for_product<Lhs>::run(lhs)), m_rhs(rhs) {}
247 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index rows() const EIGEN_NOEXCEPT {
return m_lhs.rows(); }
248 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index cols() const EIGEN_NOEXCEPT {
return m_rhs.cols(); }
250 template <
typename Dest>
251 EIGEN_DEVICE_FUNC
void evalTo(Dest& dst)
const {
253 dst = Block <
const LhsMatrixTypeNested, LhsMatrixTypeNested::RowsAtCompileTime,
254 LhsMatrixTypeNested::ColsAtCompileTime ==
Dynamic
256 : LhsMatrixTypeNested::ColsAtCompileTime - 1 > (m_lhs, 0, 0, m_lhs.rows(), m_lhs.cols() - 1) * m_rhs;
257 dst += m_lhs.col(m_lhs.cols() - 1).rowwise().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 typename make_proper_matrix_type<typename traits<MatrixType>::Scalar, MatrixType::RowsAtCompileTime,
268 Rhs::ColsAtCompileTime, MatrixType::PlainObject::Options,
269 MatrixType::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime>::type ReturnType;
272template <
typename MatrixType,
typename Rhs>
273struct homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>, Rhs>
274 :
public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType, Horizontal>, Rhs> > {
275 typedef remove_all_t<typename Rhs::Nested> RhsNested;
276 EIGEN_DEVICE_FUNC homogeneous_right_product_impl(
const MatrixType& lhs,
const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) {}
278 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index rows() const EIGEN_NOEXCEPT {
return m_lhs.rows(); }
279 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index cols() const EIGEN_NOEXCEPT {
return m_rhs.cols(); }
281 template <
typename Dest>
282 EIGEN_DEVICE_FUNC
void evalTo(Dest& dst)
const {
284 dst = m_lhs * Block <
const RhsNested,
285 RhsNested::RowsAtCompileTime ==
Dynamic ?
Dynamic : RhsNested::RowsAtCompileTime - 1,
286 RhsNested::ColsAtCompileTime > (m_rhs, 0, 0, m_rhs.rows() - 1, m_rhs.cols());
287 dst += m_rhs.row(m_rhs.rows() - 1).colwise().template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
290 typename MatrixType::Nested m_lhs;
291 typename Rhs::Nested m_rhs;
294template <
typename ArgType,
int Direction>
295struct evaluator_traits<Homogeneous<ArgType, Direction> > {
296 typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
297 typedef HomogeneousShape Shape;
301struct AssignmentKind<DenseShape, HomogeneousShape> {
302 typedef Dense2Dense Kind;
305template <
typename ArgType,
int Direction>
306struct unary_evaluator<Homogeneous<ArgType, Direction>, IndexBased>
307 : evaluator<typename Homogeneous<ArgType, Direction>::PlainObject> {
308 typedef Homogeneous<ArgType, Direction> XprType;
309 typedef typename XprType::PlainObject PlainObject;
310 typedef evaluator<PlainObject> Base;
312 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op) : Base(), m_temp(op) {
313 internal::construct_at<Base>(
this, m_temp);
321template <
typename DstXprType,
typename ArgType,
typename Scalar>
322struct Assignment<DstXprType, Homogeneous<ArgType,
Vertical>, internal::assign_op<Scalar, typename ArgType::Scalar>,
324 typedef Homogeneous<ArgType, Vertical> SrcXprType;
325 EIGEN_DEVICE_FUNC
static void run(DstXprType& dst,
const SrcXprType& src,
326 const internal::assign_op<Scalar, typename ArgType::Scalar>&) {
327 Index dstRows = src.rows();
328 Index dstCols = src.cols();
329 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
331 dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
332 dst.row(dst.rows() - 1).setOnes();
337template <
typename DstXprType,
typename ArgType,
typename Scalar>
338struct Assignment<DstXprType, Homogeneous<ArgType,
Horizontal>, internal::assign_op<Scalar, typename ArgType::Scalar>,
340 typedef Homogeneous<ArgType, Horizontal> SrcXprType;
341 EIGEN_DEVICE_FUNC
static void run(DstXprType& dst,
const SrcXprType& src,
342 const internal::assign_op<Scalar, typename ArgType::Scalar>&) {
343 Index dstRows = src.rows();
344 Index dstCols = src.cols();
345 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
347 dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();
348 dst.col(dst.cols() - 1).setOnes();
352template <
typename LhsArg,
typename Rhs,
int ProductTag>
353struct generic_product_impl<Homogeneous<LhsArg,
Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag> {
354 template <
typename Dest>
355 EIGEN_DEVICE_FUNC
static void evalTo(Dest& dst,
const Homogeneous<LhsArg, Horizontal>& lhs,
const Rhs& rhs) {
356 homogeneous_right_product_impl<Homogeneous<LhsArg, Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst);
360template <
typename Lhs,
typename Rhs>
361struct homogeneous_right_product_refactoring_helper {
362 enum { Dim = Lhs::ColsAtCompileTime, Rows = Lhs::RowsAtCompileTime };
363 typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst;
364 typedef std::remove_const_t<LinearBlockConst> LinearBlock;
365 typedef typename Rhs::ConstRowXpr ConstantColumn;
366 typedef Replicate<const ConstantColumn, Rows, 1> ConstantBlock;
367 typedef Product<Lhs, LinearBlock, LazyProduct> LinearProduct;
368 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar, typename Rhs::Scalar>,
const LinearProduct,
373template <
typename Lhs,
typename Rhs,
int ProductTag>
374struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape>
376 typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression, Rhs>::Xpr> {
377 typedef Product<Lhs, Rhs, LazyProduct> XprType;
378 typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression, Rhs> helper;
379 typedef typename helper::ConstantBlock ConstantBlock;
380 typedef typename helper::Xpr RefactoredXpr;
381 typedef evaluator<RefactoredXpr> Base;
383 EIGEN_DEVICE_FUNC
explicit product_evaluator(
const XprType& xpr)
384 : Base(xpr.lhs().nestedExpression().lazyProduct(
385 xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols())) +
386 ConstantBlock(xpr.rhs().row(xpr.rhs().rows() - 1), xpr.lhs().rows(), 1)) {}
389template <
typename Lhs,
typename RhsArg,
int ProductTag>
390struct generic_product_impl<Lhs, Homogeneous<RhsArg,
Vertical>, DenseShape, HomogeneousShape, ProductTag> {
391 template <
typename Dest>
392 EIGEN_DEVICE_FUNC
static void evalTo(Dest& dst,
const Lhs& lhs,
const Homogeneous<RhsArg, Vertical>& rhs) {
393 homogeneous_left_product_impl<Homogeneous<RhsArg, Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst);
399template <
typename Lhs,
typename RhsArg,
int ProductTag>
400struct generic_product_impl<Lhs, Homogeneous<RhsArg,
Vertical>, TriangularShape, HomogeneousShape, ProductTag> {
401 template <
typename Dest>
402 static void evalTo(Dest& dst,
const Lhs& lhs,
const Homogeneous<RhsArg, Vertical>& rhs) {
403 dst.noalias() = lhs * rhs.eval();
407template <
typename Lhs,
typename Rhs>
408struct homogeneous_left_product_refactoring_helper {
409 enum { Dim = Rhs::RowsAtCompileTime, Cols = Rhs::ColsAtCompileTime };
410 typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst;
411 typedef std::remove_const_t<LinearBlockConst> LinearBlock;
412 typedef typename Lhs::ConstColXpr ConstantColumn;
420template <
typename Lhs,
typename Rhs,
int ProductTag>
421struct product_evaluator<
Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
422 :
public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs, typename Rhs::NestedExpression>::Xpr> {
424 typedef homogeneous_left_product_refactoring_helper<Lhs, typename Rhs::NestedExpression> helper;
425 typedef typename helper::ConstantBlock ConstantBlock;
426 typedef typename helper::Xpr RefactoredXpr;
427 typedef evaluator<RefactoredXpr> Base;
429 EIGEN_DEVICE_FUNC
explicit product_evaluator(
const XprType& xpr)
431 .template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows())
432 .lazyProduct(xpr.rhs().nestedExpression()) +
433 ConstantBlock(xpr.lhs().col(xpr.lhs().cols() - 1), 1, xpr.rhs().cols())) {}
436template <
typename Scalar,
int Dim,
int Mode,
int Options,
typename RhsArg,
int ProductTag>
437struct generic_product_impl<Transform<Scalar, Dim, Mode, Options>, Homogeneous<RhsArg,
Vertical>, DenseShape,
438 HomogeneousShape, ProductTag> {
439 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
440 template <
typename Dest>
441 EIGEN_DEVICE_FUNC
static void evalTo(Dest& dst,
const TransformType& lhs,
const Homogeneous<RhsArg, Vertical>& rhs) {
442 homogeneous_left_product_impl<Homogeneous<RhsArg, Vertical>, TransformType>(lhs, rhs.nestedExpression())
447template <
typename ExpressionType,
int S
ide,
bool Transposed>
448struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
449 :
public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape> {};
Expression of a fixed-size or dynamic-size block.
Definition Block.h:110
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:79
internal::traits< Homogeneous< MatrixType, Direction_ > >::Scalar Scalar
Definition DenseBase.h:62
Derived & derived()
Definition EigenBase.h:49
Expression of one (or a set of) homogeneous vector(s)
Definition Homogeneous.h:62
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:202
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:64
const HNormalizedReturnType hnormalized() const
column or row-wise homogeneous normalization
Definition Homogeneous.h:191
const HNormalizedReturnType hnormalized() const
homogeneous normalization
Definition Homogeneous.h:166
HomogeneousReturnType homogeneous() const
Definition Homogeneous.h:126
HomogeneousReturnType homogeneous() const
Definition Homogeneous.h:143
@ Horizontal
Definition Constants.h:269
@ Vertical
Definition Constants.h:266
@ Projective
Definition Constants.h:462
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
const int Dynamic
Definition Constants.h:25