Commit 885e3f3d by Kai Westerkamp

Merge branch 'patchRender' of…

Merge branch 'patchRender' of ssh://git.breab.org:2223/kai/Unterteilungsalgorithmen into patchRender
parents e28d3501 6fbdc2c2
...@@ -420,16 +420,19 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -420,16 +420,19 @@ 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];
if(log_subdiv_trace().isDebugEnabled()){
if (i < ib_regular.length()){
Vertex v3 = vb[i3]; Vertex v3 = vb[i3];
Vertex v6 = vb[i6]; Vertex v6 = vb[i6];
Vertex v7 = vb[i7]; Vertex v7 = vb[i7];
...@@ -437,74 +440,101 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -437,74 +440,101 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
int count3 = 0; //counts other triangles with this vertex int count3 = 0; //counts other triangles with this vertex
int count6 = 0; int count6 = 0;
int count7 = 0; int count7 = 0;
if(log_subdiv_trace().isDebugEnabled()){
for (int j = 0; j < ib_combined.length(); j++){ for (int j = 0; j < ib_combined.length(); j++){
if (j != i && j != i+1 && j != i+2){ if (j != i && j != i+1 && j != i+2){
//for debugging // checking if patch is regular. //for debugging // checking if patch is regular.
if (vb[ib_combined[j]] == v3) count3++; if (vb[ib_combined[j]].samePos(v3)) count3++;
if (vb[ib_combined[j]] == v6) count6++; if (vb[ib_combined[j]].samePos(v6)) count6++;
if (vb[ib_combined[j]] == v7) count7++; if (vb[ib_combined[j]].samePos(v7)) count7++;
} }
} }
if (count3 != 5 || count6 != 5 || count7 != 5){ 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."; 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){
{
bool found0 = false;
bool found1 = false;
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 j0 = ib_combined[j];
unsigned int j1 = ib_combined[j+1]; unsigned int j1 = ib_combined[j+1];
unsigned int j2 = ib_combined[j+2]; unsigned int j2 = ib_combined[j+2];
Triangle tj(vb,j0,j1,j2);
//find i0. //TODO assert triangle 031 \exists somewhere if (t367.hasSharedEdge(tj)){
QVector<Triangle> neighbors = adj.value(tj,QVector<Triangle>());
neighbors.push_back(t367);
adj.insert(tj,neighbors);
neighbors = adj.value(t367,QVector<Triangle>());
neighbors.push_back(tj);
adj.insert(t367,neighbors);
}
}
found0 |= matchAndCompleteTriangle(j0,j1,j2,i2,i3,i0,vb); if (adj.value(t367,QVector<Triangle>()).size() != 3){
found1 |= matchAndCompleteTriangle(j0,j1,j2,i3,i4,i1,vb); qCDebug(log_subdiv)<<"no 3 adjacent triangles found";
//TODO maybe assert that triangle i0 i3 i1 actually \exists. }
}
found5 |= matchAndCompleteTriangle(j0,j1,j2,i6,i2,i5,vb); for(int i = 0; i < ib_regular.length()-2; i+=3){
found9 |= matchAndCompleteTriangle(j0,j1,j2,i10,i6,i9,vb); unsigned int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11;
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);
//todo assert that triangle i5 i9 i6 Triangle::Edge c,d;
QVector<Triangle> an = adj.value(tj,QVector<Triangle>());
if (a.name == Triangle::Edge::Name::uv){
i2 = b.c;
found8 |= matchAndCompleteTriangle(j0,j1,j2,i4,i7,i8,vb); for(int k = 0; k < an.length(); k++){
found11 |= matchAndCompleteTriangle(j0,j1,j2,i7,i10,i11,vb); 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;
}
}
}
} }
if (!(found0 && found1 && found5 && found9 && found8 && found11)){ if (!(found0 && found1 && found5 && found9 && found8 && found11)){
...@@ -518,11 +548,7 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -518,11 +548,7 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
} }
} }
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) << "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."; qCWarning(log_subdiv) << "Abort computing patch index buffer.";
return pib; return pib;
} }
...@@ -540,7 +566,6 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -540,7 +566,6 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
pib.push_back(i10); pib.push_back(i10);
pib.push_back(i11); pib.push_back(i11);
} }
}
qCDebug(log_timing)<<"PatchIndexBuffer done:"<<getTimeSting(totalTimer.elapsed()); qCDebug(log_timing)<<"PatchIndexBuffer done:"<<getTimeSting(totalTimer.elapsed());
return pib; return pib;
...@@ -623,15 +648,15 @@ bool Subdivision::matchAndCompleteTriangleIndices(unsigned int sx, unsigned int ...@@ -623,15 +648,15 @@ bool Subdivision::matchAndCompleteTriangleIndices(unsigned int sx, unsigned int
bool Subdivision::matchAndCompleteTriangle(unsigned int sx, unsigned int sy, unsigned int sz,unsigned int tx, unsigned int ty, unsigned int &tz, QVector<Vertex> vb){ bool Subdivision::matchAndCompleteTriangle(unsigned int sx, unsigned int sy, unsigned int sz,unsigned int tx, unsigned int ty, unsigned int &tz, QVector<Vertex> vb){
if (vb[sx] == vb[tx] && vb[sy] == vb[ty]){ if (vb[sx].samePos(vb[tx]) && vb[sy].samePos(vb[ty])){
tz = sz; tz = sz;
return true; return true;
} }
if (vb[sy] == vb[tx] && vb[sz] == vb[ty]){ if (vb[sy].samePos(vb[tx]) && vb[sz].samePos(vb[ty])){
tz = sx; tz = sx;
return true; return true;
} }
if (vb[sz] == vb[tx] && vb[sx] == vb[ty]){ if (vb[sz].samePos(vb[tx]) && vb[sx].samePos(vb[ty])){
tz = sy; tz = sy;
return true; return true;
} }
......
...@@ -85,6 +85,7 @@ private: ...@@ -85,6 +85,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
...@@ -95,6 +96,7 @@ private: ...@@ -95,6 +96,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_;
......
...@@ -22,11 +22,6 @@ struct Vertex ...@@ -22,11 +22,6 @@ struct Vertex
bool samePos(const Vertex& other) const; bool samePos(const Vertex& other) const;
bool operator==(const Vertex& other) const
{
return samePos(other);
}
}; };
#pragma pack(pop) #pragma pack(pop)
......
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