Commit f8ba8e10 by Philipp Adolf

Store opposite edges in a Map

This way we only have to match triangles with their succesors.
parent 384a4370
......@@ -93,6 +93,26 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
}
}
void insert_edge(QMap<Triangle, QVector<Triangle::Edge>> &opposite_edges, const Triangle &triangle, const Triangle::Edge &edge_a, const Triangle::Edge &edge_b) {
QVector<Triangle::Edge> edges = opposite_edges.value(triangle, QVector<Triangle::Edge>());
edges.resize(3);
switch (edge_a.name) {
case Triangle::Edge::Name::uv:
edges[0] = edge_b;
break;
case Triangle::Edge::Name::vw:
edges[1] = edge_b;
break;
case Triangle::Edge::Name::wu:
edges[2] = edge_b;
break;
default:
qWarning() << "got" << edge_a.name << "as edge!";
break;
}
opposite_edges.insert(triangle, edges);
}
/**
* @brief Subdivision::precomputeTables
* @param mesh
......@@ -123,6 +143,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
// for each triangle the edges of the neighbor triangles are stored.
// First the edge shared with the triangles uv edge, then vw and wu.
QMap<Triangle, QVector<Triangle::Edge>> opposite_edges;
unsigned int nib_offset = vb.length();//offset in new index buffer for edge vertices
for (int i = 0; i < triangles.length(); i++){
//schaue alle dreiecke an
......@@ -139,43 +162,28 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
*/
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_a, edge_b)) {
switch (edge_a.name) {
case Triangle::Edge::Name::uv:
uv = edge_b;
break;
case Triangle::Edge::Name::vw:
vw = edge_b;
break;
case Triangle::Edge::Name::wu:
wu = edge_b;
break;
default:
qWarning() << "got" << edge_a.name << "as edge!";
break;
}
}
for (int j = i + 1; j < triangles.length(); j++){
if (triangle.get_shared_edge(triangles[j], edge_a, edge_b)) {
insert_edge(opposite_edges, triangle, edge_a, edge_b);
insert_edge(opposite_edges, triangles[j], edge_b, edge_a);
}
}
QVector<Triangle::Edge> opposite = opposite_edges.value(triangle);
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(opposite[0].c);
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(opposite[1].c);
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);
tables.edge_indices.push_back(opposite[2].c);
//add indices to new index buffer
tables.index_buffer.push_back(triangle.u_idx());
......
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