Main MRPT website > C++ reference
MRPT logo

Block.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-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_BLOCK2_H
00027 #define EIGEN_BLOCK2_H
00028 
00029 /** \returns a dynamic-size expression of a corner of *this.
00030   *
00031   * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight,
00032   * \a Eigen::BottomLeft, \a Eigen::BottomRight.
00033   * \param cRows the number of rows in the corner
00034   * \param cCols the number of columns in the corner
00035   *
00036   * Example: \include MatrixBase_corner_enum_int_int.cpp
00037   * Output: \verbinclude MatrixBase_corner_enum_int_int.out
00038   *
00039   * \note Even though the returned expression has dynamic size, in the case
00040   * when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
00041   * which means that evaluating it does not cause a dynamic memory allocation.
00042   *
00043   * \sa class Block, block(Index,Index,Index,Index)
00044   */
00045 template<typename Derived>
00046 inline Block<Derived> DenseBase<Derived>
00047   ::corner(CornerType type, Index cRows, Index cCols)
00048 {
00049   switch(type)
00050   {
00051     default:
00052       eigen_assert(false && "Bad corner type.");
00053     case TopLeft:
00054       return Block<Derived>(derived(), 0, 0, cRows, cCols);
00055     case TopRight:
00056       return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
00057     case BottomLeft:
00058       return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
00059     case BottomRight:
00060       return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
00061   }
00062 }
00063 
00064 /** This is the const version of corner(CornerType, Index, Index).*/
00065 template<typename Derived>
00066 inline const Block<Derived>
00067 DenseBase<Derived>::corner(CornerType type, Index cRows, Index cCols) const
00068 {
00069   switch(type)
00070   {
00071     default:
00072       eigen_assert(false && "Bad corner type.");
00073     case TopLeft:
00074       return Block<Derived>(derived(), 0, 0, cRows, cCols);
00075     case TopRight:
00076       return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
00077     case BottomLeft:
00078       return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
00079     case BottomRight:
00080       return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
00081   }
00082 }
00083 
00084 /** \returns a fixed-size expression of a corner of *this.
00085   *
00086   * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight,
00087   * \a Eigen::BottomLeft, \a Eigen::BottomRight.
00088   *
00089   * The template parameters CRows and CCols arethe number of rows and columns in the corner.
00090   *
00091   * Example: \include MatrixBase_template_int_int_corner_enum.cpp
00092   * Output: \verbinclude MatrixBase_template_int_int_corner_enum.out
00093   *
00094   * \sa class Block, block(Index,Index,Index,Index)
00095   */
00096 template<typename Derived>
00097 template<int CRows, int CCols>
00098 inline Block<Derived, CRows, CCols>
00099 DenseBase<Derived>::corner(CornerType type)
00100 {
00101   switch(type)
00102   {
00103     default:
00104       eigen_assert(false && "Bad corner type.");
00105     case TopLeft:
00106       return Block<Derived, CRows, CCols>(derived(), 0, 0);
00107     case TopRight:
00108       return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
00109     case BottomLeft:
00110       return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
00111     case BottomRight:
00112       return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
00113   }
00114 }
00115 
00116 /** This is the const version of corner<int, int>(CornerType).*/
00117 template<typename Derived>
00118 template<int CRows, int CCols>
00119 inline const Block<Derived, CRows, CCols>
00120 DenseBase<Derived>::corner(CornerType type) const
00121 {
00122   switch(type)
00123   {
00124     default:
00125       eigen_assert(false && "Bad corner type.");
00126     case TopLeft:
00127       return Block<Derived, CRows, CCols>(derived(), 0, 0);
00128     case TopRight:
00129       return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
00130     case BottomLeft:
00131       return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
00132     case BottomRight:
00133       return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
00134   }
00135 }
00136 
00137 #endif // EIGEN_BLOCK2_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011