00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef MESHBASEDTISSUE_HPP_
00029 #define MESHBASEDTISSUE_HPP_
00030
00031 #include "AbstractCellCentreBasedTissue.hpp"
00032 #include "MutableMesh.hpp"
00033 #include "VoronoiTessellation.hpp"
00034 #include "Exception.hpp"
00035 #include "ArchiveLocationInfo.hpp"
00036 #include "TrianglesMeshReader.hpp"
00037
00038 #include <boost/serialization/access.hpp>
00039 #include <boost/serialization/base_object.hpp>
00040 #include <boost/serialization/set.hpp>
00041 #include <boost/serialization/vector.hpp>
00042
00043
00051 template<unsigned DIM>
00052 class MeshBasedTissue : public AbstractCellCentreBasedTissue<DIM>
00053 {
00054 friend class TestMeshBasedTissue;
00055 private:
00057 friend class boost::serialization::access;
00069 template<class Archive>
00070 void serialize(Archive & archive, const unsigned int version)
00071 {
00072 archive & boost::serialization::base_object<AbstractCellCentreBasedTissue<DIM> >(*this);
00073
00074
00075
00076 delete mpVoronoiTessellation;
00077 mpVoronoiTessellation = NULL;
00078
00079 archive & mMarkedSprings;
00080 archive & mUseAreaBasedDampingConstant;
00081
00082
00083
00084
00085
00086
00087 this->Validate();
00088 }
00089
00090 protected:
00091 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00092
00093 MutableMesh<DIM, DIM>& mrMesh;
00094
00099 VoronoiTessellation<DIM> *mpVoronoiTessellation;
00100
00105 bool mDeleteMesh;
00106
00112 std::set<std::set<TissueCell*> > mMarkedSprings;
00113
00115 out_stream mpElementFile;
00116
00118 out_stream mpVoronoiFile;
00119
00121 out_stream mpTissueAreasFile;
00122
00124 out_stream mpCellAreasFile;
00125
00127 std::set<TissueCell*> CreateCellPair(TissueCell&, TissueCell&);
00128
00130 bool mUseAreaBasedDampingConstant;
00131 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00132
00138 virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00139
00144 virtual void Validate();
00145
00146 public:
00147 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00148
00160 MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh,
00161 const std::vector<TissueCell>& rCells,
00162 const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00163 bool deleteMesh=false,
00164 bool validate=true);
00165
00171 MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh);
00172
00176 ~MeshBasedTissue();
00177
00181 MutableMesh<DIM, DIM>& rGetMesh();
00182
00186 const MutableMesh<DIM, DIM>& rGetMesh() const;
00187
00189 bool GetWriteVoronoiData();
00190
00192 bool GetWriteTissueAreas();
00193
00195 bool UseAreaBasedDampingConstant();
00196
00202 void SetOutputVoronoiData(bool writeVoronoiData);
00203
00212 unsigned AddNode(Node<DIM>* pNewNode);
00213
00222 void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00223
00232 virtual bool IsGhostNode(unsigned index);
00233
00241 double GetDampingConstant(unsigned nodeIndex);
00242
00249 void SetOutputTissueAreas(bool writeTissueAreas);
00250
00256 void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00257
00270 virtual unsigned RemoveDeadCells();
00271
00283 virtual TissueCell* AddCell(TissueCell& rNewCell, c_vector<double,DIM> newLocation, TissueCell* pParentCell=NULL);
00284
00291 void CreateOutputFiles(const std::string& rDirectory, bool cleanOutputDirectory);
00292
00296 void CloseOutputFiles();
00297
00301 void WriteResultsToFiles();
00302
00310 virtual void Update(bool hasHadBirthsOrDeaths=true);
00311
00319 Node<DIM>* GetNode(unsigned index);
00320
00326 unsigned GetNumNodes();
00327
00332 void SetBottomCellAncestors();
00333
00337 void WriteVoronoiResultsToFile();
00338
00346 void WriteTissueAreaResultsToFile();
00347
00357 void WriteCellAreaResultsToFile();
00358
00362 void CreateVoronoiTessellation();
00363
00367 VoronoiTessellation<DIM>& rGetVoronoiTessellation();
00368
00374 class SpringIterator
00375 {
00376 public:
00377
00381 Node<DIM>* GetNodeA();
00382
00386 Node<DIM>* GetNodeB();
00387
00391 TissueCell& rGetCellA();
00392
00396 TissueCell& rGetCellB();
00397
00403 bool operator!=(const MeshBasedTissue<DIM>::SpringIterator& rOther);
00404
00408 SpringIterator& operator++();
00409
00416 SpringIterator(MeshBasedTissue<DIM>& rTissue, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00417
00418 private:
00419
00421 std::set<std::set<unsigned> > mSpringsVisited;
00422
00424 MeshBasedTissue<DIM>& mrTissue;
00425
00427 typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00428 };
00429
00433 SpringIterator SpringsBegin();
00434
00438 SpringIterator SpringsEnd();
00439
00443 void CheckTissueCellPointers();
00444
00448 bool IsMarkedSpring(TissueCell&, TissueCell&);
00449
00453 void MarkSpring(TissueCell&, TissueCell&);
00454
00458 void UnmarkSpring(TissueCell&, TissueCell&);
00459
00460 };
00461 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00462
00463
00464 #include "TemplatedExport.hpp"
00465 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedTissue)
00466
00467 namespace boost
00468 {
00469 namespace serialization
00470 {
00474 template<class Archive, unsigned DIM>
00475 inline void save_construct_data(
00476 Archive & ar, const MeshBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00477 {
00478
00479 const MutableMesh<DIM,DIM> *p_mesh = &(t->rGetMesh());
00480 ar & p_mesh;
00481 }
00482
00487 template<class Archive, unsigned DIM>
00488 inline void load_construct_data(
00489 Archive & ar, MeshBasedTissue<DIM> * t, const unsigned int file_version)
00490 {
00491
00492 MutableMesh<DIM,DIM> *p_mesh;
00493 ar >> p_mesh;
00494
00495
00496 ::new(t)MeshBasedTissue<DIM>(*p_mesh);
00497 }
00498 }
00499 }
00500
00501 #endif