Chaste  Release::3.4
PapillaryFibreCalculator.hpp
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 #ifndef PAPILLARYFIBRECALCULATOR_HPP_
36 #define PAPILLARYFIBRECALCULATOR_HPP_
37 
38 #include "UblasCustomFunctions.hpp"
39 #include "TetrahedralMesh.hpp"
40 
47 {
48 // Allow the test class to use the private functions.
49 friend class TestPapillaryFibreCalculator;
50 
51 private:
55  std::vector< c_vector<double, 3> > mRadiusVectors;
57  std::vector< c_matrix<double,3,3> > mStructureTensors;
59  std::vector< c_matrix<double,3,3> > mSmoothedStructureTensors;
60 
68  c_vector<double,3> GetRadiusVectorForOneElement(unsigned elementIndex);
69 
74  void GetRadiusVectors();
75 
76 
83 
94 
95 public:
102 
108  std::vector<c_vector<double,3> > CalculateFibreOrientations();
109 
110 };
111 
112 // PUBLIC METHODS
114  : mrMesh(rMesh)
115 {
119 }
120 
122 {
124 
126 
128 
129  // Calculate eigenvalues
130  std::vector<c_vector<double,3> > fibre_orientations(mrMesh.GetNumElements());
131  for(unsigned i=0; i<fibre_orientations.size(); i++)
132  {
134  }
135 
136  return fibre_orientations;
137 }
138 
139 // PRIVATE METHODS
140 c_vector<double,3> PapillaryFibreCalculator::GetRadiusVectorForOneElement(unsigned elementIndex)
141 {
142  c_vector<double, 3> centroid = (mrMesh.GetElement(elementIndex))->CalculateCentroid();
143  // Loops over all papillary face nodes
144  c_vector<double,3> coordinates;
145 
146  double nearest_r_squared=DBL_MAX;
147  unsigned nearest_face_node = 0;
148 
150  while (bound_node_iter != mrMesh.GetBoundaryNodeIteratorEnd())
151  {
152  unsigned bound_node_index = (*bound_node_iter)->GetIndex();
153  coordinates=mrMesh.GetNode(bound_node_index)->rGetLocation();
154 
155  // Calculates the distance between the papillary face node and the centroid
156  double r_squared = norm_2(centroid-coordinates);
157  // Checks to see if it is the smallest so far - if it is, update the current smallest distance
158  if (r_squared < nearest_r_squared)
159  {
160  nearest_r_squared = r_squared;
161  nearest_face_node = bound_node_index;
162  }
163  ++bound_node_iter;
164  }
165 
166  coordinates = mrMesh.GetNode(nearest_face_node)->rGetLocation();
167  c_vector<double,3> radial_vector = coordinates-centroid;
168  return radial_vector;
169 }
170 
172 {
173  // Loops over all elements finding radius vector
175  iter != mrMesh.GetElementIteratorEnd();
176  ++iter)
177  {
178  unsigned element_index = iter->GetIndex();
179  mRadiusVectors[element_index] = GetRadiusVectorForOneElement(element_index);
180  }
181 }
182 
184 {
185  for(unsigned i=0;i<mRadiusVectors.size();i++)
186  {
187  mStructureTensors[i] = outer_prod(mRadiusVectors[i],mRadiusVectors[i]);
188  }
189 }
190 
192 {
193  const double sigma = 0.05; //cm
194  const double r_max = 0.1; //cm
195  double g_factor_sum = 0;
196  double g_factor = 0;
197 
199  elem_iter != mrMesh.GetElementIteratorEnd();
200  ++elem_iter)
201  {
202  mSmoothedStructureTensors[ elem_iter->GetIndex()] = zero_matrix<double>(3,3);
203 
204  c_vector<double, 3> centroid = elem_iter->CalculateCentroid();
205  g_factor_sum = 0;
206 
208  iter_2 != mrMesh.GetElementIteratorEnd();
209  ++iter_2)
210  {
211  c_vector<double, 3> centroid_2 = iter_2->CalculateCentroid();
212  double r = norm_2(centroid-centroid_2);
213  if (r < r_max)
214  {
215  g_factor = exp(-r/(2*sigma*sigma));
216 
217  g_factor_sum += g_factor;
218 
219  mSmoothedStructureTensors[elem_iter->GetIndex()] += g_factor*mStructureTensors[iter_2->GetIndex()];
220  }
221  }
222 
223  mSmoothedStructureTensors[elem_iter->GetIndex()] /= g_factor_sum;
224  }
225 }
226 
227 #endif /*PAPILLARYFIBRECALCULATOR_HPP_*/
228 
ElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
c_vector< double, 3 > CalculateEigenvectorForSmallestNonzeroEigenvalue(c_matrix< double, 3, 3 > &rA)
Node< SPACE_DIM > * GetNode(unsigned index) const
virtual unsigned GetNumElements() const
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const
c_vector< double, 3 > GetRadiusVectorForOneElement(unsigned elementIndex)
std::vector< c_matrix< double, 3, 3 > > mSmoothedStructureTensors
std::vector< c_vector< double, 3 > > CalculateFibreOrientations()
std::vector< c_matrix< double, 3, 3 > > mStructureTensors
PapillaryFibreCalculator(TetrahedralMesh< 3, 3 > &rMesh)
BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const
TetrahedralMesh< 3, 3 > & mrMesh
std::vector< c_vector< double, 3 > > mRadiusVectors