NanoShaper  0.3.1
NanoShaper is a tool able to triangulate and inspect an arbitray triangulated surface or several types of molecular surfaces such as the Gaussian, Skin and the SES
C:/Documents and Settings/sdecherchi/My Documents/Ricerca/software nostro/NanoShaper 0.3.1/NanoShaper/src/MeshSurface.h
Go to the documentation of this file.
00001 
00002 //---------------------------------------------------------
00006 //---------------------------------------------------------
00007 
00008 #ifndef MeshSurface_h
00009 #define MeshSurface_h
00010 
00011 #include "Surface.h"
00012 #include "./ply/ply.h"
00013 
00015 #define EPS 1e-5
00016 
00017 // enable or disable culling in intersect_triangle routine 
00018 //#define TEST_CULL 
00019 
00020 #define GRID_TRIANGLEMAP_2D(i,j,k,NA,NB) gridTriangleMap2D[(k)+(MAX_TRIANGLES_2D-1)*((j)+(NB)*(i))]
00021 #define GRIDTRIANGLEMAP(i,j,k,l,NX,NY,NZ) gridTriangleMap[(l)+(MAX_TRIANGLES-1)*((k)+(NZ)*((j)+(NY)*(i)))]
00022 
00030 class MeshSurface: public Surface
00031 {
00032 protected:
00033         unsigned int MAX_TRIANGLES;
00034         unsigned int AUX_GRID_DIM;
00035         unsigned int MAX_TRIANGLES_2D;
00036         unsigned int AUX_GRID_DIM_2D;
00037         int numVertexes;
00038         int numTriangles;
00039         int** faceMatrix;
00040         double** vertMatrix;    
00042         int* gridTriangleMap;
00044         int* gridTriangleMap2D;
00046         int nx,ny,nz;
00047         double scale;
00048         double side;
00049         double*x,*y,*z;
00050         double xmin,xmax,ymin,ymax,zmin,zmax;
00051         unsigned short*** ind;
00052         double** planes;
00053 
00055         int nx_2d,ny_2d,nz_2d;
00056         double scale_2d;
00057         double side_2d;
00058         double xmin_2d,xmax_2d,ymin_2d,ymax_2d,zmin_2d,zmax_2d;
00059         unsigned int** ind_2d;
00060 
00062         vector<int>** vertexTrianglesList;
00064         double** vertNormals;
00067         bool computeNormals;
00069         virtual void preProcessPanel();
00071         void preProcessTriangles();
00073         bool buildAuxiliaryGrid();
00075         int intersect_triangle(double orig[3], double dir[3],double vert0[3], double vert1[3], double vert2[3],double *t, double *u, double *v);
00080         bool point2triangle(double P[3],double A[3], double B[3], double C[3],double w[4],
00081                 double* proj,double *dist,double* normal,int planeID,int va,int vb,int vc);
00083         void point2plane(double p[3], double w[4],double* dist, double proj[3]);
00084         /* flag = inTriangle(P,A,B,C)
00085         says if the point p is in triangle or not
00086         flag is +1 if the vertex is in and -1 if it is out
00087         given the vertices A,B,C*/
00088         bool inTriangle(double P[3], double A[3], double B[3], double C[3]);
00090         bool checkDuplicates();
00092         bool loadOFF(char* fileName);
00094         bool loadPLY(char* fileName);
00095 
00096 public:
00098         MeshSurface();
00100         MeshSurface(DelPhiShared* ds);                  
00101 
00103 
00104         virtual bool build()
00105         {
00106                 return true;
00107         }
00108 
00109         virtual void postRayCasting()
00110         {
00111                 // remove 2d grid for ray casting 
00112                 if (gridTriangleMap2D!=NULL)
00113                         deleteVector<int>(gridTriangleMap2D);   
00114                 
00115                 if (ind_2d!=NULL)
00116                         deleteMatrix2D<unsigned int>(last_rows_ind,ind_2d);
00117 
00118                 gridTriangleMap2D = NULL;
00119                 ind_2d = NULL;
00120         }
00121 
00122         virtual bool preBoundaryProjection()
00123         {
00124                 // 3d grid is necessary only for boundary grid points projection
00125                 if (projBGP)
00126                         return buildAuxiliaryGrid();
00127                 return false;
00128         }
00129 
00131         virtual bool save(char* fileName);
00133         virtual bool load(char* fileName);
00135         bool loadMSMS(char* fileName,int numFiles=1);
00137         virtual void printSummary();            
00139         virtual bool getProjection(double p[3],double* proj1,double* proj2,
00140                 double* proj3,double* normal1,double* normal2,double* normal3);
00146         virtual void getRayIntersection(double p1[3],double p2[3],vector<pair<double,double*> >& intersections,int thdID);              
00148 
00149         void setAuxGrid(unsigned int dim,unsigned int max)
00150         {               
00151                 AUX_GRID_DIM = dim;
00152                 MAX_TRIANGLES = max;
00153         }
00154 
00158         void setAuxGrid2D(unsigned int dim,unsigned int max)
00159         {               
00160                 AUX_GRID_DIM_2D = dim;
00161                 MAX_TRIANGLES_2D = (max*dim);
00162         }
00163 
00164         virtual ~MeshSurface();
00165 };
00166 
00167 #endif