#ifndef UnitCubeCCCounter_txx #define UnitCubeCCCounter_txx #include "UnitCubeCCCounter.h" #include namespace itk { template UnitCubeCCCounter ::UnitCubeCCCounter() : m_Image(new char[TConnectivity::GetInstance().GetNeighborhoodSize()]) { } template UnitCubeCCCounter ::~UnitCubeCCCounter() { delete[] m_Image; } template template void UnitCubeCCCounter ::SetImage(Iterator imageBegin, Iterator imageEnd) { std::copy(imageBegin, imageEnd, m_Image); } template unsigned int UnitCubeCCCounter ::operator()() const { unsigned int const neighborhoodSize = TConnectivity::GetInstance().GetNeighborhoodSize(); unsigned int seed=0; // Find first seed while(seed != neighborhoodSize && (m_Image[seed] == 0 || !m_ConnectivityTest[seed] ) ) { ++seed; } std::vector processed(neighborhoodSize, false); unsigned int nbCC=0; while(seed != neighborhoodSize) { ++nbCC; processed[seed] = true; std::queue q; q.push(seed); while(!q.empty()) { unsigned int const current = q.front(); q.pop(); // For each neighbor check if m_UnitCubeNeighbors is true. for(unsigned int neighbor = 0; neighbor < neighborhoodSize; ++neighbor) { if(!processed[neighbor] && m_Image[neighbor] !=0 && m_UnitCubeNeighbors(current, neighbor)) { q.push(neighbor); processed[neighbor] = true; } } } // Look for next seed while(seed != neighborhoodSize && ( processed[seed] || m_Image[seed] == 0 || !m_ConnectivityTest[seed] ) ) { ++seed; } } return nbCC; } template template std::vector UnitCubeCCCounter ::CreateConnectivityTest() { C const & connectivity = C::GetInstance(); unsigned int const neighborhoodSize = connectivity.GetNeighborhoodSize(); std::vector test(neighborhoodSize, false); for(unsigned int i=0; i std::vector const UnitCubeCCCounter ::m_NeighborhoodConnectivityTest = UnitCubeCCCounter ::template CreateConnectivityTest< TNeighborhoodConnectivity >(); template std::vector const UnitCubeCCCounter ::m_ConnectivityTest = UnitCubeCCCounter ::template CreateConnectivityTest(); template UnitCubeNeighbors const UnitCubeCCCounter ::m_UnitCubeNeighbors = UnitCubeNeighbors(); } #endif // UnitCubeCCCounter_txx