summaryrefslogtreecommitdiff
path: root/src/animate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/animate.cpp')
-rw-r--r--src/animate.cpp139
1 files changed, 16 insertions, 123 deletions
diff --git a/src/animate.cpp b/src/animate.cpp
index 6c844d2..81bf4ac 100644
--- a/src/animate.cpp
+++ b/src/animate.cpp
@@ -1,5 +1,6 @@
#include "animate.hpp"
+#include <unistd.h>
#include <iostream>
animate::animate(double Lx, double Ly, unsigned window_size, int argc, char *argv[]) {
@@ -139,65 +140,27 @@ void animate::bond_broken(const network& n, const current_info& cur, unsigned i)
}
glEnd();
glFlush();
- if (nw > 2 && !seen_guy) {seen_guy = true; getchar();}
+// if (nw > 2 && !seen_guy) {seen_guy = true; getchar();}
}
void animate::post_fracture(network &n) {
- /*
- std::list<unsigned> crack;
-// unsigned crack_component = component[n.G.dual_edges[crack.front()].v[0]];
- unsigned crack_component = 10000;
-
- std::default_random_engine gen;
- std::uniform_real_distribution<double> dis(0.0,1.0);
-
- auto av_it = avalanches.rbegin();
-
- while (true) {
- for (unsigned e : *av_it) {
- boost::remove_edge(n.G.dual_edges[e].v[0], n.G.dual_edges[e].v[1], G);
- n.fuses[e] = false;
- }
-
- auto cracks = find_minimal_crack(G, n);
-
- if (cracks.size() == 0) {
- break;
- }
+ auto crack = find_minimal_crack(n, avalanches.back().back());
- av_it++;
- }
-
- std::vector<unsigned> component(boost::num_vertices(G));
- unsigned num = boost::connected_components(G, &component[0]);
-
- std::vector<std::list<unsigned>> components(num);
-
- for (unsigned i = 0; i < n.G.dual_vertices.size(); i++) {
- components[component[i]].push_back(i);
- }
-
-
- char key;
- while ((key = getchar()) != 'n') {
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f );
- glClear(GL_COLOR_BUFFER_BIT);
- glBegin(GL_LINES);
- glColor3f(0.0f, 0.0f, 0.0f);
- for (unsigned i = 0; i < n.G.edges.size(); i++) {
- if (!n.fuses[i]) {
- graph::coordinate r1 = n.G.vertices[n.G.edges[i].v[0]].r;
- graph::coordinate r2 = n.G.vertices[n.G.edges[i].v[1]].r;
+ for (unsigned j : crack.second) {
+ glBegin(GL_LINES);
+ glColor3d(1.0, 0.0, 0.0);
+ graph::coordinate r1 = n.G.dual_vertices[n.G.dual_edges[j].v[0]].r;
+ graph::coordinate r2 = n.G.dual_vertices[n.G.dual_edges[j].v[1]].r;
- if (n.G.edges[i].crossings[0]) {
+ if (n.G.dual_edges[j].crossings[0]) {
if (r1.x < r2.x) {
r1.x += n.G.L.x;
} else {
r2.x += n.G.L.x;
}
}
- if (n.G.edges[i].crossings[1]) {
+ if (n.G.dual_edges[j].crossings[1]) {
if (r1.y < r2.y) {
r1.y += n.G.L.y;
} else {
@@ -205,82 +168,12 @@ void animate::post_fracture(network &n) {
}
}
- glVertex2d(r1.x, r1.y);
- glVertex2d(r2.x, r2.y);
- }
- }
- glEnd();
-
- switch (key) {
- case 's' :
- for (auto edge : crack) {
- glColor3f(1.0f, 0.0f, 0.0f);
- glBegin(GL_POLYGON);
- for (const graph::coordinate &r : n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon) {
- glVertex2d(r.x, r.y);
- }
- glEnd();
- glBegin(GL_POLYGON);
- for (const graph::coordinate &r : n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon) {
- glVertex2d(r.x, r.y);
- }
- glEnd();
- }
- glFlush();
- break;
-
- case 'c' :
- for (unsigned i = 0; i < num; i++) {
- if (i == crack_component) {
- glColor3d(1.0, 0.0, 0.0);
- } else {
- glColor3d(dis(gen), dis(gen), dis(gen));
- }
-
- for (auto it = components[i].begin(); it != components[i].end(); it++) {
- glBegin(GL_POLYGON); // Each set of 3 vertices form a triangle
- for (const graph::coordinate &r: n.G.dual_vertices[*it].polygon) {
- glVertex2d(r.x, r.y);
- }
- glEnd();
- }
- }
- glFlush();
- break;
-
- case 'C' :
- for (unsigned i = 0; i < num; i++) {
- if (components[i].size() > 1) {
- if (i == crack_component) {
- glColor3d(1.0, 0.0, 0.0);
- } else {
- glColor3d(dis(gen), dis(gen), dis(gen));
- }
-
- for (auto it = components[i].begin(); it != components[i].end(); it++) {
- glBegin(GL_POLYGON); // Each set of 3 vertices form a triangle
- for (const graph::coordinate &r :n.G.dual_vertices[*it].polygon) {
- glVertex2d(r.x, r.y);
- }
- glEnd();
- }
- }
- }
- glFlush();
- break;
-
- case 'm' :
- for (auto it = components[crack_component].begin(); it != components[crack_component].end(); it++) {
- glBegin(GL_POLYGON);
- glColor3d(1.0, 0.0, 0.0);
- for (const graph::coordinate &r :n.G.dual_vertices[*it].polygon) {
- glVertex2d(r.x, r.y);
- }
- glEnd();
- }
- glFlush();
- }
+ glVertex2d(r1.x, r1.y);
+ glVertex2d(r2.x, r2.y);
+ glEnd();
}
-*/
+ glFlush();
+
+ getchar();
}