diff --git a/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVectorTest.cpp b/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVectorTest.cpp index 90fcc05897..e875b55a1a 100644 --- a/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVectorTest.cpp +++ b/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVectorTest.cpp @@ -1,251 +1,278 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include "mitkPhotoacousticSmartVector.h" class mitkPhotoacousticVectorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPhotoacousticVectorTestSuite); - MITK_TEST(TestNormalizedVector); - MITK_TEST(TestRotatedVectorZeroDegrees); + MITK_TEST(TestNormalizeVector); + MITK_TEST(TestRotateVectorZeroDegrees); MITK_TEST(TestRotatedVectorPositiveDegrees); - MITK_TEST(TestRotatedVectorZeroDegrees); + MITK_TEST(TestRotateVectorZeroDegrees); MITK_TEST(TestRotatedVectorAroundAllAxis); - MITK_TEST(TestScaledVector); - MITK_TEST(TestClonedVector); + MITK_TEST(TestScaleVector); + MITK_TEST(TestCloneVector); CPPUNIT_TEST_SUITE_END(); private: mitk::PhotoacousticSmartVector::Pointer m_TestVector; mitk::PhotoacousticSmartVector::Pointer m_TestReturnVector; const double DIF_VAL = 0.001; const double TWO_PI = 6.283185; public: void setUp() { m_TestVector = mitk::PhotoacousticSmartVector::New(); m_TestReturnVector = mitk::PhotoacousticSmartVector::New(); } - void TestNormalizedVector() + void TestNormalizeVector() { std::stringstream output; int a = 2; int b = 3; int c = 4; m_TestVector->SetElement(0,a); m_TestVector->SetElement(1,b); m_TestVector->SetElement(2,c); output << "The vectorlength should be"; output << sqrt(a*a+b*b+c*c); CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), sqrt(a*a+b*b+c*c), m_TestVector->GetNorm()); output.flush(); m_TestVector->Normalize(); CPPUNIT_ASSERT_EQUAL_MESSAGE("The vectorlength should be 1.", true, m_TestVector->GetNorm()-1 < DIF_VAL); } - void TestRotatedVectorZeroDegrees() + void TestRotateVectorZeroDegrees() { int a = 1; int b = 2; int c = 3; double length; m_TestVector->SetElement(0,a); m_TestVector->SetElement(1,b); m_TestVector->SetElement(2,c); length = m_TestVector->GetNorm(); m_TestVector->Rotate(0,0); CPPUNIT_ASSERT_EQUAL_MESSAGE("The vector length should be equal", length, m_TestVector->GetNorm()); CPPUNIT_ASSERT_MESSAGE("The vector value at index0 should be 1.0", m_TestVector->GetElement(0) - 1 < DIF_VAL); CPPUNIT_ASSERT_MESSAGE("The vector value at index1 should be 2.0", m_TestVector->GetElement(1) - 2 < DIF_VAL); CPPUNIT_ASSERT_MESSAGE("The vector value at index2 should be 3.0", m_TestVector->GetElement(2) - 3 < DIF_VAL); } void TestRotatedVectorPositiveDegrees() { MITK_INFO << atan2(0, 0); for(int r = 0; r<10; r++) { for(double phi = 0.1; phi < 3; phi+=0.1) { for(double theta = 0.1; theta < 3; theta+=0.1) { double rotateTheta = 0.1; double rotatePhi = 0.1; m_TestVector->SetElement(0, r * sin(theta) * cos(phi)); m_TestVector->SetElement(1, r * sin(theta) * sin(phi)); m_TestVector->SetElement(2, r * cos(theta)); m_TestVector->Rotate(rotateTheta, rotatePhi); double newTheta = fmod(theta + rotateTheta, TWO_PI); double newPhi = fmod(phi + rotatePhi, TWO_PI); double expectedX = r * sin(newTheta) * cos(newPhi); double expectedY = r * sin(newTheta) * sin(newPhi); double expectedZ = r * cos(newTheta); CPPUNIT_ASSERT_MESSAGE("The vector value at index0 should be " + std::to_string(expectedX) + " but was " + std::to_string(m_TestVector->GetElement(0)) + " at r=" + std::to_string(r) + " phi=" + std::to_string(phi) + " theta=" + std::to_string(theta), m_TestVector->GetElement(0) - expectedX < DIF_VAL); CPPUNIT_ASSERT_MESSAGE("The vector value at index1 should be " + std::to_string(expectedY) + " but was " + std::to_string(m_TestVector->GetElement(0)) + " at r=" + std::to_string(r) + " phi=" + std::to_string(phi) + " theta=" + std::to_string(theta), m_TestVector->GetElement(1) - expectedY < DIF_VAL); CPPUNIT_ASSERT_MESSAGE("The vector value at index2 should be " + std::to_string(expectedZ) + " but was " + std::to_string(m_TestVector->GetElement(0)) + " at r=" + std::to_string(r) + " phi=" + std::to_string(phi) + " theta=" + std::to_string(theta), m_TestVector->GetElement(2) - expectedZ < DIF_VAL); } } } } void TestRotatedVectorNegativeDegrees() { - //TODO rewrite this test + for(int r = 0; r<10; r++) + { + for(double phi = -0.1; phi > -3; phi-=0.1) + { + for(double theta = -0.1; theta > -3; theta-=0.1) + { - } + double rotateTheta = -0.1; + double rotatePhi = -0.1; - void TestRotatedVectorAroundAllAxis() - { + m_TestVector->SetElement(0, r * sin(theta) * cos(phi)); + m_TestVector->SetElement(1, r * sin(theta) * sin(phi)); + m_TestVector->SetElement(2, r * cos(theta)); + + m_TestVector->Rotate(rotateTheta, rotatePhi); + + double newTheta = fmod(theta + rotateTheta, TWO_PI); + double newPhi = fmod(phi + rotatePhi, TWO_PI); + + double expectedX = r * sin(newTheta) * cos(newPhi); + double expectedY = r * sin(newTheta) * sin(newPhi); + double expectedZ = r * cos(newTheta); - //TODO rewrite this test + CPPUNIT_ASSERT_MESSAGE("The vector value at index0 should be " + std::to_string(expectedX) + " but was " + std::to_string(m_TestVector->GetElement(0)) + + " at r=" + std::to_string(r) + " phi=" + std::to_string(phi) + " theta=" + std::to_string(theta), + m_TestVector->GetElement(0) - expectedX < DIF_VAL); + CPPUNIT_ASSERT_MESSAGE("The vector value at index1 should be " + std::to_string(expectedY) + " but was " + std::to_string(m_TestVector->GetElement(0)) + + " at r=" + std::to_string(r) + " phi=" + std::to_string(phi) + " theta=" + std::to_string(theta), + m_TestVector->GetElement(1) - expectedY < DIF_VAL); + CPPUNIT_ASSERT_MESSAGE("The vector value at index2 should be " + std::to_string(expectedZ) + " but was " + std::to_string(m_TestVector->GetElement(0)) + + " at r=" + std::to_string(r) + " phi=" + std::to_string(phi) + " theta=" + std::to_string(theta), + m_TestVector->GetElement(2) - expectedZ < DIF_VAL); + } + } + } } - void TestScaledVector() + void TestScaleVector() { double a = 1.0; double b = 2.0; double c = 3.0; double length; for (double testFactor = -2.0; testFactor<=2.0; testFactor+=0.3) { double potElement0Fctr; double potElement1Fctr; double potElement2Fctr; double testLength; std::stringstream output; m_TestVector->SetElement(0,a); m_TestVector->SetElement(1,b); m_TestVector->SetElement(2,c); length = m_TestVector->GetNorm(); potElement0Fctr = (m_TestVector->GetElement(0)*testFactor)*(m_TestVector->GetElement(0)*testFactor); potElement1Fctr = (m_TestVector->GetElement(1)*testFactor)*(m_TestVector->GetElement(1)*testFactor); potElement2Fctr = (m_TestVector->GetElement(2)*testFactor)*(m_TestVector->GetElement(2)*testFactor); testLength = sqrt(potElement0Fctr + potElement1Fctr + potElement2Fctr); m_TestVector->Scale(testFactor); CPPUNIT_ASSERT_EQUAL_MESSAGE("The vector length should not be equal", sqrt(potElement0Fctr + potElement1Fctr + potElement2Fctr), m_TestVector->GetNorm()); output << "The vector value at index0 should be"; output << a*testFactor; CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), a*testFactor, m_TestVector->GetElement(0)); output.flush(); output << "The vector value at index1 should be"; output << b*testFactor; CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), b*testFactor, m_TestVector->GetElement(1)); output.flush(); output << "The vector value at index2 should be"; output << c*testFactor; CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), c*testFactor, m_TestVector->GetElement(2)); output.flush(); } } - void TestClonedVector() + void TestCloneVector() { int a = 1; int b = 2; int c = 3; m_TestVector->SetElement(0,a); m_TestVector->SetElement(1,b); m_TestVector->SetElement(2,c); m_TestReturnVector = m_TestVector->Clone(); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector length should be equal",(m_TestVector->GetNorm()),m_TestReturnVector->GetNorm()); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be equal", m_TestVector->GetElement(0), m_TestReturnVector->GetElement(0)); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index1 should be equal", m_TestVector->GetElement(1), m_TestReturnVector->GetElement(1)); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index2 should be equal", m_TestVector->GetElement(2), m_TestReturnVector->GetElement(2)); m_TestReturnVector->Rotate(M_PI/4,M_PI/4); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be not equal", true, m_TestVector->GetElement(0)!= m_TestReturnVector->GetElement(0)); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be not equal", true, m_TestVector->GetElement(1)!= m_TestReturnVector->GetElement(1)); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be not equal", true, m_TestVector->GetElement(2)!= m_TestReturnVector->GetElement(2)); for(double testFactor = -2.0; testFactor<=2.0; testFactor+=0.3) { m_TestReturnVector->Scale(testFactor); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be not equal", true, m_TestVector->GetElement(0)!= m_TestReturnVector->GetElement(0)); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be not equal", true, m_TestVector->GetElement(1)!= m_TestReturnVector->GetElement(1)); CPPUNIT_ASSERT_EQUAL_MESSAGE( "The vector value at index0 should be not equal", true, m_TestVector->GetElement(2)!= m_TestReturnVector->GetElement(2)); } } void tearDown() { m_TestVector = nullptr; m_TestReturnVector = nullptr; } }; MITK_TEST_SUITE_REGISTRATION(mitkPhotoacousticVector) diff --git a/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselMeanderStrategyTest.cpp b/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselMeanderStrategyTest.cpp index f6fb287d66..8a3b620167 100644 --- a/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselMeanderStrategyTest.cpp +++ b/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselMeanderStrategyTest.cpp @@ -1,127 +1,121 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include "mitkPhotoacousticVolume.h" #include "mitkPhotoacousticTissueGenerator.h" #include "mitkPhotoacousticVesselMeanderStrategy.h" class mitkPhotoacousticVesselMeanderStrategyTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPhotoacousticVesselMeanderStrategyTestSuite); MITK_TEST(TestCalculateNewPositionInStraightLine); - MITK_TEST(TestCalculateRandomlyDivergingPosition); CPPUNIT_TEST_SUITE_END(); private: mitk::PhotoacousticVesselMeanderStrategy::Pointer m_TestVector; mitk::PhotoacousticSmartVector::Pointer m_TestPostion; mitk::PhotoacousticSmartVector::Pointer m_TestDirection; public: void setUp() { m_TestVector = mitk::PhotoacousticVesselMeanderStrategy::New(); m_TestPostion = mitk::PhotoacousticSmartVector::New(); m_TestDirection = mitk::PhotoacousticSmartVector::New(); } void TestCalculateNewPositionInStraightLine() { std::stringstream output; int a = 0; int b = 1; int c = 2; int d = 3; int e = 4; int f = 5; for(int i = -2; i <= 2; i++) { if(i == 0) { i++; } for(int j = -2; j <= 2; j++ ) { if(j == 0) { j++; } m_TestPostion -> SetElement(0,a*i); m_TestPostion -> SetElement(1,b*i); m_TestPostion -> SetElement(2,c*i); m_TestDirection -> SetElement(0,d*j); m_TestDirection -> SetElement(1,e*j); m_TestDirection -> SetElement(2,f*j); m_TestVector->CalculateNewPositionInStraightLine(m_TestPostion,m_TestDirection, 0, nullptr); MITK_INFO<<"m_TestPosition Element(0) ="<GetElement(0); MITK_INFO<<"Data0 ="<<(a*i) + (d*j); MITK_INFO<<"m_TestPosition Element(1) ="<GetElement(1); MITK_INFO<<"Data1 ="<<(b*i) + (e*j); MITK_INFO<<"m_TestPosition Element(2) ="<GetElement(2); MITK_INFO<<"Data2 ="<<(c*i) + (f*j); output << "Element0 from m_TestPosition should be "; output << a*i + d*j; CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), true, a*i + d*j == m_TestPostion->GetElement(0)); output.flush(); output << "Element1 from m_TestPosition should be "; output << b*i + e*j; CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), true, b*i + e*j == m_TestPostion->GetElement(1)); output.flush(); output << "Element2 from m_TestPosition should be "; output << c*i + f*j; CPPUNIT_ASSERT_EQUAL_MESSAGE( output.str(), true, c*i + f*j == m_TestPostion->GetElement(2)); output.flush(); } } } - void TestCalculateRandomlyDivergingPosition() - { - - } - void tearDown() { m_TestVector = nullptr; m_TestPostion = nullptr; m_TestDirection = nullptr; } }; MITK_TEST_SUITE_REGISTRATION(mitkPhotoacousticVesselMeanderStrategy) diff --git a/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselTest.cpp b/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselTest.cpp index 5a42275893..ba5e5d9e10 100644 --- a/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselTest.cpp +++ b/Modules/PhotoacousticSimulation/Testing/mitkPhotoacousticVesselTest.cpp @@ -1,76 +1,76 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include "mitkPhotoacousticVolume.h" #include "mitkPhotoacousticSmartVector.h" #include "mitkPhotoacousticVessel.h" class mitkPhotoacousticVesselTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPhotoacousticVesselTestSuite); MITK_TEST(TestInitializedVesselOnlyZero); CPPUNIT_TEST_SUITE_END(); private: mitk::PhotoacousticVessel::Pointer m_TestVessel; mitk::PhotoacousticSmartVector::Pointer m_TestInitialPosition; mitk::PhotoacousticSmartVector::Pointer m_TestInitialDirection; public: void setUp() { m_TestVessel = mitk::PhotoacousticVessel ::New(); m_TestInitialPosition = mitk::PhotoacousticSmartVector::New(); m_TestInitialDirection = mitk::PhotoacousticSmartVector::New(); } void TestInitializedVesselOnlyZero() { int a = 1; int b = 2; int c = 3; int d = 4; int e = 5; int f = 6; m_TestInitialPosition->SetElement(0,a); m_TestInitialPosition->SetElement(1,b); m_TestInitialPosition->SetElement(2,c); m_TestInitialDirection->SetElement(0,d); m_TestInitialDirection->SetElement(1,e); m_TestInitialDirection->SetElement(2,f); - } + } void tearDown() { m_TestVessel = nullptr; m_TestInitialPosition = nullptr; m_TestInitialDirection = nullptr; } }; MITK_TEST_SUITE_REGISTRATION(mitkPhotoacousticVessel)