From b76ee21ac17dbfc630bb16d66fec4b1c2ee4013a Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 2 Apr 2015 12:28:46 +0000 Subject: Added writing to file functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@538 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 429568c33608ad8f49508513379e33cd6a73b006 --- .../include/gudhi/Witness_complex.h | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/Witness_complex/include/gudhi/Witness_complex.h') diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index bcfe0f38..1b50ca95 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -208,7 +208,7 @@ namespace Gudhi { } k++; } - print_sc(root()); std::cout << std::endl; + //print_sc(root()); std::cout << std::endl; } /** \brief Construction of witness complex from points given explicitly @@ -254,6 +254,44 @@ private: std::cout << ")"; } + public: + /** \brief Print functions + */ + + void st_to_file(std::ofstream& out_file) + { + sc_to_file(out_file, root()); + } + + private: + void sc_to_file(std::ofstream& out_file, Siblings * sibl) + { + if (sibl == NULL) + out_file << "&"; + else + children_to_file(out_file, sibl->members_); + } + + void children_to_file(std::ofstream& out_file, Dictionary map) + { + out_file << "("; + if (!map.empty()) + { + out_file << map.begin()->first; + if (has_children(map.begin())) + sc_to_file(out_file, map.begin()->second.children()); + typename Dictionary::iterator it; + for (it = map.begin()+1; it != map.end(); ++it) + { + out_file << "," << it->first; + if (has_children(it)) + sc_to_file(out_file, it->second.children()); + } + } + out_file << ")"; + } + + /** \brief Check if the facets of the k-dimensional simplex witnessed * by witness witness_id are already in the complex. * inserted_vertex is the handle of the (k+1)-th vertex witnessed by witness_id -- cgit v1.2.3