Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2f6559b7006594cad03af173263c219e > files > 4746

mrpt-doc-0.9.4-0.1.20110110svn2383.fc15.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>The MRPT project: eigen_plugins_impl.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> &gt; <b>C++ reference</b> </div>
<div align="right">
<a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a>
</div>
<!-- Generated by Doxygen 1.7.2 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
          <span class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </span><span class="right"></span>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>eigen_plugins_impl.h</h1>  </div>
</div>
<div class="contents">
<a href="eigen__plugins__impl_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* +---------------------------------------------------------------------------+</span>
<a name="l00002"></a>00002 <span class="comment">   |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |</span>
<a name="l00003"></a>00003 <span class="comment">   |                                                                           |</span>
<a name="l00004"></a>00004 <span class="comment">   |                   http://mrpt.sourceforge.net/                            |</span>
<a name="l00005"></a>00005 <span class="comment">   |                                                                           |</span>
<a name="l00006"></a>00006 <span class="comment">   |   Copyright (C) 2005-2011  University of Malaga                           |</span>
<a name="l00007"></a>00007 <span class="comment">   |                                                                           |</span>
<a name="l00008"></a>00008 <span class="comment">   |    This software was written by the Machine Perception and Intelligent    |</span>
<a name="l00009"></a>00009 <span class="comment">   |      Robotics Lab, University of Malaga (Spain).                          |</span>
<a name="l00010"></a>00010 <span class="comment">   |    Contact: Jose-Luis Blanco  &lt;jlblanco@ctima.uma.es&gt;                     |</span>
<a name="l00011"></a>00011 <span class="comment">   |                                                                           |</span>
<a name="l00012"></a>00012 <span class="comment">   |  This file is part of the MRPT project.                                   |</span>
<a name="l00013"></a>00013 <span class="comment">   |                                                                           |</span>
<a name="l00014"></a>00014 <span class="comment">   |     MRPT is free software: you can redistribute it and/or modify          |</span>
<a name="l00015"></a>00015 <span class="comment">   |     it under the terms of the GNU General Public License as published by  |</span>
<a name="l00016"></a>00016 <span class="comment">   |     the Free Software Foundation, either version 3 of the License, or     |</span>
<a name="l00017"></a>00017 <span class="comment">   |     (at your option) any later version.                                   |</span>
<a name="l00018"></a>00018 <span class="comment">   |                                                                           |</span>
<a name="l00019"></a>00019 <span class="comment">   |   MRPT is distributed in the hope that it will be useful,                 |</span>
<a name="l00020"></a>00020 <span class="comment">   |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |</span>
<a name="l00021"></a>00021 <span class="comment">   |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |</span>
<a name="l00022"></a>00022 <span class="comment">   |     GNU General Public License for more details.                          |</span>
<a name="l00023"></a>00023 <span class="comment">   |                                                                           |</span>
<a name="l00024"></a>00024 <span class="comment">   |     You should have received a copy of the GNU General Public License     |</span>
<a name="l00025"></a>00025 <span class="comment">   |     along with MRPT.  If not, see &lt;http://www.gnu.org/licenses/&gt;.         |</span>
<a name="l00026"></a>00026 <span class="comment">   |                                                                           |</span>
<a name="l00027"></a>00027 <span class="comment">   +---------------------------------------------------------------------------+ */</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#ifndef MRPT_EIGEN_PLUGINS_IMPL_H</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define MRPT_EIGEN_PLUGINS_IMPL_H</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span>
<a name="l00032"></a>00032 <span class="comment">// -------------------------------------------------------------------------</span>
<a name="l00033"></a>00033 <span class="comment">//  This file implements some templates which had to be left only declared</span>
<a name="l00034"></a>00034 <span class="comment">//   in the &quot;plug-in&quot; headers &quot;eigen_plugins.h&quot; within Eigen::MatrixBase&lt;&gt;</span>
<a name="l00035"></a>00035 <span class="comment">// -------------------------------------------------------------------------</span>
<a name="l00036"></a>00036 
<a name="l00037"></a><a class="code" href="namespaceinternal__mrpt.html">00037</a> <span class="keyword">namespace </span>internal_mrpt
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039         <span class="comment">// Generic version for all kind of matrices:</span>
<a name="l00040"></a>00040         <span class="keyword">template</span>&lt;<span class="keywordtype">int</span> R, <span class="keywordtype">int</span> C&gt;
<a name="l00041"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html">00041</a>         <span class="keyword">struct </span><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html">MatOrVecResizer</a>
<a name="l00042"></a>00042         {
<a name="l00043"></a>00043                 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> S, <span class="keywordtype">int</span> Opt, <span class="keywordtype">int</span> MaxR, <span class="keywordtype">int</span> MaxC&gt;
<a name="l00044"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">00044</a>                 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">doit</a>(Eigen::Matrix&lt;S,R,C,Opt,MaxR,MaxC&gt; &amp;mat, <span class="keywordtype">size_t</span> new_rows,<span class="keywordtype">size_t</span> new_cols)
<a name="l00045"></a>00045                 {<a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices."></a>
<a name="l00046"></a>00046 <a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices.">			::mrpt::math::detail::TAuxResizer&lt;Eigen::Matrix&lt;S,R,C,Opt,MaxR,MaxC&gt;</a>,Eigen::Matrix&lt;S,R,C,Opt,MaxR,MaxC&gt;::SizeAtCompileTime&gt;::internal_resize(mat,new_rows,new_cols);
<a name="l00047"></a>00047                         <span class="comment">//mat.derived().conservativeResize(new_rows,new_cols);</span>
<a name="l00048"></a>00048                 }
<a name="l00049"></a>00049         };
<a name="l00050"></a>00050         <span class="comment">// Specialization for column matrices:</span>
<a name="l00051"></a>00051         <span class="keyword">template</span>&lt;<span class="keywordtype">int</span> R&gt;
<a name="l00052"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer_3_01_r_00_011_01_4.html">00052</a>         <span class="keyword">struct </span><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html">MatOrVecResizer</a>&lt;R,1&gt;
<a name="l00053"></a>00053         {
<a name="l00054"></a>00054                 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> S, <span class="keywordtype">int</span> Opt, <span class="keywordtype">int</span> MaxR, <span class="keywordtype">int</span> MaxC&gt;
<a name="l00055"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer_3_01_r_00_011_01_4.html#a9a29e6b406b85ef239a78324469512d6">00055</a>                 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">doit</a>(Eigen::Matrix&lt;S,R,1,Opt,MaxR,MaxC&gt; &amp;mat, <span class="keywordtype">size_t</span> new_rows,<span class="keywordtype">size_t</span> new_cols)
<a name="l00056"></a>00056                 {<a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices."></a>
<a name="l00057"></a>00057 <a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices.">			::mrpt::math::detail::TAuxResizer&lt;Eigen::Matrix&lt;S,R,1,Opt,MaxR,MaxC&gt;</a>,Eigen::Matrix&lt;S,R,1,Opt,MaxR,MaxC&gt;::SizeAtCompileTime&gt;::internal_resize(mat,new_rows);
<a name="l00058"></a>00058                         <span class="comment">//mat.derived().conservativeResize(new_rows);</span>
<a name="l00059"></a>00059                 }
<a name="l00060"></a>00060         };
<a name="l00061"></a>00061         <span class="comment">// Specialization for row matrices:</span>
<a name="l00062"></a>00062         <span class="keyword">template</span>&lt;<span class="keywordtype">int</span> C&gt;
<a name="l00063"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer_3_011_00_01_c_01_4.html">00063</a>         <span class="keyword">struct </span><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html">MatOrVecResizer</a>&lt;1,C&gt;
<a name="l00064"></a>00064         {
<a name="l00065"></a>00065                 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> S, <span class="keywordtype">int</span> Opt, <span class="keywordtype">int</span> MaxR, <span class="keywordtype">int</span> MaxC&gt;
<a name="l00066"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer_3_011_00_01_c_01_4.html#ae29d4d035d2de305d6f5e5f2dc7bf62b">00066</a>                 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">doit</a>(Eigen::Matrix&lt;S,1,C,Opt,MaxR,MaxC&gt; &amp;mat, <span class="keywordtype">size_t</span> new_rows,<span class="keywordtype">size_t</span> new_cols)
<a name="l00067"></a>00067                 {<a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices."></a>
<a name="l00068"></a>00068 <a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices.">			::mrpt::math::detail::TAuxResizer&lt;Eigen::Matrix&lt;S,1,C,Opt,MaxR,MaxC&gt;</a>,Eigen::Matrix&lt;S,1,C,Opt,MaxR,MaxC&gt;::SizeAtCompileTime&gt;::internal_resize(mat,new_cols);
<a name="l00069"></a>00069                         <span class="comment">//mat.derived().conservativeResize(new_cols);</span>
<a name="l00070"></a>00070                 }
<a name="l00071"></a>00071         };
<a name="l00072"></a>00072         <span class="keyword">template</span>&lt;&gt;
<a name="l00073"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer_3_011_00_011_01_4.html">00073</a>         <span class="keyword">struct </span><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html">MatOrVecResizer</a>&lt;1,1&gt;
<a name="l00074"></a>00074         {
<a name="l00075"></a>00075                 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> S, <span class="keywordtype">int</span> Opt, <span class="keywordtype">int</span> MaxR, <span class="keywordtype">int</span> MaxC&gt;
<a name="l00076"></a><a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer_3_011_00_011_01_4.html#a53f8f1ca9cc4919cda4bb527d2c4daf7">00076</a>                 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">doit</a>(Eigen::Matrix&lt;S,1,1,Opt,MaxR,MaxC&gt; &amp;mat, <span class="keywordtype">size_t</span> new_rows,<span class="keywordtype">size_t</span> new_cols)
<a name="l00077"></a>00077                 {<a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices."></a>
<a name="l00078"></a>00078 <a class="code" href="structmrpt_1_1math_1_1detail_1_1_t_aux_resizer.html" title="Internal resize which compiles to nothing on fixed-size matrices.">			::mrpt::math::detail::TAuxResizer&lt;Eigen::Matrix&lt;S,1,1,Opt,MaxR,MaxC&gt;</a>,Eigen::Matrix&lt;S,1,1,Opt,MaxR,MaxC&gt;::SizeAtCompileTime&gt;::internal_resize(mat,new_cols);
<a name="l00079"></a>00079                         <span class="comment">//mat.derived().conservativeResize(new_cols);</span>
<a name="l00080"></a>00080                 }
<a name="l00081"></a>00081         };
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 <span class="comment"></span>
<a name="l00084"></a>00084 <span class="comment">/** Compute the eigenvectors and eigenvalues, both returned as matrices: eigenvectors are the columns, and eigenvalues</span>
<a name="l00085"></a>00085 <span class="comment">  */</span>
<a name="l00086"></a>00086 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00087"></a>00087 <span class="keyword">template</span> &lt;<span class="keyword">class</span> MATRIX1,<span class="keyword">class</span> MATRIX2&gt;
<a name="l00088"></a><a class="code" href="class_matrix_base.html#a47f85667e12e2d918bd1c86f1ae7b5b5">00088</a> <a class="code" href="_macros_8h.html#af2b60117c00a6e75812de43bfe7db3b1">EIGEN_STRONG_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#ad9d64daca9c54b042b101c7d543a6a82" title="[For square matrices only] Compute the eigenvectors and eigenvalues (sorted), both returned as matric...">Eigen::MatrixBase&lt;Derived&gt;::eigenVectors</a>( MATRIX1 &amp; eVecs, MATRIX2 &amp; eVals )<span class="keyword"> const</span>
<a name="l00089"></a>00089 <span class="keyword"></span>{
<a name="l00090"></a>00090         <a class="code" href="class_matrix.html" title="The matrix class, also used for vectors and row-vectors.">Matrix&lt;Scalar,Dynamic,1&gt;</a> evals;
<a name="l00091"></a>00091         <a class="code" href="eigen__plugins_8h.html#ace71c8645aed9fc976d29e30a11c72e9" title="[For square matrices only] Compute the eigenvectors and eigenvalues (sorted), eigenvectors are the co...">eigenVectorsVec</a>(eVecs,evals);
<a name="l00092"></a>00092         eVals.resize(evals.size(),evals.size());
<a name="l00093"></a>00093         eVals.setZero();
<a name="l00094"></a>00094         eVals.diagonal()=evals;
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096 <span class="comment"></span>
<a name="l00097"></a>00097 <span class="comment">/** Compute the eigenvectors and eigenvalues, both returned as matrices: eigenvectors are the columns, and eigenvalues</span>
<a name="l00098"></a>00098 <span class="comment">  */</span>
<a name="l00099"></a>00099 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00100"></a>00100 <span class="keyword">template</span> &lt;<span class="keyword">class</span> MATRIX1,<span class="keyword">class</span> VECTOR1&gt;
<a name="l00101"></a><a class="code" href="class_matrix_base.html#a696a1b756767c5acdd7a29281ae17f38">00101</a> <a class="code" href="_macros_8h.html#af2b60117c00a6e75812de43bfe7db3b1">EIGEN_STRONG_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#ace71c8645aed9fc976d29e30a11c72e9" title="[For square matrices only] Compute the eigenvectors and eigenvalues (sorted), eigenvectors are the co...">Eigen::MatrixBase&lt;Derived&gt;::eigenVectorsVec</a>( MATRIX1 &amp; eVecs, VECTOR1 &amp; eVals )<span class="keyword"> const</span>
<a name="l00102"></a>00102 <span class="keyword"></span>{
<a name="l00103"></a>00103         <a class="code" href="class_eigen_1_1_eigen_solver.html">Eigen::EigenSolver&lt; Derived &gt;</a> es(*<span class="keyword">this</span>, <span class="keyword">true</span>);
<a name="l00104"></a>00104         eVecs = es.<a class="code" href="class_eigen_1_1_eigen_solver.html#a87f0ca0e3a49bc6d7514980450cea279" title="Returns the eigenvectors of given matrix.">eigenvectors</a>().real(); <span class="comment">// Keep only the real part of complex matrix</span>
<a name="l00105"></a>00105         eVals = es.<a class="code" href="class_eigen_1_1_eigen_solver.html#a6075e8bbebc162e91c3e092dedc718b3" title="Returns the eigenvalues of given matrix.">eigenvalues</a>().real(); <span class="comment">// Keep only the real part of complex matrix</span>
<a name="l00106"></a>00106 
<a name="l00107"></a>00107         <span class="comment">// Sort by ascending eigenvalues:</span>
<a name="l00108"></a>00108         std::vector&lt;std::pair&lt;Scalar,Index&gt; &gt; D;
<a name="l00109"></a>00109         D.reserve(eVals.size());
<a name="l00110"></a>00110         <span class="keywordflow">for</span> (<a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a> i=0;i&lt;eVals.size();i++)
<a name="l00111"></a>00111                 D.push_back(std::make_pair&lt;Scalar,Index&gt;(eVals.coeff(i,0),i));
<a name="l00112"></a>00112         std::sort(D.begin(),D.end());
<a name="l00113"></a>00113         MATRIX1 sortedEigs;
<a name="l00114"></a>00114         sortedEigs.resizeLike(eVecs);
<a name="l00115"></a>00115         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i&lt;eVals.size();i++)
<a name="l00116"></a>00116         {
<a name="l00117"></a>00117                 eVals.coeffRef(i,0)=D[i].first;
<a name="l00118"></a>00118                 sortedEigs.col(i)=eVecs.col(D[i].second);
<a name="l00119"></a>00119         }
<a name="l00120"></a>00120         eVecs = sortedEigs;
<a name="l00121"></a>00121 }
<a name="l00122"></a>00122 <span class="comment"></span>
<a name="l00123"></a>00123 <span class="comment">/** Compute the eigenvectors and eigenvalues, both returned as matrices: eigenvectors are the columns, and eigenvalues</span>
<a name="l00124"></a>00124 <span class="comment">  */</span>
<a name="l00125"></a>00125 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00126"></a>00126 <span class="keyword">template</span> &lt;<span class="keyword">class</span> MATRIX1,<span class="keyword">class</span> MATRIX2&gt;
<a name="l00127"></a><a class="code" href="class_matrix_base.html#a41e8c361fa30575f709052dc9a202caf">00127</a> <a class="code" href="_macros_8h.html#af2b60117c00a6e75812de43bfe7db3b1">EIGEN_STRONG_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#a03e2071c9063100bc1ab8e4f1f0225d9" title="[For symmetric matrices only] Compute the eigenvectors and eigenvalues (in no particular order)...">Eigen::MatrixBase&lt;Derived&gt;::eigenVectorsSymmetric</a>( MATRIX1 &amp; eVecs, MATRIX2 &amp; eVals )<span class="keyword"> const</span>
<a name="l00128"></a>00128 <span class="keyword"></span>{
<a name="l00129"></a>00129         <a class="code" href="class_matrix.html" title="The matrix class, also used for vectors and row-vectors.">Matrix&lt;Scalar,Dynamic,1&gt;</a> evals;
<a name="l00130"></a>00130         <a class="code" href="eigen__plugins_8h.html#a0ce2472c17f4fb930a8b89d36547ebd7" title="[For symmetric matrices only] Compute the eigenvectors and eigenvalues (in no particular order)...">eigenVectorsSymmetricVec</a>(eVecs,evals);
<a name="l00131"></a>00131         eVals.resize(evals.size(),evals.size());
<a name="l00132"></a>00132         eVals.setZero();
<a name="l00133"></a>00133         eVals.diagonal()=evals;
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135 <span class="comment"></span>
<a name="l00136"></a>00136 <span class="comment">/** Compute the eigenvectors and eigenvalues, both returned as matrices: eigenvectors are the columns, and eigenvalues</span>
<a name="l00137"></a>00137 <span class="comment">  */</span>
<a name="l00138"></a>00138 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00139"></a>00139 <span class="keyword">template</span> &lt;<span class="keyword">class</span> MATRIX1,<span class="keyword">class</span> VECTOR1&gt;
<a name="l00140"></a><a class="code" href="class_matrix_base.html#a4b6ad837d160010302dda5488b32d31f">00140</a> <a class="code" href="_macros_8h.html#af2b60117c00a6e75812de43bfe7db3b1">EIGEN_STRONG_INLINE</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#a0ce2472c17f4fb930a8b89d36547ebd7" title="[For symmetric matrices only] Compute the eigenvectors and eigenvalues (in no particular order)...">Eigen::MatrixBase&lt;Derived&gt;::eigenVectorsSymmetricVec</a>( MATRIX1 &amp; eVecs, VECTOR1 &amp; eVals )<span class="keyword"> const</span>
<a name="l00141"></a>00141 <span class="keyword"></span>{
<a name="l00142"></a>00142         <span class="comment">// This solver returns the eigenvectors already sorted.</span>
<a name="l00143"></a>00143         <a class="code" href="class_eigen_1_1_self_adjoint_eigen_solver.html">Eigen::SelfAdjointEigenSolver&lt;Derived&gt;</a> eigensolver(*<span class="keyword">this</span>);
<a name="l00144"></a>00144         eVecs = eigensolver.<a class="code" href="class_eigen_1_1_self_adjoint_eigen_solver.html#a2ca4bc813f2ef2e8b906c8b053a9bc32" title="Returns the eigenvectors of given matrix (pencil).">eigenvectors</a>();
<a name="l00145"></a>00145         eVals = eigensolver.<a class="code" href="class_eigen_1_1_self_adjoint_eigen_solver.html#a71d2b0316c8454851e884be2d6b28777" title="Returns the eigenvalues of given matrix (pencil).">eigenvalues</a>();
<a name="l00146"></a>00146 }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148 
<a name="l00149"></a>00149 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00150"></a><a class="code" href="class_matrix_base.html#ac04eb8dfe32320df28462e29e4d50be1">00150</a> <span class="keywordtype">bool</span> <a class="code" href="eigen__plugins_8h.html#a2cef7b6558f3749d76a8a6b551a769f4" title="Read a matrix from a string in Matlab-like format, for example &amp;quot;[1 0 2; 0 4 -1]&amp;quot; The string...">Eigen::MatrixBase&lt;Derived&gt;::fromMatlabStringFormat</a>(<span class="keyword">const</span> std::string &amp;s, <span class="keywordtype">bool</span> dumpErrorMsgToStdErr)
<a name="l00151"></a>00151 {
<a name="l00152"></a>00152         <span class="comment">// Start with a (0,0) matrix:</span>
<a name="l00153"></a>00153         <span class="keywordflow">if</span> ( Derived::RowsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a>)
<a name="l00154"></a>00154                 (*this) = Derived();
<a name="l00155"></a>00155 
<a name="l00156"></a>00156         <span class="comment">// Look for starting &quot;[&quot;.</span>
<a name="l00157"></a>00157         <span class="keywordtype">size_t</span>  ini = s.find_first_not_of(<span class="stringliteral">&quot; \t\r\n&quot;</span>);
<a name="l00158"></a>00158         <span class="keywordflow">if</span> (ini==std::string::npos || s[ini]!=<span class="charliteral">&#39;[&#39;</span>) { <span class="keywordflow">return</span> <span class="keyword">false</span>; }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160         <span class="keywordtype">size_t</span>  <a class="code" href="eigen__plugins_8h.html#ade5b39864c905cbb824d0ff6eb0d888c">end</a> = s.find_last_not_of(<span class="stringliteral">&quot; \t\r\n&quot;</span>);
<a name="l00161"></a>00161         <span class="keywordflow">if</span> (end==std::string::npos || s[end]!=<span class="charliteral">&#39;]&#39;</span>) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00162"></a>00162 
<a name="l00163"></a>00163         <span class="keywordflow">if</span> (ini&gt;end) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00164"></a>00164 
<a name="l00165"></a>00165         std::vector&lt;Scalar&gt; lstElements;
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         <span class="keywordtype">size_t</span> i = ini+1;
<a name="l00168"></a>00168         <span class="keywordtype">size_t</span> nRow = 0;
<a name="l00169"></a>00169 
<a name="l00170"></a>00170         <span class="keywordflow">while</span> (i&lt;end)
<a name="l00171"></a>00171         {
<a name="l00172"></a>00172                 <span class="comment">// Extract one row:</span>
<a name="l00173"></a>00173                 <span class="keywordtype">size_t</span> end_row = s.find_first_of(<span class="stringliteral">&quot;;]&quot;</span>,i);
<a name="l00174"></a>00174                 <span class="keywordflow">if</span> (end_row==std::string::npos) { <span class="keywordflow">return</span> <span class="keyword">false</span>; }
<a name="l00175"></a>00175 
<a name="l00176"></a>00176                 <span class="comment">// We have one row in s[ i : (end_row-1) ]</span>
<a name="l00177"></a>00177                 std::stringstream  ss(s.substr(i, end_row-i ));
<a name="l00178"></a>00178                 lstElements.clear();
<a name="l00179"></a>00179                 <span class="keywordflow">try</span>
<a name="l00180"></a>00180                 {
<a name="l00181"></a>00181                         <span class="keywordflow">while</span> (!ss.eof())
<a name="l00182"></a>00182                         {
<a name="l00183"></a>00183                                 <a class="code" href="class_dense_base.html#a6a6c17e367430ca95523eb3fe7db9076">Scalar</a> val;
<a name="l00184"></a>00184                                 ss &gt;&gt; val;
<a name="l00185"></a>00185                                 <span class="keywordflow">if</span> (ss.bad() || ss.fail()) <span class="keywordflow">break</span>;
<a name="l00186"></a>00186                                 lstElements.push_back(val);
<a name="l00187"></a>00187                         }
<a name="l00188"></a>00188                 } <span class="keywordflow">catch</span> (...) { }  <span class="comment">// end of line</span>
<a name="l00189"></a>00189 
<a name="l00190"></a>00190                 <span class="comment">// Empty row? Only for the first row, then this is an empty matrix:</span>
<a name="l00191"></a>00191                 <span class="keywordflow">if</span> (lstElements.empty())
<a name="l00192"></a>00192                 {
<a name="l00193"></a>00193                         <span class="keywordflow">if</span> (nRow&gt;0)
<a name="l00194"></a>00194                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00195"></a>00195                         <span class="keywordflow">else</span>
<a name="l00196"></a>00196                         {
<a name="l00197"></a>00197                                 <span class="comment">// Else, this may be an empty matrix... if there is no next row, we&#39;ll return with a (0,0) matrix</span>
<a name="l00198"></a>00198                                 <span class="keywordflow">if</span> ( Derived::RowsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> )
<a name="l00199"></a>00199                                         (*this) = Derived();
<a name="l00200"></a>00200                         }
<a name="l00201"></a>00201                 }
<a name="l00202"></a>00202                 <span class="keywordflow">else</span>
<a name="l00203"></a>00203                 {
<a name="l00204"></a>00204                         <span class="keyword">const</span> <span class="keywordtype">size_t</span> N = lstElements.size();
<a name="l00205"></a>00205 
<a name="l00206"></a>00206                         <span class="comment">// Check valid width: All rows must have the same width</span>
<a name="l00207"></a>00207                         <span class="keywordflow">if</span> ((nRow&gt;0 &amp;&amp; <span class="keywordtype">size_t</span>(cols())!=N) ||
<a name="l00208"></a>00208                                 (nRow==0 &amp;&amp; Derived::ColsAtCompileTime!=<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> &amp;&amp; Derived::ColsAtCompileTime!=<span class="keywordtype">int</span>(N)) )
<a name="l00209"></a>00209                         {
<a name="l00210"></a>00210                                 <span class="keywordflow">if</span> (dumpErrorMsgToStdErr)
<a name="l00211"></a>00211                                         std::cerr &lt;&lt; <span class="stringliteral">&quot;[fromMatlabStringFormat] Row &quot;</span> &lt;&lt; nRow+1 &lt;&lt; <span class="stringliteral">&quot; has invalid number of columns.\n&quot;</span>;
<a name="l00212"></a>00212                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00213"></a>00213                         }
<a name="l00214"></a>00214 
<a name="l00215"></a>00215                         <span class="comment">// Append to the matrix:</span>
<a name="l00216"></a>00216                         <span class="keywordflow">if</span> ( Derived::RowsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> || Derived::ColsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> )
<a name="l00217"></a>00217                                 <a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">internal_mrpt::MatOrVecResizer&lt;Derived::RowsAtCompileTime,Derived::ColsAtCompileTime&gt;::doit</a>(derived(),nRow+1,N);
<a name="l00218"></a>00218                         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Derived::RowsAtCompileTime!=<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> &amp;&amp; <span class="keywordtype">int</span>(nRow)&gt;=Derived::RowsAtCompileTime)
<a name="l00219"></a>00219                         {
<a name="l00220"></a>00220                                 <span class="keywordflow">if</span> (dumpErrorMsgToStdErr)
<a name="l00221"></a>00221                                         std::cerr &lt;&lt; <span class="stringliteral">&quot;[fromMatlabStringFormat] Read more rows than the capacity of the fixed sized matrix.\n&quot;</span>;
<a name="l00222"></a>00222                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00223"></a>00223                         }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225                         <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> q=0;q&lt;N;q++)
<a name="l00226"></a>00226                                 coeffRef(nRow,q) = lstElements[q];
<a name="l00227"></a>00227 
<a name="l00228"></a>00228                         <span class="comment">// Go for the next row:</span>
<a name="l00229"></a>00229                         nRow++;
<a name="l00230"></a>00230                 }
<a name="l00231"></a>00231 
<a name="l00232"></a>00232                 i = end_row+1;
<a name="l00233"></a>00233         }
<a name="l00234"></a>00234         <span class="comment">// For fixed sized matrices, check size:</span>
<a name="l00235"></a>00235         <span class="keywordflow">if</span> (Derived::RowsAtCompileTime!=<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> &amp;&amp; <span class="keywordtype">int</span>(nRow)!=Derived::RowsAtCompileTime)
<a name="l00236"></a>00236         {
<a name="l00237"></a>00237                 <span class="keywordflow">if</span> (dumpErrorMsgToStdErr)
<a name="l00238"></a>00238                         std::cerr &lt;&lt; <span class="stringliteral">&quot;[fromMatlabStringFormat] Read less rows than the capacity of the fixed sized matrix.\n&quot;</span>;
<a name="l00239"></a>00239                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00240"></a>00240         }
<a name="l00241"></a>00241         <span class="keywordflow">return</span> <span class="keyword">true</span>; <span class="comment">// Ok</span>
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 
<a name="l00244"></a>00244 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00245"></a><a class="code" href="class_matrix_base.html#a2890436ee3572d164b9e305e65a0aa38">00245</a> std::string  <a class="code" href="eigen__plugins_8h.html#a4a8ae8c8ac821391e46088d63e30ef6e" title="Dump matrix in matlab format.">Eigen::MatrixBase&lt;Derived&gt;::inMatlabFormat</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> decimal_digits)<span class="keyword"> const</span>
<a name="l00246"></a>00246 <span class="keyword"></span>{
<a name="l00247"></a>00247         std::stringstream  s;
<a name="l00248"></a>00248         s &lt;&lt; <span class="stringliteral">&quot;[&quot;</span> &lt;&lt; std::scientific;
<a name="l00249"></a>00249         s.precision(decimal_digits);
<a name="l00250"></a>00250         <span class="keywordflow">for</span> (<a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a> i=0;i&lt;rows();i++)
<a name="l00251"></a>00251         {
<a name="l00252"></a>00252                 <span class="keywordflow">for</span> (<a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a> j=0;j&lt;cols();j++)
<a name="l00253"></a>00253                         s &lt;&lt; coeff(i,j) &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00254"></a>00254                 <span class="keywordflow">if</span> (i&lt;rows()-1) s &lt;&lt; <span class="stringliteral">&quot;;&quot;</span>;
<a name="l00255"></a>00255         }
<a name="l00256"></a>00256         s &lt;&lt; <span class="stringliteral">&quot;]&quot;</span>;
<a name="l00257"></a>00257         <span class="keywordflow">return</span> s.str();
<a name="l00258"></a>00258 }
<a name="l00259"></a>00259 
<a name="l00260"></a>00260 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00261"></a><a class="code" href="class_matrix_base.html#a5357caf8b41d9960c97ea94c0ec834e9">00261</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#abea6659e38ab7a50b625ea1a4af3ec72" title="Save matrix to a text file, compatible with MATLAB text format (see also the methods of matrix classe...">Eigen::MatrixBase&lt;Derived&gt;::saveToTextFile</a>(
<a name="l00262"></a>00262         <span class="keyword">const</span> std::string &amp;file,
<a name="l00263"></a>00263         <a class="code" href="namespacemrpt_1_1math.html#a5c655254dc91e1e5e5b7e43ab7572d85">mrpt::math::TMatrixTextFileFormat</a> fileFormat,
<a name="l00264"></a>00264         <span class="keywordtype">bool</span>    appendMRPTHeader,
<a name="l00265"></a>00265         <span class="keyword">const</span> std::string &amp;userHeader
<a name="l00266"></a>00266         )<span class="keyword"> const</span>
<a name="l00267"></a>00267 <span class="keyword"></span>{
<a name="l00268"></a>00268         FILE *f=<a class="code" href="namespacemrpt_1_1system_1_1os.html#a9b309cf44c48a430f3c70524e7492108" title="An OS-independent version of fopen."> ::fopen</a>(file.c_str(),<span class="stringliteral">&quot;wt&quot;</span>);
<a name="l00269"></a>00269         <span class="keywordflow">if</span> (!f)
<a name="l00270"></a>00270                 <span class="keywordflow">throw</span> std::runtime_error(std::string(<span class="stringliteral">&quot;saveToTextFile: Error opening file &quot;</span>)+file+std::string(<span class="stringliteral">&quot;&#39; for writing a matrix as text.&quot;</span>));
<a name="l00271"></a>00271 
<a name="l00272"></a>00272         <span class="keywordflow">if</span> (!userHeader.empty())
<a name="l00273"></a>00273                 <a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf.">fprintf</a>(f,<span class="stringliteral">&quot;%s&quot;</span>,userHeader.c_str() );
<a name="l00274"></a>00274 
<a name="l00275"></a>00275         <span class="keywordflow">if</span> (appendMRPTHeader)
<a name="l00276"></a>00276         {
<a name="l00277"></a>00277                 time_t rawtime;
<a name="l00278"></a>00278                 ::time(&amp;rawtime);
<a name="l00279"></a>00279                 <span class="keyword">struct </span>tm * timeinfo = ::localtime(&amp;rawtime);
<a name="l00280"></a>00280 
<a name="l00281"></a>00281                 <a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf.">fprintf</a>(f,<span class="stringliteral">&quot;%% File generated with MRPT %s at %s\n%%-----------------------------------------------------------------\n&quot;</span>,
<a name="l00282"></a>00282                         <a class="code" href="namespacemrpt_1_1system.html#a8fe63df666e65644f220e175df15c8ab" title="Returns a string describing the MRPT version including the SVN number.">mrpt::system::MRPT_getVersion</a>().c_str(),
<a name="l00283"></a>00283                         asctime(timeinfo) );
<a name="l00284"></a>00284         }
<a name="l00285"></a>00285 
<a name="l00286"></a>00286         <span class="keywordflow">for</span> (<a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a> i=0; i &lt; rows(); i++)
<a name="l00287"></a>00287         {
<a name="l00288"></a>00288                 <span class="keywordflow">for</span> (<a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a> j=0; j &lt; cols(); j++)
<a name="l00289"></a>00289                 {
<a name="l00290"></a>00290                         <span class="keywordflow">switch</span>(fileFormat)
<a name="l00291"></a>00291                         {
<a name="l00292"></a>00292                         <span class="keywordflow">case</span> <a class="code" href="namespacemrpt_1_1math.html#a5c655254dc91e1e5e5b7e43ab7572d85a40e11335e625d349cfb19366b9d23e04" title="engineering format &amp;#39;e&amp;#39;">mrpt::math::MATRIX_FORMAT_ENG</a>:<a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf."> ::fprintf</a>(f,<span class="stringliteral">&quot;%.16e&quot;</span>,<span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(coeff(i,j))); <span class="keywordflow">break</span>;
<a name="l00293"></a>00293                         <span class="keywordflow">case</span> <a class="code" href="namespacemrpt_1_1math.html#a5c655254dc91e1e5e5b7e43ab7572d85a417d954dbfac48470b7bbe455784ec19" title="fixed floating point &amp;#39;f&amp;#39;">mrpt::math::MATRIX_FORMAT_FIXED</a>:<a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf."> ::fprintf</a>(f,<span class="stringliteral">&quot;%.16f&quot;</span>,<span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(coeff(i,j))); <span class="keywordflow">break</span>;
<a name="l00294"></a>00294                         <span class="keywordflow">case</span> <a class="code" href="namespacemrpt_1_1math.html#a5c655254dc91e1e5e5b7e43ab7572d85ac1fe98ff9b96269a607dc3ae8f0edbe5" title="intergers &amp;#39;i&amp;#39;">mrpt::math::MATRIX_FORMAT_INT</a>:<a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf."> ::fprintf</a>(f,<span class="stringliteral">&quot;%i&quot;</span>,<span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(coeff(i,j))); <span class="keywordflow">break</span>;
<a name="l00295"></a>00295                         <span class="keywordflow">default</span>:
<a name="l00296"></a>00296                                 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Unsupported value for the parameter &#39;fileFormat&#39;!&quot;</span>);
<a name="l00297"></a>00297                         };
<a name="l00298"></a>00298                         <span class="comment">// Separating blank space</span>
<a name="l00299"></a>00299                         <span class="keywordflow">if</span> (j&lt;(cols()-1))<a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf."> ::fprintf</a>(f,<span class="stringliteral">&quot; &quot;</span>);
<a name="l00300"></a>00300                 }<a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf."></a>
<a name="l00301"></a>00301 <a class="code" href="namespacemrpt_1_1system_1_1os.html#a4cc3a0ea9b292a90300224b00e1c8fac" title="An OS-independent version of fprintf.">		::fprintf</a>(f,<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00302"></a>00302         }<a class="code" href="namespacemrpt_1_1system_1_1os.html#af465efb0a560da1737c595780530bddf" title="An OS-independent version of fscanf."></a>
<a name="l00303"></a>00303 <a class="code" href="namespacemrpt_1_1system_1_1os.html#af465efb0a560da1737c595780530bddf" title="An OS-independent version of fscanf.">	::fclose</a>(f);
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 
<a name="l00306"></a>00306 
<a name="l00307"></a>00307 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00308"></a><a class="code" href="class_matrix_base.html#a9f0450a2076aa79cf66d1041e48b0d94">00308</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#ad3c68c35368d8a0254192e3c34ea5f61" title="Load matrix from a text file, compatible with MATLAB text format.">Eigen::MatrixBase&lt;Derived&gt;::loadFromTextFile</a>(<span class="keyword">const</span> std::string &amp;file)
<a name="l00309"></a>00309 {
<a name="l00310"></a>00310         std::ifstream f(file.c_str());
<a name="l00311"></a>00311         <span class="keywordflow">if</span> (f.fail()) <span class="keywordflow">throw</span> std::runtime_error(std::string(<span class="stringliteral">&quot;loadFromTextFile: can&#39;t open file:&quot;</span>) + file);
<a name="l00312"></a>00312         <a class="code" href="eigen__plugins_8h.html#ad3c68c35368d8a0254192e3c34ea5f61" title="Load matrix from a text file, compatible with MATLAB text format.">loadFromTextFile</a>(f);
<a name="l00313"></a>00313 }
<a name="l00314"></a>00314 
<a name="l00315"></a>00315 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Derived&gt;
<a name="l00316"></a><a class="code" href="class_matrix_base.html#a9e577ae7369f6711c0fe35fdf5a38b7f">00316</a> <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#ad3c68c35368d8a0254192e3c34ea5f61" title="Load matrix from a text file, compatible with MATLAB text format.">Eigen::MatrixBase&lt;Derived&gt;::loadFromTextFile</a>(std::istream &amp;f)
<a name="l00317"></a>00317 {
<a name="l00318"></a>00318         <span class="comment">// This matrix is NROWS x NCOLS</span>
<a name="l00319"></a>00319         std::string             str;
<a name="l00320"></a>00320         std::vector&lt;double&gt;     fil(512);
<a name="l00321"></a>00321         <span class="keywordtype">size_t</span>  nRows = 0;
<a name="l00322"></a>00322         <span class="keywordflow">while</span> ( !f.eof() )
<a name="l00323"></a>00323         {
<a name="l00324"></a>00324                 std::getline(f,str);
<a name="l00325"></a>00325                 <span class="keywordflow">if</span> (str.size() &amp;&amp; str[0]!=<span class="charliteral">&#39;#&#39;</span> &amp;&amp; str[0]!=<span class="charliteral">&#39;%&#39;</span>)
<a name="l00326"></a>00326                 {
<a name="l00327"></a>00327                         <span class="comment">// Parse row to floats:</span>
<a name="l00328"></a>00328                         <span class="keyword">const</span> <span class="keywordtype">char</span> *ptr = str.c_str();
<a name="l00329"></a>00329                         <span class="keywordtype">char</span> *ptrEnd = NULL;
<a name="l00330"></a>00330                         <span class="keywordtype">size_t</span> i=0;
<a name="l00331"></a>00331                         <span class="comment">// Process each number in this row:</span>
<a name="l00332"></a>00332                         <span class="keywordflow">while</span> ( ptr[0] &amp;&amp; ptr!=ptrEnd )
<a name="l00333"></a>00333                         {
<a name="l00334"></a>00334                                 <span class="comment">// Find next number: (non white-space character):</span>
<a name="l00335"></a>00335                                 <span class="keywordflow">while</span> (ptr[0] &amp;&amp; (ptr[0]==<span class="charliteral">&#39; &#39;</span> || ptr[0]==<span class="charliteral">&#39;\t&#39;</span> || ptr[0]==<span class="charliteral">&#39;\r&#39;</span> || ptr[0]==<span class="charliteral">&#39;\n&#39;</span>))
<a name="l00336"></a>00336                                         ptr++;
<a name="l00337"></a>00337                                 <span class="keywordflow">if</span> (fil.size()&lt;=i)      fil.resize(fil.size()+512);
<a name="l00338"></a>00338                                 <span class="comment">// Convert to &quot;double&quot;:</span>
<a name="l00339"></a>00339                                 fil[i] = strtod(ptr,&amp;ptrEnd);
<a name="l00340"></a>00340                                 <span class="comment">// A valid conversion has been done?</span>
<a name="l00341"></a>00341                                 <span class="keywordflow">if</span> (ptr!=ptrEnd)
<a name="l00342"></a>00342                                 {
<a name="l00343"></a>00343                                         i++;    <span class="comment">// Yes</span>
<a name="l00344"></a>00344                                         ptr = ptrEnd;
<a name="l00345"></a>00345                                         ptrEnd = NULL;
<a name="l00346"></a>00346                                 }
<a name="l00347"></a>00347                         }; <span class="comment">// end while procesing this row</span>
<a name="l00348"></a>00348 
<a name="l00349"></a>00349                         <span class="comment">// &quot;i&quot;: # of columns:</span>
<a name="l00350"></a>00350                         <span class="keywordflow">if</span> ((Derived::ColsAtCompileTime!=<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> &amp;&amp; <a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a>(i)!=Derived::ColsAtCompileTime) )
<a name="l00351"></a>00351                                 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;loadFromTextFile: The matrix in the text file does not match fixed matrix size&quot;</span>);
<a name="l00352"></a>00352                         <span class="keywordflow">if</span> (Derived::ColsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> &amp;&amp; nRows&gt;0 &amp;&amp; <a class="code" href="class_dense_base.html#a059039d9d011413c873e6ae05ee912b6" title="The type of indices.">Index</a>(i)!=cols() )
<a name="l00353"></a>00353                                 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;loadFromTextFile: The matrix in the text file does not have the same number of columns in all rows&quot;</span>);
<a name="l00354"></a>00354 
<a name="l00355"></a>00355                         <span class="comment">// Append to the matrix:</span>
<a name="l00356"></a>00356                         <span class="keywordflow">if</span> ( Derived::RowsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> || Derived::ColsAtCompileTime==<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> )
<a name="l00357"></a>00357                                 <a class="code" href="structinternal__mrpt_1_1_mat_or_vec_resizer.html#a749125cbc764b7a01383e846f35fae91">internal_mrpt::MatOrVecResizer&lt;Derived::RowsAtCompileTime,Derived::ColsAtCompileTime&gt;::doit</a>(derived(),nRows+1,i);
<a name="l00358"></a>00358                         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Derived::RowsAtCompileTime!=<a class="code" href="_constants_8h.html#adc9da5be31bdce40c25a92c27999c0e3" title="This value means that a quantity is not known at compile-time, and that instead the value is stored i...">Eigen::Dynamic</a> &amp;&amp; <span class="keywordtype">int</span>(nRows)&gt;=Derived::RowsAtCompileTime)
<a name="l00359"></a>00359                                 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;loadFromTextFile: Read more rows than the capacity of the fixed sized matrix.&quot;</span>);
<a name="l00360"></a>00360 
<a name="l00361"></a>00361                         <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> q=0;q&lt;i;q++)
<a name="l00362"></a>00362                                 coeffRef(nRows,q) = <a class="code" href="class_dense_base.html#a6a6c17e367430ca95523eb3fe7db9076">Scalar</a>(fil[q]);
<a name="l00363"></a>00363 
<a name="l00364"></a>00364                         nRows++;
<a name="l00365"></a>00365                 } <span class="comment">// end if fgets</span>
<a name="l00366"></a>00366         } <span class="comment">// end while not feof</span>
<a name="l00367"></a>00367 
<a name="l00368"></a>00368         <span class="comment">// Report error as exception</span>
<a name="l00369"></a>00369         <span class="keywordflow">if</span> (!nRows)
<a name="l00370"></a>00370                 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;loadFromTextFile: Error loading from text file&quot;</span>);
<a name="l00371"></a>00371 }
<a name="l00372"></a>00372 
<a name="l00373"></a>00373 
<a name="l00374"></a>00374 <span class="preprocessor">#endif // guard define</span>
</pre></div></div>
</div>
<br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.2</a> for MRPT 0.9.4 SVN: at Mon Jan 10 22:30:30 UTC 2011</td><td></td> <td width="100"> </td> <td width="150">  </td></tr> </table> </body></html>