UnityMol  1.0.25beta
NeighborSearch.hpp
Go to the documentation of this file.
1 #if defined(__unix__) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__)
2 #define OS_UNIX
3 #endif
4 
5 #if defined(__APPLE__) || defined(__MACH__)
6 #define OS_OSX
7 #endif
8 
9 #if defined(_MSC_VER)
10 #define OS_WINDOWS
11 #endif
12 
13 //
14 // API export macro
15 // //
16 // #if defined(OS_OSX)
17 // #define API __attribute__((visibility("default")))
18 // #elif defined(OS_WINDOWS)
19 #define API __declspec(dllexport)
20 // #else
21 // #define API
22 // #endif
23 
24 
25 int clamp(int x, int minV, int maxV) {
26  return max(minV, max(x, minV));
27 }
28 
29 float computeMaxDist(float3 minVal, float3 maxVal, float maxAtomRad) {
30  return std::max(maxVal.x - minVal.x, std::max(maxVal.y - minVal.y, maxVal.z - minVal.z)) + (2 * maxAtomRad);
31 }
32 
33 
34 int3 spaceToGrid(float3 pos3D, float3 originGrid, float dx) {
35 
36  // float3 tmp = ((pos3D - originGrid) / dx);
37 
38  int3 res;
39  res.x = (int)( (pos3D.x - originGrid.x) / dx);
40  res.y = (int)( (pos3D.y - originGrid.y) / dx);
41  res.z = (int)( (pos3D.z - originGrid.z) / dx);
42  return res;
43 
44 }
45 float3 gridToSpace(int3 cellPos, float3 originGrid, float dx) {
46  float3 res;
47  res.x = originGrid.x + cellPos.x * dx;
48  res.y = originGrid.y + cellPos.y * dx;
49  res.z = originGrid.z + cellPos.z * dx;
50  return res;
51  // return (originGrid + (make_float3(cellPos.x, cellPos.y, cellPos.z) * dx) );
52 }
53 
54 int flatten3DTo1D(int3 id3d, int3 gridDim) {
55  return (gridDim.y * gridDim.z * id3d.x) + (gridDim.z * id3d.y) + id3d.z;
56 }
57 
58 
59 int3 unflatten1DTo3D(int index, int3 gridDim) {
60  int3 res;
61  res.x = index / (gridDim.y * gridDim.z); //Note the integer division . This is x
62  res.y = (index - res.x * gridDim.y * gridDim.z) / gridDim.z; //This is y
63  res.z = index - res.x * gridDim.y * gridDim.z - res.y * gridDim.z; //This is z
64  return res;
65 }
66 
67 float sqr_distance(float3 p1, float3 p2) {
68  float x = (p1.x - p2.x) * (p1.x - p2.x);
69  float y = (p1.y - p2.y) * (p1.y - p2.y);
70  float z = (p1.z - p2.z) * (p1.z - p2.z);
71 
72  return x + y + z;
73 }
74 
75 struct compare_int2 {
76  bool operator()(int2 a, int2 b) {return a.x < b.x;}
77 };
78 
79 
80 
81 
82 void getMinMax(float3 *pos, float *radii, unsigned int N, float3 *minVal, float3 *maxVal, float *maxAtom) {
83 
84  *maxAtom = 0.0f;
85  float3 vmin, vmax, coords;
86 
87  vmin.x = vmin.y = vmin.z = 100000.0f;
88  vmax.x = vmax.y = vmax.z = -100000.0f;
89 
90  for (int a = 0; a < N; a++) {
91  coords = pos[a];
92  vmin.x = std::min(vmin.x, coords.x);
93  vmin.y = std::min(vmin.y, coords.y);
94  vmin.z = std::min(vmin.z, coords.z);
95 
96  vmax.x = std::max(vmax.x, coords.x);
97  vmax.y = std::max(vmax.y, coords.y);
98  vmax.z = std::max(vmax.z, coords.z);
99 
100  float atomRad = radii[a];
101 
102  *maxAtom = std::max(*maxAtom, atomRad);
103 
104  }
105  *minVal = vmin;
106  *maxVal = vmax;
107 }
108 
109 extern "C"{
110  API void initGridNeighbor(float3 *atomPos, float *radii, int N);
111  API int findClosestAtom(float3 p);
112  API int *findAtomsInRadius(float3 p, float rad, int *resSize);
113  API void freeMem();
114 }
void getMinMax(float3 *pos, float *radii, unsigned int N, float3 *minVal, float3 *maxVal, float *maxAtom)
Definition: NeighborSearch.hpp:82
float z
Definition: MarchingCubes.h:37
API void freeMem()
Definition: NeighborSearchLib.cpp:214
float computeMaxDist(float3 minVal, float3 maxVal, float maxAtomRad)
Definition: NeighborSearch.hpp:29
Definition: MarchingCubes.h:34
Definition: MarchingCubes.h:28
bool operator()(int2 a, int2 b)
Definition: NeighborSearch.hpp:76
Definition: NeighborSearch.hpp:75
int clamp(int x, int minV, int maxV)
Definition: NeighborSearch.hpp:25
Definition: cpdb.h:57
#define API
Definition: NeighborSearch.hpp:19
float sqr_distance(float3 p1, float3 p2)
Definition: NeighborSearch.hpp:67
API void initGridNeighbor(float3 *atomPos, float *radii, int N)
Definition: NeighborSearchLib.cpp:27
int3 unflatten1DTo3D(int index, int3 gridDim)
Definition: NeighborSearch.hpp:59
float y
Definition: MarchingCubes.h:36
API int * findAtomsInRadius(float3 p, float rad, int *resSize)
Definition: NeighborSearchLib.cpp:169
float3 gridToSpace(int3 cellPos, float3 originGrid, float dx)
Definition: NeighborSearch.hpp:45
int x
Definition: cpdb.h:59
int y
Definition: MarchingCubes.h:30
int3 spaceToGrid(float3 pos3D, float3 originGrid, float dx)
Definition: NeighborSearch.hpp:34
int z
Definition: MarchingCubes.h:31
int x
Definition: MarchingCubes.h:29
API int findClosestAtom(float3 p)
Definition: NeighborSearchLib.cpp:107
float x
Definition: MarchingCubes.h:35
int flatten3DTo1D(int3 id3d, int3 gridDim)
Definition: NeighborSearch.hpp:54