20 CPPUNIT_TEST_SUITE(mitkPhotoacousticVectorTestSuite);
24 MITK_TEST(TestRotatedVectorPositiveDegrees);
29 CPPUNIT_TEST_SUITE_END();
33 mitk::pa::Vector::Pointer m_TestVector;
34 mitk::pa::Vector::Pointer m_TestReturnVector;
36 const double DIF_VAL = 0.001;
37 const double TWO_PI = 6.283185;
47 void TestNormalizeVector()
49 std::stringstream output;
54 m_TestVector->SetElement(0, a);
55 m_TestVector->SetElement(1, b);
56 m_TestVector->SetElement(2, c);
58 output <<
"The vectorlength should be";
59 output << sqrt(a*a + b*b + c*c);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE(output.str(), sqrt(a*a + b*b + c*c), m_TestVector->GetNorm());
63 m_TestVector->Normalize();
65 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vectorlength should be 1.",
true, m_TestVector->GetNorm() - 1 < DIF_VAL);
68 void TestRotateVectorZeroDegrees()
76 m_TestVector->SetElement(0, a);
77 m_TestVector->SetElement(1, b);
78 m_TestVector->SetElement(2, c);
80 length = m_TestVector->GetNorm();
82 m_TestVector->Rotate(0, 0);
84 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector length should be equal", length, m_TestVector->GetNorm());
86 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index0 should be 1.0", m_TestVector->GetElement(0) - 1 < DIF_VAL);
87 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index1 should be 2.0", m_TestVector->GetElement(1) - 2 < DIF_VAL);
88 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index2 should be 3.0", m_TestVector->GetElement(2) - 3 < DIF_VAL);
91 void TestRotatedVectorPositiveDegrees()
95 for (
int r = 0; r < 10; r++)
97 for (
double phi = 0.1; phi < 3; phi += 0.1)
99 for (
double theta = 0.1; theta < 3; theta += 0.1)
101 double rotateTheta = 0.1;
102 double rotatePhi = 0.1;
104 m_TestVector->SetElement(0, r * sin(theta) * cos(phi));
105 m_TestVector->SetElement(1, r * sin(theta) * sin(phi));
106 m_TestVector->SetElement(2, r * cos(theta));
108 m_TestVector->Rotate(rotateTheta, rotatePhi);
110 double newTheta = fmod(theta + rotateTheta, TWO_PI);
111 double newPhi = fmod(phi + rotatePhi, TWO_PI);
113 double expectedX = r * sin(newTheta) * cos(newPhi);
114 double expectedY = r * sin(newTheta) * sin(newPhi);
115 double expectedZ = r * cos(newTheta);
117 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index0 should be " + std::to_string(expectedX) +
" but was " + std::to_string(m_TestVector->GetElement(0))
118 +
" at r=" + std::to_string(r) +
" phi=" + std::to_string(phi) +
" theta=" + std::to_string(theta),
119 m_TestVector->GetElement(0) - expectedX < DIF_VAL);
120 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index1 should be " + std::to_string(expectedY) +
" but was " + std::to_string(m_TestVector->GetElement(0))
121 +
" at r=" + std::to_string(r) +
" phi=" + std::to_string(phi) +
" theta=" + std::to_string(theta),
122 m_TestVector->GetElement(1) - expectedY < DIF_VAL);
123 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index2 should be " + std::to_string(expectedZ) +
" but was " + std::to_string(m_TestVector->GetElement(0))
124 +
" at r=" + std::to_string(r) +
" phi=" + std::to_string(phi) +
" theta=" + std::to_string(theta),
125 m_TestVector->GetElement(2) - expectedZ < DIF_VAL);
131 void TestRotatedVectorNegativeDegrees()
133 for (
int r = 0; r < 10; r++)
135 for (
double phi = -0.1; phi > -3; phi -= 0.1)
137 for (
double theta = -0.1; theta > -3; theta -= 0.1)
139 double rotateTheta = -0.1;
140 double rotatePhi = -0.1;
142 m_TestVector->SetElement(0, r * sin(theta) * cos(phi));
143 m_TestVector->SetElement(1, r * sin(theta) * sin(phi));
144 m_TestVector->SetElement(2, r * cos(theta));
146 m_TestVector->Rotate(rotateTheta, rotatePhi);
148 double newTheta = fmod(theta + rotateTheta, TWO_PI);
149 double newPhi = fmod(phi + rotatePhi, TWO_PI);
151 double expectedX = r * sin(newTheta) * cos(newPhi);
152 double expectedY = r * sin(newTheta) * sin(newPhi);
153 double expectedZ = r * cos(newTheta);
155 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index0 should be " + std::to_string(expectedX) +
" but was " + std::to_string(m_TestVector->GetElement(0))
156 +
" at r=" + std::to_string(r) +
" phi=" + std::to_string(phi) +
" theta=" + std::to_string(theta),
157 m_TestVector->GetElement(0) - expectedX < DIF_VAL);
158 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index1 should be " + std::to_string(expectedY) +
" but was " + std::to_string(m_TestVector->GetElement(0))
159 +
" at r=" + std::to_string(r) +
" phi=" + std::to_string(phi) +
" theta=" + std::to_string(theta),
160 m_TestVector->GetElement(1) - expectedY < DIF_VAL);
161 CPPUNIT_ASSERT_MESSAGE(
"The vector value at index2 should be " + std::to_string(expectedZ) +
" but was " + std::to_string(m_TestVector->GetElement(0))
162 +
" at r=" + std::to_string(r) +
" phi=" + std::to_string(phi) +
" theta=" + std::to_string(theta),
163 m_TestVector->GetElement(2) - expectedZ < DIF_VAL);
169 void TestScaleVector()
175 for (
double testFactor = -2.0; testFactor <= 2.0; testFactor += 0.3)
177 double potElement0Fctr;
178 double potElement1Fctr;
179 double potElement2Fctr;
181 std::stringstream output;
183 m_TestVector->SetElement(0, a);
184 m_TestVector->SetElement(1, b);
185 m_TestVector->SetElement(2, c);
187 potElement0Fctr = (m_TestVector->GetElement(0)*testFactor)*(m_TestVector->GetElement(0)*testFactor);
188 potElement1Fctr = (m_TestVector->GetElement(1)*testFactor)*(m_TestVector->GetElement(1)*testFactor);
189 potElement2Fctr = (m_TestVector->GetElement(2)*testFactor)*(m_TestVector->GetElement(2)*testFactor);
191 m_TestVector->Scale(testFactor);
193 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector length should not be equal",
194 sqrt(potElement0Fctr + potElement1Fctr + potElement2Fctr), m_TestVector->GetNorm());
196 output <<
"The vector value at index0 should be";
197 output << a*testFactor;
198 CPPUNIT_ASSERT_EQUAL_MESSAGE(output.str(), a*testFactor, m_TestVector->GetElement(0));
201 output <<
"The vector value at index1 should be";
202 output << b*testFactor;
203 CPPUNIT_ASSERT_EQUAL_MESSAGE(output.str(), b*testFactor, m_TestVector->GetElement(1));
206 output <<
"The vector value at index2 should be";
207 output << c*testFactor;
208 CPPUNIT_ASSERT_EQUAL_MESSAGE(output.str(), c*testFactor, m_TestVector->GetElement(2));
213 void TestCloneVector()
219 m_TestVector->SetElement(0, a);
220 m_TestVector->SetElement(1, b);
221 m_TestVector->SetElement(2, c);
223 m_TestReturnVector = m_TestVector->Clone();
225 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector length should be equal", (m_TestVector->GetNorm()), m_TestReturnVector->GetNorm());
227 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be equal", m_TestVector->GetElement(0), m_TestReturnVector->GetElement(0));
228 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index1 should be equal", m_TestVector->GetElement(1), m_TestReturnVector->GetElement(1));
229 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index2 should be equal", m_TestVector->GetElement(2), m_TestReturnVector->GetElement(2));
231 m_TestReturnVector->Rotate(itk::Math::pi / 4, itk::Math::pi / 4);
233 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be not equal",
true, m_TestVector->GetElement(0) != m_TestReturnVector->GetElement(0));
234 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be not equal",
true, m_TestVector->GetElement(1) != m_TestReturnVector->GetElement(1));
235 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be not equal",
true, m_TestVector->GetElement(2) != m_TestReturnVector->GetElement(2));
237 for (
double testFactor = -2.0; testFactor <= 2.0; testFactor += 0.3)
239 m_TestReturnVector->Scale(testFactor);
241 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be not equal",
true, m_TestVector->GetElement(0) != m_TestReturnVector->GetElement(0));
242 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be not equal",
true, m_TestVector->GetElement(1) != m_TestReturnVector->GetElement(1));
243 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"The vector value at index0 should be not equal",
true, m_TestVector->GetElement(2) != m_TestReturnVector->GetElement(2));
247 void tearDown()
override 249 m_TestVector =
nullptr;
250 m_TestReturnVector =
nullptr;
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.