Commit 7c0f191a by Philipp Adolf

Only store one set of vertices in edge struct

parent 19232189
...@@ -148,43 +148,44 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -148,43 +148,44 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
* - Each edge point will be computed twice. This allows us to implicitly know the adjacent points. * - Each edge point will be computed twice. This allows us to implicitly know the adjacent points.
*/ */
Triangle::Shared_Edge edge; Triangle::Edge edge_a, edge_b;
Triangle::Shared_Edge uv, vw, wu; // These will hold the edges of the triangles next to the current one. uv will hold the edge shared with the current triangle's uv edge.
Triangle::Edge uv, vw, wu;
for (int j = 0; j < triangles.length(); j++){ for (int j = 0; j < triangles.length(); j++){
if (j != i) { if (j != i) {
if (triangle.get_shared_edge(triangles[j], edge)) { if (triangle.get_shared_edge(triangles[j], edge_a, edge_b)) {
switch (edge.edge_a) { switch (edge_a.name) {
case Triangle::Shared_Edge::Edge::uv: case Triangle::Edge::Name::uv:
uv = edge; uv = edge_b;
break; break;
case Triangle::Shared_Edge::Edge::vw: case Triangle::Edge::Name::vw:
vw = edge; vw = edge_b;
break; break;
case Triangle::Shared_Edge::Edge::wu: case Triangle::Edge::Name::wu:
wu = edge; wu = edge_b;
break; break;
default: default:
qWarning() << "got" << edge.edge_a << "as edge!"; qWarning() << "got" << edge_a.name << "as edge!";
break; break;
} }
} }
} }
} }
tables.edge_indices.push_back(uv.a1); tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(uv.a2); tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(uv.a3); tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(uv.b3); tables.edge_indices.push_back(uv.c);
tables.edge_indices.push_back(vw.a1); tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(vw.a2); tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(vw.a3); tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(vw.b3); tables.edge_indices.push_back(vw.c);
tables.edge_indices.push_back(wu.a1); tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(wu.a2); tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(wu.a3); tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(wu.b3); tables.edge_indices.push_back(wu.c);
//add indices to new index buffer //add indices to new index buffer
tables.index_buffer.push_back(x_i); tables.index_buffer.push_back(x_i);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "triangle.h" #include "triangle.h"
Triangle::Shared_Edge::Edge rotate_edge_enum(Triangle::Shared_Edge::Edge edge); Triangle::Edge::Name rotate_edge_name(Triangle::Edge::Name edge);
Triangle::Triangle() {} Triangle::Triangle() {}
...@@ -44,69 +44,63 @@ int Triangle::w_idx() const { ...@@ -44,69 +44,63 @@ int Triangle::w_idx() const {
return w_; return w_;
} }
bool Triangle::get_shared_edge(Triangle other, Shared_Edge &edge) const { bool Triangle::get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const {
if (get_shared_edge_(other, edge)) { if (get_shared_edge_(other, edge_a, edge_b)) {
return true; return true;
} }
other.rotate_indices(); other.rotate_indices();
if (get_shared_edge_(other, edge)) { if (get_shared_edge_(other, edge_a, edge_b)) {
edge.edge_b = rotate_edge_enum(rotate_edge_enum(edge.edge_b)); edge_b.name = rotate_edge_name(rotate_edge_name(edge_b.name));
return true; return true;
} }
other.rotate_indices(); other.rotate_indices();
if (get_shared_edge_(other, edge)) { if (get_shared_edge_(other, edge_a, edge_b)) {
edge.edge_b = rotate_edge_enum(edge.edge_b); edge_b.name = rotate_edge_name(edge_b.name);
return true; return true;
} }
return false; return false;
} }
bool Triangle::get_shared_edge_(const Triangle &other, Shared_Edge &edge) const { bool Triangle::get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_b) const {
if (u().samePos(other.u())) { if (u().samePos(other.u())) {
if (v().samePos(other.w())) { if (v().samePos(other.w())) {
edge.edge_a = Triangle::Shared_Edge::Edge::uv; edge_a.name = Triangle::Edge::Name::uv;
edge.edge_b = Triangle::Shared_Edge::Edge::wu; edge_a.a = u_idx();
edge_a.b = v_idx();
edge_a.c = w_idx();
edge.a1 = u_idx(); edge_b.name = Triangle::Edge::Name::wu;
edge.b1 = other.w_idx(); edge_b.a = other.w_idx();
edge_b.b = other.u_idx();
edge.a2 = v_idx(); edge_b.c = other.v_idx();
edge.b2 = other.u_idx();
edge.a3 = w_idx();
edge.b3 = other.v_idx();
return true; return true;
} else if (w().samePos(other.v())) { } else if (w().samePos(other.v())) {
edge.edge_a = Triangle::Shared_Edge::Edge::wu; edge_a.name = Triangle::Edge::Name::wu;
edge.edge_b = Triangle::Shared_Edge::Edge::uv; edge_a.a = w_idx();
edge_a.b = u_idx();
edge.a1 = u_idx(); edge_a.c = v_idx();
edge.b1 = other.u_idx();
edge.a2 = w_idx(); edge_b.name = Triangle::Edge::Name::uv;
edge.b2 = other.v_idx(); edge_b.a = other.u_idx();
edge_b.b = other.v_idx();
edge.a3 = v_idx(); edge_b.c = other.w_idx();
edge.b3 = other.w_idx();
return true; return true;
} }
} else if (v().samePos(other.u()) && w().samePos(other.w())) { } else if (v().samePos(other.u()) && w().samePos(other.w())) {
edge.edge_a = Triangle::Shared_Edge::Edge::vw; edge_a.name = Triangle::Edge::Name::vw;
edge.edge_b = Triangle::Shared_Edge::Edge::wu; edge_a.a = v_idx();
edge_a.b = w_idx();
edge.a1 = v_idx(); edge_a.c = u_idx();
edge.b1 = other.w_idx();
edge.a2 = w_idx();
edge.b2 = other.u_idx();
edge.a3 = u_idx(); edge_b.name = Triangle::Edge::Name::wu;
edge.b3 = other.v_idx(); edge_b.a = other.w_idx();
edge_b.b = other.u_idx();
edge_b.c = other.v_idx();
return true; return true;
} }
...@@ -155,17 +149,17 @@ void Triangle::rotate_indices() { ...@@ -155,17 +149,17 @@ void Triangle::rotate_indices() {
w_ = a; w_ = a;
} }
Triangle::Shared_Edge::Edge rotate_edge_enum(Triangle::Shared_Edge::Edge edge) { Triangle::Edge::Name rotate_edge_name(Triangle::Edge::Name edge) {
switch (edge) { switch (edge) {
case Triangle::Shared_Edge::Edge::uv: case Triangle::Edge::Name::uv:
return Triangle::Shared_Edge::Edge::vw; return Triangle::Edge::Name::vw;
case Triangle::Shared_Edge::Edge::vw: case Triangle::Edge::Name::vw:
return Triangle::Shared_Edge::Edge::wu; return Triangle::Edge::Name::wu;
case Triangle::Shared_Edge::Edge::wu: case Triangle::Edge::Name::wu:
return Triangle::Shared_Edge::Edge::uv; return Triangle::Edge::Name::uv;
default: default:
qDebug() << "Default case should be unreachable"; qDebug() << "Default case should be unreachable";
return Triangle::Shared_Edge::Edge::uv; return Triangle::Edge::Name::uv;
} }
} }
......
...@@ -8,30 +8,17 @@ ...@@ -8,30 +8,17 @@
class Triangle { class Triangle {
public: public:
/** struct Edge {
* Stores the indices of the shared edge of two triangles as well as the other two indices. enum Name {
*
* a_* are the indices of the first triangle, b_* those of the second triangle.
*
* The vertices at a_1 and b_1 are at the same position as are those at a_2 and b_2.
*
* edge_a describes which edge of the first triangle is part of the shared edge.
*/
struct Shared_Edge {
enum Edge {
uv, uv,
vw, vw,
wu wu
}; };
Edge edge_a; Name name;
Edge edge_b; unsigned int a;
unsigned int a1; unsigned int b;
unsigned int b1; unsigned int c;
unsigned int a2;
unsigned int b2;
unsigned int a3;
unsigned int b3;
}; };
Triangle(); Triangle();
...@@ -46,7 +33,7 @@ class Triangle { ...@@ -46,7 +33,7 @@ class Triangle {
int v_idx() const; int v_idx() const;
int w_idx() const; int w_idx() const;
bool get_shared_edge(Triangle other, Shared_Edge &edge) const; bool get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const;
Triangle &operator=(const Triangle &other); Triangle &operator=(const Triangle &other);
...@@ -62,7 +49,7 @@ class Triangle { ...@@ -62,7 +49,7 @@ class Triangle {
int w_; int w_;
void rotate_indices(); void rotate_indices();
bool get_shared_edge_(const Triangle &other, Shared_Edge &edge) const; bool get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_b) const;
}; };
QDebug operator<<(QDebug d, const Triangle &triangle); QDebug operator<<(QDebug d, const Triangle &triangle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment