Commit aa57fa9797a94e473d7058067bd8de8c5a56ee93

Authored by pranathivemuri
1 parent 121ccba7

nothing changed

Showing 1 changed file with 50 additions and 39 deletions   Show diff stats
stim/visualization/network.h
... ... @@ -5,7 +5,7 @@
5 5 #include <stim/visualization/obj.h>
6 6 #include <list>
7 7 #include <ANN/ANN.h>
8   -#include "fiber.h"
  8 +#include <stim/visualization/fiber.h>
9 9 #include <sstream>
10 10  
11 11  
... ... @@ -25,22 +25,22 @@ class network{
25 25 class edge : public fiber<T>
26 26 {
27 27 public:
28   - int Node1, Node2; //unique id's designating the starting and ending
  28 + int n[2]; //unique id's designating the starting and ending
29 29  
30 30 ///default constructor
31 31 edge() : fiber<T>()
32 32 {
33   - Node1 = -1; Node2 = -1;
  33 + n[0] = -1; n[1] = -1;
34 34 }
35 35  
36 36 ///sized costructor with two known nodes.
37   - ///@param startId: int storing idx assigned to Node1.
38   - ///@param endId: int storing idx assigned to Node2.
  37 + ///@param startId: int storing idx assigned to n[0].
  38 + ///@param endId: int storing idx assigned to n[1].
39 39 ///@param n: int for the number of points in the fiber.
40 40 edge(int startId, int endId, int n)
41 41 :fiber<T>(n)
42 42 {
43   - Node1 = startId; Node2 = endId;
  43 + n[0] = startId; n[1] = endId;
44 44 }
45 45  
46 46 ///constructor from a std::vector of stim::vecs of positions and radii.
... ... @@ -49,18 +49,18 @@ class network{
49 49 edge(std::vector< stim::vec<T> > pos, std::vector< stim::vec<T> > radii)
50 50 : fiber<T>(pos, radii)
51 51 {
52   - Node1 = -1; Node2 = -1;
  52 + n[0] = -1; n[1] = -1;
53 53 }
54 54  
55 55 ///constructor from an std::vector of stim::vecs of positions and radii as well as a known starting and ending node.
56 56 ///@param pos: Vector of stim vecs storing the positions of the fiber.
57 57 ///@param mag: Vector of stim vecs storing the radii of the fiber.
58   - ///@param id1: int storing idx assigned to Node1.
59   - ///@param id2: int storing idx assigned to Node2.
  58 + ///@param id1: int storing idx assigned to n[0].
  59 + ///@param id2: int storing idx assigned to n[1].
60 60 edge(std::vector< stim::vec<T> > pos, std::vector< stim::vec<T> > radii, int id1, int id2)
61 61 : fiber<T>(pos, radii)
62 62 {
63   - Node1 = id1; Node2 = id2;
  63 + n[0] = id1; n[1] = id2;
64 64 }
65 65  
66 66  
... ... @@ -72,11 +72,11 @@ class network{
72 72 */
73 73 ///sets the endpoints to the two int values.
74 74 ///@param int id1: index of node1.
75   - ///@param int id2: index of node2.
  75 + ///@param int id2: index of n[1].
76 76 void
77 77 setEndpoints(int id1, int id2)
78 78 {
79   - Node1 = id1; Node2 = id2;
  79 + n[0] = id1; n[1] = id2;
80 80 }
81 81  
82 82  
... ... @@ -258,8 +258,8 @@ class network{
258 258 //remake the edge, such that the starting point of this edge
259 259 //is the same the split point, but the end edge is the old end.
260 260 V.push_back(node(ce[ce.size()-1]));
261   - int tempNodeId = E[startId]->Node1;
262   - E[startId] = new edge(ce, cm, (V.size()-1), E[startId]->Node2);
  261 + int tempNodeId = E[startId]->n[0];
  262 + E[startId] = new edge(ce, cm, (V.size()-1), E[startId]->n[1]);
263 263 V[V.size()-1].addEdge(startId);
264 264  
265 265  
... ... @@ -281,19 +281,19 @@ class network{
281 281 V[V.size()-2].addEdge(E.size()-1);
282 282 } else {
283 283 stim::vec<T> pz = E[startId]->nearest(pos[0]);
284   - if((V[ E[startId]->Node1].getPosition() - pz).len() <
285   - (V[E[startId]->Node2].getPosition() - pz).len())
  284 + if((V[ E[startId]->n[0]].getPosition() - pz).len() <
  285 + (V[E[startId]->n[1]].getPosition() - pz).len())
286 286 {
287 287 unsigned int point = E[startId]->nearest_idx(pos[0]);
288 288 pos.insert(pos.begin(), E[startId]->nearest(pos[0]));
289 289 stim::vec<T> v(E[startId]->radius(point), E[startId]->radius(point));
290 290 radii.insert(radii.begin(), v);
291 291 V.push_back(node(pos[pos.size()-1]));
292   - edge *a = new edge(pos, radii, E[startId]->Node1, (V.size()-1));
  292 + edge *a = new edge(pos, radii, E[startId]->n[0], (V.size()-1));
293 293 E.push_back(a);
294 294  
295 295 V[V.size()-1].addEdge(E.size()-1);
296   - V[ E[startId]->Node1].addEdge(E.size()-1);
  296 + V[ E[startId]->n[0]].addEdge(E.size()-1);
297 297  
298 298 }
299 299 else
... ... @@ -303,11 +303,11 @@ class network{
303 303 stim::vec<T> v(E[startId]->radius(point), E[startId]->radius(point));
304 304 radii.insert(radii.begin(), v);
305 305 V.push_back(node(pos[pos.size()-1]));
306   - edge *a = new edge(pos, radii, E[startId]->Node2, (V.size()-1));
  306 + edge *a = new edge(pos, radii, E[startId]->n[1], (V.size()-1));
307 307 E.push_back(a);
308 308  
309 309 V[V.size()-1].addEdge(E.size()-1);
310   - V[ E[startId]->Node2].addEdge(E.size()-1);
  310 + V[ E[startId]->n[1]].addEdge(E.size()-1);
311 311 }
312 312 }
313 313 }
... ... @@ -340,8 +340,8 @@ class network{
340 340 //remake the edge, such that the ending point of this edge
341 341 //is the same as before, but the starting edge is new.
342 342 V.push_back(node(ce[ce.size()-1])); //split point.
343   - int tempNodeId = E[endId]->Node2;
344   - E[endId] = new edge(ce, cm, E[endId]->Node1, (V.size()-1));
  343 + int tempNodeId = E[endId]->n[1];
  344 + E[endId] = new edge(ce, cm, E[endId]->n[0], (V.size()-1));
345 345 V[V.size()-1].addEdge(endId);
346 346  
347 347 //add that other part of the fiber (temp[1])
... ... @@ -366,19 +366,19 @@ class network{
366 366 }
367 367 else {
368 368 stim::vec<T> pz = E[endId]->nearest(pos[0]);
369   - if((V[ E[endId]->Node1].getPosition() - pz).len() <
370   - (V[E[endId]->Node2].getPosition() - pz).len())
  369 + if((V[ E[endId]->n[0]].getPosition() - pz).len() <
  370 + (V[E[endId]->n[1]].getPosition() - pz).len())
371 371 {
372 372 unsigned int point = E[endId]->nearest_idx(pos[0]);
373 373 pos.insert(pos.begin(), E[endId]->nearest(pos[0]));
374 374 stim::vec<T> v(E[endId]->radius(point), E[endId]->radius(point));
375 375 radii.insert(radii.begin(), v);
376 376 V.push_back(node(pos[pos.size()-1]));
377   - edge *a = new edge(pos, radii, E[endId]->Node1, (V.size()-1));
  377 + edge *a = new edge(pos, radii, E[endId]->n[0], (V.size()-1));
378 378 E.push_back(a);
379 379  
380 380 V[V.size()-1].addEdge(E.size()-1);
381   - V[ E[endId]->Node1].addEdge(E.size()-1);
  381 + V[ E[endId]->n[0]].addEdge(E.size()-1);
382 382  
383 383 }
384 384 else
... ... @@ -388,11 +388,11 @@ class network{
388 388 stim::vec<T> v(E[endId]->radius(point), E[endId]->radius(point));
389 389 radii.insert(radii.begin(), v);
390 390 V.push_back(node(pos[pos.size()-1]));
391   - edge *a = new edge(pos, radii, E[endId]->Node2, (V.size()-1));
  391 + edge *a = new edge(pos, radii, E[endId]->n[1], (V.size()-1));
392 392 E.push_back(a);
393 393  
394 394 V[V.size()-1].addEdge(E.size()-1);
395   - V[ E[endId]->Node2].addEdge(E.size()-1);
  395 + V[ E[endId]->n[1]].addEdge(E.size()-1);
396 396 }
397 397 }
398 398 }
... ... @@ -431,8 +431,8 @@ class network{
431 431 // std::cout << ce.size() << std::endl;
432 432 //remake the edge, such that the starting point of this edge
433 433 //is the same as before, but the end edge is new.
434   - int tempNodeId = E[startId]->Node1;
435   - E[startId] = new edge(ce, cm, (V.size()-1), E[startId]->Node2);
  434 + int tempNodeId = E[startId]->n[0];
  435 + E[startId] = new edge(ce, cm, (V.size()-1), E[startId]->n[1]);
436 436 V[V.size()-1].addEdge(startId);
437 437  
438 438 //add the other part of the fiber (temp[1])
... ... @@ -446,19 +446,19 @@ class network{
446 446 }
447 447 else {
448 448 stim::vec<T> pz = E[endId]->nearest(pos[0]);
449   - if((V[ E[endId]->Node1].getPosition() - pz).len() <
450   - (V[E[endId]->Node2].getPosition() - pz).len())
  449 + if((V[ E[endId]->n[0]].getPosition() - pz).len() <
  450 + (V[E[endId]->n[1]].getPosition() - pz).len())
451 451 {
452 452 unsigned int point = E[endId]->nearest_idx(pos[0]);
453 453 pos.insert(pos.begin(), E[endId]->nearest(pos[0]));
454 454 stim::vec<T> v(E[endId]->radius(point), E[endId]->radius(point));
455 455 radii.insert(radii.begin(), v);
456 456 V.push_back(node(pos[pos.size()-1]));
457   - edge *a = new edge(pos, radii, E[endId]->Node1, (V.size()-1));
  457 + edge *a = new edge(pos, radii, E[endId]->n[0], (V.size()-1));
458 458 E.push_back(a);
459 459  
460 460 V[V.size()-1].addEdge(E.size()-1);
461   - V[ E[endId]->Node1].addEdge(E.size()-1);
  461 + V[ E[endId]->n[0]].addEdge(E.size()-1);
462 462  
463 463 }
464 464 else
... ... @@ -468,11 +468,11 @@ class network{
468 468 stim::vec<T> v(E[endId]->radius(point), E[endId]->radius(point));
469 469 radii.insert(radii.begin(), v);
470 470 V.push_back(node(pos[pos.size()-1]));
471   - edge *a = new edge(pos, radii, E[endId]->Node2, (V.size()-1));
  471 + edge *a = new edge(pos, radii, E[endId]->n[1], (V.size()-1));
472 472 E.push_back(a);
473 473  
474 474 V[V.size()-1].addEdge(E.size()-1);
475   - V[ E[endId]->Node2].addEdge(E.size()-1);
  475 + V[ E[endId]->n[1]].addEdge(E.size()-1);
476 476 }
477 477 }
478 478 }
... ... @@ -534,7 +534,7 @@ class network{
534 534 nodes_to_str(int i)
535 535 {
536 536 std::stringstream ss;
537   - ss << "[from Node " << E[i].Node1 << " to " << E[i].Node2 << "]";
  537 + ss << "[from Node " << E[i].n[0] << " to " << E[i].n[1] << "]";
538 538 return ss.str();
539 539 }
540 540  
... ... @@ -552,6 +552,17 @@ class network{
552 552 ofs.close();
553 553 }
554 554  
  555 + //void
  556 + //to_obj()
  557 + //{
  558 + // std::ofstream ofs;
  559 + // ofs.open("Graph.obj", std::ofstream::out | std::ofstream::app);
  560 + // for(int i = 0; i < V.size(); i++)
  561 + // {
  562 + // ofs << V[i].edges_to_str() << "\n";
  563 + // }
  564 + // ofs.close();
  565 + //}
555 566 ///exports the graph.
556 567 void
557 568 to_gdf()
... ... @@ -563,11 +574,11 @@ class network{
563 574 {
564 575 ofs << i << "\n";
565 576 }
566   - ofs << "edgedef>node1 VARCHAR, node2 VARCHAR, weight INT, length FLOAT, av_radius FLOAT \n";
  577 + ofs << "edgedef>node1 VARCHAR, n[1] VARCHAR, weight INT, length FLOAT, av_radius FLOAT \n";
567 578 for(int i = 0; i < E.size(); i++)
568 579 {
569 580 float len;
570   - ofs << E[i]->Node1 << "," << E[i]->Node2 << "," <<E[i]->n_pts()
  581 + ofs << E[i]->n[0] << "," << E[i]->n[1] << "," <<E[i]->n_pts()
571 582 << ","<< E[i]->length() << "," << E[i]->radius(len) << "\n";
572 583 }
573 584 ofs.close();
... ...