Main MRPT website > C++ reference
MRPT logo

CDetectableObject.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  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 
00029 #ifndef CDetectableObject_H
00030 #define CDetectableObject_H
00031 
00032 #include <mrpt/utils/CSerializable.h>
00033 #include <mrpt/slam/CObservation.h>
00034 
00035 #include <mrpt/detectors/link_pragmas.h>
00036 
00037 namespace mrpt
00038 {
00039         namespace detectors
00040         {
00041                 using namespace mrpt::slam;
00042 
00043                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CDetectableObject, mrpt::utils::CSerializable, DETECTORS_IMPEXP )
00044 
00045                 /** Base class that contains common atributes and functions of detectable objects.
00046                   * It was initially thought for detected objects in images from cams, but it's easily
00047                   * expandable to other source types (f.i. scanners).
00048                   */
00049                 class DETECTORS_IMPEXP CDetectableObject: public mrpt::utils::CSerializable
00050                 {
00051                         DEFINE_VIRTUAL_SERIALIZABLE( CDetectableObject )
00052 
00053                 public:
00054 
00055                         std::string     m_id; //!< Must be an unique id for each detectable object
00056 
00057                         CObservationPtr obs; //!< Observation wich contain the deteted object
00058 
00059                         inline void setObservation( CObservationPtr newObs ){   obs = newObs;   };
00060 
00061                 }; // End of class
00062 
00063 
00064                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CDetectable2D, mrpt::detectors::CDetectableObject, DETECTORS_IMPEXP )
00065 
00066                 class DETECTORS_IMPEXP CDetectable2D: public CDetectableObject
00067                 {
00068                         DEFINE_SERIALIZABLE( CDetectable2D )
00069 
00070                 public:
00071 
00072                         float m_x, m_y; //!< 2D Coordinates of detected object
00073                         float m_height, m_width; //!< Size of detected object
00074 
00075                         /** Extra constructor */
00076                         CDetectable2D( const int &x = 0, const int &y = 0, const int &height = 0, const int &width = 0 )
00077                                 : m_x(x), m_y(y), m_height(height), m_width(width) 
00078                         {};
00079 
00080                         /** Copy pointer content constructor */
00081                         CDetectable2D( const CDetectable2D *d )
00082                         {       
00083                                 *this = *d;
00084                         };
00085                         
00086                         /** Compute distance between centers of two detectable 2D objects.
00087                           * \return calculated distance.
00088                           */
00089                         inline double distanceTo( const CDetectable2D &d2 )
00090                         {       
00091                                 // Calculate objects centers
00092                                 double c_x1 = ( m_x + m_width/2 );
00093                                 double c_x2 = ( d2.m_x + d2.m_width/2 );
00094                                 double c_y1 = ( m_y + m_height/2 ) ;
00095                                 double c_y2 = ( d2.m_y + d2.m_height/2 ) ;
00096 
00097                                 return sqrt( pow( c_x1 - c_x2, 2 ) + pow( c_y1 - c_y2, 2 ) );
00098                         };
00099 
00100                 };
00101 
00102                 
00103                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CDetectable3D, mrpt::detectors::CDetectable2D, DETECTORS_IMPEXP )
00104 
00105                 class DETECTORS_IMPEXP CDetectable3D: public CDetectable2D
00106                 {
00107                         DEFINE_SERIALIZABLE( CDetectable3D )
00108 
00109                 public:
00110 
00111                         CDetectable3D(){};
00112 
00113                         CDetectable3D( const CDetectable2DPtr &object2d )
00114                                 : CDetectable2D( object2d.pointer() ), m_z(0)
00115                         { };
00116 
00117                         /** Copy pointer content constructor */
00118                         CDetectable3D( const CDetectable3D *d )
00119                         {       
00120                                 *this = *d;
00121                         };
00122 
00123                                 
00124                         float           m_z; //!< Z coordinate of detected object
00125 
00126                 }; // End of class
00127         }
00128 
00129 }
00130 
00131 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011