matrix.h
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2011, Johannes Meyer and Martin Nowara, TU Darmstadt
00003 // All rights reserved.
00004 
00005 // Redistribution and use in source and binary forms, with or without
00006 // modification, are permitted provided that the following conditions are met:
00007 //     * Redistributions of source code must retain the above copyright
00008 //       notice, this list of conditions and the following disclaimer.
00009 //     * Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //     * Neither the name of the Flight Systems and Automatic Control group,
00013 //       TU Darmstadt, nor the names of its contributors may be used to
00014 //       endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //=================================================================================================
00028 
00029 #ifndef HECTOR_POSE_ESTIMATION_MATRIX_H
00030 #define HECTOR_POSE_ESTIMATION_MATRIX_H
00031 
00032 #include <Eigen/Geometry>
00033 #include <stdexcept>
00034 
00035 #define ASSERT_SYMMETRIC_MATRIX_TO_BE_SYMMETRIC
00036 #define ASSERT_SYMMETRIC_MATRIX_TO_BE_SYMMETRIC_PRECISION 1e-5
00037 #define FORCE_SYMMETRIC_MATRIX_TO_BE_SYMMETRIC
00038 
00039 namespace hector_pose_estimation {
00040   using Eigen::Dynamic;
00041   using Eigen::Lower;
00042   using Eigen::Upper;
00043 
00044   typedef double ScalarType;
00045   typedef Eigen::DenseIndex IndexType;
00046   typedef Eigen::Matrix<ScalarType,Dynamic,1> ColumnVector;
00047   typedef Eigen::Matrix<ScalarType,1,Dynamic> RowVector;
00048   typedef Eigen::Matrix<ScalarType,Dynamic,Dynamic> Matrix;
00049   typedef Eigen::Quaternion<ScalarType> Quaternion;
00050 
00051   using Eigen::VectorBlock;
00052   typedef VectorBlock<ColumnVector,3>       VectorBlock3;
00053   typedef VectorBlock<ColumnVector,4>       VectorBlock4;
00054   typedef VectorBlock<const ColumnVector,3> ConstVectorBlock3;
00055   typedef VectorBlock<const ColumnVector,4> ConstVectorBlock4;
00056 
00057   using Eigen::Block;
00058   typedef Eigen::Block<Matrix,Dynamic,Dynamic> MatrixBlock;
00059 
00060   template <int Rows>
00061   class ColumnVector_ : public Eigen::Matrix<ScalarType,Rows,1> {
00062   public:
00063     EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Rows != Dynamic) // is this really required if Eigen::Matrix is the base class?
00064 
00065     typedef ColumnVector_<Rows> Derived;
00066     typedef Eigen::Matrix<ScalarType,Rows,1> Base;
00067     typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00068     typedef typename Eigen::internal::traits<Base>::Index Index;
00069     typedef Eigen::Map<Base> Map;
00070     typedef Eigen::Map<const Base> ConstMap;
00071 
00072     ColumnVector_() { this->setZero(); }
00073     ColumnVector_(Scalar value) { this->setConstant(value); }
00074     ColumnVector_(Scalar x, Scalar y, Scalar z) : Eigen::Matrix<ScalarType,Rows,1>(x, y, z) {}
00075     template <typename OtherDerived> ColumnVector_(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
00076 
00077     EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
00078   };
00079   typedef ColumnVector_<3> ColumnVector3;
00080 
00081   template <int Cols>
00082   class RowVector_ : public Eigen::Matrix<ScalarType,1,Cols> {
00083   public:
00084     EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Cols != Dynamic) // is this really required if Eigen::Matrix is the base class?
00085 
00086     typedef RowVector_<Cols> Derived;
00087     typedef Eigen::Matrix<ScalarType,1,Cols> Base;
00088     typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00089     typedef typename Eigen::internal::traits<Base>::Index Index;
00090     typedef Eigen::Map<Base> Map;
00091     typedef Eigen::Map<const Base> ConstMap;
00092 
00093     RowVector_() { this->setZero(); }
00094     RowVector_(Scalar value) { this->setConstant(value); }
00095     RowVector_(Scalar x, Scalar y, Scalar z) : Eigen::Matrix<ScalarType,1,Cols>(x, y, z) {}
00096     template <typename OtherDerived> RowVector_(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
00097 
00098     EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
00099   };
00100   typedef RowVector_<3> RowVector3;
00101 
00102   template <int Rows, int Cols>
00103   class Matrix_ : public Eigen::Matrix<ScalarType,Rows,Cols> {
00104   public:
00105     EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(Rows != Dynamic || Cols != Dynamic) // is this really required if Eigen::Matrix is the base class?
00106 
00107     typedef Matrix_<Rows,Cols> Derived;
00108     typedef Eigen::Matrix<ScalarType,Rows,Cols> Base;
00109     typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00110     typedef typename Eigen::internal::traits<Base>::Index Index;
00111     typedef Eigen::Map<Base> Map;
00112     typedef Eigen::Map<const Base> ConstMap;
00113 
00114     Matrix_() { this->setZero(); }
00115     Matrix_(Scalar value) { this->setConstant(value); }
00116     template <typename OtherDerived> Matrix_(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
00117 
00118     EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
00119 
00120   protected:
00121     explicit Matrix_(Index rows, Index cols) : Base(rows, cols) {}
00122   };
00123   typedef Matrix_<3,3> Matrix3;
00124 
00125 //  namespace internal {
00126 //    template <int RowsCols>
00127 //    class SymmetricMatrixStorage {
00128 //    public:
00129 //      EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(RowsCols != Dynamic)
00130 //      typedef typename Matrix_<RowsCols,RowsCols>::Base Base;
00131 //      typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00132 //      typedef typename Eigen::internal::traits<Base>::Index Index;
00133 
00134 //      SymmetricMatrixStorage() {}
00135 //      template <typename OtherDerived> SymmetricMatrixStorage(const Eigen::MatrixBase<OtherDerived>& other) : storage_(other) {}
00136 
00137 //    protected:
00138 //      explicit SymmetricMatrixStorage(Index dim) : storage_(dim) {}
00139 //      Matrix_<RowsCols,RowsCols> storage_;
00140 //    };
00141 //  }
00142 
00143 //  template <int RowsCols>
00144 //  class SymmetricMatrix_ : public internal::SymmetricMatrixStorage<RowsCols>, public Eigen::SelfAdjointView<typename internal::SymmetricMatrixStorage<RowsCols>::Base,Upper> {
00145 //  public:
00146 //    typedef internal::SymmetricMatrixStorage<RowsCols> Storage;
00147 //    typedef typename Storage::Base Base;
00148 //    typedef Eigen::SelfAdjointView<typename Storage::Base,Upper> SelfAdjointViewType;
00150 //    typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00151 //    typedef typename Eigen::internal::traits<Base>::Index Index;
00152 //    using Storage::storage_;
00153 
00154 //    // Constructors
00155 //    SymmetricMatrix_() : SelfAdjointViewType(storage_) {}
00156 //    SymmetricMatrix_(Scalar value) : SelfAdjointViewType(storage_) { this->setConstant(value); }
00157 //    template <int OtherRowsCols> SymmetricMatrix_(const SymmetricMatrix_<OtherRowsCols>& other) : Storage(other), SelfAdjointViewType(storage_) {}
00158 //    template <typename OtherDerived> SymmetricMatrix_(const Eigen::MatrixBase<OtherDerived>& other) : Storage(other), SelfAdjointViewType(storage_) {}
00159 
00160 //    SymmetricMatrix_<RowsCols>& setZero() {
00161 //      storage_.setZero();
00162 //      return *this;
00163 //    }
00164 
00165 //    SymmetricMatrix_<RowsCols>& setConstant(Scalar scalar) {
00166 //      storage_.setConstant(scalar);
00167 //      return *this;
00168 //    }
00169 
00170 //    template<int BlockRows, int BlockCols>
00171 //    Block<Base, BlockRows, BlockCols> block(Index startRow, Index startCol) {
00172 //      eigen_assert(startRow <= startCol);
00173 //      return storage_.block<BlockRows,BlockCols>(startRow, startCol);
00174 //    }
00175 
00176 //    template<int BlockRows, int BlockCols>
00177 //    const Block<const Base, BlockRows, BlockCols> block(Index startRow, Index startCol) const {
00178 //      eigen_assert(startRow <= startCol);
00179 //      return storage_.block<BlockRows,BlockCols>(startRow, startCol);
00180 //    }
00181 
00182 //    void conservativeResize(Index rows, Index cols) {
00183 //      storage_.conservativeResize(rows, cols);
00184 //    }
00185 
00186 //    void conservativeResize(Index size) {
00187 //      storage_.conservativeResize(size, size);
00188 //    }
00189 
00190 //    using SelfAdjointViewType::operator*;
00191 //    SymmetricMatrix_<RowsCols> operator*(const Scalar& scalar) {
00192 //      return SymmetricMatrix_<RowsCols>(storage_ * scalar);
00193 //    }
00194 
00195 //    template <int OtherRowsCols> SymmetricMatrix_<RowsCols>& operator=(const SymmetricMatrix_<OtherRowsCols>& other) {
00196 //      storage_ = other;
00197 //      return *this;
00198 //    }
00199 
00200 //    template <typename OtherDerived> SymmetricMatrix_<RowsCols>& operator=(const Eigen::MatrixBase<OtherDerived>& other) {
00201 //      storage_ = other;
00202 //      return *this;
00203 //    }
00204 
00205 //    template <typename Other> SymmetricMatrix_<RowsCols>& operator+(const Other& other) {
00206 //      storage_ += other;
00207 //      return *this;
00208 //    }
00209 
00210 //    template <typename Other> SymmetricMatrix_<RowsCols>& operator-(const Other& other) {
00211 //      storage_ -= other;
00212 //      return *this;
00213 //    }
00214 
00215 //    template <typename OtherDerived> SymmetricMatrix_<Derived::RowsAtCompileTime> quadratic(const Eigen::MatrixBase<OtherDerived>& other) {
00216 //      return other * (*this) * other.transpose();
00217 //    }
00218 
00219 //    SymmetricMatrix_<RowsCols> inverse() const {
00220 //      return SymmetricMatrix_<RowsCols>(this->toDenseMatrix().inverse());
00221 //    }
00222 
00223 //  protected:
00224 //    explicit SymmetricMatrix_(Index dim) : Storage(dim), SelfAdjointViewType(storage_) {}
00225 //  };
00226 
00227 //  template <int RowsCols>
00228 //  std::ostream& operator<<(std::ostream& os, const SymmetricMatrix_<RowsCols>& matrix) {
00229 //    return os << matrix.storage_;
00230 //  }
00231 
00232   template <int RowsCols>
00233   class SymmetricMatrix_ : public Matrix_<RowsCols,RowsCols> {
00234   public:
00235     EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(RowsCols != Dynamic) // is this really required if Eigen::Matrix is the base class?
00236 
00237     typedef SymmetricMatrix_<RowsCols> Derived;
00238     typedef Matrix_<RowsCols,RowsCols> Storage;
00239     typedef typename Storage::Base Base;
00240     typedef Eigen::SelfAdjointView<typename Storage::Base,Upper> SelfAdjointView;
00241     typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00242     typedef typename Eigen::internal::traits<Base>::Index Index;
00243     typedef Eigen::Map<Base> Map;
00244     typedef Eigen::Map<const Base> ConstMap;
00245 
00246     // Constructors
00247     SymmetricMatrix_() {}
00248     SymmetricMatrix_(Scalar value) { this->setConstant(value); }
00249     template <typename OtherDerived> SymmetricMatrix_(const Eigen::MatrixBase<OtherDerived>& other) : Storage(other) { symmetric(); }
00250 
00251     template <typename OtherDerived> Derived& operator=(const Eigen::MatrixBase<OtherDerived>& other) {
00252       this->Base::operator=(other);
00253       return symmetric();
00254     }
00255 
00256     Derived& symmetric() {
00257 #if defined(ASSERT_SYMMETRIC_MATRIX_TO_BE_SYMMETRIC)
00258       eigen_assert(this->isApprox(this->transpose(), ASSERT_SYMMETRIC_MATRIX_TO_BE_SYMMETRIC_PRECISION));
00259 #endif
00260 #if defined(FORCE_SYMMETRIC_MATRIX_TO_BE_SYMMETRIC)
00261       this->template triangularView<Eigen::Lower>() = this->transpose();
00262 #endif
00263       return *this;
00264     }
00265 
00266 //    template <typename OtherDerived> SymmetricMatrix_<Derived::RowsAtCompileTime> quadratic(const Eigen::MatrixBase<OtherDerived>& other) {
00267 //      return other * this->template selfadjointView<Upper>() * other.transpose();
00268 //    }
00269 
00270     Derived inverse() const {
00271 //      return this->template selfadjointView<Upper>().inverse();
00272       return this->Storage::inverse().eval();
00273     }
00274 
00275   protected:
00276     explicit SymmetricMatrix_(Index dim) : Storage(dim, dim) {}
00277   };
00278   typedef SymmetricMatrix_<3> SymmetricMatrix3;
00279 
00280   class SymmetricMatrix : public SymmetricMatrix_<Dynamic> {
00281   public:
00282     typedef SymmetricMatrix Derived;
00283     typedef SymmetricMatrix_<Dynamic> Storage;
00284     typedef typename Storage::Base Base;
00285     typedef Eigen::SelfAdjointView<typename Storage::Base,Upper> SelfAdjointView;
00286     typedef typename Eigen::internal::traits<Base>::Scalar Scalar;
00287     typedef typename Eigen::internal::traits<Base>::Index Index;
00288     typedef Eigen::Map<Base> Map;
00289     typedef Eigen::Map<const Base> ConstMap;
00290 
00291     // Constructors
00292     SymmetricMatrix() : SymmetricMatrix_<Dynamic>() {}
00293     SymmetricMatrix(Index dim) : SymmetricMatrix_<Dynamic>(dim) { this->setZero(); }
00294     SymmetricMatrix(Index dim, Scalar value) : SymmetricMatrix_<Dynamic>(dim) { this->setConstant(value); }
00295     template <int OtherRowsCols> SymmetricMatrix(const SymmetricMatrix_<OtherRowsCols>& other) : SymmetricMatrix_<Dynamic>(other) {}
00296     template <typename OtherDerived> SymmetricMatrix(const Eigen::MatrixBase<OtherDerived>& other) : SymmetricMatrix_<Dynamic>(other) {}
00297 
00298     template <typename OtherDerived> Derived& operator=(const Eigen::MatrixBase<OtherDerived>& other) {
00299       this->Base::operator=(other);
00300       return symmetric();
00301     }
00302 
00303     Derived& symmetric() {
00304       Storage::symmetric();
00305       return *this;
00306     }
00307 
00308     void resize(Index size) {
00309       Base::resize(size, size);
00310     }
00311 
00312     void conservativeResize(Index size) {
00313       Base::conservativeResize(size, size);
00314     }
00315   };
00316 
00317 } // namespace hector_pose_estimation
00318 
00319 #endif // HECTOR_POSE_ESTIMATION_MATRIX_H


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Mon Oct 6 2014 00:24:16