diff --git a/gtsam/base/DerivedValue.h b/gtsam/base/DerivedValue.h deleted file mode 100644 index f01156bd6..000000000 --- a/gtsam/base/DerivedValue.h +++ /dev/null @@ -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 -#include - -////////////////// -// The following includes windows.h in some MSVC versions, so we undef min, max, and ERROR -#include - -#ifdef min -#undef min -#endif - -#ifdef max -#undef max -#endif - -#ifdef ERROR -#undef ERROR -#endif -////////////////// - - -namespace gtsam { - -template -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::malloc(); - DERIVED* ptr = new(place) DERIVED(static_cast(*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::free((void*)this); // Release memory from pool - } - - /** - * Clone this value (normal clone on the heap, delete with 'delete' operator) - */ - virtual boost::shared_ptr clone() const { - return boost::make_shared(static_cast(*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(p); - - // Return the result of calling equals on the derived class - return (static_cast(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(this))->retract(delta); - - // Create a Value pointer copy of the result - void* resultAsValuePlace = boost::singleton_pool::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(value2); - - // Return the result of calling localCoordinates on the derived class - return (static_cast(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(rhs); - - // Do the assignment and return the result - return (static_cast(this))->operator=(derivedRhs); - } - - /// Conversion to the derived class - operator const DERIVED& () const { - return static_cast(*this); - } - - /// Conversion to the derived class - operator DERIVED& () { - return static_cast(*this); - } - -protected: - /// Assignment operator, protected because only the Value or DERIVED - /// assignment operators should be used. - DerivedValue& operator=(const DerivedValue& /*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 */ diff --git a/gtsam/base/Value.h b/gtsam/base/Value.h index 2d5b9d879..1cccf0319 100644 --- a/gtsam/base/Value.h +++ b/gtsam/base/Value.h @@ -11,7 +11,7 @@ /** * @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 * @date Jan 14, 2012 */ @@ -27,58 +27,11 @@ namespace gtsam { /** - * This is the interface class for any value that may be used as a variable - * assignment in a factor graph, and which you must derive to create new - * variable types to use with gtsam. Examples of built-in classes - * implementing this are mainly in geometry, including Rot3, Pose2, etc. - * - * 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{ \\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 { - 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 + * This is the base class for any type to be stored in Values. + * Note: As of GTSAM 4.0, Value types should no longer derive from Value or + * DerivedValue. Use type traits instead. + * 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. */ class GTSAM_EXPORT Value { public: diff --git a/gtsam/nonlinear/Values-inl.h b/gtsam/nonlinear/Values-inl.h index 40979b86c..7e14578c3 100644 --- a/gtsam/nonlinear/Values-inl.h +++ b/gtsam/nonlinear/Values-inl.h @@ -26,7 +26,6 @@ #include -#include #include // Only so Eclipse finds class definition namespace gtsam { diff --git a/gtsam/precompiled_header.h b/gtsam/precompiled_header.h index 37ab01cf2..5ff2a55c5 100644 --- a/gtsam/precompiled_header.h +++ b/gtsam/precompiled_header.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include