Chaste  Build::
VesselNetworkCellPopulationInteractor.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 "VesselNetworkCellPopulationInteractor.hpp"
37 
38 template<unsigned DIM>
40  mpNetwork()
41 {
42 
43 }
44 
45 template<unsigned DIM>
47 {
48 
49 }
50 
51 template<unsigned DIM>
52 void VesselNetworkCellPopulationInteractor<DIM>::LabelVesselsInCellPopulation(AbstractCellPopulation<DIM>& rCellPopulation, units::quantity<unit::length> cellLengthScale,
53  boost::shared_ptr<AbstractCellMutationState> pTipMutationState,
54  boost::shared_ptr<AbstractCellMutationState> pStalkState,
55  double threshold)
56 {
57  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();cell_iter != rCellPopulation.End();++cell_iter)
58  {
59  DimensionalChastePoint<DIM> cell_location = DimensionalChastePoint<DIM>(rCellPopulation.GetLocationOfCellCentre(*cell_iter), cellLengthScale);
60  boost::shared_ptr<VesselNode<DIM> > p_nearest_node = mpNetwork->GetNearestNode(cell_location);
61  units::quantity<unit::length> node_distance = p_nearest_node->GetDistance(cell_location);
62  std::pair<boost::shared_ptr<VesselSegment<DIM> >, units::quantity<unit::length> > segment_distance_pair = mpNetwork->GetNearestSegment(cell_location);
63  if (segment_distance_pair.second < threshold * cellLengthScale || node_distance < threshold * cellLengthScale)
64  {
65  if(p_nearest_node->IsMigrating())
66  {
67  cell_iter->SetMutationState(pTipMutationState);
68  }
69  else
70  {
71  cell_iter->SetMutationState(pStalkState);
72  }
73  }
74  }
75 }
76 
77 template<unsigned DIM>
78 void VesselNetworkCellPopulationInteractor<DIM>::PartitionNetworkOverCells(AbstractCellPopulation<DIM>& rCellPopulation, units::quantity<unit::length> cellLengthScale,
79  double threshold)
80 {
81  // Loop through each cell add get its location. If the centre falls along a vessel, split the vessel at that location
82 
83  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();cell_iter != rCellPopulation.End();++cell_iter)
84  {
85  DimensionalChastePoint<DIM> cell_location = DimensionalChastePoint<DIM>(rCellPopulation.GetLocationOfCellCentre(*cell_iter), cellLengthScale);
86  boost::shared_ptr<VesselNode<DIM> > p_nearest_node = mpNetwork->GetNearestNode(cell_location);
87  units::quantity<unit::length> node_distance = p_nearest_node->GetDistance(cell_location);
88 
89  std::pair<boost::shared_ptr<VesselSegment<DIM> >, units::quantity<unit::length> > segment_distance_pair = mpNetwork->GetNearestSegment(cell_location);
90  if (segment_distance_pair.second < threshold*cellLengthScale || node_distance < threshold*cellLengthScale)
91  {
92  if (node_distance >= threshold*cellLengthScale)
93  {
94  boost::shared_ptr<Vessel<DIM> > pVessel = segment_distance_pair.first->GetVessel();
95  pVessel->DivideSegment(cell_location);
96  pVessel->UpdateNodes();
97  }
98  mpNetwork->UpdateNodes();
99  mpNetwork->UpdateSegments();
100  mpNetwork->UpdateVesselNodes();
101  }
102  }
103 }
104 
105 template<unsigned DIM>
106 void VesselNetworkCellPopulationInteractor<DIM>::KillNonVesselOverlappingCells(AbstractCellPopulation<DIM>& rCellPopulation, units::quantity<unit::length> cellLengthScale,
107  double threshold)
108 {
109  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();cell_iter != rCellPopulation.End();++cell_iter)
110  {
111  DimensionalChastePoint<DIM> cell_location = DimensionalChastePoint<DIM>(rCellPopulation.GetLocationOfCellCentre(*cell_iter), cellLengthScale);
112  boost::shared_ptr<VesselNode<DIM> > p_nearest_node = mpNetwork->GetNearestNode(cell_location);
113  units::quantity<unit::length> node_distance = p_nearest_node->GetDistance(cell_location);
114 
115  std::pair<boost::shared_ptr<VesselSegment<DIM> >, units::quantity<unit::length> > segment_distance_pair = mpNetwork->GetNearestSegment(cell_location);
116  if (segment_distance_pair.second > threshold*cellLengthScale and node_distance > threshold*cellLengthScale)
117  {
118  cell_iter->Kill();
119  }
120  }
121  rCellPopulation.RemoveDeadCells();
122 }
123 
124 template<unsigned DIM>
125 void VesselNetworkCellPopulationInteractor<DIM>::KillOverlappingVesselCells(AbstractCellPopulation<DIM>& rCellPopulation, units::quantity<unit::length> cellLengthScale,
126  double threshold)
127 {
128  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();cell_iter != rCellPopulation.End();++cell_iter)
129  {
130  DimensionalChastePoint<DIM> cell_location = DimensionalChastePoint<DIM>(rCellPopulation.GetLocationOfCellCentre(*cell_iter), cellLengthScale);
131  boost::shared_ptr<VesselNode<DIM> > p_nearest_node = mpNetwork->GetNearestNode(cell_location);
132  units::quantity<unit::length> node_distance = p_nearest_node->GetDistance(cell_location);
133 
134  std::pair<boost::shared_ptr<VesselSegment<DIM> >, units::quantity<unit::length> > segment_distance_pair = mpNetwork->GetNearestSegment(cell_location);
135  if (segment_distance_pair.second < threshold*cellLengthScale or node_distance < threshold*cellLengthScale)
136  {
137  cell_iter->Kill();
138  }
139  }
140  rCellPopulation.RemoveDeadCells();
141 }
142 
143 template<unsigned DIM>
145 {
146  mpNetwork = pNetwork;
147 }
148 
149 // Explicit instantiation
units::quantity< unit::length > GetDistance(const DimensionalChastePoint< DIM > &rLocation) const
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< DIM > > pNetwork)
void PartitionNetworkOverCells(AbstractCellPopulation< DIM > &rCellPopulation, units::quantity< unit::length > cellLengthScale, double threshold=1.25e-6)
void LabelVesselsInCellPopulation(AbstractCellPopulation< DIM > &cellPopulation, units::quantity< unit::length > cellLengthScale, boost::shared_ptr< AbstractCellMutationState > pTipMutationState, boost::shared_ptr< AbstractCellMutationState > pStalkState, double threshold=1.25e-6)
boost::shared_ptr< VesselNetwork< DIM > > mpNetwork
void KillNonVesselOverlappingCells(AbstractCellPopulation< DIM > &rCellPopulation, units::quantity< unit::length > cellLengthScale, double threshold=1.25e-6)
void KillOverlappingVesselCells(AbstractCellPopulation< DIM > &rCellPopulation, units::quantity< unit::length > cellLengthScale, double threshold=1.25e-6)