Skip to content

Commit

Permalink
Added topology parameter to I/O functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vvmarko committed Dec 1, 2022
1 parent a0d50e7 commit 2b3bfed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
15 changes: 14 additions & 1 deletion input-and-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void save_complex_to_xml_file(SimpComp* simpComp, const string& filename)
* <"complex_name">
* <name> "complex_name" </name>
* <dimension> "D" </dimension>
* <topology> "topology of the complex" </topology>
* [<level lvl="l"> "simplices_id_list" </level> ...]
* [
* <ksimplex id="ksimplex_ID">
Expand Down Expand Up @@ -77,6 +78,13 @@ void save_complex_to_xml_file(SimpComp* simpComp, const string& filename)
xml_node<>* dimensionNode = treeXml.allocate_node(node_element, dimensionCString, DCString);
base->append_node(dimensionNode);

// Node called topology keeps the topology of the complex
string topologyString = "topology";
// rapidxml uses these C-style strings:
char* topologyCString = treeXml.allocate_string(topologyString.c_str(), topologyString.length() + 1);
xml_node<>* topologyNode = treeXml.allocate_node(node_element, topologyCString, simpComp->topology.c_str());
base->append_node(topologyNode);

// We iterate through all the levels and get ids of simplices at that level
vector<xml_node<>*> levels = get_element_levels_as_xml_nodes(simpComp, treeXml);
for (auto nd : levels) base->append_node(nd);
Expand Down Expand Up @@ -248,9 +256,14 @@ SimpComp* read_complex_from_xml_file( rapidxml::xml_document<>& doc )

int sc_dimension = stoi(current_node->value()); // Complex dimension.
// std::cout << "Complex dimension: " << sc_dimension << "." << std::endl;
current_node = current_node->next_sibling();

string sc_topology = current_node->value(); // Complex topology.
// std::cout << "Complex topology: " << sc_topology << "." << std::endl;

SimpComp* sc = new SimpComp(sc_name, sc_dimension);

sc->topology = sc_topology;

vector<size_t>* simplices;
for (current_node = current_node->next_sibling(); // Read all other nodes
current_node != 0;
Expand Down
10 changes: 8 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ int main(){
g1->print_detailed();
*/

SimpComp *simpComp = seed_sphere_intuitively(5, "5-sfera");
SimpComp *simpComp = seed_sphere(3, "3-sfera");
UniqueIDColor::colorize_entire_complex(simpComp);
save_complex_to_xml_file(simpComp,"proba.xml");
SimpComp *sc2 = read_complex_from_xml_file("proba.xml");
save_complex_to_xml_file(sc2,"proba2.xml");
sc2->print_detailed();

/*
string s=simpComp->print_html();
cout << "<br><br>";
cout << s;
cout << "<br><br>";
s=simpComp->elements[0][1]->neighbors->print_html();
cout << s << endl;
cout << "<br><br>";

*/

/*
SimpComp *simpComp = seed_sphere_intuitively(3, "moja_sfera");
Expand Down
2 changes: 1 addition & 1 deletion simpcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ void SimpComp::print_detailed(){
cout << "=================================================================" << endl;
cout << endl;
cout << "Name of the complex: " << name << endl;
cout << "Topology of the complex: " << topology << endl;
cout << "Dimension: " << D << endl;
cout << "Topology: " << topology << endl;
cout << "List of elements:" << endl;
cout << "---------------------------------------------" << endl;
print_compact();
Expand Down

0 comments on commit 2b3bfed

Please sign in to comment.