Newer
Older
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
#ifndef PARAMS_H
#define PARAMS_H
#include <cmath>
#include <iostream>
#include <string.h>
#define PI 3.14159265f
///helper class for the PolarListAgent agents
class PolarPair {
public:
PolarPair() { ang = 0.f ; dist = 0.f; }
PolarPair(const float a, const float d) :
ang(a), dist(d) {}
float ang,dist;
};
///helper class to sort lists of this kind
class SortPolarPair {
public:
bool operator()(const PolarPair& a, const PolarPair& b) const
{ return(a.ang < b.ang); }
};
///simply a 3D vector...
template <typename T>
class Vector3d {
public:
///the vector data
T x,y,z;
///default constructor...
Vector3d(void) :
x(0), y(0), z(0) {}
///init constructor...
Vector3d(const T xx,const T yy,const T zz) :
x(xx), y(yy), z(zz) {}
///init constructor...
Vector3d(const T xyz) :
x(xyz), y(xyz), z(xyz) {}
///copy constructor...
Vector3d(const Vector3d<T>& vec)
{
this->x=vec.x;
this->y=vec.y;
this->z=vec.z;
}
void Reset(void)
{ x=y=z=0; }
T Len() const { return (T)sqrt (x*x + y*y + z*z); }
T Mod() const{ return (T)sqrt (x*x + y*y + z*z); }
T Mod2() const{ return x*x + y*y + z*z; }
T LenQ()const { return x*x + y*y + z*z; }
T Sum() { return x + y + z; }
Vector3d<T> Ort() const { T l = Len(); return l ? Vector3d<T>(x/l, y/l, z/l) : Vector3d<T>(0, 0, 0); }
Vector3d<T>& operator=(const Vector3d<T>& vec)
{
this->x=vec.x;
this->y=vec.y;
this->z=vec.z;
return( *this );
}
/// unary minus = negate
Vector3d<T> operator-() const { return Vector3d<T>(-x,-y,-z); }
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
Vector3d<T>& operator=(const T scalar)
{
this->x=scalar;
this->y=scalar;
this->z=scalar;
return( *this );
}
Vector3d<T>& operator+=(const Vector3d<T>& vec)
{
this->x+=vec.x;
this->y+=vec.y;
this->z+=vec.z;
return( *this );
}
Vector3d<T>& operator-=(const Vector3d<T>& vec)
{
this->x-=vec.x;
this->y-=vec.y;
this->z-=vec.z;
return( *this );
}
Vector3d<T>& operator*=(const T& scal)
{
this->x*=scal;
this->y*=scal;
this->z*=scal;
return( *this );
}
Vector3d<T>& operator/=(const T& scal)
{
this->x/=scal;
this->y/=scal;
this->z/=scal;
return( *this );
}
T Angle(const Vector3d<T> &p2) const
{
return (T)(acos(Ort() * p2.Ort()) * 180.0 / PI);
}
};
template <class T> inline Vector3d<T> operator+ (const Vector3d<T>& v1,
const Vector3d<T>& v2) {
Vector3d<T> v = v1; v += v2; return v; }
template <class T> inline Vector3d<T> operator- (const Vector3d<T>& v1,
const Vector3d<T>& v2) {
Vector3d<T> v = v1; v -= v2; return v; }
template <class T> inline T operator * (const Vector3d<T> &p,
const Vector3d<T> &p1) {
return p.x * p1.x + p.y * p1.y + p.z * p1.z; }
template <class T> inline Vector3d<T> operator+ (const Vector3d<T>& v, T s) {
return Vector3d<T>(v.x + s, v.y + s, v.z + s); }
template <class T> inline Vector3d<T> operator- (const Vector3d<T>& v, T s) {
return Vector3d<T>(v.x - s, v.y - s, v.z - s); }
template <class T> inline Vector3d<T> operator* (const Vector3d<T>& v, T s) {
return Vector3d<T>(v.x * s, v.y * s, v.z * s); }
template <class T> inline Vector3d<T> operator/ (const Vector3d<T>& v, T s) {
return Vector3d<T>(v.x / s, v.y / s, v.z / s); }
template <class T> inline Vector3d<T> operator+ (T s, const Vector3d<T>& v) {
return Vector3d<T>(s + v.x, s + v.y, s + v.z); }
template <class T> inline Vector3d<T> operator- (T s, const Vector3d<T>& v) {
return Vector3d<T>(s - v.x, s - v.y, s - v.z); }
template <class T> inline Vector3d<T> operator* (T s, const Vector3d<T>& v) {
return Vector3d<T>(s * v.x, s * v.y, s * v.z); }
template <class T> inline Vector3d<T> operator/ (T s, const Vector3d<T>& v) {
return Vector3d<T>(s / v.x, s / v.y, s / v.z); }
template <class T>
inline Vector3d<T> Mul (const Vector3d<T> &u, const Vector3d<T> &v)
{
return Vector3d<T> (u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x);
}
template <class T>
inline void Mul (const Vector3d<T> &u, const Vector3d<T> &v, Vector3d<T> &res)
{
res.x=u.y * v.z - u.z * v.y;
res.y=u.z * v.x - u.x * v.z;
res.z=u.x * v.y - u.y * v.x;
}
typedef Vector3d<float> Vector3F;
typedef Vector3d<float> Vector3FC;
//shape of the vectors:
#define CONE_HALFANG 0.5236f //30 deg
#define CONE_LENGTH 0.15f
//time-saver: params for the rotation matrix
const float cs=cosf(CONE_HALFANG);
const float sn=sinf(CONE_HALFANG);
///returns a-b in radians, function takes care of 2PI periodicity
float SignedAngularDifference(const float& a, const float& b);
///returns |a-b| in radians, function takes care of 2PI periodicity
float AngularDifference(const float& a, const float& b);
//finally, a class that contains all global parameters of the simulation
class ParamsClass {
public:
//the scene, the playground for agents to stay within [um]
Vector3d<float> sceneOffset;
Vector3d<float> sceneSize;
//helper centre...
Vector3d<float> sceneCentre;
//the outer width between the frame and window border [um]
Vector3d<float> sceneOuterBorder;
//colour of the frame around the playground rectangle
struct {
float r,g,b;
} sceneBorderColour;
//returns true if given position is inside the scene
bool Include(const Vector3d<float> pos) const
{
return ( (pos.x >= sceneOffset.x)
&& (pos.y >= sceneOffset.y)
&& (pos.z >= sceneOffset.z)
&& (pos.x < sceneOffset.x + sceneSize.x)
&& (pos.y < sceneOffset.y + sceneSize.y)
&& (pos.z < sceneOffset.z + sceneSize.z) );
}
//simulation params
int numberOfAgents;
float friendshipDuration; //[min]
float maxCellSpeed; //[um/min]
float cellCycleLength; //[min]
float cellPhaseDuration[8]; //[min]
/**
* Initially, it is initial time of the simulation [min].
* But it is incremented as the simulation advances.
*/
float currTime;
//how much to increment the \e currTime [min]
float incrTime;
//final time of the simulation [min]
float stopTime;
size_t imgSizeX, imgSizeY; //[pixels]
float imgResX,imgResY; //[pixels per micrometer]
//all strings should include "%05d" substring to
//indicate where file index number should be printed
std::string imgOutlineFilename;
std::string imgPhantomFilename,imgMaskFilename;
std::string imgFluoFilename,imgPhCFilename;
//a filename for the "tracks.txt" file
std::string tracksFilename;
//all strings should include "%d" substring (or some similar)
//to allow for filenames indexing
std::string inputCellsFilename;
};
/// helper macro to unify reports:
#define REPORT(x) std::cout << __FUNCTION__ << "(): " << x << std::endl;
#define REPORT_NOENDL(x) std::cout << __FUNCTION__ << "(): " << x;
#ifdef SURFACE_DEBUG
#define DEBUG_REPORT(x) std::cout << x << std::endl;
#define DEBUG_REPORT_NOENDL(x) std::cout << x;
#else
#define DEBUG_REPORT(x)
#define DEBUG_REPORT_NOENDL(x)
#endif
#endif