Commit 9154f8a9 by Philipp Adolf

Generate extra triangles in precomputeEdgeTable

parent 85519081
......@@ -389,6 +389,16 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
// Maps edges to the index of the new vertex added on that edge. The keys are the indices of the two vertices defining the edge and must be in the order uv, vw or uw.
QMap<Edge, unsigned int> edge_indices;
QMap<Triangle, bool> irregular_triangles;
QVectorIterator<Triangle> it(triangles);
while (it.hasNext()) {
irregular_triangles.insert(it.next(), true);
}
// Regular neighbors of irregular triangles
// We have to generate edge vertices without putting them in the index buffer for rendering patches.
QMap<Triangle, bool> extra_triangles;
for (int i = 0; i < triangles.length(); i++){
//schaue alle dreiecke an
Triangle *triangle = &triangles[i];
......@@ -404,6 +414,17 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
*/
Triangle::Neighbors ns = neighbors.value(*triangle);
QVector<Triangle> neighboring_triangles;
neighboring_triangles += vertexNeighbors(*triangle, ns.uv, neighbors);
neighboring_triangles += vertexNeighbors(*triangle, ns.vw, neighbors);
neighboring_triangles += vertexNeighbors(*triangle, ns.wu, neighbors);
QVectorIterator<Triangle> extra(neighboring_triangles);
while (extra.hasNext()) {
Triangle extra_triangle = extra.next();
if (!irregular_triangles.contains(extra_triangle)) {
extra_triangles.insert(extra_triangle, true);
}
}
// indices of the three vertices added to the edges of this triangle
unsigned int uv, vw, wu;
......@@ -476,6 +497,99 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
tables.index_buffer.push_back(wu);
}
qDebug() << "extra triangles" << extra_triangles.size();
QMapIterator<Triangle, bool> extra_it(extra_triangles);
while (extra_it.hasNext()) {
extra_it.next();
Triangle triangle = extra_it.key();
qDebug() << triangle;
int uv = -1;
int vw = -1;
int wu = -1;
Edge edge;
Triangle::Neighbors ns = neighbors.value(triangle);
if (ns.uv.triangle != NULL) {
edge = { triangle.u_idx(), triangle.v_idx() };
if (edge_indices.contains(edge)) {
uv = edge_indices.value(edge);
} else {
uv = offset++;
edge_indices.insert(edge, uv);
edge = { ns.uv.edge.a, ns.uv.edge.b };
edge_indices.insert(edge, uv);
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(ns.uv.edge.c);
}
}
if (ns.vw.triangle != NULL) {
edge = { triangle.v_idx(), triangle.w_idx() };
if (edge_indices.contains(edge)) {
vw = edge_indices.value(edge);
} else {
vw = offset++;
edge_indices.insert(edge, vw);
edge = { ns.vw.edge.a, ns.vw.edge.b };
edge_indices.insert(edge, vw);
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(ns.vw.edge.c);
}
}
if (ns.wu.triangle != NULL) {
edge = { triangle.w_idx(), triangle.u_idx() };
if (edge_indices.contains(edge)) {
wu = edge_indices.value(edge);
} else {
wu = offset++;
edge_indices.insert(edge, wu);
edge = { ns.wu.edge.a, ns.wu.edge.b };
edge_indices.insert(edge, wu);
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(ns.wu.edge.c);
}
}
if (uv >= 0 && wu >= 0) {
tables.extra_triangles.push_back(triangle.u_idx());
tables.extra_triangles.push_back(uv);
tables.extra_triangles.push_back(wu);
}
if (vw >= 0 && uv >= 0) {
tables.extra_triangles.push_back(triangle.v_idx());
tables.extra_triangles.push_back(vw);
tables.extra_triangles.push_back(uv);
}
if (wu >= 0 && vw >= 0) {
tables.extra_triangles.push_back(triangle.w_idx());
tables.extra_triangles.push_back(wu);
tables.extra_triangles.push_back(vw);
}
if (uv >= 0 && vw >= 0 && wu >= 0) {
tables.extra_triangles.push_back(uv);
tables.extra_triangles.push_back(vw);
tables.extra_triangles.push_back(wu);
}
}
qCDebug(log_subdiv) << "Done with edge table. " << tables.edge_indices.length();
if (log_subdiv_trace().isDebugEnabled()) {
qCDebug(log_subdiv) << "Eedges found. Table: " << tables.edge_indices;
......
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