$search
00001 /* 00002 James R. Diebel 00003 Stanford University 00004 00005 Started: 24 August 2004 00006 Last revised: 00007 00008 mesh_vert.cc - class implementation of Mesh class (mesh.hh) 00009 00010 Depends on: 00011 - Mesh class (mesh.hh) 00012 */ 00013 00014 #include "bmtk/mesh.hh" 00015 #include <iostream> 00016 00017 namespace bmtk { 00018 00020 // Per-Vertex Functions // 00022 void Mesh::resetVertFlags() { 00023 if (po) cout << "- Reseting vertex flags..." << flush; 00024 for (int i=0;i<nv;i++) v[i].flag = v[i].marker = -1; 00025 if (po) cout << "Done." << endl << flush; 00026 } 00027 00028 void Mesh::findVertNormals() { 00029 if (po) cout << "- Computing vertex normals..." << flush; 00030 for (int i=0;i<nv;i++) v[i].findNormal(); 00031 if (po) cout << "Done." << endl << flush; 00032 } 00033 00034 void Mesh::findVertLengths() { 00035 if (po) cout << "- Computing vertex lengths..." << flush; 00036 for (int i=0;i<nv;i++) v[i].findLength(); 00037 if (po) cout << "Done." << endl << flush; 00038 } 00039 00040 void Mesh::findVertProps() { 00041 if (po) cout << "- Computing vertex properties..." << flush; 00042 for (int i=0;i<nv;i++) { 00043 v[i].findNormal(); 00044 v[i].findLength(); 00045 } 00046 if (po) cout << "Done." << endl << flush; 00047 } 00048 00049 void Mesh::findVertDepths() { 00050 if (po) cout << "- Computing vertex depths..." << flush; 00051 for (int i=0;i<nv;i++) { 00052 v[i].findDepth(); 00053 } 00054 if (po) cout << "Done." << endl << flush; 00055 } 00056 00057 void Mesh::findVertPotentials() { 00058 if (po) cout << "- Computing vertex potentials..." << flush; 00059 for (int i=0;i<nv;i++) { 00060 v[i].findPotential(); 00061 } 00062 if (po) cout << "Done." << endl << flush; 00063 } 00064 00065 void Mesh::findLocalEdgePotentials() { 00066 if (po) cout << "- Computing local edge potentials..." << flush; 00067 bool temp = po; 00068 po = false; 00069 resetEdgeFlags(); 00070 po = temp; 00071 for (int i=0;i<nv;i++) { 00072 v[i].findLocalEdgePotential(); 00073 } 00074 if (po) cout << "Done." << endl << flush; 00075 } 00076 00077 void Mesh::findVertGradients() { 00078 if (ut) tVG->start(); 00079 if (po) cout << "- Computing local potential gradients..." << flush; 00080 bool temp = po; 00081 po = false; 00082 resetEdgeFlags(); 00083 if (temp) cout << " edge flags, " << flush; 00084 for (int i=0;i<nv;i++) { 00085 v[i].findGradient(); 00086 } 00087 po = temp; 00088 if (po) cout << "Done." << flush; 00089 if (po) tVG->printMark(); 00090 if (ut) tVG->mark(); 00091 } 00092 00093 void Mesh::findNormGradPsi() { 00094 if (po) 00095 cout << "- Computing magnitude of gradient along search direction..." 00096 << flush; 00097 normGradPsi = 0; 00098 for (int i=0;i<nv;i++) { 00099 normGradPsi += v[i].gradPsi.dot(v[i].dir); 00100 } 00101 if (po) cout << "Done." << endl << flush; 00102 } 00103 00104 void Mesh::findSearchDirs(bool reset) { 00105 if (po) cout << "- Computing search direction..." << flush; 00106 if (po) if (reset) cout << " with CG restart... " << flush; 00107 normDir = 0; 00108 rho[iter%2] = 0; 00109 for (int i=0;i<nv;i++) { 00110 rho[iter%2] += v[i].gradPsi.len2(); 00111 v[i].dir0 = v[i].dir; 00112 } 00113 if (reset) { 00114 for (int i=0;i<nv;i++) { 00115 v[i].dir = -v[i].gradPsi; 00116 normDir += ~(v[i].dir); 00117 } 00118 } else { 00119 float beta = rho[iter%2]/rho[(iter-1)%2]; 00120 if (po) cout << " beta = " << beta << ", " << flush; 00121 for (int i=0;i<nv;i++) { 00122 v[i].findSearchDir(beta); 00123 normDir += ~(v[i].dir); 00124 } 00125 } 00126 if (po) cout << "|d| = " << normDir/nv << ", Done." << endl << flush; 00127 } 00128 00129 void Mesh::saveRefVerts() { 00130 if (po) cout << "- Saving reference vertex positions..." << flush; 00131 for (int i=0;i<nv;i++) v[i].xr = v[i].x; 00132 if (po) cout << "Done." << endl << flush; 00133 } 00134 00135 void Mesh::moveVerts(float step) { 00136 if (po) cout << "- Moving vertices with global step..." << flush; 00137 for (int i=0;i<nv;i++) v[i].move(step); 00138 if (po) cout << "Done." << endl << flush; 00139 } 00140 00141 void Mesh::moveVerts() { 00142 if (po) cout << "- Moving vertices with local steps..." << flush; 00143 for (int i=0;i<nv;i++) v[i].move(); 00144 if (po) cout << "Done." << endl << flush; 00145 } 00146 00147 void Mesh::vertFaceConsistency(int num) { 00148 if (po) cout << "- Moving toward vertex-normal consistency..." << flush; 00149 bool temp = po; 00150 po = false; 00151 for (int i=0;i<num;i++) { 00152 saveRefVerts(); 00153 for (int i=0;i<nv;i++) v[i].flatten(); 00154 findFaceCenters(); 00155 } 00156 po = temp; 00157 if (po) cout << "Done." << endl << flush; 00158 } 00159 00160 } // namespace bmtk