Commit 130d3a34 by Philipp Adolf

Add method for neighbor detection

parent 6b74dff2
...@@ -42,6 +42,61 @@ int Triangle::w_idx() const { ...@@ -42,6 +42,61 @@ int Triangle::w_idx() const {
return w_; return w_;
} }
bool Triangle::get_shared_edge(Triangle other, Shared_Edge &edge) const {
if (get_shared_edge_(other, edge)) {
return true;
}
other.rotate_indices();
if (get_shared_edge_(other, edge)) {
return true;
}
other.rotate_indices();
return get_shared_edge_(other, edge);
}
bool Triangle::get_shared_edge_(const Triangle &other, Shared_Edge &edge) const {
if (u().samePos(other.u())) {
if (v().samePos(other.w())) {
edge.a1 = u_idx();
edge.b1 = other.u_idx();
edge.a2 = v_idx();
edge.b2 = other.w_idx();
edge.a3 = w_idx();
edge.b3 = other.v_idx();
return true;
} else if (w().samePos(other.v())) {
edge.a1 = u_idx();
edge.b1 = other.u_idx();
edge.a2 = w_idx();
edge.b2 = other.v_idx();
edge.a3 = v_idx();
edge.b3 = other.w_idx();
return true;
}
} else if (v().samePos(other.u()) && w().samePos(other.w())) {
edge.a1 = v_idx();
edge.b1 = other.u_idx();
edge.a2 = w_idx();
edge.b2 = other.w_idx();
edge.a3 = u_idx();
edge.b3 = other.v_idx();
return true;
}
return false;
}
Triangle &Triangle::operator=(const Triangle &other) { Triangle &Triangle::operator=(const Triangle &other) {
this->vertex_buffer_ = other.vertex_buffer_; this->vertex_buffer_ = other.vertex_buffer_;
this->u_ = other.u_; this->u_ = other.u_;
...@@ -76,6 +131,13 @@ bool Triangle::operator<(const Triangle &other) const { ...@@ -76,6 +131,13 @@ bool Triangle::operator<(const Triangle &other) const {
return false; return false;
} }
void Triangle::rotate_indices() {
unsigned int a = u_;
u_ = v_;
v_ = w_;
w_ = a;
}
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 << ")";
......
...@@ -8,6 +8,22 @@ ...@@ -8,6 +8,22 @@
class Triangle { class Triangle {
public: 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.
*/
struct Shared_Edge {
unsigned int a1;
unsigned int b1;
unsigned int a2;
unsigned int b2;
unsigned int a3;
unsigned int b3;
};
Triangle(); Triangle();
Triangle(const Triangle &other); Triangle(const Triangle &other);
Triangle(const QVector<Vertex> &vertex_buffer, int u, int v, int w); Triangle(const QVector<Vertex> &vertex_buffer, int u, int v, int w);
...@@ -20,6 +36,8 @@ class Triangle { ...@@ -20,6 +36,8 @@ 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;
Triangle &operator=(const Triangle &other); Triangle &operator=(const Triangle &other);
// == and < both ignore the vertex buffer, they only compare indices. // == and < both ignore the vertex buffer, they only compare indices.
...@@ -32,6 +50,9 @@ class Triangle { ...@@ -32,6 +50,9 @@ class Triangle {
int u_; int u_;
int v_; int v_;
int w_; int w_;
void rotate_indices();
bool get_shared_edge_(const Triangle &other, Shared_Edge &edge) 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