Chaste  Build::
VesselNetworkGeometryCalculator.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  */
35 
36 #include "Exception.hpp"
37 #include "VesselNetworkGeometryCalculator.hpp"
38 #include "GeometryTools.hpp"
39 
40 template <unsigned DIM>
42  mpVesselNetwork()
43 {
44 
45 }
46 
47 template <unsigned DIM>
49 {
50 
51 }
52 
53 template <unsigned DIM>
54 boost::shared_ptr<VesselNetworkGeometryCalculator<DIM> > VesselNetworkGeometryCalculator<DIM>::Create()
55 {
56  MAKE_PTR(VesselNetworkGeometryCalculator<DIM>, pSelf);
57  return pSelf;
58 }
59 
60 template <unsigned DIM>
61 std::vector<units::quantity<unit::length> > VesselNetworkGeometryCalculator<DIM>::GetInterCapillaryDistances()
62 {
63  if(!mpVesselNetwork)
64  {
65  EXCEPTION("Vessel network not set in geometry calculator");
66  }
67 
68  std::vector<boost::shared_ptr<Vessel<DIM> > > vessels = mpVesselNetwork->GetVessels();
69  std::vector<units::quantity<unit::length> > distances;
70  for(unsigned idx=0; idx<vessels.size(); idx++)
71  {
72  units::quantity<unit::length> min_distance = 1.e6 * unit::metres;
73  for(unsigned jdx=0; jdx<vessels.size(); jdx++)
74  {
75  if(vessels[idx]!=vessels[jdx])
76  {
77  units::quantity<unit::length> distance = vessels[idx]->GetStartNode()->GetDistance(vessels[jdx]->GetStartNode()->rGetLocation());
78  if(distance < min_distance)
79  {
80  min_distance = distance;
81  }
82  }
83  }
84  distances.push_back(min_distance);
85  }
86  return distances;
87 }
88 
89 template <unsigned DIM>
91 {
92  if(!mpVesselNetwork)
93  {
94  EXCEPTION("Vessel network not set in geometry calculator");
95  }
96 
97  std::vector<boost::shared_ptr<Vessel<DIM> > > vessels = mpVesselNetwork->GetVessels();
98  units::quantity<unit::length> length = 0.0* unit::metres;
99  for(unsigned idx=0; idx<vessels.size(); idx++)
100  {
101  length += vessels[idx]->GetLength();
102  }
103  return length;
104 }
105 
106 template <unsigned DIM>
108 {
109  if(!mpVesselNetwork)
110  {
111  EXCEPTION("Vessel network not set in geometry calculator");
112  }
113 
114  units::quantity<unit::volume> volume = 0.0*units::pow<3>(unit::metres);
115  std::vector<boost::shared_ptr<VesselSegment<DIM> > > segments = mpVesselNetwork->GetVesselSegments();
116  for(unsigned idx=0; idx< segments.size(); idx++)
117  {
118  volume += segments[idx]->GetLength() * segments[idx]->GetRadius() * segments[idx]->GetRadius() * M_PI;
119  }
120  return volume;
121 }
122 
123 template <unsigned DIM>
125 {
126  if(!mpVesselNetwork)
127  {
128  EXCEPTION("Vessel network not set in geometry calculator");
129  }
130 
131  units::quantity<unit::area> area = 0.0*units::pow<2>(unit::metres);
132  std::vector<boost::shared_ptr<VesselSegment<DIM> > > segments = mpVesselNetwork->GetVesselSegments();
133  for(unsigned idx=0; idx< segments.size(); idx++)
134  {
135  area += segments[idx]->GetLength() * 2.0 * segments[idx]->GetRadius() * M_PI;
136  }
137  return area;
138 }
139 
140 template <unsigned DIM>
142 {
143  if(!mpVesselNetwork)
144  {
145  EXCEPTION("Vessel network not set in geometry calculator");
146  }
147 
148  std::vector<boost::shared_ptr<VesselSegment<DIM> > > segments = mpVesselNetwork->GetVesselSegments();
149 
150  // store segment midpoints
151  std::vector<DimensionalChastePoint<DIM> > midpoints(segments.size());
152  for(unsigned idx=0; idx<segments.size(); idx++)
153  {
154  midpoints[idx] = segments[idx]->GetMidPoint();
155  }
156 
157  // get intersegment distances
158  units::quantity<unit::length> av_dist = 0.0 * unit::metres;
159  for(unsigned idx=0; idx<segments.size(); idx++)
160  {
161  units::quantity<unit::length> min_dist = 1.e6 * unit::metres;
162  for(unsigned jdx=0; jdx<segments.size(); jdx++)
163  {
164  if(segments[idx] != segments[jdx] && segments[idx]->GetVessel() != segments[jdx]->GetVessel())
165  {
166  units::quantity<unit::length> dist = GetDistance(midpoints[idx], midpoints[jdx]);
167  if(dist < min_dist)
168  {
169  min_dist = dist;
170  }
171  }
172  }
173  av_dist += min_dist;
174  }
175  return av_dist / double(segments.size());
176 }
177 
178 template <unsigned DIM>
180 {
181  if(!mpVesselNetwork)
182  {
183  EXCEPTION("Vessel network not set in geometry calculator");
184  }
185 
186  return GetTotalLength() / double(mpVesselNetwork->GetVessels().size());
187 }
188 
189 template <unsigned DIM>
190 std::vector<unsigned> VesselNetworkGeometryCalculator<DIM>::GetVesselLengthDistribution(double binSpacing, unsigned numberOfBins)
191 {
192  if(!mpVesselNetwork)
193  {
194  EXCEPTION("Vessel network not set in geometry calculator");
195  }
196 
197  std::vector<unsigned> bins(numberOfBins, 0);
198 
199  // populate the bins
200  std::vector<boost::shared_ptr<Vessel<DIM> > > vessels = mpVesselNetwork->GetVessels();
201  for(unsigned idx=0; idx<vessels.size(); idx++)
202  {
203  unsigned bin_label = std::floor(vessels[idx]->GetLength() / (binSpacing*unit::metres));
204  if(bin_label > numberOfBins)
205  {
206  bin_label = numberOfBins;
207  }
208  bins[bin_label]++;
209  }
210  return bins;
211 }
212 
213 template <unsigned DIM>
215 {
216  mpVesselNetwork = pVesselNetwork;
217 }
218 
219 // Explicit instantiation
222 
units::quantity< unit::length > GetTotalLength()
boost::shared_ptr< VesselNetwork< DIM > > mpVesselNetwork
units::quantity< unit::volume > GetTotalVolume()
units::quantity< unit::area > GetTotalSurfaceArea()
units::quantity< unit::length > GetAverageVesselLength()
std::vector< unsigned > GetVesselLengthDistribution(double binSpacing=10.0, unsigned numberOfBins=10)
units::quantity< unit::length > GetAverageInterSegmentDistance()
std::vector< units::quantity< unit::length > > GetInterCapillaryDistances()
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< DIM > > pVesselNetwork)
static boost::shared_ptr< VesselNetworkGeometryCalculator< DIM > > Create()