From 057ea93beacf593c79e03b5179a94e2889f714c2 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Thu, 13 Jul 2017 15:33:32 -0500 Subject: [PATCH] add flow velocity vector field visualization feature replacing the former flow direction indicating method --- flow.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- main.cu | 32 ++++++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/flow.h b/flow.h index 7159085..83229e3 100644 --- a/flow.h +++ b/flow.h @@ -1076,6 +1076,64 @@ namespace stim { glFlush(); } + // draw flow velocity field, glyph + void glyph(std::vector color, GLint subdivision, T r = 4.0f) { + + // v1----v2-->v3 + T k = 4.0f; // quartering + stim::vec3 v1, v2, v3; // three point + stim::vec3 d; // direction vector + stim::circle tmp_c; + std::vector > cp1(subdivision + 1); + std::vector > cp2(subdivision + 1); + + for (unsigned i = 0; i < num_edge; i++) { // for every edge + glColor3f((float)color[i * 3 + 0] / 255.0f, (float)color[i * 3 + 1] / 255.0f, (float)color[i * 3 + 2] / 255.0f); + for (unsigned j = 0; j < E[i].size() - 1; j++) { // for every point on that edge + + // consider the velocity valuence + if (v[i] > 0) { // positive, from start point to end point + v1 = E[i][j]; + v3 = E[i][j + 1]; + } + else { // negative, from end point to start point + v1 = E[i][j + 1]; + v3 = E[i][j]; + } + d = v3 - v1; + // place the arrow in the middel of one edge + v2 = v1 + (1.0f / k * 2.0f) * d; // looks like =->= + v1 = v1 + (1.0f / k) * d; + v3 = v3 - (1.0f / k) * d; + d = d.norm(); + tmp_c.rotate(d); + + // render the cylinder part + stim::circle c1(v1, r / 2, d, tmp_c.U); + cp1 = c1.glpoints(subdivision); + stim::circle c2(v2, r / 2, d, tmp_c.U); + cp2 = c2.glpoints(subdivision); + + glBegin(GL_QUAD_STRIP); + for (unsigned k = 0; k < cp1.size(); k++) { + glVertex3f(cp1[k][0], cp1[k][1], cp1[k][2]); + glVertex3f(cp2[k][0], cp2[k][1], cp2[k][2]); + } + glEnd(); + + // render the cone part + stim::circle c3(v2, r, d, tmp_c.U); + cp2 = c3.glpoints(subdivision); + glBegin(GL_TRIANGLE_FAN); + glVertex3f(v3[0], v3[1], v3[2]); + for (unsigned k = 0; k < cp2.size(); k++) + glVertex3f(cp2[k][0], cp2[k][1], cp2[k][2]); + glEnd(); + } + } + glFlush(); + } + // display the total volume flow rate void display_flow_rate(T in, T out) { @@ -1609,7 +1667,8 @@ namespace stim { width = (T)origin_l / (2 * n); // updates height = (desire_l - origin_l) / (2 * n); - if (width < times * radius) { // check feasibility + // there are cases that the fragment can not satisfy the requirement for width + if (width < times * radius || n == 0) { // check feasibility ratio = 0.0f; // load desire_l = tmp_d; origin_l = tmp_l; diff --git a/main.cu b/main.cu index ec4bc9b..81da29b 100644 --- a/main.cu +++ b/main.cu @@ -84,7 +84,8 @@ bool render_direction = false; // flag indicates rendering flow direction for o bool simulation = false; // flag indicates simulation mode bool color_bound = false; // flag indicates velocity color map bound bool to_select_pressure = false; // flag indicates having selected a vertex to modify pressure -bool mark_index = true; // flag indicates marking the index near the vertex +bool mark_index = true; // flag indicates marking the index near the vertex +bool flow_direction = false; // flag indicates rendering glyph for flow velocity field unsigned pressure_index; // the index of vertex that is clicked unsigned direction_index = -1; // the index of edge that is pointed at unsigned index_index = -1; // the index of the vertex @@ -255,11 +256,18 @@ void glut_render() { } else { flow.bounding_box(); - flow.glSolidSphere(max_pressure, scale, subdivision); - if (mark_index) - flow.mark_vertex(scale); - //flow.glSolidCone(subdivision); - flow.glSolidCylinder(direction_index, color, scale, subdivision); + // render network + if (!flow_direction) { + flow.glSolidSphere(max_pressure, scale, subdivision); + if (mark_index) + flow.mark_vertex(scale); + //flow.glSolidCone(subdivision); + flow.glSolidCylinder(direction_index, color, scale, subdivision); + } + // render glyphs + else + flow.glyph(color, subdivision); + flow.glSolidCuboid(manufacture, length); if (render_direction) flow.glSolidCone(direction_index, scale, subdivision); @@ -531,9 +539,9 @@ void glut_passive_motion(int x, int y) { if (simulation || build_inlet_outlet && !mods) { bool flag = flow.epsilon_edge((float)posX, (float)posY, (float)posZ, eps, direction_index); - if (flag) + if (flag && !flow_direction) render_direction = true; - else { + else if (!flag && !flow_direction) { if (render_direction) // if the direction is displaying currently, do a short delay Sleep(300); render_direction = false; @@ -844,6 +852,14 @@ void glut_keyboard(unsigned char key, int x, int y) { case 's': flow.save_network(); break; + + // flow vector field visualization, Glyphs + case 'f': + if (flow_direction && !manufacture && (simulation || build_inlet_outlet)) + flow_direction = false; + else if(!flow_direction && !manufacture && (simulation || build_inlet_outlet)) + flow_direction = true; + break; // open/close index marks case 'e': -- libgit2 0.21.4