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://www.mrpt.org/                                |
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                   * \ingroup mrpt_detectors_grp
00049                   */
00050                 class DETECTORS_IMPEXP CDetectableObject: public mrpt::utils::CSerializable
00051                 {
00052                         DEFINE_VIRTUAL_SERIALIZABLE( CDetectableObject )
00053 
00054                 public:
00055 
00056                         std::string     m_id; //!< Must be an unique id for each detectable object
00057 
00058                         CObservationPtr obs; //!< Observation wich contain the deteted object
00059 
00060                         inline void setObservation( CObservationPtr newObs ){   obs = newObs;   };
00061 
00062                 }; // End of class
00063 
00064 
00065                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CDetectable2D, mrpt::detectors::CDetectableObject, DETECTORS_IMPEXP )
00066 
00067                 class DETECTORS_IMPEXP CDetectable2D: public CDetectableObject
00068                 {
00069                         DEFINE_SERIALIZABLE( CDetectable2D )
00070 
00071                 public:
00072 
00073                         float m_x, m_y; //!< 2D Coordinates of detected object
00074                         float m_height, m_width; //!< Size of detected object
00075 
00076                         /** Extra constructor */
00077                         CDetectable2D( const int &x = 0, const int &y = 0, const int &height = 0, const int &width = 0 )
00078                                 : m_x(x), m_y(y), m_height(height), m_width(width) 
00079                         {};
00080 
00081                         /** Copy pointer content constructor */
00082                         CDetectable2D( const CDetectable2D *d )
00083                         {       
00084                                 *this = *d;
00085                         };
00086                         
00087                         /** Compute distance between centers of two detectable 2D objects.
00088                           * \return calculated distance.
00089                           */
00090                         inline double distanceTo( const CDetectable2D &d2 )
00091                         {       
00092                                 // Calculate objects centers
00093                                 double c_x1 = ( m_x + m_width/2 );
00094                                 double c_x2 = ( d2.m_x + d2.m_width/2 );
00095                                 double c_y1 = ( m_y + m_height/2 ) ;
00096                                 double c_y2 = ( d2.m_y + d2.m_height/2 ) ;
00097 
00098                                 return sqrt( pow( c_x1 - c_x2, 2 ) + pow( c_y1 - c_y2, 2 ) );
00099                         };
00100 
00101                 };
00102 
00103                 
00104                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CDetectable3D, mrpt::detectors::CDetectable2D, DETECTORS_IMPEXP )
00105 
00106                 class DETECTORS_IMPEXP CDetectable3D: public CDetectable2D
00107                 {
00108                         DEFINE_SERIALIZABLE( CDetectable3D )
00109 
00110                 public:
00111 
00112                         CDetectable3D(){};
00113 
00114                         CDetectable3D( const CDetectable2DPtr &object2d )
00115                                 : CDetectable2D( object2d.pointer() ), m_z(0)
00116                         { };
00117 
00118                         /** Copy pointer content constructor */
00119                         CDetectable3D( const CDetectable3D *d )
00120                         {       
00121                                 *this = *d;
00122                         };
00123 
00124                                 
00125                         float           m_z; //!< Z coordinate of detected object
00126 
00127                 }; // End of class
00128         }
00129 
00130 }
00131 
00132 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011