Medical Imaging Interaction Toolkit  2018.4.99-36d69b77
Medical Imaging Interaction Toolkit
mitkPAVessel.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 "mitkPAVessel.h"
14 #include <chrono>
15 #include <thread>
16 
17 mitk::pa::Vessel::Vessel(VesselProperties::Pointer initialProperties) :
18  m_RangeDistribution(itk::Math::pi / 16, itk::Math::pi / 8),
19  m_SignDistribution(-1, 1)
20 {
21  m_Finished = false;
22  //Copy this so it may be reused for other vessels.
23  m_VesselProperties = VesselProperties::New(initialProperties);
24  m_RadiusRangeDistribution = std::uniform_real_distribution<>(NEW_RADIUS_MINIMUM_RELATIVE_SIZE,
25  NEW_RADIUS_MAXIMUM_RELATIVE_SIZE);
26  m_VesselMeanderStrategy = VesselMeanderStrategy::New();
27  m_WalkedDistance = 0;
28  m_VesselDrawer = VesselDrawer::New();
29 }
30 
32 {
33  m_VesselProperties = nullptr;
34  m_VesselMeanderStrategy = nullptr;
35 }
36 
37 void mitk::pa::Vessel::ExpandVessel(InSilicoTissueVolume::Pointer volume,
38  CalculateNewVesselPositionCallback calculateNewPosition, double bendingFactor, std::mt19937* rng)
39 {
40  m_VesselDrawer->ExpandAndDrawVesselInVolume(m_VesselProperties, volume);
41  (m_VesselMeanderStrategy->*calculateNewPosition)(m_VesselProperties->GetDirectionVector(), bendingFactor, rng);
42  m_WalkedDistance += (m_VesselProperties->GetDirectionVector()->GetNorm() / volume->GetSpacing());
43 }
44 
46 {
47  return m_VesselProperties->GetBifurcationFrequency() < m_WalkedDistance;
48 }
49 
50 int mitk::pa::Vessel::GetSign(std::mt19937 *rng)
51 {
52  if (m_SignDistribution(*rng) < 0)
53  return -1;
54 
55  return 1;
56 }
57 
58 mitk::pa::Vessel::Pointer mitk::pa::Vessel::Bifurcate(std::mt19937* rng)
59 {
60  VesselProperties::Pointer vesselParams = VesselProperties::New(m_VesselProperties);
61  double thetaChange = m_RangeDistribution(*rng) * GetSign(rng);
62  double phiChange = m_RangeDistribution(*rng) * GetSign(rng);
63 
64  vesselParams->GetDirectionVector()->Rotate(thetaChange, phiChange);
65  m_VesselProperties->GetDirectionVector()->Rotate(-thetaChange, -phiChange);
66 
67  double newRadius = m_RadiusRangeDistribution(*rng)*m_VesselProperties->GetRadiusInVoxel();
68  vesselParams->SetRadiusInVoxel(newRadius);
69  m_VesselProperties->SetRadiusInVoxel(
70  sqrt(m_VesselProperties->GetRadiusInVoxel()*m_VesselProperties->GetRadiusInVoxel() - newRadius*newRadius));
71 
72  m_WalkedDistance = 0;
73 
74  return Vessel::New(vesselParams);
75 }
76 
78 {
79  return m_VesselProperties->GetRadiusInVoxel() < MINIMUM_VESSEL_RADIUS;
80 }
81 
82 bool mitk::pa::Equal(const Vessel::Pointer leftHandSide, const Vessel::Pointer rightHandSide, double eps, bool verbose)
83 {
84  MITK_INFO(verbose) << "=== mitk::pa::Vessel Equal ===";
85 
86  if (rightHandSide.IsNull() || leftHandSide.IsNull())
87  {
88  MITK_INFO(verbose) << "Cannot compare nullpointers";
89  return false;
90  }
91 
92  if (leftHandSide->IsFinished() != rightHandSide->IsFinished())
93  {
94  MITK_INFO(verbose) << "Not same finished state.";
95  return false;
96  }
97 
98  if (leftHandSide->CanBifurcate() != rightHandSide->CanBifurcate())
99  {
100  MITK_INFO(verbose) << "Not same bifurcation state.";
101  return false;
102  }
103 
104  if (!Equal(leftHandSide->GetVesselProperties(), rightHandSide->GetVesselProperties(), eps, verbose))
105  {
106  MITK_INFO(verbose) << "Vesselproperties not equal";
107  return false;
108  }
109 
110  return true;
111 }
~Vessel() override
#define MITK_INFO
Definition: mitkLogMacros.h:18
Vessel::Pointer Bifurcate(std::mt19937 *rng)
Bifurcate bifurcates this vessel into two new ones. Makes sure that the volume of the vessels stays t...
bool CanBifurcate()
CanBifurcate.
MITKPHOTOACOUSTICSLIB_EXPORT bool Equal(const MonteCarloThreadHandler::Pointer leftHandSide, const MonteCarloThreadHandler::Pointer rightHandSide, double eps, bool verbose)
Equal A function comparing two thread handlers for beeing equal.
bool verbose(false)
void ExpandVessel(mitk::pa::InSilicoTissueVolume::Pointer volume, CalculateNewVesselPositionCallback calculateNewPosition, double bendingFactor, std::mt19937 *rng)
ExpandVessel makes this Vessel expand one step in its current direction. After expanding, the vessel will draw itself into the given InSilicoTissueVolume.
Vessel(VesselProperties::Pointer parameters)
bool IsFinished()
IsFinished.
MITKCORE_EXPORT const ScalarType eps
static Pointer New()
void(VesselMeanderStrategy::* CalculateNewVesselPositionCallback)(Vector::Pointer, double, std::mt19937 *)
Definition: mitkPAVessel.h:41