Chaste Release::3.1
HeartGeometryInformation.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 #ifndef HEARTGEOMETRYINFORMATION_HPP_
00036 #define HEARTGEOMETRYINFORMATION_HPP_
00037 
00038 #include <vector>
00039 #include <string>
00040 #include <set>
00041 #include "DistanceMapCalculator.hpp"
00042 #include "AbstractTetrahedralMesh.hpp"
00043 #include "ChasteCuboid.hpp"
00044 
00046 typedef enum HeartLayerType_
00047 {
00048     ENDO = 0,
00049     MID,
00050     EPI
00051 } HeartLayerType;
00052 
00054 typedef unsigned HeartRegionType;
00055 
00056 
00061 template<unsigned SPACE_DIM>
00062 class HeartGeometryInformation
00063 {
00064 private:
00065 
00067     static const double LEFT_SEPTUM_SIZE;
00069     static const double RIGHT_SEPTUM_SIZE;
00070 
00072     std::vector<unsigned> mEpiSurface;
00073 
00075     std::vector<unsigned> mEndoSurface;
00076 
00078     std::vector<unsigned> mLVSurface;
00079 
00081     std::vector<unsigned> mRVSurface;
00082 
00092     void GetNodesAtSurface(const std::string& surfaceFile, std::vector<unsigned>& rSurfaceNodes, bool indexFromZero=true) const;
00093 
00100     void ProcessLine(const std::string& line, std::set<unsigned>& rSurfaceNodeIndexSet, unsigned offset) const;
00101 
00109     double GetDistanceToEndo(unsigned nodeIndex);
00110 
00117     double GetDistanceToEpi(unsigned nodeIndex);
00118 
00120     AbstractTetrahedralMesh<SPACE_DIM,SPACE_DIM>* mpMesh;
00121 
00123     std::vector<double> mDistMapEpicardium;
00124 
00126     std::vector<double> mDistMapEndocardium;
00127 
00129     std::vector<double> mDistMapRightVentricle;
00130 
00132     std::vector<double> mDistMapLeftVentricle;
00133 
00135     unsigned mNumberOfSurfacesProvided;
00136 
00138     std::vector<HeartLayerType> mLayerForEachNode;
00139 
00145     ChasteCuboid<SPACE_DIM> CalculateBoundingBoxOfSurface(const std::vector<unsigned>& rSurfaceNodes);
00146 
00147 public:
00149 
00150     static const HeartRegionType LEFT_VENTRICLE_WALL=1001;
00152     static const HeartRegionType RIGHT_VENTRICLE_WALL=1002;
00154     static const HeartRegionType LEFT_SEPTUM=1003;
00156     static const HeartRegionType RIGHT_SEPTUM=1004;
00158     static const HeartRegionType LEFT_VENTRICLE_SURFACE=1005;
00160     static const HeartRegionType RIGHT_VENTRICLE_SURFACE=1006;
00162     static const HeartRegionType UNKNOWN=1007;
00163 
00172     HeartGeometryInformation (AbstractTetrahedralMesh<SPACE_DIM,SPACE_DIM>& rMesh,
00173                               const std::string& rEpiFile,
00174                               const std::string& rEndoFile,
00175                               bool indexFromZero);
00176 
00177 
00191     HeartGeometryInformation (AbstractTetrahedralMesh<SPACE_DIM,SPACE_DIM>& rMesh,
00192                               const std::string& rEpiFile,
00193                               const std::string& rLVFile,
00194                               const std::string& rRVFile,
00195                               bool indexFromZero);
00196 
00206     HeartGeometryInformation (std::string nodeHeterogeneityFileName);
00207 
00212     HeartRegionType GetHeartRegion (unsigned nodeIndex) const;
00213 
00218     std::vector<double>& rGetDistanceMapEpicardium()
00219     {
00220         return mDistMapEpicardium;
00221     }
00222 
00227     std::vector<double>& rGetDistanceMapEndocardium()
00228     {
00229         assert(mNumberOfSurfacesProvided==2);
00230         return mDistMapEndocardium;
00231     }
00232 
00237     std::vector<double>& rGetDistanceMapRightVentricle()
00238     {
00239         assert(mNumberOfSurfacesProvided==3);
00240         return mDistMapRightVentricle;
00241     }
00242 
00247     std::vector<double>& rGetDistanceMapLeftVentricle()
00248     {
00249         assert(mNumberOfSurfacesProvided==3);
00250         return mDistMapLeftVentricle;
00251     }
00252 
00254     const std::vector<unsigned>& rGetNodesOnEpiSurface()
00255     {
00256         return mEpiSurface;
00257     }
00258 
00259 
00261     const std::vector<unsigned>& rGetNodesOnEndoSurface()
00262     {
00263         assert(mNumberOfSurfacesProvided==2);
00264         return mEndoSurface;
00265     }
00266 
00268     const std::vector<unsigned>& rGetNodesOnLVSurface()
00269     {
00270         assert(mNumberOfSurfacesProvided==3);
00271         return mLVSurface;
00272     }
00273 
00275     const std::vector<unsigned>& rGetNodesOnRVSurface()
00276     {
00277         assert(mNumberOfSurfacesProvided==3);
00278         return mRVSurface;
00279     }
00280 
00284     const std::vector<HeartLayerType>& rGetLayerForEachNode()
00285     {
00286         assert(mLayerForEachNode.size()>0);
00287         return mLayerForEachNode;
00288     }
00289 
00295     double CalculateRelativeWallPosition(unsigned nodeIndex);
00296 
00302     void DetermineLayerForEachNode(double epiFraction, double endoFraction);
00303 
00311     void WriteLayerForEachNode(std::string outputDir, std::string file);
00312 
00319     inline ChasteCuboid<SPACE_DIM> CalculateBoundingBoxOfEpi()
00320     {
00321         return CalculateBoundingBoxOfSurface(mEpiSurface);
00322     }
00329     inline ChasteCuboid<SPACE_DIM> CalculateBoundingBoxOfEndo()
00330     {
00331         return CalculateBoundingBoxOfSurface(mEndoSurface);
00332     }
00339     inline ChasteCuboid<SPACE_DIM> CalculateBoundingBoxOfLV()
00340     {
00341         return CalculateBoundingBoxOfSurface(mLVSurface);
00342     }
00349      inline ChasteCuboid<SPACE_DIM> CalculateBoundingBoxOfRV()
00350     {
00351         return CalculateBoundingBoxOfSurface(mRVSurface);
00352     }
00353 };
00354 #endif //HEARTGEOMETRYINFORMATION_HPP_
00355