diff --git a/gtsam/inference/BayesTree-inl.h b/gtsam/inference/BayesTree-inl.h index c63553ac2..cddd642f0 100644 --- a/gtsam/inference/BayesTree-inl.h +++ b/gtsam/inference/BayesTree-inl.h @@ -730,7 +730,7 @@ namespace gtsam { this->removeClique(clique); // remove path above me - this->removePath(sharedClique(clique->parent_.lock()), bn, orphans); + this->removePath(typename BayesTreeClique::shared_ptr(clique->parent_.lock()), bn, orphans); // add children to list of orphans (splice also removed them from clique->children_) orphans.splice (orphans.begin(), clique->children_); diff --git a/gtsam/inference/BayesTree.h b/gtsam/inference/BayesTree.h index eeebf45bc..45dea6e49 100644 --- a/gtsam/inference/BayesTree.h +++ b/gtsam/inference/BayesTree.h @@ -304,35 +304,52 @@ namespace gtsam { * * Since our Conditional class already handles multiple frontal variables, * this Clique contains exactly 1 conditional. + * + * This is the default clique type in a BayesTree, but some algorithms, like + * iSAM2 (see ISAM2Clique), use a different clique type in order to store + * extra data along with the clique. */ - template + template struct BayesTreeClique { + }; + + + /* ************************************************************************* */ + /** + * This is the base class for BayesTree cliques. The default and standard + * derived type is BayesTreeClique, but some algorithms, like iSAM2, use a + * different clique type in order to store extra data along with the clique. + */ + template + struct BayesTreeCliqueBase { + protected: void assertInvariants() const; public: - typedef BayesTreeClique This; - typedef CONDITIONAL ConditionalType; - typedef boost::shared_ptr sharedConditional; + typedef BayesTreeClique This; + typedef DERIVED DerivedType; + typedef typename DERIVED::ConditionalType ConditionalType; + typedef boost::shared_ptr sharedConditional; typedef typename boost::shared_ptr shared_ptr; typedef typename boost::weak_ptr weak_ptr; - typedef typename CONDITIONAL::FactorType FactorType; + typedef typename ConditionalType::FactorType FactorType; typedef typename FactorGraph::Eliminate Eliminate; sharedConditional conditional_; weak_ptr parent_; std::list children_; - friend class BayesTree; + friend class BayesTree; /** Default constructor */ - BayesTreeClique() {} + BayesTreeCliqueBase() {} /** Construct from a conditional, leaving parent and child pointers uninitialized */ - BayesTreeClique(const sharedConditional& conditional); + BayesTreeCliqueBase(const sharedConditional& conditional); - virtual ~BayesTreeClique() {} + virtual ~BayesTreeCliqueBase() {} /** Construct shared_ptr from a conditional, leaving parent and child pointers uninitialized */ static shared_ptr Create(const sharedConditional& conditional) { return shared_ptr(new BayesTreeClique(conditional)); } @@ -349,10 +366,10 @@ namespace gtsam { void print(const std::string& s = "") const; /** The arrow operator accesses the conditional */ - const CONDITIONAL* operator->() const { return conditional_.get(); } + const ConditionalType* operator->() const { return conditional_.get(); } /** The arrow operator accesses the conditional */ - CONDITIONAL* operator->() { return conditional_.get(); } + ConditionalType* operator->() { return conditional_.get(); } /** Access the conditional */ const sharedConditional& conditional() const { return conditional_; } @@ -382,7 +399,7 @@ namespace gtsam { /** return the conditional P(S|Root) on the separator given the root */ // TODO: create a cached version - BayesNet shortcut(shared_ptr root, Eliminate function); + BayesNet shortcut(shared_ptr root, Eliminate function); /** return the marginal P(C) of the clique */ FactorGraph marginal(shared_ptr root, Eliminate function);