DerivedValue.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
12 /*
13  * @file DerivedValue.h
14  * @date Jan 26, 2012
15  * @author Duy Nguyen Ta
16  */
17 
18 #pragma once
19 
20 #include <gtsam/base/Value.h>
21 #include <boost/make_shared.hpp>
22 
24 // The following includes windows.h in some MSVC versions, so we undef min, max, and ERROR
25 #include <boost/pool/singleton_pool.hpp>
26 
27 #ifdef min
28 #undef min
29 #endif
30 
31 #ifdef max
32 #undef max
33 #endif
34 
35 #ifdef ERROR
36 #undef ERROR
37 #endif
38 
40 
41 namespace rtabmap {
42 
43 template<class DERIVED>
44 class DerivedValue : public gtsam::Value {
45 
46 protected:
48 
49 public:
50 
51  virtual ~DerivedValue() {}
52 
58  virtual gtsam::Value* clone_() const {
59  void *place = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
60  DERIVED* ptr = new(place) DERIVED(static_cast<const DERIVED&>(*this));
61  return ptr;
62  }
63 
67  virtual void deallocate_() const {
68  this->~DerivedValue(); // Virtual destructor cleans up the derived object
69  boost::singleton_pool<PoolTag, sizeof(DERIVED)>::free((void*)this); // Release memory from pool
70  }
71 
75 #if GTSAM_VERSION_NUMERIC >= 40300
76  virtual std::shared_ptr<gtsam::Value> clone() const {
77  return std::make_shared<DERIVED>(static_cast<const DERIVED&>(*this));
78  }
79  #else
81  return boost::make_shared<DERIVED>(static_cast<const DERIVED&>(*this));
82  }
83 #endif
84 
86  virtual bool equals_(const gtsam::Value& p, double tol = 1e-9) const {
87  // Cast the base class Value pointer to a derived class pointer
88  const DERIVED& derivedValue2 = dynamic_cast<const DERIVED&>(p);
89 
90  // Return the result of calling equals on the derived class
91  return (static_cast<const DERIVED*>(this))->equals(derivedValue2, tol);
92  }
93 
95  virtual gtsam::Value* retract_(const gtsam::Vector& delta) const {
96  // Call retract on the derived class
97  const DERIVED retractResult = (static_cast<const DERIVED*>(this))->retract(delta);
98 
99  // Create a Value pointer copy of the result
100  void* resultAsValuePlace = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
101  gtsam::Value* resultAsValue = new(resultAsValuePlace) DERIVED(retractResult);
102 
103  // Return the pointer to the Value base class
104  return resultAsValue;
105  }
106 
108  virtual gtsam::Vector localCoordinates_(const gtsam::Value& value2) const {
109  // Cast the base class Value pointer to a derived class pointer
110  const DERIVED& derivedValue2 = dynamic_cast<const DERIVED&>(value2);
111 
112  // Return the result of calling localCoordinates on the derived class
113  return (static_cast<const DERIVED*>(this))->localCoordinates(derivedValue2);
114  }
115 
117  virtual gtsam::Value& operator=(const gtsam::Value& rhs) {
118  // Cast the base class Value pointer to a derived class pointer
119  const DERIVED& derivedRhs = dynamic_cast<const DERIVED&>(rhs);
120 
121  // Do the assignment and return the result
122  return (static_cast<DERIVED*>(this))->operator=(derivedRhs);
123  }
124 
126  operator const DERIVED& () const {
127  return static_cast<const DERIVED&>(*this);
128  }
129 
131  operator DERIVED& () {
132  return static_cast<DERIVED&>(*this);
133  }
134 
135 protected:
139  // Nothing to do, do not call base class assignment operator
140  return *this;
141  }
142 
143 private:
145  struct PoolTag { };
146 
147 };
148 
149 } /* namespace gtsam */
rtabmap::DerivedValue::localCoordinates_
virtual gtsam::Vector localCoordinates_(const gtsam::Value &value2) const
Generic Value interface version of localCoordinates.
Definition: DerivedValue.h:108
rtabmap::DerivedValue::PoolTag
Fake Tag struct for singleton pool allocator. In fact, it is never used!
Definition: DerivedValue.h:145
rtabmap::DerivedValue::operator=
DerivedValue< DERIVED > & operator=(const DerivedValue< DERIVED > &)
Definition: DerivedValue.h:138
boost::shared_ptr
rtabmap::DerivedValue::equals_
virtual bool equals_(const gtsam::Value &p, double tol=1e-9) const
equals implementing generic Value interface
Definition: DerivedValue.h:86
rtabmap::DerivedValue::operator=
virtual gtsam::Value & operator=(const gtsam::Value &rhs)
Assignment operator.
Definition: DerivedValue.h:117
gtsam::Vector
Eigen::VectorXd Vector
rtabmap::DerivedValue::deallocate_
virtual void deallocate_() const
Definition: DerivedValue.h:67
rtabmap::DerivedValue::clone_
virtual gtsam::Value * clone_() const
Definition: DerivedValue.h:58
rtabmap::DerivedValue::retract_
virtual gtsam::Value * retract_(const gtsam::Vector &delta) const
Generic Value interface version of retract.
Definition: DerivedValue.h:95
delta
def delta(g0, g1)
Value.h
gtsam::Value
p
Point3_ p(2)
rtabmap::DerivedValue::~DerivedValue
virtual ~DerivedValue()
Definition: DerivedValue.h:51
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
rtabmap::DerivedValue::clone
virtual boost::shared_ptr< gtsam::Value > clone() const
Definition: DerivedValue.h:80
rtabmap::DerivedValue
Definition: DerivedValue.h:44
rtabmap::DerivedValue::DerivedValue
DerivedValue()
Definition: DerivedValue.h:47
tol
const G double tol
rtabmap
Definition: CameraARCore.cpp:35


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:09