Warning, file /include/eigen3/Eigen/src/Geometry/Homogeneous.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_HOMOGENEOUS_H
0011 #define EIGEN_HOMOGENEOUS_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 namespace internal {
0031
0032 template<typename MatrixType,int Direction>
0033 struct traits<Homogeneous<MatrixType,Direction> >
0034 : traits<MatrixType>
0035 {
0036 typedef typename traits<MatrixType>::StorageKind StorageKind;
0037 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
0038 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
0039 enum {
0040 RowsPlusOne = (MatrixType::RowsAtCompileTime != Dynamic) ?
0041 int(MatrixType::RowsAtCompileTime) + 1 : Dynamic,
0042 ColsPlusOne = (MatrixType::ColsAtCompileTime != Dynamic) ?
0043 int(MatrixType::ColsAtCompileTime) + 1 : Dynamic,
0044 RowsAtCompileTime = Direction==Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
0045 ColsAtCompileTime = Direction==Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
0046 MaxRowsAtCompileTime = RowsAtCompileTime,
0047 MaxColsAtCompileTime = ColsAtCompileTime,
0048 TmpFlags = _MatrixTypeNested::Flags & HereditaryBits,
0049 Flags = ColsAtCompileTime==1 ? (TmpFlags & ~RowMajorBit)
0050 : RowsAtCompileTime==1 ? (TmpFlags | RowMajorBit)
0051 : TmpFlags
0052 };
0053 };
0054
0055 template<typename MatrixType,typename Lhs> struct homogeneous_left_product_impl;
0056 template<typename MatrixType,typename Rhs> struct homogeneous_right_product_impl;
0057
0058 }
0059
0060 template<typename MatrixType,int _Direction> class Homogeneous
0061 : public MatrixBase<Homogeneous<MatrixType,_Direction> >, internal::no_assignment_operator
0062 {
0063 public:
0064
0065 typedef MatrixType NestedExpression;
0066 enum { Direction = _Direction };
0067
0068 typedef MatrixBase<Homogeneous> Base;
0069 EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous)
0070
0071 EIGEN_DEVICE_FUNC explicit inline Homogeneous(const MatrixType& matrix)
0072 : m_matrix(matrix)
0073 {}
0074
0075 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0076 inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows() + (int(Direction)==Vertical ? 1 : 0); }
0077 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0078 inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols() + (int(Direction)==Horizontal ? 1 : 0); }
0079
0080 EIGEN_DEVICE_FUNC const NestedExpression& nestedExpression() const { return m_matrix; }
0081
0082 template<typename Rhs>
0083 EIGEN_DEVICE_FUNC inline const Product<Homogeneous,Rhs>
0084 operator* (const MatrixBase<Rhs>& rhs) const
0085 {
0086 eigen_assert(int(Direction)==Horizontal);
0087 return Product<Homogeneous,Rhs>(*this,rhs.derived());
0088 }
0089
0090 template<typename Lhs> friend
0091 EIGEN_DEVICE_FUNC inline const Product<Lhs,Homogeneous>
0092 operator* (const MatrixBase<Lhs>& lhs, const Homogeneous& rhs)
0093 {
0094 eigen_assert(int(Direction)==Vertical);
0095 return Product<Lhs,Homogeneous>(lhs.derived(),rhs);
0096 }
0097
0098 template<typename Scalar, int Dim, int Mode, int Options> friend
0099 EIGEN_DEVICE_FUNC inline const Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous >
0100 operator* (const Transform<Scalar,Dim,Mode,Options>& lhs, const Homogeneous& rhs)
0101 {
0102 eigen_assert(int(Direction)==Vertical);
0103 return Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous>(lhs,rhs);
0104 }
0105
0106 template<typename Func>
0107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::result_of<Func(Scalar,Scalar)>::type
0108 redux(const Func& func) const
0109 {
0110 return func(m_matrix.redux(func), Scalar(1));
0111 }
0112
0113 protected:
0114 typename MatrixType::Nested m_matrix;
0115 };
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 template<typename Derived>
0131 EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::HomogeneousReturnType
0132 MatrixBase<Derived>::homogeneous() const
0133 {
0134 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
0135 return HomogeneousReturnType(derived());
0136 }
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 template<typename ExpressionType, int Direction>
0149 EIGEN_DEVICE_FUNC inline Homogeneous<ExpressionType,Direction>
0150 VectorwiseOp<ExpressionType,Direction>::homogeneous() const
0151 {
0152 return HomogeneousReturnType(_expression());
0153 }
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 template<typename Derived>
0173 EIGEN_DEVICE_FUNC inline const typename MatrixBase<Derived>::HNormalizedReturnType
0174 MatrixBase<Derived>::hnormalized() const
0175 {
0176 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
0177 return ConstStartMinusOne(derived(),0,0,
0178 ColsAtCompileTime==1?size()-1:1,
0179 ColsAtCompileTime==1?1:size()-1) / coeff(size()-1);
0180 }
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 template<typename ExpressionType, int Direction>
0197 EIGEN_DEVICE_FUNC inline const typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType
0198 VectorwiseOp<ExpressionType,Direction>::hnormalized() const
0199 {
0200 return HNormalized_Block(_expression(),0,0,
0201 Direction==Vertical ? _expression().rows()-1 : _expression().rows(),
0202 Direction==Horizontal ? _expression().cols()-1 : _expression().cols()).cwiseQuotient(
0203 Replicate<HNormalized_Factors,
0204 Direction==Vertical ? HNormalized_SizeMinusOne : 1,
0205 Direction==Horizontal ? HNormalized_SizeMinusOne : 1>
0206 (HNormalized_Factors(_expression(),
0207 Direction==Vertical ? _expression().rows()-1:0,
0208 Direction==Horizontal ? _expression().cols()-1:0,
0209 Direction==Vertical ? 1 : _expression().rows(),
0210 Direction==Horizontal ? 1 : _expression().cols()),
0211 Direction==Vertical ? _expression().rows()-1 : 1,
0212 Direction==Horizontal ? _expression().cols()-1 : 1));
0213 }
0214
0215 namespace internal {
0216
0217 template<typename MatrixOrTransformType>
0218 struct take_matrix_for_product
0219 {
0220 typedef MatrixOrTransformType type;
0221 EIGEN_DEVICE_FUNC static const type& run(const type &x) { return x; }
0222 };
0223
0224 template<typename Scalar, int Dim, int Mode,int Options>
0225 struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
0226 {
0227 typedef Transform<Scalar, Dim, Mode, Options> TransformType;
0228 typedef typename internal::add_const<typename TransformType::ConstAffinePart>::type type;
0229 EIGEN_DEVICE_FUNC static type run (const TransformType& x) { return x.affine(); }
0230 };
0231
0232 template<typename Scalar, int Dim, int Options>
0233 struct take_matrix_for_product<Transform<Scalar, Dim, Projective, Options> >
0234 {
0235 typedef Transform<Scalar, Dim, Projective, Options> TransformType;
0236 typedef typename TransformType::MatrixType type;
0237 EIGEN_DEVICE_FUNC static const type& run (const TransformType& x) { return x.matrix(); }
0238 };
0239
0240 template<typename MatrixType,typename Lhs>
0241 struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
0242 {
0243 typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
0244 typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
0245 typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
0246 typedef typename make_proper_matrix_type<
0247 typename traits<MatrixTypeCleaned>::Scalar,
0248 LhsMatrixTypeCleaned::RowsAtCompileTime,
0249 MatrixTypeCleaned::ColsAtCompileTime,
0250 MatrixTypeCleaned::PlainObject::Options,
0251 LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
0252 MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
0253 };
0254
0255 template<typename MatrixType,typename Lhs>
0256 struct homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs>
0257 : public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
0258 {
0259 typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
0260 typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
0261 typedef typename remove_all<typename LhsMatrixTypeCleaned::Nested>::type LhsMatrixTypeNested;
0262 EIGEN_DEVICE_FUNC homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs)
0263 : m_lhs(take_matrix_for_product<Lhs>::run(lhs)),
0264 m_rhs(rhs)
0265 {}
0266
0267 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0268 inline Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
0269 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0270 inline Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
0271
0272 template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const
0273 {
0274
0275 dst = Block<const LhsMatrixTypeNested,
0276 LhsMatrixTypeNested::RowsAtCompileTime,
0277 LhsMatrixTypeNested::ColsAtCompileTime==Dynamic?Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1>
0278 (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs;
0279 dst += m_lhs.col(m_lhs.cols()-1).rowwise()
0280 .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
0281 }
0282
0283 typename LhsMatrixTypeCleaned::Nested m_lhs;
0284 typename MatrixType::Nested m_rhs;
0285 };
0286
0287 template<typename MatrixType,typename Rhs>
0288 struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
0289 {
0290 typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar,
0291 MatrixType::RowsAtCompileTime,
0292 Rhs::ColsAtCompileTime,
0293 MatrixType::PlainObject::Options,
0294 MatrixType::MaxRowsAtCompileTime,
0295 Rhs::MaxColsAtCompileTime>::type ReturnType;
0296 };
0297
0298 template<typename MatrixType,typename Rhs>
0299 struct homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs>
0300 : public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
0301 {
0302 typedef typename remove_all<typename Rhs::Nested>::type RhsNested;
0303 EIGEN_DEVICE_FUNC homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs)
0304 : m_lhs(lhs), m_rhs(rhs)
0305 {}
0306
0307 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
0308 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
0309
0310 template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const
0311 {
0312
0313 dst = m_lhs * Block<const RhsNested,
0314 RhsNested::RowsAtCompileTime==Dynamic?Dynamic:RhsNested::RowsAtCompileTime-1,
0315 RhsNested::ColsAtCompileTime>
0316 (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols());
0317 dst += m_rhs.row(m_rhs.rows()-1).colwise()
0318 .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
0319 }
0320
0321 typename MatrixType::Nested m_lhs;
0322 typename Rhs::Nested m_rhs;
0323 };
0324
0325 template<typename ArgType,int Direction>
0326 struct evaluator_traits<Homogeneous<ArgType,Direction> >
0327 {
0328 typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
0329 typedef HomogeneousShape Shape;
0330 };
0331
0332 template<> struct AssignmentKind<DenseShape,HomogeneousShape> { typedef Dense2Dense Kind; };
0333
0334
0335 template<typename ArgType,int Direction>
0336 struct unary_evaluator<Homogeneous<ArgType,Direction>, IndexBased>
0337 : evaluator<typename Homogeneous<ArgType,Direction>::PlainObject >
0338 {
0339 typedef Homogeneous<ArgType,Direction> XprType;
0340 typedef typename XprType::PlainObject PlainObject;
0341 typedef evaluator<PlainObject> Base;
0342
0343 EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op)
0344 : Base(), m_temp(op)
0345 {
0346 ::new (static_cast<Base*>(this)) Base(m_temp);
0347 }
0348
0349 protected:
0350 PlainObject m_temp;
0351 };
0352
0353
0354 template< typename DstXprType, typename ArgType, typename Scalar>
0355 struct Assignment<DstXprType, Homogeneous<ArgType,Vertical>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
0356 {
0357 typedef Homogeneous<ArgType,Vertical> SrcXprType;
0358 EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &)
0359 {
0360 Index dstRows = src.rows();
0361 Index dstCols = src.cols();
0362 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
0363 dst.resize(dstRows, dstCols);
0364
0365 dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
0366 dst.row(dst.rows()-1).setOnes();
0367 }
0368 };
0369
0370
0371 template< typename DstXprType, typename ArgType, typename Scalar>
0372 struct Assignment<DstXprType, Homogeneous<ArgType,Horizontal>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
0373 {
0374 typedef Homogeneous<ArgType,Horizontal> SrcXprType;
0375 EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &)
0376 {
0377 Index dstRows = src.rows();
0378 Index dstCols = src.cols();
0379 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
0380 dst.resize(dstRows, dstCols);
0381
0382 dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();
0383 dst.col(dst.cols()-1).setOnes();
0384 }
0385 };
0386
0387 template<typename LhsArg, typename Rhs, int ProductTag>
0388 struct generic_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag>
0389 {
0390 template<typename Dest>
0391 EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Homogeneous<LhsArg,Horizontal>& lhs, const Rhs& rhs)
0392 {
0393 homogeneous_right_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst);
0394 }
0395 };
0396
0397 template<typename Lhs,typename Rhs>
0398 struct homogeneous_right_product_refactoring_helper
0399 {
0400 enum {
0401 Dim = Lhs::ColsAtCompileTime,
0402 Rows = Lhs::RowsAtCompileTime
0403 };
0404 typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst;
0405 typedef typename remove_const<LinearBlockConst>::type LinearBlock;
0406 typedef typename Rhs::ConstRowXpr ConstantColumn;
0407 typedef Replicate<const ConstantColumn,Rows,1> ConstantBlock;
0408 typedef Product<Lhs,LinearBlock,LazyProduct> LinearProduct;
0409 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr;
0410 };
0411
0412 template<typename Lhs, typename Rhs, int ProductTag>
0413 struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape>
0414 : public evaluator<typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs>::Xpr>
0415 {
0416 typedef Product<Lhs, Rhs, LazyProduct> XprType;
0417 typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs> helper;
0418 typedef typename helper::ConstantBlock ConstantBlock;
0419 typedef typename helper::Xpr RefactoredXpr;
0420 typedef evaluator<RefactoredXpr> Base;
0421
0422 EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
0423 : Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols()) )
0424 + ConstantBlock(xpr.rhs().row(xpr.rhs().rows()-1),xpr.lhs().rows(), 1) )
0425 {}
0426 };
0427
0428 template<typename Lhs, typename RhsArg, int ProductTag>
0429 struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag>
0430 {
0431 template<typename Dest>
0432 EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
0433 {
0434 homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst);
0435 }
0436 };
0437
0438
0439
0440 template<typename Lhs, typename RhsArg, int ProductTag>
0441 struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, TriangularShape, HomogeneousShape, ProductTag>
0442 {
0443 template<typename Dest>
0444 static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
0445 {
0446 dst.noalias() = lhs * rhs.eval();
0447 }
0448 };
0449
0450 template<typename Lhs,typename Rhs>
0451 struct homogeneous_left_product_refactoring_helper
0452 {
0453 enum {
0454 Dim = Rhs::RowsAtCompileTime,
0455 Cols = Rhs::ColsAtCompileTime
0456 };
0457 typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst;
0458 typedef typename remove_const<LinearBlockConst>::type LinearBlock;
0459 typedef typename Lhs::ConstColXpr ConstantColumn;
0460 typedef Replicate<const ConstantColumn,1,Cols> ConstantBlock;
0461 typedef Product<LinearBlock,Rhs,LazyProduct> LinearProduct;
0462 typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr;
0463 };
0464
0465 template<typename Lhs, typename Rhs, int ProductTag>
0466 struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
0467 : public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression>::Xpr>
0468 {
0469 typedef Product<Lhs, Rhs, LazyProduct> XprType;
0470 typedef homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression> helper;
0471 typedef typename helper::ConstantBlock ConstantBlock;
0472 typedef typename helper::Xpr RefactoredXpr;
0473 typedef evaluator<RefactoredXpr> Base;
0474
0475 EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
0476 : Base( xpr.lhs().template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows()) .lazyProduct( xpr.rhs().nestedExpression() )
0477 + ConstantBlock(xpr.lhs().col(xpr.lhs().cols()-1),1,xpr.rhs().cols()) )
0478 {}
0479 };
0480
0481 template<typename Scalar, int Dim, int Mode,int Options, typename RhsArg, int ProductTag>
0482 struct generic_product_impl<Transform<Scalar,Dim,Mode,Options>, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag>
0483 {
0484 typedef Transform<Scalar,Dim,Mode,Options> TransformType;
0485 template<typename Dest>
0486 EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const TransformType& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
0487 {
0488 homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, TransformType>(lhs, rhs.nestedExpression()).evalTo(dst);
0489 }
0490 };
0491
0492 template<typename ExpressionType, int Side, bool Transposed>
0493 struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
0494 : public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
0495 {};
0496
0497 }
0498
0499 }
0500
0501 #endif