NanoShaper
0.7.2
NanoShaper is a tool able to triangulate and inspect an arbitray triangulated surface or several types of molecular surfaces
|
00001 00002 //--------------------------------------------------------- 00006 //--------------------------------------------------------- 00007 00008 #ifndef MeshSurface_h 00009 #define MeshSurface_h 00010 00011 #include "Surface.h" 00012 00013 #ifdef DBGMEM_CRT 00014 #define _CRTDBG_MAP_ALLOC 00015 #define _CRTDBG_MAP_ALLOC_NEW 00016 #endif 00017 00018 #include "./ply/ply.h" 00019 00021 #define EPS 1e-5 00022 00023 // enable or disable culling in intersect_triangle routine 00024 //#define TEST_CULL 00025 00026 #define GRID_TRIANGLEMAP_2D(i,j,k,NA,NB) gridTriangleMap2D[(k)+(MAX_TRIANGLES_2D-1)*((j)+(NB)*(i))] 00027 #define GRIDTRIANGLEMAP(i,j,k,l,NX,NY,NZ) gridTriangleMap[(l)+(MAX_TRIANGLES-1)*((k)+(NZ)*((j)+(NY)*(i)))] 00028 00036 class MeshSurface: public Surface 00037 { 00038 protected: 00039 unsigned int MAX_TRIANGLES; 00040 unsigned int AUX_GRID_DIM; 00041 unsigned int MAX_TRIANGLES_2D; 00042 unsigned int AUX_GRID_DIM_2D; 00043 int numVertexes; 00044 int numTriangles; 00045 int** faceMatrix; 00046 double** vertMatrix; 00048 int* gridTriangleMap; 00050 int* gridTriangleMap2D; 00052 int nx,ny,nz; 00053 double scale; 00054 double side; 00055 double*x,*y,*z; 00056 double xmin,xmax,ymin,ymax,zmin,zmax; 00057 unsigned short*** ind; 00058 double** planes; 00059 00061 int nx_2d,ny_2d,nz_2d; 00062 double scale_2d; 00063 double side_2d; 00064 double xmin_2d,xmax_2d,ymin_2d,ymax_2d,zmin_2d,zmax_2d; 00065 unsigned int** ind_2d; 00066 00068 vector<int>** vertexTrianglesList; 00070 double** vertNormals; 00073 bool computeNormals; 00075 virtual void preProcessPanel(); 00077 void preProcessTriangles(); 00079 bool buildAuxiliaryGrid(); 00081 int intersect_triangle(double orig[3], double dir[3],double vert0[3], double vert1[3], double vert2[3],double *t, double *u, double *v); 00086 bool point2triangle(double P[3],double A[3], double B[3], double C[3],double w[4], 00087 double* proj,double *dist,double* normal,int planeID,int va,int vb,int vc); 00089 void point2plane(double p[3], double w[4],double* dist, double proj[3]); 00090 /* flag = inTriangle(P,A,B,C) 00091 says if the point p is in triangle or not 00092 flag is +1 if the vertex is in and -1 if it is out 00093 given the vertices A,B,C*/ 00094 bool inTriangle(double P[3], double A[3], double B[3], double C[3]); 00096 bool checkDuplicates(); 00098 bool loadOFF(char* fileName); 00100 bool loadPLY(char* fileName); 00101 00102 public: 00104 MeshSurface(); 00106 MeshSurface(DelPhiShared* ds); 00108 MeshSurface(ConfigFile* cf,DelPhiShared* ds); 00109 00111 00112 virtual bool build() 00113 { 00114 return true; 00115 } 00116 00117 virtual void postRayCasting() 00118 { 00119 // remove 2d grid for ray casting 00120 if (gridTriangleMap2D!=NULL) 00121 deleteVector<int>(gridTriangleMap2D); 00122 00123 if (ind_2d!=NULL) 00124 deleteMatrix2D<unsigned int>(last_rows_ind,ind_2d); 00125 00126 // no more needed 00127 //gridTriangleMap2D = NULL; 00128 //ind_2d = NULL; 00129 } 00130 00131 virtual bool preBoundaryProjection() 00132 { 00133 // 3d grid is necessary only for boundary grid points projection 00134 if (projBGP) 00135 return buildAuxiliaryGrid(); 00136 return false; 00137 } 00138 00140 virtual bool save(char* fileName); 00142 virtual bool load(char* fileName); 00144 bool loadMSMS(char* fileName,int numFiles=1); 00146 virtual void printSummary(); 00148 virtual bool getProjection(double p[3],double* proj1,double* proj2, 00149 double* proj3,double* normal1,double* normal2,double* normal3); 00155 virtual void getRayIntersection(double p1[3],double p2[3],vector<pair<double,double*> >& intersections,int thdID,bool computeNormals); 00157 virtual void init(); 00159 virtual void init(ConfigFile* cf); 00161 virtual void clear(); 00163 00164 void setAuxGrid(unsigned int dim,unsigned int max) 00165 { 00166 AUX_GRID_DIM = dim; 00167 MAX_TRIANGLES = max; 00168 } 00169 00173 void setAuxGrid2D(unsigned int dim,unsigned int max) 00174 { 00175 AUX_GRID_DIM_2D = dim; 00176 MAX_TRIANGLES_2D = (max*dim); 00177 } 00178 00179 virtual ~MeshSurface(); 00180 }; 00181 00182 // expand it explicitly because Swig is not able to expand it 00183 static class MeshSurfaceRegister{ 00184 static Surface* createSurface(ConfigFile* conf,DelPhiShared* ds) 00185 { 00186 return new MeshSurface(conf,ds); 00187 } 00188 public: 00189 MeshSurfaceRegister() 00190 { 00191 surfaceFactory().add("mesh",createSurface); 00192 } 00193 } MeshSurfaceRegisterObject; 00194 00195 00196 //static SurfaceRecorder<MeshSurface> meshRecorder("mesh"); 00197 00198 #endif