2
* voxels.cpp - Voxelised data manipulation class
3
* Copyright (C) 2013 D. Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
using std::numeric_limits;
21
const float FLOAT_SMALL=
22
sqrt(numeric_limits<float>::epsilon());
27
Voxels<unsigned int> data,kernel,result;
28
data.setCallbackMethod(dummyCallback);
29
kernel.setCallbackMethod(dummyCallback);
31
const size_t NUM_SIZES=4;
32
const size_t TEST_SIZES[]= { 1, 3, 4, 7};
34
for(size_t ui=0;ui<BOUND_ENUM_END; ui++)
36
//Convolve several kernel sizes
38
for(unsigned int ui=0;ui<NUM_SIZES;ui++)
42
curSize=TEST_SIZES[ui];
44
data.resize(curSize,curSize,curSize);
45
kernel.resize(curSize,curSize,curSize);
47
//Test with a whole bunch of different fill values
48
for(size_t fillVal=0;fillVal<5;fillVal++)
53
data.convolve(kernel,result,BOUND_CLIP);
56
result.getSize(nX,nY,nZ);
58
TEST(nX == 1,"convolve dimensions");
59
TEST(nY == 1,"convolve dimensions");
60
TEST(nZ == 1,"convolve dimensions");
62
TEST(result.max() == curSize*curSize*curSize*(fillVal*fillVal),
69
//Convolve several kernel sizes
70
for(unsigned int ui=0;ui<NUM_SIZES;ui++)
74
curSize=TEST_SIZES[ui];
76
data.resize(curSize,curSize,curSize);
80
data.convolve(kernel,result,BOUND_CLIP);
81
TEST(result == data, "convolve identity");
92
TEST(fabs(data.trapezIntegral() - 1.0f )< FLOAT_SMALL,"Trapezoid test");
96
data.setBounds(Point3D(0,0,0),Point3D(1,1,1));
97
TEST(fabs(data.trapezIntegral() - 1.0f) < FLOAT_SMALL,"Trapezoid test");
98
data.setBounds(Point3D(0,0,0),Point3D(5,5,5));
99
TEST(fabs(data.trapezIntegral() - 125.0f) < FLOAT_SMALL,"Trapezoid test");
102
//Test convolution stuff
104
Voxels<float> data,kernel,result;
105
data.setCallbackMethod(dummyCallback);
106
kernel.setCallbackMethod(dummyCallback);
107
//Check that convolving with an impulse with
108
//a Gaussian gives us a Gaussian
109
//back, roughly speaking
110
kernel.setGaussianKernelCube(1.0f,10.0f,10);
112
float trapz = kernel.trapezIntegral();
113
TEST(trapz < 1.5f && trapz > 0.5f, "Trapezoidal kernel integral test");
116
data.resize(20,20,20);
118
data.setData(10,10,10,1.0f);
119
data.convolve(kernel,result,BOUND_CLIP);
121
TEST(result.max() > 0 && result.max() < 1.0f,"result should be nonzero, and less than the original input (convolve only squeezes maxima/minima)");
122
//Gaussian @ x=0, stdev 1
123
TEST(fabs(result.max() - kernel.max()) < FLOAT_SMALL
124
,"Gaussian kernel test- maxima of convolved and kernel should be the same");
138
TEST(fabs(f-3.0*3.0*3.0*2.0 )< FLOAT_SMALL,"getsum test");
139
TEST(fabs(a.count(1.0f)- 3.0*3.0*3.0) < FLOAT_SMALL,"Count test");
147
f.setCallbackMethod(dummyCallback);
152
TEST(xs == ys && ys == zs && zs == 3,"resize tests");
157
f.setData(1,1,1,1.0f);
159
TEST(fabs(f.max() - 1.0f) < FLOAT_SMALL,"Fill and data set");
161
f.resizeKeepData(2,2,2);
164
TEST(xs == ys && ys == zs && zs == 2, "resizeKeepData");
165
TEST(f.max() == 1.0f,"resize keep data");
173
TEST(basicTests(),"basic voxel tests");
174
TEST(testConvolve()," voxel convolve");
175
TEST(simpleMath(), "voxel simple maths");