From edddb6c381d405fbdb7c6aba1aa0d586d5848346 Mon Sep 17 00:00:00 2001 From: Paul Macklin Date: Wed, 11 Dec 2024 20:18:12 -0500 Subject: [PATCH] update delete_cell() and ~Cell() using new Cell::remove_self_from_all_neighbors(); update delete_cell(int) and ~Cell() so that if the cell is deleted, it removes itself from all its neighbors' neighbor lists. --- core/PhysiCell_cell.cpp | 36 ++++++++++++++++++++++++++++++++++++ core/PhysiCell_cell.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/core/PhysiCell_cell.cpp b/core/PhysiCell_cell.cpp index 19da0a01d..e960a3ba1 100644 --- a/core/PhysiCell_cell.cpp +++ b/core/PhysiCell_cell.cpp @@ -459,6 +459,9 @@ Cell::~Cell() this->remove_all_attached_cells(); // 1.11.0 this->remove_all_spring_attachments(); + + // new Dec 5, 2024: + this->remove_self_from_all_neighbors(); // released internalized substrates (as of 1.5.x releases) this->release_internalized_substrates(); @@ -1183,6 +1186,9 @@ void delete_cell( int index ) pDeleteMe->remove_all_attached_cells(); // 1.11.0 pDeleteMe->remove_all_spring_attachments(); + + // new Dec 5, 2024: + pDeleteMe->remove_self_from_all_neighbors(); // released internalized substrates (as of 1.5.x releases) pDeleteMe->release_internalized_substrates(); @@ -3355,6 +3361,36 @@ void Cell::detach_cell_as_spring( Cell* pRemoveMe ) return; } +void Cell::remove_self_from_all_neighbors( void ) +{ + Cell* pCell = this; + // go through all neighbors (pN) of this (pC) + + for( int j = 0 ; j < pCell->state.neighbors.size(); j++ ) + { + Cell* pN = pCell->state.neighbors[j]; + + // for each pN, remove pC from list of neighbors + // find pC in neighbors + + + auto SearchResult = std::find( + pN->state.neighbors.begin(),pN->state.neighbors.end(),pCell ); + + // if pC is indeed found, remove it + // erase pC from neighbors + if( SearchResult != pN->state.neighbors.end() ) + { + // if the target is found, set the appropriate rate + pN->state.neighbors.erase( SearchResult ); + } + else + { /* future error message */ } + } + + return; +} + void Cell::remove_all_attached_cells( void ) { { diff --git a/core/PhysiCell_cell.h b/core/PhysiCell_cell.h index 573d93704..e41b3a42a 100644 --- a/core/PhysiCell_cell.h +++ b/core/PhysiCell_cell.h @@ -231,6 +231,8 @@ class Cell : public Basic_Agent void attach_cell( Cell* pAddMe ); // done void detach_cell( Cell* pRemoveMe ); // done + + void remove_self_from_all_neighbors( void ); void remove_all_attached_cells( void ); // done void attach_cell_as_spring( Cell* pAddMe ); // done