Page MenuHomec4science

cluster_grow.cpp
No OneTemporary

File Metadata

Created
Thu, Jul 18, 14:00

cluster_grow.cpp

#include "cluster_grow.hh"
/* -------------------------------------------------------------------------- */
ClusterGrow::ClusterGrow(Map2d<int> & area,
int initial_state,
int to_check_state,
int contact_state,
int no_contact_state):
current_state (initial_state),
to_check_state (to_check_state),
contact_state (contact_state),
no_contact_state(no_contact_state),
area(area){
}
/* -------------------------------------------------------------------------- */
ClusterGrow::~ClusterGrow(){
}
/* -------------------------------------------------------------------------- */
void ClusterGrow::addIndicesToExplore(std::vector<std::pair<UInt,UInt> > &
indices_to_add){
auto it = indices_to_add.begin();
auto end = indices_to_add.end();
for( ; it != end ; ++it){
int & val = area(*it);
if (val == contact_state) {
index_to_explore.push(*it);
val = to_check_state;
}
}
}
/* -------------------------------------------------------------------------- */
template <bool periodic>
void ClusterGrow::grow(UInt i, UInt j){
if (area(i,j) != contact_state) return;
++current_state;
area(i,j) = current_state;
std::vector<std::pair<UInt,UInt> > v = area.getNeighborIndexes<periodic>(i,j);
this->addIndicesToExplore(v);
while (!index_to_explore.empty()){
std::pair<UInt,UInt> ind = index_to_explore.front();
int & val = area(ind);
if (val == contact_state || val == to_check_state){
val = current_state;
std::vector<std::pair<UInt,UInt> > v = area.getNeighborIndexes<periodic>(ind);
this->addIndicesToExplore(v);
}
index_to_explore.pop();
}
}
/* -------------------------------------------------------------------------- */
template void ClusterGrow::grow<true>(UInt i, UInt j);
template void ClusterGrow::grow<false>(UInt i, UInt j);

Event Timeline