10 #ifndef EIGEN_HOMOGENEOUS_H 11 #define EIGEN_HOMOGENEOUS_H 14 #include "./InternalHeaderCheck.h" 35 template <
typename MatrixType,
int Direction>
36 struct 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)
54 template <
typename MatrixType,
typename Lhs>
55 struct homogeneous_left_product_impl;
56 template <
typename MatrixType,
typename Rhs>
57 struct homogeneous_right_product_impl;
61 template <
typename MatrixType,
int Direction_>
62 class Homogeneous :
public MatrixBase<Homogeneous<MatrixType, Direction_> >, internal::no_assignment_operator {
64 typedef MatrixType NestedExpression;
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>
82 EIGEN_DEVICE_FUNC
inline const Product<Homogeneous, Rhs> operator*(
const MatrixBase<Rhs>& rhs)
const {
83 return Product<Homogeneous, Rhs>(*
this, rhs.derived());
86 template <
typename Lhs>
87 friend EIGEN_DEVICE_FUNC
inline const Product<Lhs, Homogeneous> operator*(
const MatrixBase<Lhs>& lhs,
88 const Homogeneous& rhs) {
89 return Product<Lhs, Homogeneous>(lhs.derived(), rhs);
92 template <
typename Scalar,
int Dim,
int Mode,
int Options>
93 friend EIGEN_DEVICE_FUNC
inline const Product<Transform<Scalar, Dim, Mode, Options>, Homogeneous> operator*(
94 const Transform<Scalar, Dim, Mode, Options>& lhs,
const Homogeneous& rhs) {
95 eigen_assert(
int(Direction) ==
Vertical);
96 return Product<Transform<Scalar, Dim, Mode, Options>, Homogeneous>(lhs, rhs);
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;
123 template <
typename Derived>
125 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
140 template <
typename ExpressionType,
int Direction>
163 template <
typename Derived>
166 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
168 ColsAtCompileTime == 1 ? 1 : size() - 1) /
187 template <
typename ExpressionType,
int Direction>
191 Direction ==
Horizontal ? _expression().cols() - 1 : _expression().cols())
194 ? HNormalized_SizeMinusOne
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));
205 template <
typename MatrixOrTransformType>
206 struct take_matrix_for_product {
207 typedef MatrixOrTransformType type;
208 EIGEN_DEVICE_FUNC
static const type& run(
const type& x) {
return x; }
211 template <
typename Scalar,
int Dim,
int Mode,
int Options>
212 struct 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(); }
218 template <
typename Scalar,
int Dim,
int Options>
219 struct 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(); }
225 template <
typename MatrixType,
typename Lhs>
226 struct 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;
236 template <
typename MatrixType,
typename Lhs>
237 struct 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;
262 template <
typename MatrixType,
typename Rhs>
263 struct 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;
270 template <
typename MatrixType,
typename Rhs>
271 struct 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;
292 template <
typename ArgType,
int Direction>
293 struct evaluator_traits<Homogeneous<ArgType, Direction> > {
294 typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
295 typedef HomogeneousShape Shape;
299 struct AssignmentKind<DenseShape, HomogeneousShape> {
300 typedef Dense2Dense Kind;
303 template <
typename ArgType,
int Direction>
304 struct 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);
319 template <
typename DstXprType,
typename ArgType,
typename Scalar>
320 struct 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();
335 template <
typename DstXprType,
typename ArgType,
typename Scalar>
336 struct 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();
350 template <
typename LhsArg,
typename Rhs,
int ProductTag>
351 struct 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);
358 template <
typename Lhs,
typename Rhs>
359 struct 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,
371 template <
typename Lhs,
typename Rhs,
int ProductTag>
372 struct 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)) {}
387 template <
typename Lhs,
typename RhsArg,
int ProductTag>
388 struct 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);
397 template <
typename Lhs,
typename RhsArg,
int ProductTag>
398 struct 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();
405 template <
typename Lhs,
typename Rhs>
406 struct 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;
411 typedef Replicate<const ConstantColumn, 1, Cols> ConstantBlock;
412 typedef Product<LinearBlock, Rhs, LazyProduct> LinearProduct;
413 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar, typename Rhs::Scalar>,
const LinearProduct,
418 template <
typename Lhs,
typename Rhs,
int ProductTag>
419 struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
420 :
public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs, typename Rhs::NestedExpression>::Xpr> {
421 typedef Product<Lhs, Rhs, LazyProduct> XprType;
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)
429 .template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows())
430 .lazyProduct(xpr.rhs().nestedExpression()) +
431 ConstantBlock(xpr.lhs().col(xpr.lhs().cols() - 1), 1, xpr.rhs().cols())) {}
434 template <
typename Scalar,
int Dim,
int Mode,
int Options,
typename RhsArg,
int ProductTag>
435 struct generic_product_impl<Transform<Scalar, Dim, Mode, Options>, Homogeneous<RhsArg,
Vertical>, DenseShape,
436 HomogeneousShape, ProductTag> {
437 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
438 template <
typename Dest>
439 EIGEN_DEVICE_FUNC
static void evalTo(Dest& dst,
const TransformType& lhs,
const Homogeneous<RhsArg, Vertical>& rhs) {
440 homogeneous_left_product_impl<Homogeneous<RhsArg, Vertical>, TransformType>(lhs, rhs.nestedExpression())
445 template <
typename ExpressionType,
int S
ide,
bool Transposed>
446 struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
447 :
public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape> {};
453 #endif // EIGEN_HOMOGENEOUS_H internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:62
Definition: Constants.h:266
HomogeneousReturnType homogeneous() const
Definition: Homogeneous.h:141
const HNormalizedReturnType hnormalized() const
column or row-wise homogeneous normalization
Definition: Homogeneous.h:189
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
const unsigned int RowMajorBit
Definition: Constants.h:70
Definition: Constants.h:462
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:75
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:64
Definition: Constants.h:269
const HNormalizedReturnType hnormalized() const
homogeneous normalization
Definition: Homogeneous.h:164
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:109
const int Dynamic
Definition: Constants.h:25
HomogeneousReturnType homogeneous() const
Definition: Homogeneous.h:124
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Expression of one (or a set of) homogeneous vector(s)
Definition: ForwardDeclarations.h:477