00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CSplineInterpolator1D_H 00029 #define CSplineInterpolator1D_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 #include <mrpt/utils/CSerializable.h> 00033 #include <mrpt/utils/stl_extensions.h> 00034 00035 namespace mrpt 00036 { 00037 namespace math 00038 { 00039 // This must be added to any CSerializable derived class: 00040 DEFINE_SERIALIZABLE_PRE( CSplineInterpolator1D ) 00041 00042 /** A (persistent) sequence of (x,y) coordinates, allowing queries of intermediate points through spline interpolation, where possible. 00043 * This class internally relies on mrpt::math::spline. Optionally the y coordinate can be set as wrapped in ]-pi,pi]. 00044 * For querying interpolated points, see 00045 * \ sa mrpt::math::spline, mrpt::poses::CPose3DInterpolator 00046 */ 00047 class MRPTDLLIMPEXP CSplineInterpolator1D : public mrpt::utils::CSerializable 00048 { 00049 // This must be added to any CSerializable derived class: 00050 DEFINE_SERIALIZABLE( CSplineInterpolator1D ) 00051 00052 private: 00053 /** The placeholders for the data */ 00054 std::map<double,double> m_x2y; 00055 00056 bool m_wrap2pi; //!< Whether to wrap "y" 00057 00058 public: 00059 /** Constructor with optional initial values. */ 00060 CSplineInterpolator1D( 00061 const std::vector<double> &initial_x, 00062 const std::vector<double> &initial_y, 00063 bool wrap2pi = false 00064 ); 00065 00066 /** Constructor */ 00067 CSplineInterpolator1D( bool wrap2pi = false ); 00068 00069 /** If set to true, the interpolated data will be wrapped to ]-pi,pi] */ 00070 void setWrap2pi(bool wrap) { m_wrap2pi=wrap; } 00071 00072 /** Return the wrap property */ 00073 bool getWrap2pi() { return m_wrap2pi; } 00074 00075 /** Set all the data at once . 00076 * The vectors must have the same length. 00077 */ 00078 void setXY( const std::vector<double> &x, const std::vector<double> &y, bool clearPreviousContent = true ); 00079 00080 /** Append a new point: */ 00081 void appendXY( double x, double y ); 00082 00083 /** Clears all stored points */ 00084 void clear() { m_x2y.clear(); } 00085 00086 /** Query an interpolation of the curve at some "x". 00087 * The result is stored in "y". If the "x" point is out of range, "valid_out" is set to false. 00088 * \return A reference to "y" 00089 * \sa queryVector 00090 */ 00091 double &query( double x, double &y, bool &out_valid ) const; 00092 00093 /** As query, but for a whole vector at once. 00094 * \return false if there is at least one value that couldn't be interpolated (in this case the output is indeterminate). 00095 * \sa query 00096 */ 00097 bool queryVector( const vector_double &x, vector_double &out_y ) const; 00098 00099 }; 00100 00101 } // End of namespace 00102 } // End of namespace 00103 #endif
Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 23:10:56 EDT 2009 |