VoronoiGrowthSimulator
Based on Site Saturated Nucleation and Isotropic Growth
Loading...
Searching...
No Matches
Voronoi Class Reference

Represents a Voronoi diagram. More...

#include <Voronoi.hpp>

Collaboration diagram for Voronoi:

Public Member Functions

 Voronoi (int m, int n, int p)
 Constructs a Voronoi object with the specified dimensions and number of points.
 
void Nucleate (long long myseed)
 Nucleates the Voronoi diagram with the specified seed.
 
void Nucleate ()
 Nucleates the Voronoi diagram with a random seed.
 
void grow ()
 Grows the Voronoi diagram.
 
void Grow ()
 Grows the Voronoi diagram.
 
void WriteDataToCSV (std::string &filename)
 
 ~Voronoi ()
 Destroys the Voronoi object.
 

Public Attributes

std::vector< int > I
 
bool allgrown = false
 
std::vector< colorcolors
 

Detailed Description

Represents a Voronoi diagram.

The Voronoi class is used to create and manipulate Voronoi diagrams. It provides methods for nucleation, growth, and color assignment.

Definition at line 26 of file Voronoi.hpp.

Constructor & Destructor Documentation

◆ Voronoi()

Voronoi::Voronoi ( int m,
int n,
int p )

Constructs a Voronoi object with the specified dimensions and number of points.

Constructs a Voronoi object with the given parameters.

Parameters
mThe width of the Voronoi diagram.
nThe height of the Voronoi diagram.
pThe number of Voronoi diagram points.
mThe number of rows in the Voronoi diagram.
nThe number of columns in the Voronoi diagram.
pThe number of points in the Voronoi diagram.

Definition at line 66 of file Voronoi.cpp.

67{
68 this->m = m;
69 this->n = n;
70 this->p = p;
71 this->r = 0;
72 this->I.resize(m * n, 0);
73 this->X.resize(p, 0);
74 this->Y.resize(p, 0);
75 this->a.resize(p, Growing);
76 this->colors.resize(p+1);
77}
@ Growing
Definition Voronoi.hpp:7
std::vector< int > I
Definition Voronoi.hpp:45
std::vector< color > colors
Definition Voronoi.hpp:47

◆ ~Voronoi()

Voronoi::~Voronoi ( )

Destroys the Voronoi object.

Definition at line 480 of file Voronoi.cpp.

481{
482}

Member Function Documentation

◆ grow()

void Voronoi::grow ( )

Grows the Voronoi diagram.

Grows the Voronoi diagram by one iteration.

This function performs one iteration of the growth process for the Voronoi diagram. It checks each cell in the diagram and determines if it should be grown based on its neighbors. The growth process continues until all cells have been grown or no more growth is possible.

Note
This function assumes that the Nucleate function has been called before the first iteration of growth.
This function uses OpenMP parallelization to speed up the growth process.
This function updates the I and a arrays to reflect the growth of the diagram.
This function updates the allgrown flag to indicate if all cells have been grown.
This function updates the r variable to increase the radius of growth for the next iteration.
This function assumes that the I, a, X, Y, m, n, p, Grown, Growing, and iscomplete variables are properly initialized.

Definition at line 162 of file Voronoi.cpp.

163{
164 if (!nucleated)
165 {
166 Nucleate();
167 }
168
169 if (allgrown)
170 {
171 return ;
172 }
173
174
175
176 int xo, yo, label, low, px, py, index, N, E, W, S, val1, val2, val3, val4;
177 const int s = I.size();
178 N = 0;
179 E = 0;
180 W = 0;
181 S = 0;
182
183#pragma omp parallel for private(xo, yo, label, low, px, py, N, E, W, S, index, val1, val2, val3, val4) schedule(dynamic)
184 for (int k = 0; k < p; ++k)
185 {
186
187 if (a[k] == 1)
188 {
189
190 xo = X[k];
191 yo = Y[k];
192 a[k] = Grown;
193
194 label = k + 1;
195 low = 0;
196 for (int i = 0; i <= r; ++i)
197 {
198 for (int j = 0; j <= r; ++j)
199 {
200
201 if (i * i + j * j < r * r)
202 {
203 px = xo + i;
204 py = yo + j;
205
206 if (px >= 0 && px < m && py >= 0 && py < n)
207 {
208 index = (n)*px + py;
209
210 if (I[index] == 0)
211 {
212
213 N = index - n;
214 E = index + n;
215 W = index + 1;
216 S = index - 1;
217
218 if (N >= 0 && N < s)
219 {
220 val1 = I[N];
221 }
222 else
223 {
224 val1 = 0;
225 }
226
227 if (E >= 0 && E < s)
228 {
229 val2 = I[E];
230 }
231 else
232 {
233 val2 = 0;
234 }
235
236 if (W >= 0 && W < s)
237 {
238 val3 = I[W];
239 }
240 else
241 {
242 val3 = 0;
243 }
244
245 if (S >= 0 && S < s)
246 {
247 val4 = I[S];
248 }
249 else
250 {
251 val4 = 0;
252 }
253
254 if (val1 == label || val2 == label || val3 == label || val4 == label)
255 {
256 I[index] = label;
257 a[k] = Growing;
258 }
259 }
260 }
261
262 px = xo - i;
263 py = yo + j;
264
265 if (px >= 0 && px < m && py >= 0 && py < n)
266 {
267 index = (n)*px + py;
268
269 if (I[index] == 0)
270 {
271
272 N = index - n;
273 E = index + n;
274 W = index + 1;
275 S = index - 1;
276
277 if (N >= 0 && N < s)
278 {
279 val1 = I[N];
280 }
281 else
282 {
283 val1 = 0;
284 }
285
286 if (E >= 0 && E < s)
287 {
288 val2 = I[E];
289 }
290 else
291 {
292 val2 = 0;
293 }
294
295 if (W >= 0 && W < s)
296 {
297 val3 = I[W];
298 }
299 else
300 {
301 val3 = 0;
302 }
303
304 if (S >= 0 && S < s)
305 {
306 val4 = I[S];
307 }
308 else
309 {
310 val4 = 0;
311 }
312
313 if (val1 == label || val2 == label || val3 == label || val4 == label)
314 {
315 I[index] = label;
316 a[k] = Growing;
317 }
318 }
319 }
320
321 px = xo + i;
322 py = yo - j;
323
324 if (px >= 0 && px < m && py >= 0 && py < n)
325 {
326 index = (n)*px + py;
327
328 if (I[index] == 0)
329 {
330
331 N = index - n;
332 E = index + n;
333 W = index + 1;
334 S = index - 1;
335
336 if (N >= 0 && N < s)
337 {
338 val1 = I[N];
339 }
340 else
341 {
342 val1 = 0;
343 }
344
345 if (E >= 0 && E < s)
346 {
347 val2 = I[E];
348 }
349 else
350 {
351 val2 = 0;
352 }
353
354 if (W >= 0 && W < s)
355 {
356 val3 = I[W];
357 }
358 else
359 {
360 val3 = 0;
361 }
362
363 if (S >= 0 && S < s)
364 {
365 val4 = I[S];
366 }
367 else
368 {
369 val4 = 0;
370 }
371
372 if (val1 == label || val2 == label || val3 == label || val4 == label)
373 {
374 I[index] = label;
375 a[k] = Growing;
376 }
377 }
378 }
379
380 px = xo - i;
381 py = yo - j;
382
383 if (px >= 0 && px < m && py >= 0 && py < n)
384 {
385 index = (n)*px + py;
386
387 if (I[index] == 0)
388 {
389
390 N = index - n;
391 E = index + n;
392 W = index + 1;
393 S = index - 1;
394
395 if (N >= 0 && N < s)
396 {
397 val1 = I[N];
398 }
399 else
400 {
401 val1 = 0;
402 }
403
404 if (E >= 0 && E < s)
405 {
406 val2 = I[E];
407 }
408 else
409 {
410 val2 = 0;
411 }
412
413 if (W >= 0 && W < s)
414 {
415 val3 = I[W];
416 }
417 else
418 {
419 val3 = 0;
420 }
421
422 if (S >= 0 && S < s)
423 {
424 val4 = I[S];
425 }
426 else
427 {
428 val4 = 0;
429 }
430
431 if (val1 == label || val2 == label || val3 == label || val4 == label)
432 {
433 I[index] = label;
434 a[k] = Growing;
435 }
436 }
437 }
438 }
439 }
440 }
441 }
442 }
443
445 r = r + 1;
446}
bool iscomplete(const std::vector< int > &I)
Definition Voronoi.cpp:24
@ Grown
Definition Voronoi.hpp:7
bool allgrown
Definition Voronoi.hpp:46
void Nucleate()
Nucleates the Voronoi diagram with a random seed.
Definition Voronoi.cpp:124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Grow()

void Voronoi::Grow ( )

Grows the Voronoi diagram.

Deprecated
Use the grow() method instead.

Definition at line 448 of file Voronoi.cpp.

449{
450 while (!allgrown)
451 {
452 grow();
453 }
454
455}
void grow()
Grows the Voronoi diagram.
Definition Voronoi.cpp:162
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nucleate() [1/2]

void Voronoi::Nucleate ( )

Nucleates the Voronoi diagram with a random seed.

Nucleates the Voronoi diagram by creating a new MTEngine object, calling the nucleate function, and then deleting the MTEngine object.

Definition at line 124 of file Voronoi.cpp.

125{
126 MTEngine* M = new MTEngine();
127 nucleate(M);
128 delete M;
129}
A class that represents a random number generator engine.
Definition MTEngine.hpp:22
Here is the caller graph for this function:

◆ Nucleate() [2/2]

void Voronoi::Nucleate ( long long myseed)

Nucleates the Voronoi diagram with the specified seed.

Parameters
myseedThe seed used for nucleation.

Nucleates the Voronoi diagram with the given seed.

Parameters
myseedThe seed used for random number generation.

Definition at line 136 of file Voronoi.cpp.

137{
138 MTEngine* M = new MTEngine(myseed);
139 nucleate(M);
140 delete M;
141}
Here is the caller graph for this function:

◆ WriteDataToCSV()

void Voronoi::WriteDataToCSV ( std::string & filename)

Writes the 2D data (I) to a CSV file.

Parameters
filenameThe name of the CSV file to write the data to.

Definition at line 463 of file Voronoi.cpp.

464{
465 std::ofstream fout;
466 fout.open(filename.c_str());
467 for (int i = 0; i < m; ++i)
468 {
469 for (int j = 0; j < n-1; ++j)
470 {
471 int index = (n)*i + j;
472 fout<<I[index]<<",";
473 }
474 fout<<I[n*i + n-1]<<"\n";
475 //fout<<endl;
476 }
477 fout.close();
478}
Here is the caller graph for this function:

Member Data Documentation

◆ allgrown

bool Voronoi::allgrown = false

Flag indicating if all points in the Voronoi diagram have grown.

Definition at line 46 of file Voronoi.hpp.

◆ colors

std::vector<color> Voronoi::colors

The colors assigned to each Voronoi diagram point.

Definition at line 47 of file Voronoi.hpp.

◆ I

std::vector<int> Voronoi::I

The index of the Voronoi diagram point each pixel belongs to.

Definition at line 45 of file Voronoi.hpp.


The documentation for this class was generated from the following files: