Commit b3ed332c by Alisa Jung

precomputation of edge table. results seem correct for cube.

parent cbc4b424
......@@ -195,6 +195,10 @@ QVector<unsigned int> Mesh::MeshEntry::getIndexBuffer(){
return indices;
}
QVector<Vertex> Mesh::MeshEntry::getVertexBuffer(){
return vertices;
}
void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString debugoffset){
newNode.name = node->mName.length != 0 ? node->mName.C_Str() : "";
newNode.transformation = QMatrix4x4(node->mTransformation[0]);
......
......@@ -28,6 +28,12 @@ struct Vertex
this->tex = tex;
this->normal = normal;
}
bool samePos(const Vertex& other) const{
return pos == other.pos;
}
//TODO add some kind of toString so we can log vertices.
};
QDebug operator<< (QDebug d, const Vertex &v);
......@@ -46,6 +52,8 @@ public:
MeshEntry();
~MeshEntry();
QVector<unsigned int> getIndexBuffer();
QVector<Vertex> getVertexBuffer();
void init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices);
......@@ -113,7 +121,6 @@ private:
void renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M);
void renderMesh(QOpenGLShaderProgram *shader, int index);
void findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max);
......
......@@ -14,6 +14,15 @@ void Subdivision::init() {
shader = initComputeShaderProgram();
}
QVector<unsigned int> Subdivision::fillVector(unsigned int a, unsigned int b, unsigned int c,unsigned int d){
QVector<unsigned int> x;
x.push_back(a);
x.push_back(b);
x.push_back(c);
x.push_back(d);
return x;
}
QOpenGLShaderProgram *Subdivision::initComputeShaderProgram(){
QString source = QLatin1String(":/subdivision.compute");
......@@ -55,43 +64,86 @@ void Subdivision::precomputeTables(Mesh *mesh) {
qDebug()<<"Mesh found. Index:"<<firstMeshEntryIndex;
//die drei zeilen machen das bild schwarz. wenn man davor returnt tuts.
Mesh::MeshEntry firstMeshEntry = mesh->getMeshEntry(firstMeshEntryIndex);
QVector<unsigned int> ib = firstMeshEntry.getIndexBuffer();
Mesh::MeshEntry *firstMeshEntry = mesh->getMeshEntry(firstMeshEntryIndex);
QVector<unsigned int> ib = firstMeshEntry->getIndexBuffer();
qDebug()<<"Index Buffer: "<<ib;
return;
//todo find adjacent triangles:
/*
QVector<Vertex> vb = firstMeshEntry->getVertexBuffer();
//qDebug()<<"Vertex Buffer: "<<vb;
QVector<QVector<unsigned int>> edgeIndices_base;
for (int i = 0; i < ib.length(); i+=3){
//schaue alle dreiecke an
unsigned int x, y, z;
x_index = ib[i];
y_index = ib[i+1];
z_index = ib[i+2];
Vertex x, y, z;
unsigned int x_i = ib[i];
unsigned int y_i = ib[i+1];
unsigned int z_i = ib[i+2];
x = vb[x_i];//todo maybe check array length
y = vb[y_i];
z = vb[z_i];
//get vertices x,y,z from vertex buffer
for (int j = i+3; j < ib.length(); j+= 3){
//search all following triangles for common edge
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_index = ib[j];
b_index = ib[j+1];
c_index = in[j+2];
a = vb[a_i];
b = vb[b_i];
c = vb[c_i];
//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)){
edgeIndices_base.push_back(fillVector(x_i,y_i,z_i,b_i));
}
if (x.samePos(a) && z.samePos(b)){
edgeIndices_base.push_back(fillVector(x_i,z_i,y_i,c_i));
}
if (x.samePos(b) && y.samePos(a)){
edgeIndices_base.push_back(fillVector(x_i,y_i,z_i,c_i));
}
if (x.samePos(b) && z.samePos(c)){
edgeIndices_base.push_back(fillVector(x_i,z_i,y_i,a_i));
}
if (x.samePos(c) && y.samePos(b)){
edgeIndices_base.push_back(fillVector(x_i,y_i,z_i,a_i));
}
if (x.samePos(c) && z.samePos(a)){
edgeIndices_base.push_back(fillVector(x_i,z_i,y_i,b_i));
}
//for xy
//for yz
//for zx
if (y.samePos(a) && z.samePos(c)){
edgeIndices_base.push_back(fillVector(y_i,z_i,x_i,b_i));
}
if (y.samePos(b) && z.samePos(a)){
edgeIndices_base.push_back(fillVector(y_i,z_i,x_i,c_i));
}
if (y.samePos(c) && z.samePos(b)){
edgeIndices_base.push_back(fillVector(y_i,z_i,x_i,a_i));
}
}//quadratische Laufzeit ftw
}
qDebug()<<"Done with edge table. "<<edgeIndices_base.length()<<" edges found. Table: "<<edgeIndices_base;
if (true){
qDebug()<<"Table (long version):";
for (int i = 0; i < edgeIndices_base.length(); i++){
qDebug()<<"blub:"<<edgeIndices_base[i];
}
}
*
* */
//TODO save/return edge table
}
void Subdivision::runShader(Mesh *mesh) {
......
......@@ -22,6 +22,8 @@ private:
QOpenGLShaderProgram *initComputeShaderProgram();
void precomputeTables(Mesh *mesh);
void runShader(Mesh *mesh);
QVector<unsigned int> fillVector(unsigned int a, unsigned int b, unsigned int c,unsigned int d);
};
#endif
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