Commit 19232189 by Philipp Adolf

Use Shared_Edge for edge vertex generation

parent 50e17989
......@@ -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.
*/
//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++){
if (j != i){
//search all following triangles for common edge
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();
//get vertices for a,b,c from vertex buffer
//comparisons: xy = ba, cb, ac.
//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);
if (j != i) {
if (triangle.get_shared_edge(triangles[j], edge)) {
switch (edge.edge_a) {
case Triangle::Shared_Edge::Edge::uv:
uv = edge;
break;
case Triangle::Shared_Edge::Edge::vw:
vw = edge;
break;
case Triangle::Shared_Edge::Edge::wu:
wu = edge;
break;
default:
qWarning() << "got" << edge.edge_a << "as edge!";
break;
}
}
}
}
//find indices for edge point on yz-edge
for (int j = 0; j < triangles.length(); j++){
if (j != i){
//search all following triangles for common edge
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);
}
}
}
tables.edge_indices.push_back(uv.a1);
tables.edge_indices.push_back(uv.a2);
tables.edge_indices.push_back(uv.a3);
tables.edge_indices.push_back(uv.b3);
//find indices for edge point on xy-edge
for (int j = 0; j < triangles.length(); j++){
if (j != i){
//search all following triangles for common edge
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
tables.edge_indices.push_back(vw.a1);
tables.edge_indices.push_back(vw.a2);
tables.edge_indices.push_back(vw.a3);
tables.edge_indices.push_back(vw.b3);
if (edge_indices_buffer.length() == 12){
//copy edge indices buffer to actual edge indices
for (int k = 0; k < edge_indices_buffer.length(); k++){
tables.edge_indices.push_back(edge_indices_buffer[k]);
}
tables.edge_indices.push_back(wu.a1);
tables.edge_indices.push_back(wu.a2);
tables.edge_indices.push_back(wu.a3);
tables.edge_indices.push_back(wu.b3);
//add indices to new index buffer
tables.index_buffer.push_back(x_i);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 2);
//add indices to new index buffer
tables.index_buffer.push_back(x_i);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(y_i);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(y_i);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(z_i);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(z_i);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset + 2);
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
nib_offset += 3;
}
qDebug()<<"Done with edge table. "<<tables.edge_indices.length();
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