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) {
* - Each edge point will be computed twice. This allows us to implicitly know the adjacent points.
*/
Triangle::Shared_Edge edge;
Triangle::Shared_Edge uv, vw, wu;
Triangle::Edge edge_a, edge_b;
// 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++){
if (j != i) {
if (triangle.get_shared_edge(triangles[j], edge)) {
switch (edge.edge_a) {
case Triangle::Shared_Edge::Edge::uv:
uv = edge;
if (triangle.get_shared_edge(triangles[j], edge_a, edge_b)) {
switch (edge_a.name) {
case Triangle::Edge::Name::uv:
uv = edge_b;
break;
case Triangle::Shared_Edge::Edge::vw:
vw = edge;
case Triangle::Edge::Name::vw:
vw = edge_b;
break;
case Triangle::Shared_Edge::Edge::wu:
wu = edge;
case Triangle::Edge::Name::wu:
wu = edge_b;
break;
default:
qWarning() << "got" << edge.edge_a << "as edge!";
qWarning() << "got" << edge_a.name << "as edge!";
break;
}
}
}
}
tables.edge_indices.push_back(uv.a1);
tables.edge_indices.push_back(uv.a2);
tables.edge_indices.push_back(uv.a3);
tables.edge_indices.push_back(uv.b3);
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(uv.c);
tables.edge_indices.push_back(vw.a1);
tables.edge_indices.push_back(vw.a2);
tables.edge_indices.push_back(vw.a3);
tables.edge_indices.push_back(vw.b3);
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(vw.c);
tables.edge_indices.push_back(wu.a1);
tables.edge_indices.push_back(wu.a2);
tables.edge_indices.push_back(wu.a3);
tables.edge_indices.push_back(wu.b3);
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(wu.c);
//add indices to new index buffer
tables.index_buffer.push_back(x_i);
......
......@@ -2,7 +2,7 @@
#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() {}
......@@ -44,69 +44,63 @@ int Triangle::w_idx() const {
return w_;
}
bool Triangle::get_shared_edge(Triangle other, Shared_Edge &edge) const {
if (get_shared_edge_(other, edge)) {
bool Triangle::get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const {
if (get_shared_edge_(other, edge_a, edge_b)) {
return true;
}
other.rotate_indices();
if (get_shared_edge_(other, edge)) {
edge.edge_b = rotate_edge_enum(rotate_edge_enum(edge.edge_b));
if (get_shared_edge_(other, edge_a, edge_b)) {
edge_b.name = rotate_edge_name(rotate_edge_name(edge_b.name));
return true;
}
other.rotate_indices();
if (get_shared_edge_(other, edge)) {
edge.edge_b = rotate_edge_enum(edge.edge_b);
if (get_shared_edge_(other, edge_a, edge_b)) {
edge_b.name = rotate_edge_name(edge_b.name);
return true;
}
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 (v().samePos(other.w())) {
edge.edge_a = Triangle::Shared_Edge::Edge::uv;
edge.edge_b = Triangle::Shared_Edge::Edge::wu;
edge_a.name = Triangle::Edge::Name::uv;
edge_a.a = u_idx();
edge_a.b = v_idx();
edge_a.c = w_idx();
edge.a1 = u_idx();
edge.b1 = other.w_idx();
edge.a2 = v_idx();
edge.b2 = other.u_idx();
edge.a3 = w_idx();
edge.b3 = other.v_idx();
edge_b.name = Triangle::Edge::Name::wu;
edge_b.a = other.w_idx();
edge_b.b = other.u_idx();
edge_b.c = other.v_idx();
return true;
} else if (w().samePos(other.v())) {
edge.edge_a = Triangle::Shared_Edge::Edge::wu;
edge.edge_b = Triangle::Shared_Edge::Edge::uv;
edge.a1 = u_idx();
edge.b1 = other.u_idx();
edge_a.name = Triangle::Edge::Name::wu;
edge_a.a = w_idx();
edge_a.b = u_idx();
edge_a.c = v_idx();
edge.a2 = w_idx();
edge.b2 = other.v_idx();
edge.a3 = v_idx();
edge.b3 = other.w_idx();
edge_b.name = Triangle::Edge::Name::uv;
edge_b.a = other.u_idx();
edge_b.b = other.v_idx();
edge_b.c = other.w_idx();
return true;
}
} else if (v().samePos(other.u()) && w().samePos(other.w())) {
edge.edge_a = Triangle::Shared_Edge::Edge::vw;
edge.edge_b = Triangle::Shared_Edge::Edge::wu;
edge.a1 = v_idx();
edge.b1 = other.w_idx();
edge.a2 = w_idx();
edge.b2 = other.u_idx();
edge_a.name = Triangle::Edge::Name::vw;
edge_a.a = v_idx();
edge_a.b = w_idx();
edge_a.c = u_idx();
edge.a3 = u_idx();
edge.b3 = other.v_idx();
edge_b.name = Triangle::Edge::Name::wu;
edge_b.a = other.w_idx();
edge_b.b = other.u_idx();
edge_b.c = other.v_idx();
return true;
}
......@@ -155,17 +149,17 @@ void Triangle::rotate_indices() {
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) {
case Triangle::Shared_Edge::Edge::uv:
return Triangle::Shared_Edge::Edge::vw;
case Triangle::Shared_Edge::Edge::vw:
return Triangle::Shared_Edge::Edge::wu;
case Triangle::Shared_Edge::Edge::wu:
return Triangle::Shared_Edge::Edge::uv;
case Triangle::Edge::Name::uv:
return Triangle::Edge::Name::vw;
case Triangle::Edge::Name::vw:
return Triangle::Edge::Name::wu;
case Triangle::Edge::Name::wu:
return Triangle::Edge::Name::uv;
default:
qDebug() << "Default case should be unreachable";
return Triangle::Shared_Edge::Edge::uv;
return Triangle::Edge::Name::uv;
}
}
......
......@@ -8,30 +8,17 @@
class Triangle {
public:
/**
* Stores the indices of the shared edge of two triangles as well as the other two indices.
*
* 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 {
struct Edge {
enum Name {
uv,
vw,
wu
};
Edge edge_a;
Edge edge_b;
unsigned int a1;
unsigned int b1;
unsigned int a2;
unsigned int b2;
unsigned int a3;
unsigned int b3;
Name name;
unsigned int a;
unsigned int b;
unsigned int c;
};
Triangle();
......@@ -46,7 +33,7 @@ class Triangle {
int v_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);
......@@ -62,7 +49,7 @@ class Triangle {
int w_;
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);
......
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