-
Notifications
You must be signed in to change notification settings - Fork 2
/
neumann.cpp
70 lines (65 loc) · 2.12 KB
/
neumann.cpp
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
#include <iostream>
#include <windows.h>
#include <ctime>
#include <list>
#include <cmath>
#include <myglwidget.h>
#include "neumann.h"
using namespace std;
Neumann::Neumann()
{
}
std::vector<Parent_Algorithm::Coordinate> Neumann::Generate_Filling(int16_t*** voxels, short int numCubes, int n, std::vector<Coordinate> grains)
{
unsigned int counter_max = pow(numCubes,3);
while (!grains.empty())
{
Coordinate temp;
int16_t x,y,z;
std::vector<Coordinate> newGrains;
for(size_t i = 0; i < grains.size(); i++)
{
temp = grains[i];
x = temp.x;
y = temp.y;
z = temp.z;
for (int16_t k = -1; k < 2; k+=2)
{
int16_t newX = k+x;
int16_t newY = k+y;
int16_t newZ = k+z;
bool isValidX = (newX >= 0 && newX < numCubes) && voxels[newX][y][z] == 0;
bool isValidY = (newY >= 0 && newY < numCubes) && voxels[x][newY][z] == 0;
bool isValidZ = (newZ >= 0 && newZ < numCubes) && voxels[x][y][newZ] == 0;
if (isValidX)
{
voxels[newX][y][z] = voxels[x][y][z];
newGrains.push_back({newX,y,z});
counter++;
}
if (isValidY)
{
voxels[x][newY][z] = voxels[x][y][z];
newGrains.push_back({x,newY,z});
counter++;
}
if (isValidZ)
{
voxels[x][y][newZ] = voxels[x][y][z];
newGrains.push_back({x,y,newZ});
counter++;
}
}
}
grains.clear();
grains.insert(grains.end(), newGrains.begin(), newGrains.end());
IterationNumber++;
double o = (double)counter/counter_max;
qDebug().nospace() << o << "\t" << IterationNumber << "\t" << grains.size();
if (n == 1)
{
break;
}
}
return grains;
}