Commit 1bab235a4cc48d71e0f3ac2e6850c3ad2a59708c

Authored by pranathivemuri
1 parent 0b5fdc0d

add node function added and corrected edge to string function

Showing 1 changed file with 32 additions and 5 deletions   Show diff stats
stim/visualization/network.h
... ... @@ -488,6 +488,12 @@ class network{
488 488 edge *a = new edge(pos,radii);
489 489 E.push_back(a);
490 490 }
  491 + void
  492 + addNode(stim::vec<T> nodes)
  493 + {
  494 + node *a = new node(nodes);
  495 + V.push_back(nodes);
  496 + }
491 497  
492 498 ///adds an edge from two std::lists with positions and radii.
493 499 /// NOT NECESSARY.
... ... @@ -505,7 +511,7 @@ class network{
505 511 std::stringstream ss;
506 512 for(unsigned int i = 0; i < E.size(); i++)
507 513 {
508   - ss << i << ": " << E[i].str() << std::endl;
  514 + ss << i << ": " << E[i]->str() << std::endl;
509 515 }
510 516 return(ss.str());
511 517 }
... ... @@ -566,14 +572,35 @@ class network{
566 572 ofs << "edgedef>node1 VARCHAR, node2 VARCHAR, weight INT, length FLOAT, av_radius FLOAT \n";
567 573 for(int i = 0; i < E.size(); i++)
568 574 {
569   - float len;
570 575 ofs << E[i]->Node1 << "," << E[i]->Node2 << "," <<E[i]->n_pts()
571   - << ","<< E[i]->length() << "," << E[i]->radius(len) << "\n";
  576 + << ","<< E[i]->length() << "," << E[i]->average_radius() << "\n";
  577 + }
  578 + ofs.close();
  579 + }
  580 + void
  581 + myfunction (T i) { // function:
  582 + std::cout << ' ' << i;
  583 + }
  584 + ///exports the graph.
  585 + void
  586 + to_obj()
  587 + {
  588 + std::ofstream ofs;
  589 + ofs.open("Graph.obj", std::ofstream::out | std::ofstream::app);
  590 + for(int i = 0; i < V.size(); i++)
  591 + {
  592 + std::vector<T> myvector;
  593 + myvector = V[i]
  594 + ofs << "v " << for_each (myvector.begin(), myvector.end(), myfunction) << "\n";
  595 +
  596 + }
  597 + for(unsigned int i = 0; i < E.size(); i++)
  598 + {
  599 + ofs << "l " << E[i]->str() << "\n";
572 600 }
573 601 ofs.close();
574 602 }
575   -};
576 603  
577 604 };
578   -
  605 +};
579 606 #endif
... ...