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) { ...@@ -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 * @brief Subdivision::precomputeTables
* @param mesh * @param mesh
...@@ -123,6 +143,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -123,6 +143,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//compute edge table //compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices. //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 unsigned int nib_offset = vb.length();//offset in new index buffer for edge vertices
for (int i = 0; i < triangles.length(); i++){ for (int i = 0; i < triangles.length(); i++){
//schaue alle dreiecke an //schaue alle dreiecke an
...@@ -139,43 +162,28 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -139,43 +162,28 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
*/ */
Triangle::Edge edge_a, edge_b; 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. for (int j = i + 1; j < triangles.length(); j++){
Triangle::Edge uv, vw, wu; if (triangle.get_shared_edge(triangles[j], edge_a, edge_b)) {
for (int j = 0; j < triangles.length(); j++){ insert_edge(opposite_edges, triangle, edge_a, edge_b);
if (j != i) { insert_edge(opposite_edges, triangles[j], edge_b, edge_a);
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;
}
}
} }
} }
QVector<Triangle::Edge> opposite = opposite_edges.value(triangle);
tables.edge_indices.push_back(triangle.u_idx()); tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx()); tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_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.v_idx());
tables.edge_indices.push_back(triangle.w_idx()); tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_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.w_idx());
tables.edge_indices.push_back(triangle.u_idx()); tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_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 //add indices to new index buffer
tables.index_buffer.push_back(triangle.u_idx()); 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