NanoShaper  0.7.2
NanoShaper is a tool able to triangulate and inspect an arbitray triangulated surface or several types of molecular surfaces
C:/Documents and Settings/sdecherchi/My Documents/Ricerca/software nostro/NanoShaper0.7/src/tools.h
00001 
00002 //---------------------------------------------------------
00003 /*    @file             tools.h
00004 *     @brief    tools.h Includes some common tools
00005 *                                                                                                               */
00006 //---------------------------------------------------------
00007 
00008 #ifndef tools_h
00009 #define tools_h
00010 
00011 #include "globals.h"
00012 
00013 #ifdef DBGMEM_CRT
00014         #define _CRTDBG_MAP_ALLOC
00015         #define _CRTDBG_MAP_ALLOC_NEW
00016 #endif
00017 
00018 #include "./sturm/solve.h"
00019 #include <string>
00020 
00021 #include "jama_eig.h"
00022 
00023 using namespace TNT;
00024 using namespace JAMA;
00025 
00026 #define SMALL_SHIFT_MAP 7
00027 #define SHIFT_MAP 27
00028 
00030 
00031 static const int shift_map[SHIFT_MAP][3]=       {       
00032                                                 {0,0,0},
00033                                                 {0,0,-1},
00034                                                 {0,0,+1},
00035                                                 {0,+1,0},
00036                                                 {0,+1,-1},
00037                                                 {0,+1,+1},
00038                                                 {0,-1,0},
00039                                                 {0,-1,-1},
00040                                                 {0,-1,+1},
00041 
00042                                                 {+1,0,0},
00043                                                 {+1,0,-1},
00044                                                 {+1,0,+1},
00045                                                 {+1,+1,0},
00046                                                 {+1,+1,-1},
00047                                                 {+1,+1,+1},
00048                                                 {+1,-1,0},
00049                                                 {+1,-1,-1},
00050                                                 {+1,-1,+1},
00051 
00052                                                 {-1,0,0},
00053                                                 {-1,0,-1},
00054                                                 {-1,0,+1},
00055                                                 {-1,+1,0},
00056                                                 {-1,+1,-1},
00057                                                 {-1,+1,+1},
00058                                                 {-1,-1,0},
00059                                                 {-1,-1,-1},
00060                                                 {-1,-1,+1}      };
00061 
00062 
00063 static const boost::uint32_t MASK[32]={
00064         0x00000001,
00065         0x00000002,
00066         0x00000004,
00067         0x00000008, 
00068         0x00000010, 
00069         0x00000020, 
00070         0x00000040, 
00071         0x00000080, 
00072         0x00000100, 
00073         0x00000200, 
00074         0x00000400, 
00075         0x00000800, 
00076         0x00001000, 
00077         0x00002000, 
00078         0x00004000, 
00079         0x00008000, 
00080         0x00010000, 
00081         0x00020000,
00082         0x00040000, 
00083         0x00080000,
00084         0x00100000,
00085         0x00200000,
00086         0x00400000,
00087         0x00800000,
00088         0x01000000,
00089         0x02000000,
00090         0x04000000,
00091         0x08000000,
00092         0x10000000,
00093         0x20000000,
00094         0x40000000,
00095         0x80000000,
00096 };
00097 static const int shift_map2[SMALL_SHIFT_MAP][3]=        {       
00098                                                 {0,0,0},
00099                                                 {+1,0,0},
00100                                                 {0,+1,0},
00101                                                 {0,0,+1},
00102                                                 {-1,0,0},
00103                                                 {0,-1,0},
00104                                                 {0,0,-1}, };
00105 
00106 
00108 static const int edgeTable[256]={
00109         0x0  , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
00110         0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
00111         0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
00112         0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
00113         0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c,
00114         0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
00115         0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac,
00116         0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
00117         0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c,
00118         0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
00119         0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc,
00120         0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
00121         0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c,
00122         0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
00123         0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc ,
00124         0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
00125         0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
00126         0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
00127         0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
00128         0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
00129         0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
00130         0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
00131         0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
00132         0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460,
00133         0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
00134         0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0,
00135         0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
00136         0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230,
00137         0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
00138         0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190,
00139         0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
00140         0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0   };
00141 
00142 // xg-hside = 0
00143 // xg+hside = 1
00144 // yg-hside = 2
00145 // yg+hside = 3
00146 // zg-hside = 4
00147 // zg+hside = 5
00148 
00149 static const int mulTable[8][3] =
00150 {{0,2,4},
00151 {1,2,4},
00152 {1,3,4},
00153 {0,2,4},
00154 {0,2,5},
00155 {1,2,5},
00156 {1,3,5},
00157 {0,3,5}};
00158 
00159 static const int triTable[256][16] =
00160         {{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00161         {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00162         {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00163         {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00164         {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00165         {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00166         {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00167         {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1},
00168         {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00169         {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00170         {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00171         {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1},
00172         {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00173         {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1},
00174         {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1},
00175         {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00176         {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00177         {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00178         {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00179         {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1},
00180         {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00181         {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1},
00182         {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
00183         {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1},
00184         {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00185         {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1},
00186         {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
00187         {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1},
00188         {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1},
00189         {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1},
00190         {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1},
00191         {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1},
00192         {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00193         {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00194         {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00195         {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1},
00196         {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00197         {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
00198         {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1},
00199         {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1},
00200         {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00201         {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
00202         {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
00203         {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1},
00204         {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1},
00205         {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1},
00206         {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1},
00207         {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1},
00208         {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00209         {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1},
00210         {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1},
00211         {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00212         {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1},
00213         {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1},
00214         {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1},
00215         {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
00216         {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1},
00217         {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1},
00218         {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1},
00219         {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1},
00220         {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1},
00221         {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1},
00222         {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1},
00223         {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00224         {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00225         {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00226         {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00227         {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
00228         {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00229         {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1},
00230         {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1},
00231         {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1},
00232         {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00233         {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
00234         {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
00235         {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1},
00236         {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1},
00237         {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1},
00238         {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1},
00239         {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1},
00240         {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00241         {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1},
00242         {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
00243         {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1},
00244         {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1},
00245         {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1},
00246         {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1},
00247         {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1},
00248         {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
00249         {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1},
00250         {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1},
00251         {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1},
00252         {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1},
00253         {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1},
00254         {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1},
00255         {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1},
00256         {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00257         {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1},
00258         {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1},
00259         {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1},
00260         {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1},
00261         {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1},
00262         {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00263         {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1},
00264         {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1},
00265         {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1},
00266         {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1},
00267         {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1},
00268         {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1},
00269         {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1},
00270         {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1},
00271         {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00272         {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1},
00273         {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1},
00274         {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1},
00275         {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1},
00276         {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1},
00277         {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1},
00278         {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1},
00279         {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00280         {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1},
00281         {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1},
00282         {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1},
00283         {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1},
00284         {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1},
00285         {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00286         {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1},
00287         {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00288         {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00289         {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00290         {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00291         {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
00292         {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00293         {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
00294         {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
00295         {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1},
00296         {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00297         {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1},
00298         {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1},
00299         {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1},
00300         {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1},
00301         {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1},
00302         {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1},
00303         {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1},
00304         {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00305         {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1},
00306         {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1},
00307         {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1},
00308         {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1},
00309         {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1},
00310         {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1},
00311         {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1},
00312         {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1},
00313         {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00314         {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1},
00315         {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
00316         {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1},
00317         {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1},
00318         {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1},
00319         {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00320         {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00321         {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
00322         {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
00323         {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1},
00324         {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
00325         {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1},
00326         {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1},
00327         {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1},
00328         {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
00329         {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1},
00330         {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1},
00331         {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1},
00332         {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1},
00333         {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1},
00334         {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1},
00335         {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1},
00336         {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1},
00337         {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1},
00338         {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1},
00339         {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1},
00340         {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1},
00341         {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1},
00342         {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1},
00343         {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1},
00344         {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1},
00345         {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1},
00346         {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1},
00347         {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00348         {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1},
00349         {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1},
00350         {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00351         {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00352         {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00353         {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1},
00354         {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
00355         {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1},
00356         {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1},
00357         {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1},
00358         {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1},
00359         {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1},
00360         {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1},
00361         {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1},
00362         {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1},
00363         {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1},
00364         {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00365         {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1},
00366         {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
00367         {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00368         {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1},
00369         {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1},
00370         {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1},
00371         {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1},
00372         {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1},
00373         {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1},
00374         {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1},
00375         {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00376         {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1},
00377         {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1},
00378         {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1},
00379         {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1},
00380         {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
00381         {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00382         {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1},
00383         {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00384         {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1},
00385         {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1},
00386         {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1},
00387         {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1},
00388         {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1},
00389         {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1},
00390         {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1},
00391         {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1},
00392         {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1},
00393         {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1},
00394         {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1},
00395         {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00396         {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1},
00397         {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1},
00398         {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00399         {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00400         {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00401         {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1},
00402         {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1},
00403         {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00404         {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1},
00405         {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1},
00406         {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00407         {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00408         {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1},
00409         {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00410         {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1},
00411         {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00412         {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00413         {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00414         {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00415         {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}};
00416 
00418 
00419 #define MAX_POLY_DEGREE 10 // max polynomial degree supported by the bgp projection routine (6 is needed for skin, 4 by Connolly)
00420 
00422 
00424 class Point
00425 {
00426 public:
00427         double pos[3];  
00428         Point()
00429         {
00430                 pos[0]=0;
00431                 pos[1]=0;
00432                 pos[2]=0; 
00433         }
00434         Point(const double x,const double y,const double z)
00435         {
00436                 pos[0] = x;
00437                 pos[1] = y;
00438                 pos[2] = z;
00439         }
00440         Point(const Point& p)
00441         {
00442                 pos[0]= p.pos[0];
00443                 pos[1]= p.pos[1];
00444                 pos[2]= p.pos[2];
00445         }
00446         
00447         double squaredDist(const Point* const x)
00448         {
00449                 double acc =0;
00450                 for (int i=0;i<3;i++)
00451                 {       
00452                         double t = x->pos[i]-pos[i];
00453                         acc += t*t;
00454                 }
00455                 return acc;
00456         }
00457 
00458         double dot(const Point* const x)
00459         {
00460                 double acc =0;
00461                 for (int i=0;i<3;i++)
00462                         acc += x->pos[i]*pos[i];
00463                 return acc;
00464         }
00465 
00466 
00467         double norm(const Point* const  x)
00468         {
00469                 double acc =0;
00470                 for (int i=0;i<3;i++)
00471                         acc += (pos[i])*(pos[i]);
00472                 return sqrt(acc);
00473         }
00474         
00475         double dist(const Point *const x)
00476         {
00477                 double acc = 0;
00478                 for (int i=0;i<3;i++)
00479                 {
00480                         double t = x->pos[i]-pos[i];
00481                         acc += t*t;
00482                 }
00483                 return sqrt(acc);
00484         }
00485 
00486         void sumInPlace(const Point  *const x)
00487         {               
00488                 for (int i=0;i<3;i++)
00489                 {
00490                         pos[0]+=x->pos[0];      
00491                         pos[1]+=x->pos[1];
00492                         pos[2]+=x->pos[2];
00493                 }
00494         }
00495 
00496         Point* sum(const Point  *const x)
00497         {       
00498                 Point* p = new Point();
00499                 for (int i=0;i<3;i++)
00500                 {
00501                         p->pos[0]=pos[0]+x->pos[0];     
00502                         p->pos[1]=pos[1]+x->pos[1];     
00503                         p->pos[2]=pos[2]+x->pos[2];     
00504                 }
00505                 return p;
00506         }
00507 };
00508 
00509 class AtomInfo
00510 {
00511 protected:
00512         string name;
00513         int resNum;
00514         string resName;
00515         string chain;
00516 
00517 public:
00518         
00519         AtomInfo()
00520         {
00521                 name = "X";
00522                 resNum = -1;
00523                 resName = "UNK";
00524                 chain = "X";
00525         }
00526 
00527         AtomInfo(const string name,const int resNum,const string resName,const string chain)
00528         {
00529                 this->name = name;
00530                 this->resNum = resNum;
00531                 this->resName = resName;
00532                 this->chain = chain;
00533         }
00534 
00535         const string& getName()
00536         {
00537                 return name;
00538         }
00539 
00540         void setName(const string name)
00541         {
00542                 this->name = name;
00543         }
00544 
00545         const string& getResName()
00546         {
00547                 return resName;
00548         }
00549 
00550         void setResName(const string res)
00551         {
00552                 resName = res;
00553         }
00554 
00555         const int& getResNum()
00556         {
00557                 return resNum;
00558         }
00559 
00560         void setResNum(const int res)
00561         {
00562                 resNum = res;
00563         }
00564 
00565         void setChain(const string ch)
00566         {
00567                 chain = ch;
00568         }
00569 
00570         const string& getChain()
00571         {
00572                 return chain;
00573         }
00574         
00576         AtomInfo(const AtomInfo & p)
00577         {
00578                 name = p.name;
00579                 resNum = p.resNum;
00580                 resName = p.resName;
00581                 chain = p.chain;
00582         }
00583 };
00584 
00586 class Timer
00587 {
00588         private:
00589 
00590         #ifdef ENABLE_BOOST_CHRONO
00591                 boost::chrono::high_resolution_clock::time_point start_t,end_t;         
00592         #else
00593                 time_t start_t, end_t;
00594         #endif
00595 
00596         public:
00597 
00598                 Timer()
00599                 {
00600                 }
00601 
00602                 void start()
00603                 {
00604                         #ifdef ENABLE_BOOST_CHRONO
00605                                 start_t = boost::chrono::high_resolution_clock::now();
00606                         #else
00607                                 time(&start_t);
00608                         #endif                  
00609                 }
00610 
00611                 double stop()
00612                 {
00613                         #ifdef ENABLE_BOOST_CHRONO
00614                                 end_t = boost::chrono::high_resolution_clock::now();
00615                                 boost::chrono::milliseconds ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(end_t-start_t);
00616                                 return ms.count()/1000.;                        
00617                         #else
00618                                 time(&end_t);                           
00619                                 return difftime(end_t, start_t);
00620                         #endif                                  
00621                 }
00622 };
00623 
00625 class Atom: public Point
00626 {
00627 public:
00628         double radius;
00629         double radius2;
00630         double charge;
00631         int dielectric;
00632         AtomInfo ai;
00633 
00634         Atom():Point()
00635         {
00636                 radius=0;
00637                 charge=0;
00638                 dielectric=0; 
00639         }
00640         
00641         Atom(const double x,const double y,const double z,const double r,const double c,const int d):Point(x,y,z)
00642         {
00643                 radius = r;
00644                 radius2 = r*r;
00645                 charge = c;
00646                 dielectric = d;
00647         }
00648 
00649         Atom(const double x,const double y,const double z,const double r,const double c,const int d,const string name,const string resName,const int resNum,const string chain):Point(x,y,z)
00650         {
00651                 radius = r;
00652                 radius2 = r*r;
00653                 charge = c;
00654                 dielectric = d;         
00655                 ai.setName(name);
00656                 ai.setResName(resName);
00657                 ai.setChain(chain);
00658                 ai.setResNum(resNum);
00659         }
00660         
00661         // copy constructor
00662         Atom(Atom & p):Point(p)
00663         {
00664                 radius = p.radius;
00665                 charge = p.charge;
00666                 dielectric = p.dielectric;
00667                 ai.setChain(p.ai.getChain());
00668                 ai.setResNum(p.ai.getResNum());
00669                 ai.setResName(p.ai.getResName());
00670                 ai.setName(p.ai.getName());
00671         }
00672 
00673         void print()
00674         {
00675                 cout << endl << endl << "Atom Info:" << endl;
00676                 cout << "\tname -> " << ai.getName() << endl;
00677                 cout << "\tresidue name -> " << ai.getResName() << endl;
00678                 cout << "\tresidue number -> " << ai.getResNum() << endl;
00679                 cout << "\tchain -> " << ai.getChain() << endl;
00680                 cout << "\tposx -> " << pos[0] << endl ;
00681                 cout << "\tposy -> " << pos[1] << endl ;
00682                 cout << "\tposz -> " << pos[2] << endl ;
00683                 cout << "\tcharge -> " << charge << endl ;
00684                 cout << "\tradius -> " << radius << endl ;
00685                 cout << "\tdielectric -> " << dielectric;
00686         }
00687 
00688 };
00689 
00690 
00692 
00693 template<class T> void cleanDelete(T*& t)
00694 {
00695         if (t!=NULL)
00696         {
00697                 delete t;
00698                 t = NULL;
00699         }
00700         else
00701         {
00702                 cout << endl << WARN << "Attempting to de-allocate a null object!";
00703         }
00704 }
00705 
00706 template<class T> void cleanDeleteV(T*& t)
00707 {
00708         if (t!=NULL)
00709         {
00710                 delete[] t;
00711                 t = NULL;
00712         }
00713         else
00714         {
00715                 cout << endl << WARN << "Attempting to de-allocate a null vector object!";
00716         }
00717 }
00718 
00719 template<class T> inline T read4DVector(const T *const var,const int i,const int j,const int k,const int l,const int nx,const int ny,const int nz,const int nl)
00720 {
00721         #ifdef CHECK_BOUNDS
00722         if (i>=nx || j>=ny || k>=nz || l>=nl || i<0 || j<0 || k<0 || l<0)
00723         {
00724                 cout << endl << ERR << "Out of bound error in reading 4DVector";
00725                 exit(-1);
00726         }
00727         #endif
00728         
00729         size_t index = i+nx*(j+ny*(k+nz*l));
00730         return var[index];
00731 }
00732 
00733 template<class T> inline void write4DVector(T *const var,const T val,const int i,const int j,const int k,const int l,const int nx,const int ny,const int nz,const int nl)
00734 {
00735         #ifdef CHECK_BOUNDS
00736         if (i>=nx || j>=ny || k>=nz || l>=nl || i<0 || j<0 || k<0 || l<0)
00737         {
00738                 cout << endl << ERR << "Out of bound error in writing 4DVector";
00739                 exit(-1);
00740         }
00741         #endif
00742 
00743         size_t index = i+nx*(j+ny*(k+nz*l));
00744         var[index] = val;
00745 }
00746 
00747 template<class T> inline T read3DVector(const T *const var,const int i,const int j,const int k,const int nx,const int ny,const int nz)
00748 {
00749         #ifdef CHECK_BOUNDS
00750         if (i>=nx || j>=ny || k>=nz || i<0 || j<0 || k<0)
00751         {
00752                 cout << endl << ERR << "Out of bound error in reading 3DVector";
00753                 exit(-1);
00754         }
00755         #endif
00756 
00757         size_t index = i+nx*(j+ny*k);
00758         return var[index];
00759 }
00760 
00761 template<class T> inline void write3DVector(T *const var,const T val,const int i,const int j,const int k,const int nx,const int ny,const int nz)
00762 {
00763         #ifdef CHECK_BOUNDS
00764         if (i>=nx || j>=ny || k>=nz || i<0 || j<0 || k<0)
00765         {
00766                 cout << endl << ERR << "Out of bound error in writing 3DVector";
00767                 exit(-1);
00768         }
00769         #endif
00770 
00771         size_t index = i+nx*(j+ny*k);
00772         var[index] = val;
00773 }
00774 
00775 template<class T> inline T read2DVector(const T *const var,const int i,const int j,const int nx,const int ny)
00776 {
00777         #ifdef CHECK_BOUNDS
00778         if (i>=nx || j>=ny || i<0 || j<0)
00779         {
00780                 cout << endl << ERR << "Out of bound error in reading 2DVector";
00781                 exit(-1);
00782         }
00783         #endif
00784 
00785         size_t index = i+nx*j;
00786         return var[index];
00787 }
00788 
00789 template<class T> inline void write2DVector(T *const var,const T val,const int i,const int j,const int nx,const int ny)
00790 {
00791         #ifdef CHECK_BOUNDS
00792         if (i>=nx || j>=ny || i<0 || j<0)
00793         {
00794                 cout << endl << ERR << "Out of bound error in reading 2DVector";
00795                 exit(-1);
00796         }
00797         #endif
00798 
00799         size_t index = i+nx*j;
00800         var[index] = val;
00801 }
00802 
00803 template<class T> inline T readVector(const T *const var,const int i,const int nx)
00804 {
00805         #ifdef CHECK_BOUNDS
00806         if (i>=nx || i<0)
00807         {
00808                 cout << endl << ERR << "Out of bound error in reading Vector";
00809                 exit(-1);
00810         }
00811         #endif
00812         
00813         return var[i];
00814 }
00815 
00816 template<class T> inline void writeVector(T *const var,const T val,const int i,const int nx)
00817 {
00818         #ifdef CHECK_BOUNDS
00819         if (i>=nx || i<0)
00820         {
00821                 cout << endl << ERR << "Out of bound error in writing Vector";
00822                 exit(-1);
00823         }
00824         #endif
00825         var[index] = val;
00826 }
00827 
00828 
00829 template<class T> T* allocateVector(size_t n)
00830 {
00831         T* t = (T*)malloc(sizeof(T)*n);
00832         if (t==NULL)
00833         {
00834                 cout << endl << ERR << "Not enough memory to allocate vector ";
00835                 return NULL;
00836         }
00837         return t;
00838 }
00839 
00840 template<class T>  T** allocateMatrix2D(int nrows,int ncol)
00841 {
00842         T** t = (T**)malloc(sizeof(T*)*nrows);
00843         if (t==NULL)
00844         {
00845                 cout << endl << ERR << "Not enough memory to allocate 2D matrix ";
00846                 return NULL;
00847         }
00848         for (int i=0;i<nrows;i++)
00849         {
00850                 t[i] = (T*)malloc(sizeof(T)*ncol);
00851                 
00852                 if (t[i]==NULL)
00853                 {
00854                         cout << endl << ERR << "Not enough memory to allocate 2D matrix ";
00855                         return NULL;
00856                 }       
00857         }
00858         return t;
00859 }
00860 
00861 template<class T>  T*** allocateMatrix3D(int nx,int ny,int nz)
00862 {
00863         T*** t = (T***)malloc(sizeof(T**)*nx);
00864         if (t==NULL)
00865         {
00866                 cout << endl << ERR << "Not enough memory to allocate 3D matrix ";
00867                 return NULL;
00868         }
00869         for (int i=0;i<nx;i++)
00870         {
00871                 t[i] = (T**)malloc(sizeof(T*)*ny);
00872                 if (t[i]==NULL)
00873                 {       
00874                         cout << endl << ERR << "Not enough memory to allocate 3D matrix ";
00875                         return NULL;
00876                 }
00877 
00878                 for (int j=0;j<ny;j++)
00879                 {
00880                         t[i][j] =  (T*)malloc(sizeof(T)*nz);
00881                         if (t[i][j]==NULL)
00882                         {       
00883                                 cout << endl << ERR << "Not enough memory to allocate 3D matrix ";
00884                                 return NULL;
00885                         }
00886                 }
00887         }
00888         return t;
00889 }
00890 
00891 template<class T> void deleteVector(T*& t)
00892 {
00893         if (t!=NULL)
00894         {
00895                 free(t);
00896                 t = NULL;
00897         }
00898         else
00899         {
00900                 cout << endl << WARN << "Attempting to de-allocate a null vector!";
00901         }
00902 }
00903 
00904 template<class T> void deleteMatrix2D(int nrows,T**& t)
00905 {
00906         if (t!=NULL)
00907         {
00908                 for (int i=0;i<nrows;i++)
00909                         free(t[i]);
00910                 free(t);
00911                 t = NULL;
00912         }
00913         else
00914         {
00915                 cout << endl << WARN << "Attempting to de-allocate a null vector!";
00916         }
00917 }
00918 
00919 template<class T> void deleteMatrix3D(int nx,int ny,T***& t)
00920 {
00921         if (t!=NULL)
00922         {
00923                 for (int i=0;i<nx;i++)
00924                 {
00925                         for (int j=0;j<ny;j++)
00926                                 free(t[i][j]);
00927                         free(t[i]);
00928                 }
00929                 free(t);
00930                 t = NULL;
00931         }
00932         else
00933         {
00934                 cout << endl << WARN << "Attempting to de-allocate a null vector!";
00935         }
00936 }
00937 
00939 
00942 inline boost::uint32_t* allocateVectorBool(size_t n)
00943 {
00944         int nw = n/32;
00945         if ((n%32)!=0)
00946                 nw++;
00947         boost::uint32_t* ptr = (boost::uint32_t*)malloc(nw*4);
00948         if (ptr==NULL)
00949                 cout << endl << ERR << "Not enough memory to allocate bit vector";      
00950         return ptr;
00951 }
00952 
00953 inline void deleteVectorBool(boost::uint32_t*& t)
00954 {
00955         if (t!=NULL)
00956         {
00957                 free(t);
00958                 t = NULL;
00959         }
00960         else
00961         {
00962                 cout << endl << WARN << "Attempting to de-allocate a null bool vector!";
00963         }
00964 }
00965 
00966 inline bool read3DVectorBool(boost::uint32_t* const var,const int i,const int j,const int k,const int nx,const int ny,const int nz)
00967 {
00968         #ifdef CHECK_BOUNDS
00969         if (i>=nx || j>=ny || k>=nz || i<0 || j<0 || k<0)
00970         {
00971                 cout << endl << ERR << "Out of bound error in reading 3DVector";
00972                 exit(-1);
00973         }
00974         #endif
00975 
00976         size_t index = i+nx*(j+ny*k);
00977         size_t word_index = index/32;
00978         size_t position = index%32;
00979         boost::uint32_t mask = MASK[position];
00980         return ((var[word_index] & mask)==mask);
00981 }
00982 
00983 inline void write3DVectorBool(boost::uint32_t* const var,const bool val, const int i,const int j,const int k,const int nx,const int ny,const int nz)
00984 {
00985         #ifdef CHECK_BOUNDS
00986         if (i>=nx || j>=ny || k>=nz || i<0 || j<0 || k<0)
00987         {
00988                 cout << endl << ERR << "Out of bound error in reading 3DVector";
00989                 exit(-1);
00990         }
00991         #endif
00992 
00993         size_t index = i+nx*(j+ny*k);
00994         size_t word_index = index/32;
00995         size_t position = index%32;
00996         boost::uint32_t mask = MASK[position];
00997         var[word_index]= val ? (var[word_index] | mask) : (var[word_index] & ~mask) ;
00998 }
00999 
01004 template<class T> T* allocateAlignedVector(size_t n,int bitAlignment) 
01005 {
01006     T* mem = (T*)malloc(n*sizeof(T)+bitAlignment+sizeof(void*));
01007     T** ptr = (T**)((long)(mem+bitAlignment+sizeof(void*)) & ~(bitAlignment-1));
01008     ptr[-1] = mem;
01009 
01010         if (mem==NULL)
01011         {
01012                 cout << endl << ERR << "Not enough memory to allocate aligned vector ";
01013                 return NULL;
01014         }
01015 
01016     return (T*)ptr;
01017 }
01018 
01019 template<class T> void deleteAlignedVector(T*& ptr) 
01020 {
01021         if (ptr==NULL)
01022         {
01023                 cout << endl << WARN << "Attempting to de-allocate a null aligned vector!";
01024                 return;
01025         }
01026 
01027     free(((T**)ptr)[-1]);
01028         ptr = NULL;
01029 }
01030 
01031 
01033 
01035 bool compKeepIndex(pair<double,double*> a, pair<double,double*> b);
01036 
01038 
01039 typedef std::pair<double,int> indexed_double;
01040 bool index_double_comparator( const indexed_double& l, const indexed_double& r);
01041 
01043 
01047 bool testInCube(const double proj0,const double proj1,const double proj2,const double point0,const double point1,const double point2,const double side,const double toll=0);
01048 double rintp(const double x);
01049 string toLowerCase(string str);
01050 void cleanLine();
01051 
01052 static long int SEED=1234;
01053 // randnumber between 0 and 1
01054 double randnum();
01055 
01059 void getRealRootsCompanion(double *const poly,const int degree,double *const roots,int& numroots);
01062 void getRealRootsSturm(const double *const polyy,const int degree,double *const roots,int& numrootss);
01064 void plane3points(const double p1[3],const double p2[3],const double p3[3],double w[4],const bool normalize=true);
01066 void point2plane(const double p[3],double w[4],double* const dist, double proj[3]);
01068 void inplace_invert4x4(double M[4][4]);
01070 void Matrix4x4MultiplyBy4x4 (const double src1[4][4],const double src2[4][4], double dest[4][4]);
01072 bool raySphere(const double *const orig,const double *const dir,const double *const sphere_center,const double sphere_radius,double *const t1,double *const t2);
01074 void getNormalToSphere(const double *const y,const double *const center,const double radius,double *const normal);
01076 void projectToSphere(const double* const y,const double *const center,const double radius,double *const proj,double& dist);
01077 
01078 
01079 #endif