Commit 5418ded6 by Philipp Adolf

Store which edge was matched in Shared_Edge

parent 130d3a34
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include "triangle.h" #include "triangle.h"
Triangle::Shared_Edge::Edge rotate_edge_enum(Triangle::Shared_Edge::Edge edge);
Triangle::Triangle() {} Triangle::Triangle() {}
Triangle::Triangle(const Triangle &other) { Triangle::Triangle(const Triangle &other) {
...@@ -49,27 +51,39 @@ bool Triangle::get_shared_edge(Triangle other, Shared_Edge &edge) const { ...@@ -49,27 +51,39 @@ bool Triangle::get_shared_edge(Triangle other, Shared_Edge &edge) const {
other.rotate_indices(); other.rotate_indices();
if (get_shared_edge_(other, edge)) { if (get_shared_edge_(other, edge)) {
edge.edge_b = rotate_edge_enum(rotate_edge_enum(edge.edge_b));
return true; return true;
} }
other.rotate_indices(); other.rotate_indices();
return get_shared_edge_(other, edge); if (get_shared_edge_(other, edge)) {
edge.edge_b = rotate_edge_enum(edge.edge_b);
return true;
}
return false;
} }
bool Triangle::get_shared_edge_(const Triangle &other, Shared_Edge &edge) const { bool Triangle::get_shared_edge_(const Triangle &other, Shared_Edge &edge) 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.edge_b = Triangle::Shared_Edge::Edge::wu;
edge.a1 = u_idx(); edge.a1 = u_idx();
edge.b1 = other.u_idx(); edge.b1 = other.w_idx();
edge.a2 = v_idx(); edge.a2 = v_idx();
edge.b2 = other.w_idx(); edge.b2 = other.u_idx();
edge.a3 = w_idx(); edge.a3 = w_idx();
edge.b3 = other.v_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.edge_b = Triangle::Shared_Edge::Edge::uv;
edge.a1 = u_idx(); edge.a1 = u_idx();
edge.b1 = other.u_idx(); edge.b1 = other.u_idx();
...@@ -82,11 +96,14 @@ bool Triangle::get_shared_edge_(const Triangle &other, Shared_Edge &edge) const ...@@ -82,11 +96,14 @@ bool Triangle::get_shared_edge_(const Triangle &other, Shared_Edge &edge) const
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.edge_b = Triangle::Shared_Edge::Edge::wu;
edge.a1 = v_idx(); edge.a1 = v_idx();
edge.b1 = other.u_idx(); edge.b1 = other.w_idx();
edge.a2 = w_idx(); edge.a2 = w_idx();
edge.b2 = other.w_idx(); edge.b2 = other.u_idx();
edge.a3 = u_idx(); edge.a3 = u_idx();
edge.b3 = other.v_idx(); edge.b3 = other.v_idx();
...@@ -138,6 +155,20 @@ void Triangle::rotate_indices() { ...@@ -138,6 +155,20 @@ void Triangle::rotate_indices() {
w_ = a; w_ = a;
} }
Triangle::Shared_Edge::Edge rotate_edge_enum(Triangle::Shared_Edge::Edge 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;
default:
qDebug() << "Default case should be unreachable";
return Triangle::Shared_Edge::Edge::uv;
}
}
QDebug operator<<(QDebug d, const Triangle &triangle) { QDebug operator<<(QDebug d, const Triangle &triangle) {
QDebugStateSaver saver(d); QDebugStateSaver saver(d);
d.nospace() << "Triangle(" << triangle.u_idx() << ", " << triangle.v_idx() << ", " << triangle.w_idx() << "; " << triangle.u().pos << ", " << triangle.v().pos << ", " << triangle.w().pos << ")"; d.nospace() << "Triangle(" << triangle.u_idx() << ", " << triangle.v_idx() << ", " << triangle.w_idx() << "; " << triangle.u().pos << ", " << triangle.v().pos << ", " << triangle.w().pos << ")";
......
...@@ -14,8 +14,18 @@ class Triangle { ...@@ -14,8 +14,18 @@ class Triangle {
* a_* are the indices of the first triangle, b_* those of the second triangle. * 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. * 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 { struct Shared_Edge {
enum Edge {
uv,
vw,
wu
};
Edge edge_a;
Edge edge_b;
unsigned int a1; unsigned int a1;
unsigned int b1; unsigned int b1;
unsigned int a2; unsigned int a2;
......
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