Merged in feature/delete-derived-value (pull request #349)
Delete unused DerivedValue.hrelease/4.3a0
commit
60a6fae171
|
@ -1,143 +0,0 @@
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
||||||
* Atlanta, Georgia 30332-0415
|
|
||||||
* All Rights Reserved
|
|
||||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
||||||
|
|
||||||
* See LICENSE for the license information
|
|
||||||
|
|
||||||
* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @file DerivedValue.h
|
|
||||||
* @date Jan 26, 2012
|
|
||||||
* @author Duy Nguyen Ta
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <gtsam/base/Value.h>
|
|
||||||
#include <boost/make_shared.hpp>
|
|
||||||
|
|
||||||
//////////////////
|
|
||||||
// The following includes windows.h in some MSVC versions, so we undef min, max, and ERROR
|
|
||||||
#include <boost/pool/singleton_pool.hpp>
|
|
||||||
|
|
||||||
#ifdef min
|
|
||||||
#undef min
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef max
|
|
||||||
#undef max
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ERROR
|
|
||||||
#undef ERROR
|
|
||||||
#endif
|
|
||||||
//////////////////
|
|
||||||
|
|
||||||
|
|
||||||
namespace gtsam {
|
|
||||||
|
|
||||||
template<class DERIVED>
|
|
||||||
class DerivedValue : public Value {
|
|
||||||
|
|
||||||
protected:
|
|
||||||
DerivedValue() {}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual ~DerivedValue() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a duplicate object returned as a pointer to the generic Value interface.
|
|
||||||
* For the sake of performance, this function use singleton pool allocator instead of the normal heap allocator.
|
|
||||||
* The result must be deleted with Value::deallocate_, not with the 'delete' operator.
|
|
||||||
*/
|
|
||||||
virtual Value* clone_() const {
|
|
||||||
void *place = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
|
|
||||||
DERIVED* ptr = new(place) DERIVED(static_cast<const DERIVED&>(*this));
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy and deallocate this object, only if it was originally allocated using clone_().
|
|
||||||
*/
|
|
||||||
virtual void deallocate_() const {
|
|
||||||
this->~DerivedValue(); // Virtual destructor cleans up the derived object
|
|
||||||
boost::singleton_pool<PoolTag, sizeof(DERIVED)>::free((void*)this); // Release memory from pool
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clone this value (normal clone on the heap, delete with 'delete' operator)
|
|
||||||
*/
|
|
||||||
virtual boost::shared_ptr<Value> clone() const {
|
|
||||||
return boost::make_shared<DERIVED>(static_cast<const DERIVED&>(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// equals implementing generic Value interface
|
|
||||||
virtual bool equals_(const Value& p, double tol = 1e-9) const {
|
|
||||||
// Cast the base class Value pointer to a derived class pointer
|
|
||||||
const DERIVED& derivedValue2 = dynamic_cast<const DERIVED&>(p);
|
|
||||||
|
|
||||||
// Return the result of calling equals on the derived class
|
|
||||||
return (static_cast<const DERIVED*>(this))->equals(derivedValue2, tol);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generic Value interface version of retract
|
|
||||||
virtual Value* retract_(const Vector& delta) const {
|
|
||||||
// Call retract on the derived class
|
|
||||||
const DERIVED retractResult = (static_cast<const DERIVED*>(this))->retract(delta);
|
|
||||||
|
|
||||||
// Create a Value pointer copy of the result
|
|
||||||
void* resultAsValuePlace = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
|
|
||||||
Value* resultAsValue = new(resultAsValuePlace) DERIVED(retractResult);
|
|
||||||
|
|
||||||
// Return the pointer to the Value base class
|
|
||||||
return resultAsValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generic Value interface version of localCoordinates
|
|
||||||
virtual Vector localCoordinates_(const Value& value2) const {
|
|
||||||
// Cast the base class Value pointer to a derived class pointer
|
|
||||||
const DERIVED& derivedValue2 = dynamic_cast<const DERIVED&>(value2);
|
|
||||||
|
|
||||||
// Return the result of calling localCoordinates on the derived class
|
|
||||||
return (static_cast<const DERIVED*>(this))->localCoordinates(derivedValue2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Assignment operator
|
|
||||||
virtual Value& operator=(const Value& rhs) {
|
|
||||||
// Cast the base class Value pointer to a derived class pointer
|
|
||||||
const DERIVED& derivedRhs = dynamic_cast<const DERIVED&>(rhs);
|
|
||||||
|
|
||||||
// Do the assignment and return the result
|
|
||||||
return (static_cast<DERIVED*>(this))->operator=(derivedRhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Conversion to the derived class
|
|
||||||
operator const DERIVED& () const {
|
|
||||||
return static_cast<const DERIVED&>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Conversion to the derived class
|
|
||||||
operator DERIVED& () {
|
|
||||||
return static_cast<DERIVED&>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/// Assignment operator, protected because only the Value or DERIVED
|
|
||||||
/// assignment operators should be used.
|
|
||||||
DerivedValue<DERIVED>& operator=(const DerivedValue<DERIVED>& /*rhs*/) {
|
|
||||||
// Nothing to do, do not call base class assignment operator
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Fake Tag struct for singleton pool allocator. In fact, it is never used!
|
|
||||||
struct PoolTag { };
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} /* namespace gtsam */
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file Value.h
|
* @file Value.h
|
||||||
* @brief The interface class for any variable that can be optimized or used in a factor.
|
* @brief The base class for any variable that can be optimized or used in a factor.
|
||||||
* @author Richard Roberts
|
* @author Richard Roberts
|
||||||
* @date Jan 14, 2012
|
* @date Jan 14, 2012
|
||||||
*/
|
*/
|
||||||
|
@ -27,58 +27,11 @@
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the interface class for any value that may be used as a variable
|
* This is the base class for any type to be stored in Values.
|
||||||
* assignment in a factor graph, and which you must derive to create new
|
* Note: As of GTSAM 4.0, Value types should no longer derive from Value or
|
||||||
* variable types to use with gtsam. Examples of built-in classes
|
* DerivedValue. Use type traits instead.
|
||||||
* implementing this are mainly in geometry, including Rot3, Pose2, etc.
|
* See https://bitbucket.org/gtborg/gtsam/wiki/Migrating%20from%20GTSAM%203.X%20to%20GTSAM%204.0#markdown-header-custom-value-types
|
||||||
*
|
* for current usage and migration details.
|
||||||
* This interface specifies pure virtual retract_(), localCoordinates_() and
|
|
||||||
* equals_() functions that work with pointers and references to this interface
|
|
||||||
* class, i.e. the base class. These functions allow containers, such as
|
|
||||||
* Values can operate generically on Value objects, retracting or computing
|
|
||||||
* local coordinates for many Value objects of different types.
|
|
||||||
*
|
|
||||||
* Inheriting from the DerivedValue class template provides a generic implementation of
|
|
||||||
* the pure virtual functions retract_(), localCoordinates_(), and equals_(), eliminating
|
|
||||||
* the need to implement these functions in your class. Note that you must inherit from
|
|
||||||
* DerivedValue templated on the class you are defining. For example you cannot define
|
|
||||||
* the following
|
|
||||||
* \code
|
|
||||||
* class Rot3 : public DerivedValue<Point3>{ \\classdef }
|
|
||||||
* \endcode
|
|
||||||
*
|
|
||||||
* Using the above practice, here is an example of implementing a typical
|
|
||||||
* class derived from Value:
|
|
||||||
* \code
|
|
||||||
class GTSAM_EXPORT Rot3 : public DerivedValue<Rot3> {
|
|
||||||
public:
|
|
||||||
// Constructor, there is never a need to call the Value base class constructor.
|
|
||||||
Rot3() { ... }
|
|
||||||
|
|
||||||
// Print for unit tests and debugging (virtual, implements Value::print())
|
|
||||||
virtual void print(const std::string& str = "") const;
|
|
||||||
|
|
||||||
// Equals working directly with Rot3 objects (non-virtual, non-overriding!)
|
|
||||||
bool equals(const Rot3& other, double tol = 1e-9) const;
|
|
||||||
|
|
||||||
// Tangent space dimensionality (virtual, implements Value::dim())
|
|
||||||
virtual size_t dim() const {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// retract working directly with Rot3 objects (non-virtual, non-overriding!)
|
|
||||||
Rot3 retract(const Vector& delta) const {
|
|
||||||
// Math to implement a 3D rotation retraction e.g. exponential map
|
|
||||||
return Rot3(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// localCoordinates working directly with Rot3 objects (non-virtual, non-overriding!)
|
|
||||||
Vector localCoordinates(const Rot3& r2) const {
|
|
||||||
// Math to implement 3D rotation localCoordinates, e.g. logarithm map
|
|
||||||
return Vector(result);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
\endcode
|
|
||||||
*/
|
*/
|
||||||
class GTSAM_EXPORT Value {
|
class GTSAM_EXPORT Value {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <gtsam/base/DerivedValue.h>
|
|
||||||
#include <gtsam/nonlinear/Values.h> // Only so Eclipse finds class definition
|
#include <gtsam/nonlinear/Values.h> // Only so Eclipse finds class definition
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <gtsam/base/concepts.h>
|
#include <gtsam/base/concepts.h>
|
||||||
#include <gtsam/base/ConcurrentMap.h>
|
#include <gtsam/base/ConcurrentMap.h>
|
||||||
#include <gtsam/base/debug.h>
|
#include <gtsam/base/debug.h>
|
||||||
#include <gtsam/base/DerivedValue.h>
|
|
||||||
#include <gtsam/base/DSFVector.h>
|
#include <gtsam/base/DSFVector.h>
|
||||||
#include <gtsam/base/FastDefaultAllocator.h>
|
#include <gtsam/base/FastDefaultAllocator.h>
|
||||||
#include <gtsam/base/FastList.h>
|
#include <gtsam/base/FastList.h>
|
||||||
|
|
Loading…
Reference in New Issue