Commit 19232189 by Philipp Adolf

Use Shared_Edge for edge vertex generation

parent 50e17989
...@@ -148,155 +148,63 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -148,155 +148,63 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
* - Each edge point will be computed twice. This allows us to implicitly know the adjacent points. * - Each edge point will be computed twice. This allows us to implicitly know the adjacent points.
*/ */
//find indices for edge point on xy-edge Triangle::Shared_Edge edge;
Triangle::Shared_Edge uv, vw, wu;
for (int j = 0; j < triangles.length(); j++){ for (int j = 0; j < triangles.length(); j++){
if (j != i){ if (j != i) {
//search all following triangles for common edge if (triangle.get_shared_edge(triangles[j], edge)) {
Triangle other = triangles[j]; switch (edge.edge_a) {
Vertex a,b,c; case Triangle::Shared_Edge::Edge::uv:
unsigned int a_i, b_i, c_i; uv = edge;
a_i = other.u_idx(); break;
b_i = other.v_idx(); case Triangle::Shared_Edge::Edge::vw:
c_i = other.w_idx(); vw = edge;
break;
a = other.u(); case Triangle::Shared_Edge::Edge::wu:
b = other.v(); wu = edge;
c = other.w(); break;
default:
//get vertices for a,b,c from vertex buffer qWarning() << "got" << edge.edge_a << "as edge!";
//comparisons: xy = ba, cb, ac. break;
//yz = ba, cb, ac }
//zx = ba, cb, ac
//TODO if oder else if?
if (x.samePos(a) && y.samePos(c)){
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(b_i);
}
if (x.samePos(b) && y.samePos(a)){
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(c_i);
}
if (x.samePos(c) && y.samePos(b)){
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(a_i);
} }
} }
} }
//find indices for edge point on yz-edge tables.edge_indices.push_back(uv.a1);
for (int j = 0; j < triangles.length(); j++){ tables.edge_indices.push_back(uv.a2);
if (j != i){ tables.edge_indices.push_back(uv.a3);
//search all following triangles for common edge tables.edge_indices.push_back(uv.b3);
Triangle other = triangles[j];
Vertex a,b,c;
unsigned int a_i, b_i, c_i;
a_i = other.u_idx();
b_i = other.v_idx();
c_i = other.w_idx();
a = other.u();
b = other.v();
c = other.w();
//yz = ba, cb, ac
if (y.samePos(a) && z.samePos(c)){
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(b_i);
}
if (y.samePos(b) && z.samePos(a)){
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(c_i);
}
if (y.samePos(c) && z.samePos(b)){
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(a_i);
}
}
}
//find indices for edge point on xy-edge tables.edge_indices.push_back(vw.a1);
for (int j = 0; j < triangles.length(); j++){ tables.edge_indices.push_back(vw.a2);
if (j != i){ tables.edge_indices.push_back(vw.a3);
//search all following triangles for common edge tables.edge_indices.push_back(vw.b3);
Triangle other = triangles[j];
Vertex a,b,c;
unsigned int a_i, b_i, c_i;
a_i = other.u_idx();
b_i = other.v_idx();
c_i = other.w_idx();
a = other.u();
b = other.v();
c = other.w();
if (x.samePos(a) && z.samePos(b)){
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(c_i);
}
if (x.samePos(b) && z.samePos(c)){
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(a_i);
}
if (x.samePos(c) && z.samePos(a)){
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(b_i);
}
}
}//quadratische Laufzeit ftw
if (edge_indices_buffer.length() == 12){ tables.edge_indices.push_back(wu.a1);
//copy edge indices buffer to actual edge indices tables.edge_indices.push_back(wu.a2);
for (int k = 0; k < edge_indices_buffer.length(); k++){ tables.edge_indices.push_back(wu.a3);
tables.edge_indices.push_back(edge_indices_buffer[k]); tables.edge_indices.push_back(wu.b3);
}
//add indices to new index buffer //add indices to new index buffer
tables.index_buffer.push_back(x_i); tables.index_buffer.push_back(x_i);
tables.index_buffer.push_back(nib_offset); tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 2); tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(y_i); tables.index_buffer.push_back(y_i);
tables.index_buffer.push_back(nib_offset + 1); tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset); tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(z_i); tables.index_buffer.push_back(z_i);
tables.index_buffer.push_back(nib_offset + 2); tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset + 1); tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset); tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 1); tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset + 2); tables.index_buffer.push_back(nib_offset + 2);
nib_offset += 3; nib_offset += 3;
}else{ }
if (true || debugOutput){
qWarning()<<"Could not find all indices for edge points at ib " << i <<". Keep old triangle.";
}
//keep old, unsubdivided triangle.
tables.index_buffer.push_back(x_i);
tables.index_buffer.push_back(y_i);
tables.index_buffer.push_back(z_i);
}
//Wichtig: Wir gehen davon aus, dass wir geschlossene Oberflächen haben, dh für jede Kante von einem Dreieck wird eine passende Kante bei einem anderen Dreieck gefunden.
}//for each index in indexbuffer
qDebug()<<"Done with edge table. "<<tables.edge_indices.length(); qDebug()<<"Done with edge table. "<<tables.edge_indices.length();
if (debugOutput){ if (debugOutput){
......
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