$search
00001 #ifndef MESH_HH 00002 #define MESH_HH 00003 00004 /* 00005 James R. Diebel 00006 Stanford University 00007 00008 Started: 23 August 2004 00009 Last revised: 27 Sugust 2004 00010 00011 mesh.hh - defines Mesh class that stores an arbitrary triangular mesh with 00012 various per-vertex, per-face, and per-edge properties; uses pointers to 00013 encode connectivity information. 00014 00015 Depends on: 00016 - Vert class (vert.hh) 00017 -- Vec3d class (vec3d.hh) 00018 - Edge class (edge.hh) 00019 - Face class (face.hh) 00020 00021 There is no functionality for resizing the mesh, although vertices and faces 00022 may be flagged as inactive to effectively delete them. 00023 */ 00024 00025 #include <fstream> 00026 #include <vector> 00027 #include "region.hh" 00028 #include "vert.hh" 00029 #include "edge.hh" 00030 #include "face.hh" 00031 #include "timer.hh" 00032 #include "uspline.hh" 00033 00034 namespace bmtk { 00035 00036 using namespace std; 00037 00038 class Mesh { 00039 public: 00040 // Data 00041 char* filename; // filename associated with this mesh 00042 int nv,ne,nf,nr,nn; // #'s of things 00043 int nd; // number of datasets with same topology 00044 Vert* v; // global vertex list 00045 Edge* e; // global edge list 00046 Face* f; // global face list 00047 Region* r; // global region list; 00048 int* q; // a buffer of size nf used as a flood-fill queue 00049 int* qv; // similarly, a queue buffer, but for vertices, not faces 00050 00051 Vec3d boxMin, boxMax; // bounding box 00052 float box; // scale of the bounding box 00053 float l; // global length scale - median edge length 00054 00055 float psi; // global mesh potential 00056 float psiVert; // only the vertex part of the global potential 00057 float psiEdge; // only the edge part of the global potential 00058 float normGradPsi; // norm of gradient over entire mesh 00059 float normDir; // norm of current direction vector 00060 float rho[2]; // scaling factors for computing conjugate directions 00061 int iter; // CG iteration number 00062 int nStepsForReset; // number of CG iterations before reset 00063 int wroteIter; // last iteration that was written 00064 int maxIter; // maximum number of iterations to run 00065 00066 USpline* psiSpline; // spline representation of edge potential function 00067 00068 bool ib; // include boundary regions in computations 00069 bool po; // print output to screen 00070 float gs2; // global scaling factor for vertex variance 00071 float gsn2; // global variance for edge potential 00072 float segThresh; // threshold used in segmentation algorithm 00073 00074 // Tools 00075 ofstream foutConv; 00076 bool ut; // use timer or not 00077 Timer *tCG; 00078 Timer *tLS; 00079 Timer *tMP; 00080 Timer *tVG; 00081 Timer *tFN; 00082 void (*callBack)(); 00083 int callBackExists; 00084 00085 // Methods 00086 // constructor, destructor, destructor tool 00087 Mesh(); 00088 ~Mesh(); 00089 void cleanUp(); 00090 00091 // callback for refreshing GUI 00092 void registerCB(void (*callBack_)(void)); 00093 void update(); 00094 00095 // functions to set global properties 00096 void setVertVar(float gs2_); 00097 void setNormalVar(float gsn2_); 00098 00099 // general mesh properties 00100 void findBBox(); 00101 void normalize(); 00102 void findLength(); 00103 Mesh* pruneFaces(float factor); 00104 void findMeshProps(); 00105 void reset(); 00106 void findMeshPotential(); 00107 void findPotentials(); 00108 void doBisectionLineSearch(); 00109 void doNewtonLineSearch(); 00110 void runCG(); 00111 void anneal(); 00112 void writeConvDetails(); 00113 00114 // per face properties 00115 void findFaceNormals(); 00116 void findFaceCenters(); 00117 void findFaceDistances(); 00118 void findFaceAreas(); 00119 void findFaceProps(); 00120 void saveRefNormals(); 00121 void blurFaceNormals(int num); 00122 void resetFaceFlags(); 00123 00124 // per edge properties 00125 void findEdgeLengths(); 00126 void findEdgeAngles(); 00127 void findEdgeProps(); 00128 void findEdgePotentials(); 00129 void resetEdgeFlags(); 00130 00131 // per vertex properties 00132 void resetVertFlags(); 00133 void findVertNormals(); 00134 void findVertLengths(); 00135 void findVertProps(); 00136 void findVertDepths(); 00137 void findVertPotentials(); 00138 void findLocalEdgePotentials(); 00139 void findVertGradients(); 00140 void findVertCurvature(); 00141 void findNormGradPsi(); 00142 void findSearchDirs(bool reset = false); 00143 void saveRefVerts(); 00144 void moveVerts(float step); 00145 void moveVerts(); 00146 void vertFaceConsistency(int num); 00147 00148 // region functions 00149 void clearRegionProps(); 00150 void findRegionFaceLists(); 00151 void findRegionProps(); 00152 void findRegionNormals(); 00153 void findRegionSmoothNormals(); 00154 void findRegionSmoothNormalsOld(); 00155 void findRegionProjDist(); 00156 void findRegionVariances(); 00157 void renumberRegions(); 00158 void doSegmentationStep(); 00159 void runSegmentation(); 00160 void swapFace(Face& fi, Region& ri, Region& rj); 00161 void mergeRegions(Region& ri, Region& rj, Face& fi); 00162 void findBoundaries(); 00163 void markKeypoints(); 00164 void traceBoundary(Vert* vi, Edge* ei, Face* fi, Region* ri); 00165 void triangulateContours(); 00166 Mesh* genDecimatedMesh(); 00167 00168 // I/O functions 00169 void exportToPLY(char* plyfile); 00170 void buildFromPLY(char* plyfile); 00171 void buildFromMAP(char* mapfile, char* intfile); 00172 void buildFromGTS(char* plyfile); 00173 void buildFromLST(char* listfile); 00174 void exportToTMF(char* tmffile); 00175 void exportRegions(char* regfile); 00176 void importRegions(char* regfile); 00177 void buildFromTMF(char* tmffile); 00178 void buildFromOFF(char* offfile); 00179 void applyLineOfSightCovar(float sr); 00180 vector<int> buildFrom(float* vert, int numvert, 00181 int* faces, int numfaces); 00182 void fillVertsAndFaces(float* vertices, int numverts, 00183 int* faces, int numfaces); 00184 int findInterFaceLinks(); 00185 int readOptions(char *filename); 00186 int writeOptions(char *filename); 00187 int writeMesh(char *filename); 00188 int readMesh(char *filename); 00189 00190 // Equality tests 00191 bool operator == (const Mesh &m) const; 00192 bool operator != (const Mesh &m) const; 00193 }; 00194 00195 } // namespace bmtk 00196 00197 #endif