diff --git a/gtsam/gtsam.i b/gtsam/gtsam.i index 64e57a1d51..3a6c6edf1b 100644 --- a/gtsam/gtsam.i +++ b/gtsam/gtsam.i @@ -2056,6 +2056,7 @@ class NonlinearFactorGraph { // enabling serialization functionality void serialize() const; + void saveGraph(const string& s) const; }; #include diff --git a/gtsam/nonlinear/NonlinearFactorGraph.cpp b/gtsam/nonlinear/NonlinearFactorGraph.cpp index 0b876f3762..3063aa329b 100644 --- a/gtsam/nonlinear/NonlinearFactorGraph.cpp +++ b/gtsam/nonlinear/NonlinearFactorGraph.cpp @@ -34,6 +34,7 @@ #endif #include +#include #include using namespace std; @@ -256,6 +257,16 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values, stm << "}\n"; } +/* ************************************************************************* */ +void NonlinearFactorGraph::saveGraph( + const std::string& file, const Values& values, + const GraphvizFormatting& graphvizFormatting, + const KeyFormatter& keyFormatter) const { + std::ofstream of(file); + saveGraph(of, values, graphvizFormatting, keyFormatter); + of.close(); +} + /* ************************************************************************* */ double NonlinearFactorGraph::error(const Values& values) const { gttic(NonlinearFactorGraph_error); diff --git a/gtsam/nonlinear/NonlinearFactorGraph.h b/gtsam/nonlinear/NonlinearFactorGraph.h index 0e17700d04..989f493d39 100644 --- a/gtsam/nonlinear/NonlinearFactorGraph.h +++ b/gtsam/nonlinear/NonlinearFactorGraph.h @@ -11,7 +11,7 @@ /** * @file NonlinearFactorGraph.h - * @brief Factor Graph Constsiting of non-linear factors + * @brief Factor Graph consisting of non-linear factors * @author Frank Dellaert * @author Carlos Nieto * @author Christian Potthast @@ -111,11 +111,21 @@ namespace gtsam { /** Test equality */ bool equals(const NonlinearFactorGraph& other, double tol = 1e-9) const; - /** Write the graph in GraphViz format for visualization */ + /// Write the graph in GraphViz format for visualization void saveGraph(std::ostream& stm, const Values& values = Values(), const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(), const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + /** + * Write the graph in GraphViz format to file for visualization. + * + * This is a wrapper friendly version since wrapped languages don't have + * access to C++ streams. + */ + void saveGraph(const std::string& file, const Values& values = Values(), + const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(), + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + /** unnormalized error, \f$ 0.5 \sum_i (h_i(X_i)-z)^2/\sigma^2 \f$ in the most common case */ double error(const Values& values) const;