Page MenuHomec4science

cluster_grow.cpp
No OneTemporary

File Metadata

Created
Sat, May 25, 18:00

cluster_grow.cpp

/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "cluster_grow.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
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);
__END_TAMAAS__

Event Timeline