Commit d4e5706b by Philipp Adolf

Generate edge vertices for neighbors of irregular triangles

parent 9e18dd0c
......@@ -385,6 +385,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];
......@@ -400,6 +410,15 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
*/
Triangle::Neighbors ns = neighbors.value(*triangle);
if (!irregular_triangles.contains(*ns.uv.triangle)) {
extra_triangles.insert(*ns.uv.triangle, true);
}
if (!irregular_triangles.contains(*ns.vw.triangle)) {
extra_triangles.insert(*ns.vw.triangle, true);
}
if (!irregular_triangles.contains(*ns.wu.triangle)) {
extra_triangles.insert(*ns.wu.triangle, true);
}
// indices of the three vertices added to the edges of this triangle
unsigned int uv, vw, wu;
......@@ -472,6 +491,80 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
tables.index_buffer.push_back(wu);
}
QMapIterator<Triangle, bool> extra_it(extra_triangles);
while (extra_it.hasNext()) {
extra_it.next();
Triangle triangle = extra_it.key();
unsigned int uv, vw, wu;
Edge edge;
Triangle::Neighbors ns = neighbors.value(triangle);
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);
}
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);
}
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);
}
tables.extra_triangles.push_back(triangle.u_idx());
tables.extra_triangles.push_back(uv);
tables.extra_triangles.push_back(wu);
tables.extra_triangles.push_back(triangle.v_idx());
tables.extra_triangles.push_back(vw);
tables.extra_triangles.push_back(uv);
tables.extra_triangles.push_back(triangle.w_idx());
tables.extra_triangles.push_back(wu);
tables.extra_triangles.push_back(vw);
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;
......@@ -728,11 +821,11 @@ QVector<unsigned int> Subdivision::patchIBToTriangleIB(QVector<unsigned int> ib)
bool isVertexRegular(Triangle &triangle, Triangle::Neighbor current_neighbor, QMap<Triangle, Triangle::Neighbors> neighbors) {
unsigned int count = 1;
while (count < 6 && *current_neighbor.triangle != triangle) {
while (count < 6 && current_neighbor.triangle != NULL && *current_neighbor.triangle != triangle) {
count++;
current_neighbor = neighbors.value(*current_neighbor.triangle).get_neighbor(rotate_edge_name(current_neighbor.edge.name));
}
return count == 6 && *current_neighbor.triangle == triangle;
return count == 6 && current_neighbor.triangle != NULL && *current_neighbor.triangle == triangle;
}
void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QVector<Triangle> &regular, QVector<Triangle> &irregular) {
......
......@@ -34,6 +34,7 @@ private:
QVector<GLuint> vertex_offsets;
QVector<GLuint> index_buffer;
QVector<GLuint> patch_index_regular;
QVector<GLuint> extra_triangles;
};
struct Result
......
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