22 CPPUNIT_TEST_SUITE(mitkPhotoacoustic3dVolumeTestSuite);
23 MITK_TEST(TestCorrectGetDataAndSetDataBehavior);
24 MITK_TEST(TestCallingConstructorWithNullParameter);
25 MITK_TEST(TestCallingConstructorWithCorrectParameters);
31 CPPUNIT_TEST_SUITE_END();
35 mitk::pa::Volume::Pointer m_Photoacoustic3dVolume;
43 void TestCallingConstructorWithNullParameter()
45 bool exceptionEncountered =
false;
52 exceptionEncountered =
true;
54 CPPUNIT_ASSERT(exceptionEncountered);
57 void TestCallingConstructorWithCorrectParameters()
59 auto* data =
new double[1];
62 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 0) == 3);
63 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetXDim() == 1);
64 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetYDim() == 1);
65 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetZDim() == 1);
68 void TestModifyImage()
70 auto* data =
new double[1];
73 CPPUNIT_ASSERT_MESSAGE(std::to_string(m_Photoacoustic3dVolume->GetData(0, 0, 0)), m_Photoacoustic3dVolume->GetData(0, 0, 0) == 3);
74 m_Photoacoustic3dVolume->SetData(17, 0, 0, 0);
75 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 0) == 17);
78 void TestModifyComplexImage()
80 unsigned int xDim = 4;
81 unsigned int yDim = 7;
82 unsigned int zDim = 12;
83 unsigned int length = xDim * yDim * zDim;
84 auto* data =
new double[length];
85 for (
unsigned int i = 0; i < length; i++)
90 for (
unsigned int z = 0; z < zDim; z++)
91 for (
unsigned int y = 0; y < yDim; y++)
92 for (
unsigned int x = 0; x < xDim; x++)
94 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(x, y, z) == 5);
95 m_Photoacoustic3dVolume->SetData((x + y)*(z + 1), x, y, z);
96 CPPUNIT_ASSERT(std::abs(m_Photoacoustic3dVolume->GetData(x, y, z) - (x + y)*(z + 1)) <
mitk::eps);
100 void TestCorrectGetDataAndSetDataBehavior()
102 unsigned int xDim = 40;
103 unsigned int yDim = 7;
104 unsigned int zDim = 12;
105 unsigned int length = xDim * yDim * zDim;
106 auto* data =
new double[length];
107 for (
unsigned int i = 0; i < length; i++)
112 for (
unsigned int z = 0; z < zDim; z++)
113 for (
unsigned int y = 0; y < yDim; y++)
114 for (
unsigned int x = 0; x < xDim; x++)
116 int index = z*xDim*yDim + x*yDim + y;
117 m_Photoacoustic3dVolume->SetData(index, x, y, z);
118 CPPUNIT_ASSERT_MESSAGE(std::to_string(index), m_Photoacoustic3dVolume->GetData(x, y, z) == index);
122 void TestConvertToMitkImage()
124 auto* data =
new double[6];
132 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 0) == 3);
133 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 1) == 3);
134 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 2) == 3);
135 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 1, 0) == 3);
136 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 1, 1) == 3);
137 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 1, 2) == 3);
139 m_Photoacoustic3dVolume->SetData(17, 0, 0, 0);
140 m_Photoacoustic3dVolume->SetData(17, 0, 1, 0);
141 m_Photoacoustic3dVolume->SetData(17, 0, 1, 2);
142 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 0) == 17);
143 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 1) == 3);
144 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 2) == 3);
145 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 1, 0) == 17);
146 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 1, 1) == 3);
147 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 1, 2) == 17);
150 CPPUNIT_ASSERT(mitkImage->GetDimensions()[0] == 2);
151 CPPUNIT_ASSERT(mitkImage->GetDimensions()[1] == 1);
152 CPPUNIT_ASSERT(mitkImage->GetDimensions()[2] == 3);
155 auto* copyData = (
double*)readAccess.
GetData();
156 CPPUNIT_ASSERT_MESSAGE(std::to_string(copyData[0]), copyData[0] == 17);
157 CPPUNIT_ASSERT_MESSAGE(std::to_string(copyData[1]), copyData[1] == 17);
158 CPPUNIT_ASSERT_MESSAGE(std::to_string(copyData[2]), copyData[2] == 3);
159 CPPUNIT_ASSERT_MESSAGE(std::to_string(copyData[3]), copyData[3] == 3);
160 CPPUNIT_ASSERT_MESSAGE(std::to_string(copyData[4]), copyData[4] == 3);
161 CPPUNIT_ASSERT_MESSAGE(std::to_string(copyData[5]), copyData[5] == 17);
166 auto* data =
new double[1];
169 mitk::pa::Volume::Pointer copiedVolume = m_Photoacoustic3dVolume->DeepCopy();
171 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetXDim() == copiedVolume->GetXDim());
172 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetYDim() == copiedVolume->GetYDim());
173 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetZDim() == copiedVolume->GetZDim());
174 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 0) == 3);
175 CPPUNIT_ASSERT(copiedVolume->GetData(0, 0, 0) == 3);
176 m_Photoacoustic3dVolume->SetData(17, 0, 0, 0);
177 CPPUNIT_ASSERT(m_Photoacoustic3dVolume->GetData(0, 0, 0) == 17);
178 CPPUNIT_ASSERT(copiedVolume->GetData(0, 0, 0) == 3);
181 void AssertIndexException(
unsigned int x,
unsigned int y,
unsigned int z)
183 bool exceptionCaught =
false;
186 double thisIsIrrelevant = m_Photoacoustic3dVolume->GetData(x, y, z);
187 thisIsIrrelevant += 1;
191 exceptionCaught =
true;
193 exceptionCaught =
true;
197 CPPUNIT_ASSERT(exceptionCaught);
202 void TestCatchException()
204 auto* data =
new double[1];
208 AssertIndexException(1, 0, 0);
209 AssertIndexException(0, 1, 0);
210 AssertIndexException(0, 0, 1);
211 AssertIndexException(18, 1, 222);
214 void tearDown()
override 216 m_Photoacoustic3dVolume =
nullptr;
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
MITKCORE_EXPORT const ScalarType eps
ImageReadAccessor class to get locked read access for a particular image part.
static Volume::Pointer New(double *data, unsigned int xDim, unsigned int yDim, unsigned int zDim, double spacing)
returns smartpointer reference to a new instance of this objects. The given data array will be freed ...
const void * GetData() const
Gives const access to the data.