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_>
62class Homogeneous :
public MatrixBase<Homogeneous<MatrixType, Direction_> >, internal::no_assignment_operator {
65 enum { Direction = Direction_ };
67 typedef MatrixBase<Homogeneous> Base;
68 EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous)
70 EIGEN_DEVICE_FUNC
explicit inline Homogeneous(
const MatrixType& matrix) : m_matrix(matrix) {}
72 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
73 return m_matrix.rows() + (int(Direction) ==
Vertical ? 1 : 0);
75 EIGEN_DEVICE_FUNC
constexpr Index cols()
const 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>
86 template <
typename Lhs>
88 const Homogeneous& rhs) {
92 template <
typename Scalar,
int Dim,
int Mode,
int Options>
95 eigen_assert(
int(Direction) ==
Vertical);
99 template <
typename Func>
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename internal::result_of<Func(
Scalar,
Scalar)>::type redux(
101 const Func& func)
const {
102 return func(m_matrix.redux(func),
Scalar(1));
106 typename MatrixType::Nested m_matrix;
123template <
typename Derived>
125 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
126 return HomogeneousReturnType(derived());
140template <
typename ExpressionType,
int Direction>
143 return HomogeneousReturnType(_expression());
163template <
typename Derived>
166 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
167 return ConstStartMinusOne(derived(), 0, 0,
ColsAtCompileTime == 1 ? size() - 1 : 1,
187template <
typename ExpressionType,
int Direction>
188EIGEN_DEVICE_FUNC
inline const typename VectorwiseOp<ExpressionType, Direction>::HNormalizedReturnType
190 return HNormalized_Block(_expression(), 0, 0, Direction ==
Vertical ? _expression().rows() - 1 : _expression().rows(),
191 Direction ==
Horizontal ? _expression().cols() - 1 : _expression().cols())
192 .cwiseQuotient(
Replicate < HNormalized_Factors, Direction ==
Vertical ? HNormalized_SizeMinusOne : 1,
194 ? HNormalized_SizeMinusOne
195 : 1 > (HNormalized_Factors(_expression(), Direction ==
Vertical ? _expression().rows() - 1 : 0,
196 Direction ==
Horizontal ? _expression().cols() - 1 : 0,
197 Direction ==
Vertical ? 1 : _expression().rows(),
198 Direction ==
Horizontal ? 1 : _expression().cols()),
199 Direction ==
Vertical ? _expression().rows() - 1 : 1,
200 Direction ==
Horizontal ? _expression().cols() - 1 : 1));
205template <
typename MatrixOrTransformType>
206struct take_matrix_for_product {
207 typedef MatrixOrTransformType type;
208 EIGEN_DEVICE_FUNC
static const type& run(
const type& x) {
return x; }
211template <
typename Scalar,
int Dim,
int Mode,
int Options>
212struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> > {
213 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
214 typedef std::add_const_t<typename TransformType::ConstAffinePart> type;
215 EIGEN_DEVICE_FUNC
static type run(
const TransformType& x) {
return x.affine(); }
218template <
typename Scalar,
int Dim,
int Options>
219struct take_matrix_for_product<Transform<Scalar, Dim,
Projective, Options> > {
220 typedef Transform<Scalar, Dim, Projective, Options> TransformType;
221 typedef typename TransformType::MatrixType type;
222 EIGEN_DEVICE_FUNC
static const type& run(
const TransformType& x) {
return x.matrix(); }
225template <
typename MatrixType,
typename Lhs>
226struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>, Lhs> > {
227 typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
228 typedef remove_all_t<MatrixType> MatrixTypeCleaned;
229 typedef remove_all_t<LhsMatrixType> LhsMatrixTypeCleaned;
230 typedef typename make_proper_matrix_type<
231 typename traits<MatrixTypeCleaned>::Scalar, LhsMatrixTypeCleaned::RowsAtCompileTime,
232 MatrixTypeCleaned::ColsAtCompileTime, MatrixTypeCleaned::PlainObject::Options,
233 LhsMatrixTypeCleaned::MaxRowsAtCompileTime, MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
236template <
typename MatrixType,
typename Lhs>
237struct homogeneous_left_product_impl<Homogeneous<MatrixType,
Vertical>, Lhs>
238 :
public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType, Vertical>, Lhs> > {
239 typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
240 typedef remove_all_t<LhsMatrixType> LhsMatrixTypeCleaned;
241 typedef remove_all_t<typename LhsMatrixTypeCleaned::Nested> LhsMatrixTypeNested;
242 EIGEN_DEVICE_FUNC homogeneous_left_product_impl(
const Lhs& lhs,
const MatrixType& rhs)
243 : m_lhs(take_matrix_for_product<Lhs>::run(lhs)), m_rhs(rhs) {}
245 EIGEN_DEVICE_FUNC
constexpr Index rows() const noexcept {
return m_lhs.rows(); }
246 EIGEN_DEVICE_FUNC
constexpr Index cols() const noexcept {
return m_rhs.cols(); }
248 template <
typename Dest>
249 EIGEN_DEVICE_FUNC
void evalTo(Dest& dst)
const {
251 dst = Block <
const LhsMatrixTypeNested, LhsMatrixTypeNested::RowsAtCompileTime,
252 LhsMatrixTypeNested::ColsAtCompileTime ==
Dynamic
254 : LhsMatrixTypeNested::ColsAtCompileTime - 1 > (m_lhs, 0, 0, m_lhs.rows(), m_lhs.cols() - 1) * m_rhs;
255 dst += m_lhs.col(m_lhs.cols() - 1).rowwise().template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
258 typename LhsMatrixTypeCleaned::Nested m_lhs;
259 typename MatrixType::Nested m_rhs;
262template <
typename MatrixType,
typename Rhs>
263struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>, Rhs> > {
265 typename make_proper_matrix_type<typename traits<MatrixType>::Scalar, MatrixType::RowsAtCompileTime,
266 Rhs::ColsAtCompileTime, MatrixType::PlainObject::Options,
267 MatrixType::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime>::type ReturnType;
270template <
typename MatrixType,
typename Rhs>
271struct homogeneous_right_product_impl<Homogeneous<MatrixType,
Horizontal>, Rhs>
272 :
public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType, Horizontal>, Rhs> > {
273 typedef remove_all_t<typename Rhs::Nested> RhsNested;
274 EIGEN_DEVICE_FUNC homogeneous_right_product_impl(
const MatrixType& lhs,
const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) {}
276 EIGEN_DEVICE_FUNC
constexpr Index rows() const noexcept {
return m_lhs.rows(); }
277 EIGEN_DEVICE_FUNC
constexpr Index cols() const noexcept {
return m_rhs.cols(); }
279 template <
typename Dest>
280 EIGEN_DEVICE_FUNC
void evalTo(Dest& dst)
const {
282 dst = m_lhs * Block <
const RhsNested,
283 RhsNested::RowsAtCompileTime ==
Dynamic ?
Dynamic : RhsNested::RowsAtCompileTime - 1,
284 RhsNested::ColsAtCompileTime > (m_rhs, 0, 0, m_rhs.rows() - 1, m_rhs.cols());
285 dst += m_rhs.row(m_rhs.rows() - 1).colwise().template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
288 typename MatrixType::Nested m_lhs;
289 typename Rhs::Nested m_rhs;
292template <
typename ArgType,
int Direction>
293struct evaluator_traits<Homogeneous<ArgType, Direction> > {
294 typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
295 typedef HomogeneousShape Shape;
299struct AssignmentKind<DenseShape, HomogeneousShape> {
300 typedef Dense2Dense Kind;
303template <
typename ArgType,
int Direction>
304struct unary_evaluator<Homogeneous<ArgType, Direction>, IndexBased>
305 : evaluator<typename Homogeneous<ArgType, Direction>::PlainObject> {
306 typedef Homogeneous<ArgType, Direction> XprType;
307 typedef typename XprType::PlainObject PlainObject;
308 typedef evaluator<PlainObject> Base;
310 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op) : Base(), m_temp(op) {
311 internal::construct_at<Base>(
this, m_temp);
319template <
typename DstXprType,
typename ArgType,
typename Scalar>
320struct Assignment<DstXprType, Homogeneous<ArgType,
Vertical>, internal::assign_op<Scalar, typename ArgType::Scalar>,
322 typedef Homogeneous<ArgType, Vertical> SrcXprType;
323 EIGEN_DEVICE_FUNC
static void run(DstXprType& dst,
const SrcXprType& src,
324 const internal::assign_op<Scalar, typename ArgType::Scalar>&) {
325 Index dstRows = src.rows();
326 Index dstCols = src.cols();
327 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
329 dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
330 dst.row(dst.rows() - 1).setOnes();
335template <
typename DstXprType,
typename ArgType,
typename Scalar>
336struct Assignment<DstXprType, Homogeneous<ArgType,
Horizontal>, internal::assign_op<Scalar, typename ArgType::Scalar>,
338 typedef Homogeneous<ArgType, Horizontal> SrcXprType;
339 EIGEN_DEVICE_FUNC
static void run(DstXprType& dst,
const SrcXprType& src,
340 const internal::assign_op<Scalar, typename ArgType::Scalar>&) {
341 Index dstRows = src.rows();
342 Index dstCols = src.cols();
343 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
345 dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();
346 dst.col(dst.cols() - 1).setOnes();
350template <
typename LhsArg,
typename Rhs,
int ProductTag>
351struct generic_product_impl<Homogeneous<LhsArg,
Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag> {
352 template <
typename Dest>
353 EIGEN_DEVICE_FUNC
static void evalTo(Dest& dst,
const Homogeneous<LhsArg, Horizontal>& lhs,
const Rhs& rhs) {
354 homogeneous_right_product_impl<Homogeneous<LhsArg, Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst);
358template <
typename Lhs,
typename Rhs>
359struct homogeneous_right_product_refactoring_helper {
360 enum { Dim = Lhs::ColsAtCompileTime, Rows = Lhs::RowsAtCompileTime };
361 typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst;
362 typedef std::remove_const_t<LinearBlockConst> LinearBlock;
363 typedef typename Rhs::ConstRowXpr ConstantColumn;
364 typedef Replicate<const ConstantColumn, Rows, 1> ConstantBlock;
365 typedef Product<Lhs, LinearBlock, LazyProduct> LinearProduct;
366 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar, typename Rhs::Scalar>,
const LinearProduct,
371template <
typename Lhs,
typename Rhs,
int ProductTag>
372struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape>
374 typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression, Rhs>::Xpr> {
375 typedef Product<Lhs, Rhs, LazyProduct> XprType;
376 typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression, Rhs> helper;
377 typedef typename helper::ConstantBlock ConstantBlock;
378 typedef typename helper::Xpr RefactoredXpr;
379 typedef evaluator<RefactoredXpr> Base;
381 EIGEN_DEVICE_FUNC
explicit product_evaluator(
const XprType& xpr)
382 : Base(xpr.lhs().nestedExpression().lazyProduct(
383 xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols())) +
384 ConstantBlock(xpr.rhs().row(xpr.rhs().rows() - 1), xpr.lhs().rows(), 1)) {}
387template <
typename Lhs,
typename RhsArg,
int ProductTag>
388struct generic_product_impl<Lhs, Homogeneous<RhsArg,
Vertical>, DenseShape, HomogeneousShape, ProductTag> {
389 template <
typename Dest>
390 EIGEN_DEVICE_FUNC
static void evalTo(Dest& dst,
const Lhs& lhs,
const Homogeneous<RhsArg, Vertical>& rhs) {
391 homogeneous_left_product_impl<Homogeneous<RhsArg, Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst);
397template <
typename Lhs,
typename RhsArg,
int ProductTag>
398struct generic_product_impl<Lhs, Homogeneous<RhsArg,
Vertical>, TriangularShape, HomogeneousShape, ProductTag> {
399 template <
typename Dest>
400 static void evalTo(Dest& dst,
const Lhs& lhs,
const Homogeneous<RhsArg, Vertical>& rhs) {
401 dst.noalias() = lhs * rhs.eval();
405template <
typename Lhs,
typename Rhs>
406struct homogeneous_left_product_refactoring_helper {
407 enum { Dim = Rhs::RowsAtCompileTime, Cols = Rhs::ColsAtCompileTime };
408 typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst;
409 typedef std::remove_const_t<LinearBlockConst> LinearBlock;
410 typedef typename Lhs::ConstColXpr ConstantColumn;
418template <
typename Lhs,
typename Rhs,
int ProductTag>
419struct product_evaluator<
Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
420 :
public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs, typename Rhs::NestedExpression>::Xpr> {
422 typedef homogeneous_left_product_refactoring_helper<Lhs, typename Rhs::NestedExpression> helper;
423 typedef typename helper::ConstantBlock ConstantBlock;
424 typedef typename helper::Xpr RefactoredXpr;
425 typedef evaluator<RefactoredXpr> Base;
427 EIGEN_DEVICE_FUNC
explicit product_evaluator(
const XprType& xpr)
430 .lazyProduct(xpr.rhs().nestedExpression()) +
431 ConstantBlock(xpr.lhs().col(xpr.lhs().cols() - 1), 1, xpr.rhs().cols())) {}
434template <
typename Scalar,
int Dim,
int Mode,
int Options,
typename RhsArg,
int ProductTag>
436 HomogeneousShape, ProductTag> {
438 template <
typename Dest>
440 homogeneous_left_product_impl<Homogeneous<RhsArg, Vertical>, TransformType>(lhs, rhs.nestedExpression())
445template <
typename ExpressionType,
int S
ide,
bool Transposed>
446struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
447 :
public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape> {};
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:79
NColsBlockXpr<... >::Type leftCols(NColsType n)
Definition DenseBase.h:802
@ ColsAtCompileTime
Definition DenseBase.h:102
Expression of one (or a set of) homogeneous vector(s)
Definition Homogeneous.h:62
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:189
const HNormalizedReturnType hnormalized() const
homogeneous normalization
Definition Homogeneous.h:164
HomogeneousReturnType homogeneous() const
Definition Homogeneous.h:124
HomogeneousReturnType homogeneous() const
Definition Homogeneous.h:141
@ 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 B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int Dynamic
Definition Constants.h:25