Commit 50e17989 by Philipp Adolf

Use QVector<Triangle> for edge detection

parent 5418ded6
#include <memory>
#include "subdivision.h"
#include "triangle.h"
Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
{
......@@ -114,22 +115,28 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if(debugOutput)
qDebug()<<"Vertex Buffer: "<<vb;
QVector<Triangle> triangles;
for (int i = 0; i < ib.length(); i+=3) {
triangles.push_back(Triangle(vb, ib[i], ib[i+1], ib[i+2]));
}
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
unsigned int nib_offset = vb.length();//offset in new index buffer for edge vertices
for (int i = 0; i < ib.length(); i+=3){
for (int i = 0; i < triangles.length(); i++){
//schaue alle dreiecke an
Triangle triangle = triangles[i];
Vertex x, y, z;
unsigned int x_i = ib[i];
unsigned int y_i = ib[i+1];
unsigned int z_i = ib[i+2];
unsigned int x_i = triangle.u_idx();
unsigned int y_i = triangle.v_idx();
unsigned int z_i = triangle.w_idx();
//get vertices x,y,z from vertex buffer
x = vb[x_i];//todo maybe check array length
y = vb[y_i];
z = vb[z_i];
x = triangle.u();
y = triangle.v();
z = triangle.w();
QVector<unsigned int> edge_indices_buffer;//push all edge indices into this, then check if enough edge indices were found. if yes, copy to Tables and add to new index buffer.
......@@ -142,18 +149,19 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
*/
//find indices for edge point on xy-edge
for (int j = 0; j < ib.length(); j+= 3){
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 = ib[j];
b_i = ib[j+1];
c_i = ib[j+2];
a_i = other.u_idx();
b_i = other.v_idx();
c_i = other.w_idx();
a = vb[a_i];
b = vb[b_i];
c = vb[c_i];
a = other.u();
b = other.v();
c = other.w();
//get vertices for a,b,c from vertex buffer
//comparisons: xy = ba, cb, ac.
......@@ -182,18 +190,19 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}
//find indices for edge point on yz-edge
for (int j = 0; j < ib.length(); j+= 3){
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 = ib[j];
b_i = ib[j+1];
c_i = ib[j+2];
a_i = other.u_idx();
b_i = other.v_idx();
c_i = other.w_idx();
a = vb[a_i];
b = vb[b_i];
c = vb[c_i];
a = other.u();
b = other.v();
c = other.w();
//yz = ba, cb, ac
if (y.samePos(a) && z.samePos(c)){
......@@ -218,19 +227,19 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}
//find indices for edge point on xy-edge
for (int j = 0; j < ib.length(); j+= 3){
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 = ib[j];
b_i = ib[j+1];
c_i = ib[j+2];
a = vb[a_i];
b = vb[b_i];
c = vb[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);
......@@ -253,7 +262,6 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}
}//quadratische Laufzeit ftw
if (edge_indices_buffer.length() == 12){
//copy edge indices buffer to actual edge indices
for (int k = 0; k < edge_indices_buffer.length(); k++){
......@@ -261,15 +269,15 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
}
//add indices to new index buffer
tables.index_buffer.push_back(ib[i]);
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(ib[i+1]);
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(ib[i+2]);
tables.index_buffer.push_back(z_i);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset + 1);
......@@ -283,9 +291,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
qWarning()<<"Could not find all indices for edge points at ib " << i <<". Keep old triangle.";
}
//keep old, unsubdivided triangle.
tables.index_buffer.push_back(ib[i]);
tables.index_buffer.push_back(ib[i+1]);
tables.index_buffer.push_back(ib[i+2]);
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
......
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