diff --git a/CMakeLists.txt b/CMakeLists.txt index fb25d2dd8..96efa97dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ else() option(GTSAM_BUILD_SHARED_LIBRARY "Enable/Disable building of a shared version of gtsam" ON) endif() option(GTSAM_BUILD_STATIC_LIBRARY "Enable/Disable building of a static version of gtsam" ON) +option(GTSAM_BUILD_TYPE_POSTFIXES "Enable/Disable appending the build type to the name of compiled libraries" OFF) option(GTSAM_USE_QUATERNIONS "Enable/Disable using an internal Quaternion representation for rotations instead of rotation matrices" OFF) if(MSVC) option(GTSAM_BUILD_CONVENIENCE_LIBRARIES "Enable/Disable use of convenience libraries for faster development rebuilds, but slower install" OFF) @@ -170,6 +171,7 @@ print_config_flag(${GTSAM_BUILD_TESTS} "Build Tests print_config_flag(${GTSAM_BUILD_WRAP} "Build Wrap ") print_config_flag(${GTSAM_BUILD_SHARED_LIBRARY} "Build shared GTSAM Library ") print_config_flag(${GTSAM_BUILD_STATIC_LIBRARY} "Build static GTSAM Library ") +print_config_flag(${GTSAM_BUILD_TYPE_POSTFIXES} "Put build-type in library name ") print_config_flag(${GTSAM_BUILD_CONVENIENCE_LIBRARIES} "Build Convenience Libraries ") if(GTSAM_UNSTABLE_AVAILABLE) print_config_flag(${GTSAM_BUILD_UNSTABLE} "Build libgtsam_unstable ") diff --git a/gtsam/base/types.cpp b/gtsam/base/types.cpp new file mode 100644 index 000000000..ea4db72c8 --- /dev/null +++ b/gtsam/base/types.cpp @@ -0,0 +1,30 @@ +/* ---------------------------------------------------------------------------- + + * 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 types.h + * @brief Typedefs for easier changing of types + * @author Richard Roberts + * @date Aug 21, 2010 + * @addtogroup base + */ + +#include + +#include + +namespace gtsam { + + std::string _defaultIndexFormatter(Index j) { + return boost::lexical_cast(j); + } + +} \ No newline at end of file diff --git a/gtsam/base/types.h b/gtsam/base/types.h index 5559518b3..a42c2acc5 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -21,6 +21,7 @@ #include +#include #include namespace gtsam { @@ -32,6 +33,11 @@ namespace gtsam { * to a nonlinear key and then to a Symbol. */ typedef boost::function IndexFormatter; + std::string _defaultIndexFormatter(Index j); + + /** The default IndexFormatter outputs the index */ + static const IndexFormatter DefaultIndexFormatter = &_defaultIndexFormatter; + /** * Helper class that uses templates to select between two types based on * whether TEST_TYPE is const or not. diff --git a/gtsam/discrete/DiscreteConditional.h b/gtsam/discrete/DiscreteConditional.h index 6de9989f2..e05bfd669 100644 --- a/gtsam/discrete/DiscreteConditional.h +++ b/gtsam/discrete/DiscreteConditional.h @@ -64,8 +64,8 @@ namespace gtsam { /** GTSAM-style print */ void print(const std::string& s = "Discrete Conditional: ", - const boost::function& formatter - = &(boost::lexical_cast)) const { + const IndexFormatter& formatter + =DefaultIndexFormatter) const { std::cout << s << std::endl; IndexConditional::print(s, formatter); Potentials::print(s); diff --git a/gtsam/discrete/DiscreteFactor.h b/gtsam/discrete/DiscreteFactor.h index deac7efce..9b1130bae 100644 --- a/gtsam/discrete/DiscreteFactor.h +++ b/gtsam/discrete/DiscreteFactor.h @@ -83,8 +83,8 @@ namespace gtsam { // print virtual void print(const std::string& s = "DiscreteFactor\n", - const boost::function& formatter - = &(boost::lexical_cast)) const { + const IndexFormatter& formatter + =DefaultIndexFormatter) const { IndexFactor::print(s,formatter); } diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h index 44b814507..0f399abdd 100644 --- a/gtsam/discrete/DiscreteFactorGraph.h +++ b/gtsam/discrete/DiscreteFactorGraph.h @@ -78,7 +78,7 @@ public: /// print void print(const std::string& s = "DiscreteFactorGraph", - const IndexFormatter& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter =DefaultIndexFormatter) const; }; // DiscreteFactorGraph diff --git a/gtsam/inference/BayesNet-inl.h b/gtsam/inference/BayesNet-inl.h index 89361e8fc..c306cb39d 100644 --- a/gtsam/inference/BayesNet-inl.h +++ b/gtsam/inference/BayesNet-inl.h @@ -35,7 +35,7 @@ namespace gtsam { /* ************************************************************************* */ template void BayesNet::print(const std::string& s, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { std::cout << s; BOOST_REVERSE_FOREACH(sharedConditional conditional, conditionals_) conditional->print("Conditional", formatter); diff --git a/gtsam/inference/BayesNet.h b/gtsam/inference/BayesNet.h index 32abd9ed6..67d59c48d 100644 --- a/gtsam/inference/BayesNet.h +++ b/gtsam/inference/BayesNet.h @@ -91,7 +91,7 @@ public: /** print */ void print(const std::string& s = "", - const boost::function& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; /** print statistics */ void printStats(const std::string& s = "") const; diff --git a/gtsam/inference/BayesTree.h b/gtsam/inference/BayesTree.h index 6413e4b0d..7391e9a10 100644 --- a/gtsam/inference/BayesTree.h +++ b/gtsam/inference/BayesTree.h @@ -71,7 +71,7 @@ namespace gtsam { // A convenience class for a list of shared cliques struct Cliques : public std::list { void print(const std::string& s = "Cliques", - const IndexFormatter& indexFormatter = &(boost::lexical_cast)) const; + const IndexFormatter& indexFormatter = DefaultIndexFormatter) const; bool equals(const Cliques& other, double tol = 1e-9) const; }; @@ -178,7 +178,7 @@ namespace gtsam { /** print */ void print(const std::string& s = "", - const IndexFormatter& indexFormatter = &(boost::lexical_cast) ) const; + const IndexFormatter& indexFormatter = DefaultIndexFormatter ) const; /// @} /// @name Standard Interface @@ -236,7 +236,7 @@ namespace gtsam { */ /** saves the Tree to a text file in GraphViz format */ - void saveGraph(const std::string& s, const IndexFormatter& indexFormatter = &(boost::lexical_cast) ) const; + void saveGraph(const std::string& s, const IndexFormatter& indexFormatter = DefaultIndexFormatter ) const; /// @} /// @name Advanced Interface diff --git a/gtsam/inference/BayesTreeCliqueBase.h b/gtsam/inference/BayesTreeCliqueBase.h index d054fe43f..a2fb8feef 100644 --- a/gtsam/inference/BayesTreeCliqueBase.h +++ b/gtsam/inference/BayesTreeCliqueBase.h @@ -93,10 +93,10 @@ namespace gtsam { } /** print this node */ - void print(const std::string& s = "", const IndexFormatter& indexFormatter = &(boost::lexical_cast) ) const; + void print(const std::string& s = "", const IndexFormatter& indexFormatter = DefaultIndexFormatter ) const; /** print this node and entire subtree below it */ - void printTree(const std::string& indent="", const IndexFormatter& indexFormatter = &(boost::lexical_cast) ) const; + void printTree(const std::string& indent="", const IndexFormatter& indexFormatter = DefaultIndexFormatter ) const; /// @} /// @name Standard Interface diff --git a/gtsam/inference/ClusterTree-inl.h b/gtsam/inference/ClusterTree-inl.h index b3fe204e7..3b8deb316 100644 --- a/gtsam/inference/ClusterTree-inl.h +++ b/gtsam/inference/ClusterTree-inl.h @@ -72,7 +72,7 @@ namespace gtsam { /* ************************************************************************* */ template void ClusterTree::Cluster::print(const std::string& indent, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { std::cout << indent; BOOST_FOREACH(const Index key, frontal) std::cout << formatter(key) << " "; @@ -85,7 +85,7 @@ namespace gtsam { /* ************************************************************************* */ template void ClusterTree::Cluster::printTree(const std::string& indent, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { print(indent, formatter); BOOST_FOREACH(const shared_ptr& child, children_) child->printTree(indent + " ", formatter); @@ -96,7 +96,7 @@ namespace gtsam { * ************************************************************************* */ template void ClusterTree::print(const std::string& str, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { std::cout << str << std::endl; if (root_) root_->printTree("", formatter); } diff --git a/gtsam/inference/ClusterTree.h b/gtsam/inference/ClusterTree.h index f253fe4d6..276ef374d 100644 --- a/gtsam/inference/ClusterTree.h +++ b/gtsam/inference/ClusterTree.h @@ -78,10 +78,10 @@ namespace gtsam { Cluster(FRONTALIT firstFrontal, FRONTALIT lastFrontal, SEPARATORIT firstSeparator, SEPARATORIT lastSeparator); /// print - void print(const std::string& indent, const boost::function& formatter = &(boost::lexical_cast)) const; + void print(const std::string& indent, const IndexFormatter& formatter = DefaultIndexFormatter) const; /// print the enire tree - void printTree(const std::string& indent, const boost::function& formatter = &(boost::lexical_cast)) const; + void printTree(const std::string& indent, const IndexFormatter& formatter = DefaultIndexFormatter) const; /// check equality bool equals(const Cluster& other) const; @@ -127,7 +127,7 @@ namespace gtsam { /// @{ /// print the object - void print(const std::string& str="", const boost::function& formatter = &(boost::lexical_cast)) const; + void print(const std::string& str="", const IndexFormatter& formatter = DefaultIndexFormatter) const; /** check equality */ bool equals(const ClusterTree& other, double tol = 1e-9) const; diff --git a/gtsam/inference/Conditional.h b/gtsam/inference/Conditional.h index 97f885596..8363c1800 100644 --- a/gtsam/inference/Conditional.h +++ b/gtsam/inference/Conditional.h @@ -131,8 +131,7 @@ public: /// @{ /** print with optional formatter */ - void print(const std::string& s = "Conditional", - const boost::function& formatter = &(boost::lexical_cast) ) const; + void print(const std::string& s = "Conditional", const IndexFormatter& formatter = DefaultIndexFormatter) const; /** check equality */ template @@ -201,7 +200,7 @@ private: /* ************************************************************************* */ template -void Conditional::print(const std::string& s, const boost::function& formatter) const { +void Conditional::print(const std::string& s, const IndexFormatter& formatter) const { std::cout << s << " P("; BOOST_FOREACH(KeyType key, frontals()) std::cout << " " << formatter(key); if (nrParents()>0) std::cout << " |"; diff --git a/gtsam/inference/EliminationTree-inl.h b/gtsam/inference/EliminationTree-inl.h index 81c98c926..2e977aa4b 100644 --- a/gtsam/inference/EliminationTree-inl.h +++ b/gtsam/inference/EliminationTree-inl.h @@ -167,7 +167,7 @@ EliminationTree::Create(const FactorGraph& factorGraph) { /* ************************************************************************* */ template void EliminationTree::print(const std::string& name, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { std::cout << name << " (" << formatter(key_) << ")" << std::endl; BOOST_FOREACH(const sharedFactor& factor, factors_) { factor->print(name + " ", formatter); } diff --git a/gtsam/inference/EliminationTree.h b/gtsam/inference/EliminationTree.h index 8e57a7208..495fb40c8 100644 --- a/gtsam/inference/EliminationTree.h +++ b/gtsam/inference/EliminationTree.h @@ -144,7 +144,7 @@ public: /** Print the tree to cout */ void print(const std::string& name = "EliminationTree: ", - const boost::function& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; /** Test whether the tree is equal to another */ bool equals(const EliminationTree& other, double tol = 1e-9) const; diff --git a/gtsam/inference/Factor-inl.h b/gtsam/inference/Factor-inl.h index ad9f43701..6636b646c 100644 --- a/gtsam/inference/Factor-inl.h +++ b/gtsam/inference/Factor-inl.h @@ -57,7 +57,7 @@ namespace gtsam { /* ************************************************************************* */ template void Factor::print(const std::string& s, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { std::cout << s << " "; BOOST_FOREACH(KEY key, keys_) std::cout << " " << formatter(key); std::cout << std::endl; diff --git a/gtsam/inference/Factor.h b/gtsam/inference/Factor.h index 0e80fc8ea..d81c911a3 100644 --- a/gtsam/inference/Factor.h +++ b/gtsam/inference/Factor.h @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace gtsam { @@ -193,7 +194,7 @@ public: /// print void print(const std::string& s = "Factor", - const boost::function& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; /// check equality bool equals(const This& other, double tol = 1e-9) const; diff --git a/gtsam/inference/FactorGraph-inl.h b/gtsam/inference/FactorGraph-inl.h index c787655af..caf18d60e 100644 --- a/gtsam/inference/FactorGraph-inl.h +++ b/gtsam/inference/FactorGraph-inl.h @@ -49,7 +49,7 @@ namespace gtsam { /* ************************************************************************* */ template void FactorGraph::print(const std::string& s, - const boost::function& formatter) const { + const IndexFormatter& formatter) const { std::cout << s << std::endl; std::cout << "size: " << size() << std::endl; for (size_t i = 0; i < factors_.size(); i++) { diff --git a/gtsam/inference/FactorGraph.h b/gtsam/inference/FactorGraph.h index 905afc55c..d0b9952d5 100644 --- a/gtsam/inference/FactorGraph.h +++ b/gtsam/inference/FactorGraph.h @@ -139,7 +139,7 @@ template class BayesTree; /** print out graph */ void print(const std::string& s = "FactorGraph", - const boost::function& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; /** Check equality */ bool equals(const This& fg, double tol = 1e-9) const; diff --git a/gtsam/linear/GaussianConditional.h b/gtsam/linear/GaussianConditional.h index 68b537c2d..5b7801156 100644 --- a/gtsam/linear/GaussianConditional.h +++ b/gtsam/linear/GaussianConditional.h @@ -139,7 +139,7 @@ public: /** print */ void print(const std::string& = "GaussianConditional", - const IndexFormatter& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; /** equals function */ bool equals(const GaussianConditional &cg, double tol = 1e-9) const; diff --git a/gtsam/linear/GaussianDensity.h b/gtsam/linear/GaussianDensity.h index 61db582f4..4d4f673f9 100644 --- a/gtsam/linear/GaussianDensity.h +++ b/gtsam/linear/GaussianDensity.h @@ -55,7 +55,7 @@ namespace gtsam { /// print void print(const std::string& = "GaussianDensity", - const IndexFormatter& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter =DefaultIndexFormatter) const; /// Mean \f$ \mu = R^{-1} d \f$ Vector mean() const; diff --git a/gtsam/linear/GaussianFactor.h b/gtsam/linear/GaussianFactor.h index 64e4e970c..a20c09a43 100644 --- a/gtsam/linear/GaussianFactor.h +++ b/gtsam/linear/GaussianFactor.h @@ -84,7 +84,7 @@ namespace gtsam { // Implementing Testable interface virtual void print(const std::string& s = "", - const IndexFormatter& formatter = &(boost::lexical_cast)) const = 0; + const IndexFormatter& formatter = DefaultIndexFormatter) const = 0; virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const = 0; diff --git a/gtsam/linear/HessianFactor.h b/gtsam/linear/HessianFactor.h index 92f5c06d0..f90a33c5e 100644 --- a/gtsam/linear/HessianFactor.h +++ b/gtsam/linear/HessianFactor.h @@ -219,7 +219,7 @@ namespace gtsam { /** Print the factor for debugging and testing (implementing Testable) */ virtual void print(const std::string& s = "", - const IndexFormatter& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; /** Compare to another factor for testing (implementing Testable) */ virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const; diff --git a/gtsam/linear/JacobianFactor.h b/gtsam/linear/JacobianFactor.h index 14d073576..0ac085987 100644 --- a/gtsam/linear/JacobianFactor.h +++ b/gtsam/linear/JacobianFactor.h @@ -152,7 +152,7 @@ namespace gtsam { // Implementing Testable interface virtual void print(const std::string& s = "", - const IndexFormatter& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter = DefaultIndexFormatter) const; virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const; Vector unweighted_error(const VectorValues& c) const; /** (A*x-b) */ diff --git a/gtsam/linear/VectorValues.h b/gtsam/linear/VectorValues.h index 89c59a6ad..04c280577 100644 --- a/gtsam/linear/VectorValues.h +++ b/gtsam/linear/VectorValues.h @@ -169,7 +169,7 @@ namespace gtsam { /** print required by Testable for unit testing */ void print(const std::string& str = "VectorValues: ", - const IndexFormatter& formatter = &(boost::lexical_cast)) const; + const IndexFormatter& formatter =DefaultIndexFormatter) const; /** equals required by Testable for unit testing */ bool equals(const VectorValues& x, double tol = 1e-9) const; diff --git a/gtsam/nonlinear/ISAM2.h b/gtsam/nonlinear/ISAM2.h index 00c8a026c..c118cb44e 100644 --- a/gtsam/nonlinear/ISAM2.h +++ b/gtsam/nonlinear/ISAM2.h @@ -287,7 +287,7 @@ public: /** print this node */ void print(const std::string& s = "", - const IndexFormatter& formatter = &(boost::lexical_cast)) const { + const IndexFormatter& formatter = DefaultIndexFormatter) const { Base::print(s,formatter); if(cachedFactor_) cachedFactor_->print(s + "Cached: ", formatter);