-
Notifications
You must be signed in to change notification settings - Fork 4
/
MGrid.h
138 lines (108 loc) · 3.49 KB
/
MGrid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Pharmit
Copyright (c) David Ryan Koes, University of Pittsburgh and contributors.
All rights reserved.
Pharmit is licensed under both the BSD 3-clause license and the GNU
Public License version 2. Any use of the code that retains its reliance
on the GPL-licensed OpenBabel library is subject to the terms of the GPL2.
Use of the Pharmit code independently of OpenBabel (or any other
GPL2 licensed software) may choose between the BSD or GPL licenses.
See the LICENSE file provided with the distribution for more information.
*/
/*
* MGrid.h
*
* Created on: Nov 21, 2011
* A class for representing a grid of molecular data.
* Author: dkoes
*/
#ifndef MGRID_H_
#define MGRID_H_
#include <cassert>
#include <bm/bm.h>
#include <vector>
#include "Cube.h"
#include <eigen3/Eigen/Core>
typedef bm::bvector<bm::standard_allocator> bvect;
class MGrid
{
void gridToPoint(unsigned long g, double& x, double& y, double& z) const;
int pointToGrid(double x, double y, double z) const;
void markZChord(double x, double y, double z, double r);
void markYZCircle(double x, double y, double z, double r);
void shrinkByOne();
void growByOne();
void makeFace(Eigen::Vector3f pt, int which, double r,
vector<Eigen::Vector3f>& vertices, vector<Eigen::Vector3f>& normals, vector<int>& faces);
double dimension; //max size, in distance unites
double resolution; //size of each grid cube
bvect grid;
public:
struct Point
{
float x, y, z;
Point(): x(0), y(0), z(0) {}
Point(float X, float Y, float Z): x(X), y(Y), z(Z) {}
};
MGrid(): dimension(32), resolution(0.5) {}
MGrid(float d, float r): dimension(d), resolution(r) {}
~MGrid() {}
void markXYZSphere(double x, double y, double z, double r);
double getResolution() const { return resolution; }
double getDimension() const { return dimension; }
void copyFrom(const MGrid& from); //keeps current grid dim/res, samples from from
bool test(float x, float y, float z) const
{
int pt = pointToGrid(x,y,z);
if(pt >= 0)
return grid.test(pt);
else
return true; //for exposed point testing and shrinking this makes the most sense
}
bool inGrid(float x, float y, float z) const
{
return pointToGrid(x,y,z) >= 0;
}
//test for x,y,z - match signature expected from oct tree creation
bool containsPoint(float x, float y, float z) const
{
return test(x,y,z);
}
//return true if possibly intersects cube - by always returning true
//explores every grid point with contains point resulting in some
//unnecessary oct-tree creation
bool intersects(const Cube& cube) const
{
return true;
}
void setPoint(float x, float y, float z);
void makeSurface(const MGrid& sagrid, double probe);
bool isInteriorPoint(float x, float y, float z) const;
bool isExposedPoint(float x, float y, float z) const;
bool isSolitaryPoint(float x, float y, float z) const;
//return true if at least part of the sphere fits in the grid
bool sphereInGrid(float x, float y, float z, float r) const;
void shrink(double amount);
void grow(double amount);
void operator&=(MGrid& rhs)
{
assert(dimension == rhs.dimension && resolution == rhs.resolution);
grid &= rhs.grid;
}
void operator|=(MGrid& rhs)
{
assert(dimension == rhs.dimension && resolution == rhs.resolution);
grid |= rhs.grid;
}
void clear()
{
grid.clear();
}
unsigned numSet() const
{
return grid.count();
}
void getSetPoints(std::vector<Point>& points) const;
void makeMesh(vector<Eigen::Vector3f>& vertices, vector<Eigen::Vector3f>& normals, vector<int>& faces);
};
#endif /* MGRID_H_ */