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 "MeshArchiveInfo.hpp"
00036
00037 #include <boost/serialization/access.hpp>
00038 #include <boost/serialization/base_object.hpp>
00039 #include <boost/serialization/set.hpp>
00040 #include <boost/serialization/vector.hpp>
00041
00042
00050 template<unsigned DIM>
00051 class MeshBasedTissue : public AbstractCellCentreBasedTissue<DIM>
00052 {
00053 friend class TestMeshBasedTissue;
00054
00055 protected:
00056 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00057
00058 MutableMesh<DIM, DIM>& mrMesh;
00059
00064 VoronoiTessellation<DIM>* mpVoronoiTessellation;
00065
00070 bool mDeleteMesh;
00071
00077 std::set<std::set<TissueCell*> > mMarkedSprings;
00078
00080 bool mWriteVoronoiData;
00081
00083 bool mFollowLoggedCell;
00084
00086 bool mWriteTissueAreas;
00087
00089 out_stream mpElementFile;
00090
00092 out_stream mpVoronoiFile;
00093
00095 out_stream mpTissueAreasFile;
00096
00098 std::set<TissueCell*> CreateCellPair(TissueCell&, TissueCell&);
00099
00101 bool mUseAreaBasedDampingConstant;
00102 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00103
00105 friend class boost::serialization::access;
00117 template<class Archive>
00118 void serialize(Archive & archive, const unsigned int version)
00119 {
00120 archive & boost::serialization::base_object<AbstractCellCentreBasedTissue<DIM> >(*this);
00121
00122
00123
00124 delete mpVoronoiTessellation;
00125 mpVoronoiTessellation = NULL;
00126
00127 archive & mMarkedSprings;
00128 archive & mWriteVoronoiData;
00129 archive & mFollowLoggedCell;
00130 archive & mWriteTissueAreas;
00131 archive & mUseAreaBasedDampingConstant;
00132
00133
00134
00135
00136
00137
00138 }
00139
00145 virtual void UpdateGhostNodesAfterReMesh(NodeMap& rMap);
00146
00151 virtual void Validate();
00152
00153 public:
00154 #define COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00155
00167 MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh,
00168 const std::vector<TissueCell>& rCells,
00169 const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00170 bool deleteMesh=false,
00171 bool validate=true);
00172
00178 MeshBasedTissue(MutableMesh<DIM, DIM>& rMesh);
00179
00183 ~MeshBasedTissue();
00184
00188 MutableMesh<DIM, DIM>& rGetMesh();
00189
00193 const MutableMesh<DIM, DIM>& rGetMesh() const;
00194
00196 bool GetWriteVoronoiData();
00197
00199 bool GetWriteTissueAreas();
00200
00202 bool UseAreaBasedDampingConstant();
00203
00209 void SetWriteVoronoiData(bool writeVoronoiData, bool followLoggedCell);
00210
00219 unsigned AddNode(Node<DIM> *pNewNode);
00220
00229 void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation);
00230
00239 virtual bool IsGhostNode(unsigned index);
00240
00248 double GetDampingConstant(unsigned nodeIndex);
00249
00255 void SetWriteTissueAreas(bool writeTissueAreas);
00256
00262 void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant);
00263
00276 virtual unsigned RemoveDeadCells();
00277
00289 virtual TissueCell* AddCell(TissueCell& rNewCell, c_vector<double,DIM> newLocation, TissueCell* pParentCell=NULL);
00290
00298 void WriteMeshToFile(const std::string &rArchiveDirectory, const std::string &rMeshFileName);
00299
00311 void CreateOutputFiles(const std::string &rDirectory,
00312 bool rCleanOutputDirectory,
00313 bool outputCellMutationStates,
00314 bool outputCellTypes,
00315 bool outputCellVariables,
00316 bool outputCellCyclePhases,
00317 bool outputCellAncestors);
00327 void CloseOutputFiles(bool outputCellMutationStates,
00328 bool outputCellTypes,
00329 bool outputCellVariables,
00330 bool outputCellCyclePhases,
00331 bool outputCellAncestors);
00332
00342 void WriteResultsToFiles(bool outputCellMutationStates,
00343 bool outputCellTypes,
00344 bool outputCellVariables,
00345 bool outputCellCyclePhases,
00346 bool outputCellAncestors);
00347
00352 virtual void Update();
00353
00361 Node<DIM>* GetNode(unsigned index);
00362
00368 unsigned GetNumNodes();
00369
00374 void SetBottomCellAncestors();
00375
00379 void WriteVoronoiResultsToFile();
00380
00384 void WriteTissueAreaResultsToFile();
00385
00389 void CreateVoronoiTessellation();
00390
00394 VoronoiTessellation<DIM>& rGetVoronoiTessellation();
00395
00401 class SpringIterator
00402 {
00403 public:
00404
00408 Node<DIM>* GetNodeA();
00409
00413 Node<DIM>* GetNodeB();
00414
00418 TissueCell& rGetCellA();
00419
00423 TissueCell& rGetCellB();
00424
00430 bool operator!=(const SpringIterator& other);
00431
00435 SpringIterator& operator++();
00436
00443 SpringIterator(MeshBasedTissue& rTissue, typename MutableMesh<DIM,DIM>::EdgeIterator edgeIter);
00444
00445 private:
00446
00448 std::set<std::set<unsigned> > mSpringsVisited;
00449
00451 MeshBasedTissue& mrTissue;
00452
00454 typename MutableMesh<DIM, DIM>::EdgeIterator mEdgeIter;
00455 };
00456
00460 SpringIterator SpringsBegin();
00461
00465 SpringIterator SpringsEnd();
00466
00470 void CheckTissueCellPointers();
00471
00475 bool IsMarkedSpring(TissueCell&, TissueCell&);
00476
00480 void MarkSpring(TissueCell&, TissueCell&);
00481
00485 void UnmarkSpring(TissueCell&, TissueCell&);
00486
00487 };
00488 #undef COVERAGE_IGNORE //Avoid prototypes being treated as code by gcov
00489
00490
00491 #include "TemplatedExport.hpp"
00492 EXPORT_TEMPLATE_CLASS_SAME_DIMS(MeshBasedTissue)
00493
00494 namespace boost
00495 {
00496 namespace serialization
00497 {
00501 template<class Archive, unsigned DIM>
00502 inline void save_construct_data(
00503 Archive & ar, const MeshBasedTissue<DIM> * t, const BOOST_PFTO unsigned int file_version)
00504 {
00505
00506 const MutableMesh<DIM,DIM>* p_mesh = &(t->rGetMesh());
00507 ar & p_mesh;
00508 }
00509
00514 template<class Archive, unsigned DIM>
00515 inline void load_construct_data(
00516 Archive & ar, MeshBasedTissue<DIM> * t, const unsigned int file_version)
00517 {
00518
00519 assert(MeshArchiveInfo::meshPathname.length() > 0);
00520 MutableMesh<DIM,DIM>* p_mesh;
00521 ar >> p_mesh;
00522
00523
00524 p_mesh->Clear();
00525 TrianglesMeshReader<DIM,DIM> mesh_reader(MeshArchiveInfo::meshPathname);
00526 p_mesh->ConstructFromMeshReader(mesh_reader);
00527
00528
00529 NodeMap map(p_mesh->GetNumNodes());
00530 p_mesh->ReMesh(map);
00531
00532
00533 ::new(t)MeshBasedTissue<DIM>(*p_mesh);
00534 }
00535 }
00536 }
00537
00538 #endif