Select.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_SELECT_H
00011 #define EIGEN_SELECT_H
00012 
00013 namespace Eigen { 
00014 
00030 namespace internal {
00031 template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
00032 struct traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
00033  : traits<ThenMatrixType>
00034 {
00035   typedef typename traits<ThenMatrixType>::Scalar Scalar;
00036   typedef Dense StorageKind;
00037   typedef typename traits<ThenMatrixType>::XprKind XprKind;
00038   typedef typename ConditionMatrixType::Nested ConditionMatrixNested;
00039   typedef typename ThenMatrixType::Nested ThenMatrixNested;
00040   typedef typename ElseMatrixType::Nested ElseMatrixNested;
00041   enum {
00042     RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime,
00043     ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime,
00044     MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime,
00045     MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime,
00046     Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & HereditaryBits,
00047     CoeffReadCost = traits<typename remove_all<ConditionMatrixNested>::type>::CoeffReadCost
00048                   + EIGEN_SIZE_MAX(traits<typename remove_all<ThenMatrixNested>::type>::CoeffReadCost,
00049                                    traits<typename remove_all<ElseMatrixNested>::type>::CoeffReadCost)
00050   };
00051 };
00052 }
00053 
00054 template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
00055 class Select : internal::no_assignment_operator,
00056   public internal::dense_xpr_base< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::type
00057 {
00058   public:
00059 
00060     typedef typename internal::dense_xpr_base<Select>::type Base;
00061     EIGEN_DENSE_PUBLIC_INTERFACE(Select)
00062 
00063     Select(const ConditionMatrixType& a_conditionMatrix,
00064            const ThenMatrixType& a_thenMatrix,
00065            const ElseMatrixType& a_elseMatrix)
00066       : m_condition(a_conditionMatrix), m_then(a_thenMatrix), m_else(a_elseMatrix)
00067     {
00068       eigen_assert(m_condition.rows() == m_then.rows() && m_condition.rows() == m_else.rows());
00069       eigen_assert(m_condition.cols() == m_then.cols() && m_condition.cols() == m_else.cols());
00070     }
00071 
00072     Index rows() const { return m_condition.rows(); }
00073     Index cols() const { return m_condition.cols(); }
00074 
00075     const Scalar coeff(Index i, Index j) const
00076     {
00077       if (m_condition.coeff(i,j))
00078         return m_then.coeff(i,j);
00079       else
00080         return m_else.coeff(i,j);
00081     }
00082 
00083     const Scalar coeff(Index i) const
00084     {
00085       if (m_condition.coeff(i))
00086         return m_then.coeff(i);
00087       else
00088         return m_else.coeff(i);
00089     }
00090 
00091     const ConditionMatrixType& conditionMatrix() const
00092     {
00093       return m_condition;
00094     }
00095 
00096     const ThenMatrixType& thenMatrix() const
00097     {
00098       return m_then;
00099     }
00100 
00101     const ElseMatrixType& elseMatrix() const
00102     {
00103       return m_else;
00104     }
00105 
00106   protected:
00107     typename ConditionMatrixType::Nested m_condition;
00108     typename ThenMatrixType::Nested m_then;
00109     typename ElseMatrixType::Nested m_else;
00110 };
00111 
00112 
00121 template<typename Derived>
00122 template<typename ThenDerived,typename ElseDerived>
00123 inline const Select<Derived,ThenDerived,ElseDerived>
00124 DenseBase<Derived>::select(const DenseBase<ThenDerived>& thenMatrix,
00125                             const DenseBase<ElseDerived>& elseMatrix) const
00126 {
00127   return Select<Derived,ThenDerived,ElseDerived>(derived(), thenMatrix.derived(), elseMatrix.derived());
00128 }
00129 
00135 template<typename Derived>
00136 template<typename ThenDerived>
00137 inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
00138 DenseBase<Derived>::select(const DenseBase<ThenDerived>& thenMatrix,
00139                            const typename ThenDerived::Scalar& elseScalar) const
00140 {
00141   return Select<Derived,ThenDerived,typename ThenDerived::ConstantReturnType>(
00142     derived(), thenMatrix.derived(), ThenDerived::Constant(rows(),cols(),elseScalar));
00143 }
00144 
00150 template<typename Derived>
00151 template<typename ElseDerived>
00152 inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
00153 DenseBase<Derived>::select(const typename ElseDerived::Scalar& thenScalar,
00154                            const DenseBase<ElseDerived>& elseMatrix) const
00155 {
00156   return Select<Derived,typename ElseDerived::ConstantReturnType,ElseDerived>(
00157     derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.derived());
00158 }
00159 
00160 } // end namespace Eigen
00161 
00162 #endif // EIGEN_SELECT_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:59:34