-
Notifications
You must be signed in to change notification settings - Fork 7
/
PDSampling.h
177 lines (123 loc) · 3.89 KB
/
PDSampling.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// $Id: PDSampling.h,v 1.6 2006/07/06 23:13:18 zr Exp $
#include <vector>
#include "RNG.h"
#define kMaxPointsPerCell 9
double timeInSeconds(void);
class RangeList;
class ScallopedRegion;
class Vec2 {
public:
Vec2() {};
Vec2(float _x, float _y) : x(_x), y(_y) {};
float x,y;
float length() { return sqrt(x*x + y*y); }
bool operator ==(const Vec2 &b) const { return x==b.x && y==b.y; }
Vec2 operator +(Vec2 b) { return Vec2(x+b.x, y+b.y); }
Vec2 operator -(Vec2 b) { return Vec2(x-b.x, y-b.y); }
Vec2 operator *(Vec2 b) { return Vec2(x*b.x, y*b.y); }
Vec2 operator /(Vec2 b) { return Vec2(x/b.x, y*b.y); }
Vec2 operator +(float n) { return Vec2(x+n, y+n); }
Vec2 operator -(float n) { return Vec2(x-n, y-n); }
Vec2 operator *(float n) { return Vec2(x*n, y*n); }
Vec2 operator /(float n) { return Vec2(x/n, y*n); }
Vec2 &operator +=(Vec2 b) { x+=b.x; y+=b.y; return *this; }
Vec2 &operator -=(Vec2 b) { x-=b.x; y-=b.y; return *this; }
Vec2 &operator *=(Vec2 b) { x*=b.x; y*=b.y; return *this; }
Vec2 &operator /=(Vec2 b) { x/=b.x; y/=b.y; return *this; }
Vec2 &operator +=(float n) { x+=n; y+=n; return *this; }
Vec2 &operator -=(float n) { x-=n; y-=n; return *this; }
Vec2 &operator *=(float n) { x*=n; y*=n; return *this; }
Vec2 &operator /=(float n) { x/=n; y/=n; return *this; }
};
///
class PDSampler {
protected:
RNG m_rng;
std::vector<int> m_neighbors;
int (*m_grid)[kMaxPointsPerCell];
int m_gridSize;
float m_gridCellSize;
public:
std::vector<Vec2> points;
float radius;
bool isTiled;
public:
PDSampler(float radius, bool isTiled, bool usesGrid=true);
virtual ~PDSampler() { };
//
bool pointInDomain(Vec2 &a);
// return shortest distance between _a_
// and _b_ (accounting for tiling)
float getDistanceSquared(Vec2 &a, Vec2 &b) { Vec2 v = getTiled(b-a); return v.x*v.x + v.y*v.y; }
float getDistance(Vec2 &a, Vec2 &b) { return sqrt(getDistanceSquared(a, b)); }
// generate a random point in square
Vec2 randomPoint();
// return tiled coordinates of _v_
Vec2 getTiled(Vec2 v);
// return grid x,y for point
void getGridXY(Vec2 &v, int *gx_out, int *gy_out);
// add _pt_ to point list and grid
void addPoint(Vec2 pt);
// populate m_neighbors with list of
// all points within _radius_ of _pt_
// and return number of such points
int findNeighbors(Vec2 &pt, float radius);
// return distance to closest neighbor within _radius_
float findClosestNeighbor(Vec2 &pt, float radius);
// find available angle ranges on boundary for candidate
// by subtracting occluded neighbor ranges from _rl_
void findNeighborRanges(int index, RangeList &rl);
// extend point set by boundary sampling until domain is
// full
void maximize();
// apply one step of Lloyd relaxation
void relax();
//
virtual void complete() = 0;
};
///
class DartThrowing : public PDSampler {
private:
int m_minMaxThrows, m_maxThrowsMult;
public:
DartThrowing(float radius, bool isTiled, int minMaxThrows, int maxThrowsMult);
virtual void complete();
};
///
class BestCandidate : public PDSampler {
private:
int m_multiplier, m_N;
public:
BestCandidate(float radius, bool isTiled, int multiplier);
virtual void complete();
};
///
class BoundarySampler : public PDSampler {
public:
BoundarySampler(float radius, bool isTiled) : PDSampler(radius, isTiled) {};
virtual void complete();
};
///
class PureSampler : public PDSampler {
public:
PureSampler(float radius) : PDSampler(radius, true) {};
virtual void complete();
};
///
class LinearPureSampler : public PDSampler {
public:
LinearPureSampler(float radius) : PDSampler(radius, true) {};
virtual void complete();
};
///
class PenroseSampler : public PDSampler {
public:
PenroseSampler(float radius) : PDSampler(radius, false, false) {};
virtual void complete();
};
///
class UniformSampler : public PDSampler {
public:
UniformSampler(float radius) : PDSampler(radius, false, false) {};
virtual void complete();
};