Main MRPT website > C++ reference
MRPT logo
CProbabilityParticle.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPROBABILITYPARTICLE_H
29 #define CPROBABILITYPARTICLE_H
30 
31 #include <mrpt/utils/utils_defs.h>
33 
34 namespace mrpt
35 {
36 namespace bayes
37 {
38  /** A template class for holding a the data and the weight of a particle.
39  * Particles are composed of two parts:
40  * - A state vector descritor, which in this case can be any user defined CSerializable class
41  * - A (logarithmic) weight value.
42  *
43  * This structure is used within CParticleFilterData, see that class for more information.
44  * \ingroup mrpt_base_grp
45  */
46  template <class T>
48  {
49  public:
50  /** The data associated with this particle.
51  */
52  T *d;
53 
54  /** The (logarithmic) weight value for this particle.
55  */
56  double log_w;
57 
58  /** Default constructor:
59  */
61  {
62  }
63 
64  /** Copy constructor:
65  */
67  {
68  if (o.d)
69  {
70  // Copy
71  d = new T(*o.d);
72  }
73  }
74 
75  /** Copy operator
76  */
78  {
79  if (this == &o) return *this;
80  log_w = o.log_w;
81  if (o.d)
82  {
83  // Copy semantic:
84  if (d)
85  *d = *o.d; // Copy using the object "operator =".
86  else d = new T(*o.d); // Create a new object from the copy constructor
87  }
88  else
89  {
90  if (d)
91  {
92  delete d;
93  d = NULL;
94  }
95  }
96  return *this;
97  }
98  };
99 
100  } // end namespace
101 } // end namespace
102 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013