diff --git a/hw04/oglwidget.cpp b/hw04/oglwidget.cpp index f96660f..0078d70 100644 --- a/hw04/oglwidget.cpp +++ b/hw04/oglwidget.cpp @@ -98,6 +98,10 @@ void subDivLoop(); +int matchEdge(Tri tri, int vertex, int vertex1); + +void connectivityAlgo(); + Tri::Tri() { it[0] = -1; it[1] = -1; @@ -133,12 +137,17 @@ pts[iv[1]].Print(); cout << " - " << valences[iv[2]] << "x "; pts[iv[2]].Print(); + cout << endl << "Edges: " << ie[0] << " " << ie[1] << " " << ie[2] << endl; +// pts[ie[0]].Print(); +// pts[ie[1]].Print(); +// pts[ie[2]].Print(); + cout << endl; } float beta_n( int n) { - float an = (3.0f/8.0f) + pow((3.0f/8.0f) + (1.0f/4.0f)*cos(2.0f*PI/n), 2); + float an = (3.0f/8.0f) + float(pow((3.0f/8.0f) + (1.0f/4.0f)*cos(2.0f*PI/n), 2)); return (8.0f/5.0f)*an - (3.0f/5.0f); } @@ -176,24 +185,42 @@ // subDivEdgeMidpoint(); // subDivEdgeMidpoint(); + + +// for (auto triag : tris) { +// triag.Print(); +// } + +} + +void connectivityAlgo() { + for (int i = 0; i < pts.size(); ++i) { + valences[i] = 0; + } + // Connectivity Algorithm for (int i = 0; i < tris.size(); ++i) { Tri triag = tris[i]; - int n = 0; // Search for neighbour for (int ti = 0; ti < tris.size(); ++ti) { if (i == ti) continue; Tri t = tris[ti]; int count = 0; - for (int x : triag.iv) { + int side = 0; + for (int x = 0; x < 3; ++x) { + bool hit = false; for (int y : t.iv) { - if (x == y) - count++; + if (triag.iv[x] == y) + hit = true; } + if (hit) + count++; + else + side = x; } // if two points are the same, they are neighbours if (count == 2) - triag.it[n++] = ti; + triag.it[side] = ti; } // increase valence for each vertex of triangle @@ -203,23 +230,46 @@ tris[i] = triag; } - - - for (auto triag : tris) { - triag.Print(); - } - subDivLoop(); - - - saveData(); } void subDivLoop() { + for (int i = 0; i < tris.size(); ++i) { + Tri triag = tris[i]; + Vertex a = pts[triag.iv[0]]; + Vertex b = pts[triag.iv[1]]; + Vertex c = pts[triag.iv[2]]; + + for (int tI = 0; tI < 3; ++tI) { + Tri t = tris[triag.it[tI]]; + int otherEI = 0; + for (int j = 0; j < 3; ++j) { + if (t.it[j] == i) { + otherEI = j; + break; + } + } + if (i < triag.it[tI]) { + Vertex d = pts[t.iv[otherEI]]; + Vertex e = (1.0f/8.0f)*((((tI == 1 || tI == 2) ? 3.0f : 1.0f)*a) + (((tI == 0 || tI == 2) ? 3.0f : 1.0f)*b) + (((tI == 1 || tI == 0) ? 3.0f : 1.0f)*c) + d); + triag.ie[tI] = pts.size(); + pts.push_back(e); + valences.push_back(0); + } else { + // edge-mask already calculated + + triag.ie[tI] = t.ie[otherEI]; + } + } + + tris[i] = triag; + } + for( int i=0; i< pts.size(); i++){ // multiply every vertex with beta - break; int n = valences[i]; // n = valence of v_i + if (n < 3) continue; float beta = beta_n( n); + cout << i << " " << n << " " << beta << " " <