Medical Imaging Interaction Toolkit  2018.4.99-dcb22cd7
Medical Imaging Interaction Toolkit
mitkPhotoacousticVesselTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include <mitkTestFixture.h>
14 #include <mitkTestingMacros.h>
15 
16 #include <mitkImageReadAccessor.h>
17 
19 #include "mitkPAVector.h"
20 #include "mitkPAVessel.h"
21 
22 class mitkPhotoacousticVesselTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkPhotoacousticVesselTestSuite);
25  MITK_TEST(testEmptyInitializationProperties);
26  MITK_TEST(testWalkInStraightLine);
27  MITK_TEST(testBifurcate);
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
31  mitk::pa::Vessel::Pointer m_TestVessel;
34  mitk::pa::InSilicoTissueVolume::Pointer m_TestInSilicoVolume;
35  mitk::pa::TissueGeneratorParameters::Pointer m_TestVolumeParameters;
36 
37 public:
38 
39  void setUp() override
40  {
41  auto params = mitk::pa::VesselProperties::New();
42  m_TestVessel = mitk::pa::Vessel::New(params);
45  m_TestVolumeParameters = createTestVolumeParameters();
46  auto rng = std::mt19937();
47  m_TestInSilicoVolume = mitk::pa::InSilicoTissueVolume::New(m_TestVolumeParameters, &rng);
48  }
49 
50  mitk::pa::TissueGeneratorParameters::Pointer createTestVolumeParameters()
51  {
52  auto returnParameters =
54 
55  returnParameters->SetXDim(10);
56  returnParameters->SetYDim(10);
57  returnParameters->SetZDim(10);
58  returnParameters->SetMinBackgroundAbsorption(0);
59  returnParameters->SetMaxBackgroundAbsorption(0);
60  returnParameters->SetBackgroundScattering(0);
61  returnParameters->SetBackgroundAnisotropy(0);
62  return returnParameters;
63  }
64 
65  void testEmptyInitializationProperties()
66  {
67  CPPUNIT_ASSERT(m_TestVessel->CanBifurcate() == false);
68  CPPUNIT_ASSERT(m_TestVessel->IsFinished() == true);
69  }
70 
71  void testWalkInStraightLine()
72  {
73  auto testPosition = mitk::pa::Vector::New();
74  testPosition->SetElement(0, 0);
75  testPosition->SetElement(1, 4);
76  testPosition->SetElement(2, 4);
77  auto testDirection = mitk::pa::Vector::New();
78  testDirection->SetElement(0, 1);
79  testDirection->SetElement(1, 0);
80  testDirection->SetElement(2, 0);
81  auto params = mitk::pa::VesselProperties::New();
82  params->SetDoPartialVolume(false);
83  params->SetRadiusInVoxel(1);
84  params->SetBifurcationFrequency(100);
85  params->SetAbsorptionCoefficient(10);
86  params->SetScatteringCoefficient(10);
87  params->SetAnisotopyCoefficient(10);
88  params->SetPositionVector(testPosition);
89  params->SetDirectionVector(testDirection);
90  m_TestVessel = mitk::pa::Vessel::New(params);
91 
92  CPPUNIT_ASSERT(m_TestVessel->CanBifurcate() == false);
93  CPPUNIT_ASSERT(m_TestVessel->IsFinished() == false);
94 
95  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 4)),
96  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 4)) <= mitk::eps);
97 
98  m_TestVessel->ExpandVessel(m_TestInSilicoVolume, m_StraightLine, 0, nullptr);
99 
100  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 4)),
101  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 4) - 10) <= mitk::eps);
102  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 5, 4)),
103  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 5, 4)) <= mitk::eps);
104  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 6, 4)),
105  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 6, 4)) <= mitk::eps);
106  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 5)),
107  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 5)) <= mitk::eps);
108  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 6)),
109  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 6)) <= mitk::eps);
110 
111  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4)),
112  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4)) <= mitk::eps);
113  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(2, 4, 4)),
114  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(2, 4, 4)) <= mitk::eps);
115 
116  m_TestVessel->ExpandVessel(m_TestInSilicoVolume, m_StraightLine, 0, nullptr);
117 
118  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4)),
119  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4) - 10) <= mitk::eps);
120  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 5, 4)),
121  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 5, 4)) <= mitk::eps);
122  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 6, 4)),
123  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 6, 4)) <= mitk::eps);
124  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 5)),
125  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 5)) <= mitk::eps);
126  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 6)),
127  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 6)) <= mitk::eps);
128 
129  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4)),
130  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 4) - 10) <= mitk::eps);
131  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4)),
132  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(1, 4, 4) - 10) <= mitk::eps);
133  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(2, 4, 4)),
134  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(2, 4, 4)) <= mitk::eps);
135  CPPUNIT_ASSERT_MESSAGE(std::to_string(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(3, 4, 4)),
136  std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(3, 4, 4)) <= mitk::eps);
137  }
138 
139  void testBifurcate()
140  {
141  auto testPosition = mitk::pa::Vector::New();
142  testPosition->SetElement(0, 0);
143  testPosition->SetElement(1, 4);
144  testPosition->SetElement(2, 4);
145  auto testDirection = mitk::pa::Vector::New();
146  testDirection->SetElement(0, 1);
147  testDirection->SetElement(1, 0);
148  testDirection->SetElement(2, 0);
149  auto params = mitk::pa::VesselProperties::New();
150  params->SetRadiusInVoxel(1);
151  params->SetBifurcationFrequency(1);
152  params->SetAbsorptionCoefficient(10);
153  params->SetScatteringCoefficient(10);
154  params->SetAnisotopyCoefficient(10);
155  params->SetPositionVector(testPosition);
156  params->SetDirectionVector(testDirection);
157  m_TestVessel = mitk::pa::Vessel::New(params);
158 
159  CPPUNIT_ASSERT(m_TestVessel->CanBifurcate() == false);
160  CPPUNIT_ASSERT(m_TestVessel->IsFinished() == false);
161 
162  CPPUNIT_ASSERT(std::abs(m_TestInSilicoVolume->GetAbsorptionVolume()->GetData(0, 4, 4)) <= mitk::eps);
163 
164  m_TestVessel->ExpandVessel(m_TestInSilicoVolume, m_StraightLine, 0, nullptr);
165  m_TestVessel->ExpandVessel(m_TestInSilicoVolume, m_StraightLine, 0, nullptr);
166 
167  CPPUNIT_ASSERT(m_TestVessel->CanBifurcate() == true);
168  std::mt19937 rng;
169  auto bifurcationVessel = m_TestVessel->Bifurcate(&rng);
170 
171  CPPUNIT_ASSERT(m_TestVessel->CanBifurcate() == false);
172  CPPUNIT_ASSERT(bifurcationVessel->CanBifurcate() == false);
173  }
174 
175  void tearDown() override
176  {
177  }
178 };
179 
180 MITK_TEST_SUITE_REGISTRATION(mitkPhotoacousticVessel)
void CalculateNewRandomlyDivergingDirectionVector(Vector::Pointer direction, double bendingFactor, std::mt19937 *rng)
CalculateRandomlyDivergingPosition calculates the new position by modifying the direction vector rand...
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static InSilicoTissueVolume::Pointer New(mitk::pa::Volume::Pointer absorptionVolume, Volume::Pointer scatteringVolume, Volume::Pointer anisotropyVolume, Volume::Pointer segmentationVolume, TissueGeneratorParameters::Pointer tissueParameters, mitk::PropertyList::Pointer propertyList)
Test fixture for parameterized tests.
void CalculateNewDirectionVectorInStraightLine(Vector::Pointer direction, double bendingFactor, std::mt19937 *rng)
CalculateNewPositionInStraightLine calculates the new position by just following the direction vector...
static Pointer New()
MITKCORE_EXPORT const ScalarType eps
void(VesselMeanderStrategy::* CalculateNewVesselPositionCallback)(Vector::Pointer, double, std::mt19937 *)
Definition: mitkPAVessel.h:41