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,126 +420,151 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
totalTimer.start();
qCDebug(log_timing)<<"PatchIndexBuffer started";
QVector<unsigned int> pib;
QVector<unsigned int> ib_combined = ib_regular + ib_irregular;
for (int i = 0; i < ib_regular.length() - 2; i+=3){
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
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
i3 = ib_regular[i];
i6 = ib_regular[i+1];
i7 = ib_regular[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;
i3 = ib_combined[i];
i6 = ib_combined[i+1];
i7 = ib_combined[i+2];
if(log_subdiv_trace().isDebugEnabled()){
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]] == v3) count3++;
if (vb[ib_combined[j]] == v6) count6++;
if (vb[ib_combined[j]] == v7) count7++;
if (i < ib_regular.length()){
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;
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.";
}
}
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.
{
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 j1 = ib_combined[j+1];
unsigned int j2 = ib_combined[j+2];
//find i0. //TODO assert triangle 031 \exists somewhere
found0 |= matchAndCompleteTriangle(j0,j1,j2,i2,i3,i0,vb);
found1 |= matchAndCompleteTriangle(j0,j1,j2,i3,i4,i1,vb);
//TODO maybe assert that triangle i0 i3 i1 actually \exists.
found5 |= matchAndCompleteTriangle(j0,j1,j2,i6,i2,i5,vb);
found9 |= matchAndCompleteTriangle(j0,j1,j2,i10,i6,i9,vb);
for (int j = i+3; 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];
//todo assert that triangle i5 i9 i6
Triangle tj(vb,j0,j1,j2);
found8 |= matchAndCompleteTriangle(j0,j1,j2,i4,i7,i8,vb);
found11 |= matchAndCompleteTriangle(j0,j1,j2,i7,i10,i11,vb);
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);
}
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){
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];
for(int i = 0; i < ib_regular.length()-2; i+=3){
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);
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:"<<getTimeSting(totalTimer.elapsed());
......@@ -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){
if (vb[sx] == vb[tx] && vb[sy] == vb[ty]){
if (vb[sx].samePos(vb[tx]) && vb[sy].samePos(vb[ty])){
tz = sz;
return true;
}
if (vb[sy] == vb[tx] && vb[sz] == vb[ty]){
if (vb[sy].samePos(vb[tx]) && vb[sz].samePos(vb[ty])){
tz = sx;
return true;
}
if (vb[sz] == vb[tx] && vb[sx] == vb[ty]){
if (vb[sz].samePos(vb[tx]) && vb[sx].samePos(vb[ty])){
tz = sy;
return true;
}
......
......@@ -85,6 +85,7 @@ private:
/**
* @brief matchAndCompleteTriangle if vertices at indices tx ty matches vertices at indices sxsy, sysz or szsy,
* 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 sy source triangle: second vertex index
* @param sz source triangle: third vertex index
......@@ -95,6 +96,7 @@ private:
* @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);
};
#endif
......@@ -64,6 +64,11 @@ bool Triangle::get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const
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 {
if (u().samePos(other.u())) {
if (v().samePos(other.w())) {
......@@ -108,6 +113,21 @@ bool Triangle::get_shared_edge_(const Triangle &other, Edge &edge_a, Edge &edge_
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) {
this->vertex_buffer_ = other.vertex_buffer_;
this->u_ = other.u_;
......
......@@ -35,6 +35,8 @@ class Triangle {
bool get_shared_edge(Triangle other, Edge &edge_a, Edge &edge_b) const;
bool hasSharedEdge(Triangle other);
Triangle &operator=(const Triangle &other);
// == and < both ignore the vertex buffer, they only compare indices.
......@@ -42,6 +44,9 @@ class Triangle {
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:
QVector<Vertex> vertex_buffer_;
unsigned int u_;
......
......@@ -22,11 +22,6 @@ struct Vertex
bool samePos(const Vertex& other) const;
bool operator==(const Vertex& other) const
{
return samePos(other);
}
};
#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