Commit 6fbdc2c2 by Alisa Jung

Performance Boost for getPatchIndexBuffer? TODO Kai mess das mal

Conflicts: QTProject/subdivision.cpp
parent 02506fd3
...@@ -414,123 +414,151 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -414,123 +414,151 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
totalTimer.start(); totalTimer.start();
qCDebug(log_timing)<<"PatchIndexBuffer started"; qCDebug(log_timing)<<"PatchIndexBuffer started";
QVector<unsigned int> pib; QVector<unsigned int> pib;
QVector<unsigned int> ib_combined = ib_regular + ib_irregular; QVector<unsigned int> ib_combined = ib_regular + ib_irregular; //DO NOT swap regular and irregular! iteration over ib_combined starting from index in ib_regular
for (int i = 0; i < ib_regular.length() - 2; i+=3){ QMap<Triangle,QVector<Triangle>> adj;
for (int i = 0; i < ib_combined.length() - 2; i+=3){
unsigned int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11; unsigned int i3,i6,i7;
//alles gegen den uzs //alles gegen den uzs
i3 = ib_regular[i]; i3 = ib_combined[i];
i6 = ib_regular[i+1]; i6 = ib_combined[i+1];
i7 = ib_regular[i+2]; i7 = ib_combined[i+2];
Vertex v3 = vb[i3];
Vertex v6 = vb[i6];
Vertex v7 = vb[i7];
int count3 = 0; //counts other triangles with this vertex
int count6 = 0;
int count7 = 0;
if(log_subdiv_trace().isDebugEnabled()){ if(log_subdiv_trace().isDebugEnabled()){
for (int j = 0; j < ib_combined.length(); j++){ if (i < ib_regular.length()){
if (j != i && j != i+1 && j != i+2){ Vertex v3 = vb[i3];
//for debugging // checking if patch is regular. Vertex v6 = vb[i6];
if (vb[ib_combined[j]].samePos(v3)) count3++; Vertex v7 = vb[i7];
if (vb[ib_combined[j]].samePos(v6)) count6++;
if (vb[ib_combined[j]].samePos(v7)) count7++; int count3 = 0; //counts other triangles with this vertex
int count6 = 0;
int count7 = 0;
for (int j = 0; j < ib_combined.length(); j++){
if (j != i && j != i+1 && j != i+2){
//for debugging // checking if patch is regular.
if (vb[ib_combined[j]].samePos(v3)) count3++;
if (vb[ib_combined[j]].samePos(v6)) count6++;
if (vb[ib_combined[j]].samePos(v7)) count7++;
}
}
if (count3 != 5 || count6 != 5 || count7 != 5){
qCWarning(log_subdiv) << "Counts wrong! 3: "<< count3 <<", 6: " << count6 << ", 7: " << count7 << ".\nEither this patch is not regular, or you didn't pass all neighboring triangles.";
} }
}
}
//find triangles with shared edge. Fills i2, i4, i10.
{
bool found36 = false;
bool found67 = false;
bool found73 = false;
for (int j = 0; j < ib_combined.length() - 2; j+=3){
unsigned int j0 = ib_combined[j];
unsigned int j1 = ib_combined[j+1];
unsigned int j2 = ib_combined[j+2];
//Dreieck angrenzend an Kante i3 i6
found36 |= matchAndCompleteTriangle(j0,j1,j2,i6,i3,i2,vb);
//Dreieck angrenzend an Kante i6 i7
found67 |= matchAndCompleteTriangle(j0,j1,j2,i7,i6,i10,vb);
//Dreieck angrenzend an Kante i7 i3
found73 |= matchAndCompleteTriangle(j0,j1,j2,i3,i7,i4,vb);
}
if (!(found36 && found67 && found73)){
qCWarning(log_subdiv) << "Didnt find neighbour. duplicate vertex? Abort.";
return pib;
} }
} }
Triangle t367(vb,i3,i6,i7);
//find last missing triangles. for (int j = i+3; j < ib_combined.length()-2; j += 3){
{ unsigned int j0 = ib_combined[j];
bool found0 = false; unsigned int j1 = ib_combined[j+1];
bool found1 = false; unsigned int j2 = ib_combined[j+2];
bool found5 = false;
bool found9 = false;
bool found8 = false;
bool found11 = false;
for (int j = 0; j < ib_combined.length() - 2; j+=3){
unsigned int j0 = ib_combined[j];
unsigned int j1 = ib_combined[j+1];
unsigned int j2 = ib_combined[j+2];
//find i0. //TODO assert triangle 031 \exists somewhere Triangle tj(vb,j0,j1,j2);
found0 |= matchAndCompleteTriangle(j0,j1,j2,i2,i3,i0,vb); if (t367.hasSharedEdge(tj)){
found1 |= matchAndCompleteTriangle(j0,j1,j2,i3,i4,i1,vb); QVector<Triangle> neighbors = adj.value(tj,QVector<Triangle>());
//TODO maybe assert that triangle i0 i3 i1 actually \exists. neighbors.push_back(t367);
adj.insert(tj,neighbors);
found5 |= matchAndCompleteTriangle(j0,j1,j2,i6,i2,i5,vb); neighbors = adj.value(t367,QVector<Triangle>());
found9 |= matchAndCompleteTriangle(j0,j1,j2,i10,i6,i9,vb); neighbors.push_back(tj);
adj.insert(t367,neighbors);
//todo assert that triangle i5 i9 i6
found8 |= matchAndCompleteTriangle(j0,j1,j2,i4,i7,i8,vb);
found11 |= matchAndCompleteTriangle(j0,j1,j2,i7,i10,i11,vb);
} }
if (!(found0 && found1 && found5 && found9 && found8 && found11)){ }
qCWarning(log_subdiv) << "Couldnt find some neighbour at i= " << i;
qCWarning(log_subdiv) << "i3: " << i3 << ", i6: " << i6 << " i7: " << i7 << " i2 " << i2;
if (adj.value(t367,QVector<Triangle>()).size() != 3){
qCDebug(log_subdiv)<<"no 3 adjacent triangles found";
}
}
for (int k = 0; k < ib_combined.length() - 2; k+= 3){ for(int i = 0; i < ib_regular.length()-2; i+=3){
if (ib_combined[k] == i3 || ib_combined[k+1] == i3 || ib_combined[k+2] == i3){ unsigned int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11;
qCWarning(log_subdiv) << "i3 adjacent: " << ib_combined[k] << ", " << ib_combined[k+1] << ", " << ib_combined[k+2]; i3 = ib_regular[i];
i6 = ib_regular[i+1];
i7 = ib_regular[i+2];
Triangle ti(vb,i3,i6,i7);
bool found0, found1, found5, found8, found9, found11;
QVector<Triangle> neighbors = adj.value(ti,QVector<Triangle>());
for (int j = 0; j < neighbors.length(); j++){
Triangle::Edge a,b;
Triangle tj = neighbors[j];
ti.get_shared_edge(tj,a,b);
Triangle::Edge c,d;
QVector<Triangle> an = adj.value(tj,QVector<Triangle>());
if (a.name == Triangle::Edge::Name::uv){
i2 = b.c;
for(int k = 0; k < an.length(); k++){
tj.get_shared_edge(an[k],c,d);
if (tj.next_ctrclockwise(b,c)){
i0 = d.c;
found0 = true;
}
if (tj.next_clockwise(b,c)){
i5 = d.c;
found5 = true;
}
}
} else if (a.name == Triangle::Edge::Name::vw){
i10 = b.c;
for (int k = 0; k < an.length(); k++){
tj.get_shared_edge(an[k],c,d);
if (tj.next_ctrclockwise(b,c)){
i9 = d.c;
found9 = true;
}
if (tj.next_clockwise(b,c)){
i11 = d.c;
found11 = true;
}
}
} else if (a.name == Triangle::Edge::Name::wu){
i4 = b.c;
for (int k = 0; k < an.length(); k++){
tj.get_shared_edge(an[k],c,d);
if (tj.next_ctrclockwise(b,c)){
i8 = d.c;
found8 = true;
}
if (tj.next_clockwise(b,c)){
i1 = d.c;
found1 = true;
} }
} }
qCWarning(log_subdiv) << "Couldnt find some neighbour at i= " << i;
qCWarning(log_subdiv) << "found: 0 1 5 9 8 11 \n" << found0 << found1 << found5 << found9 << found8 << found11;
qCWarning(log_subdiv) << "Count3: " << count3 << " count6: " << count6 << " count7: " << count7;
qCWarning(log_subdiv) << "Abort computing patch index buffer.";
return pib;
} }
//else qCWarning(log_subdiv) << "found all neighbours for patch.";
pib.push_back(i0);
pib.push_back(i1);
pib.push_back(i2);
pib.push_back(i3);
pib.push_back(i4);
pib.push_back(i5);
pib.push_back(i6);
pib.push_back(i7);
pib.push_back(i8);
pib.push_back(i9);
pib.push_back(i10);
pib.push_back(i11);
} }
if (!(found0 && found1 && found5 && found9 && found8 && found11)){
qCWarning(log_subdiv) << "Couldnt find some neighbour at i= " << i;
qCWarning(log_subdiv) << "i3: " << i3 << ", i6: " << i6 << " i7: " << i7 << " i2 " << i2;
for (int k = 0; k < ib_combined.length() - 2; k+= 3){
if (ib_combined[k] == i3 || ib_combined[k+1] == i3 || ib_combined[k+2] == i3){
qCWarning(log_subdiv) << "i3 adjacent: " << ib_combined[k] << ", " << ib_combined[k+1] << ", " << ib_combined[k+2];
}
}
qCWarning(log_subdiv) << "found: 0 1 5 9 8 11 \n" << found0 << found1 << found5 << found9 << found8 << found11;
qCWarning(log_subdiv) << "Abort computing patch index buffer.";
return pib;
}
//else qCWarning(log_subdiv) << "found all neighbours for patch.";
pib.push_back(i0);
pib.push_back(i1);
pib.push_back(i2);
pib.push_back(i3);
pib.push_back(i4);
pib.push_back(i5);
pib.push_back(i6);
pib.push_back(i7);
pib.push_back(i8);
pib.push_back(i9);
pib.push_back(i10);
pib.push_back(i11);
} }
qCDebug(log_timing)<<"PatchIndexBuffer done:"<<totalTimer.elapsed()<<"ms"; qCDebug(log_timing)<<"PatchIndexBuffer done:"<<totalTimer.elapsed()<<"ms";
......
...@@ -83,6 +83,7 @@ private: ...@@ -83,6 +83,7 @@ private:
/** /**
* @brief matchAndCompleteTriangle if vertices at indices tx ty matches vertices at indices sxsy, sysz or szsy, * @brief matchAndCompleteTriangle if vertices at indices tx ty matches vertices at indices sxsy, sysz or szsy,
* fill tz with third source vertex index. * fill tz with third source vertex index.
* both s(xyz) and t(xyz) are in SAME DIRECTION: matches sx with tx, sy with ty (..)
* @param sx source triangle: first vertex index * @param sx source triangle: first vertex index
* @param sy source triangle: second vertex index * @param sy source triangle: second vertex index
* @param sz source triangle: third vertex index * @param sz source triangle: third vertex index
...@@ -93,6 +94,7 @@ private: ...@@ -93,6 +94,7 @@ private:
* @return true if triangles could be matched and tz was filled. * @return true if triangles could be matched and tz was filled.
*/ */
bool matchAndCompleteTriangle(unsigned int sx, unsigned int sy, unsigned int sz, unsigned int tx, unsigned int ty, unsigned int &tz, QVector<Vertex> vb); bool matchAndCompleteTriangle(unsigned int sx, unsigned int sy, unsigned int sz, unsigned int tx, unsigned int ty, unsigned int &tz, QVector<Vertex> vb);
}; };
#endif #endif
...@@ -64,6 +64,11 @@ bool Triangle::get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const ...@@ -64,6 +64,11 @@ bool Triangle::get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const
return false; return false;
} }
bool Triangle::hasSharedEdge(Triangle other){
Edge a,b;
return get_shared_edge(other,a,b);
}
bool Triangle::get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_b) const { bool Triangle::get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_b) const {
if (u().samePos(other.u())) { if (u().samePos(other.u())) {
if (v().samePos(other.w())) { if (v().samePos(other.w())) {
...@@ -108,6 +113,21 @@ bool Triangle::get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_ ...@@ -108,6 +113,21 @@ bool Triangle::get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_
return false; return false;
} }
//e.g. first.name = uv, next.name = vw
bool Triangle::next_ctrclockwise(Edge first, Edge next) const{
return (first.name == Triangle::Edge::Name::uv &&
next.name == Triangle::Edge::Name::vw)
||(first.name == Triangle::Edge::Name::vw &&
next.name == Triangle::Edge::Name::wu)
||(first.name == Triangle::Edge::Name::wu &&
next.name == Triangle::Edge::Name::uv);
}
//e.g. first.name = vw, next.name = uv
bool Triangle::next_clockwise(Edge first, Edge next) const{
return next_ctrclockwise(next,first);
}
Triangle &Triangle::operator=(const Triangle &other) { Triangle &Triangle::operator=(const Triangle &other) {
this->vertex_buffer_ = other.vertex_buffer_; this->vertex_buffer_ = other.vertex_buffer_;
this->u_ = other.u_; this->u_ = other.u_;
......
...@@ -35,6 +35,8 @@ class Triangle { ...@@ -35,6 +35,8 @@ class Triangle {
bool get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const; bool get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const;
bool hasSharedEdge(Triangle other);
Triangle &operator=(const Triangle &other); Triangle &operator=(const Triangle &other);
// == and < both ignore the vertex buffer, they only compare indices. // == and < both ignore the vertex buffer, they only compare indices.
...@@ -42,6 +44,9 @@ class Triangle { ...@@ -42,6 +44,9 @@ class Triangle {
bool operator==(const Triangle &other) const; bool operator==(const Triangle &other) const;
bool operator<(const Triangle &other) const; bool operator<(const Triangle &other) const;
bool next_ctrclockwise(Edge first, Edge next) const;
bool next_clockwise(Edge first, Edge next) const;
private: private:
QVector<Vertex> vertex_buffer_; QVector<Vertex> vertex_buffer_;
unsigned int u_; unsigned int u_;
......
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