Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkConnectedComponentAlgorithm.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkConnectedComponentAlgorithm.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-13 18:54:27 $
00007   Version:   $Revision: 1.3 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkConnectedComponentAlgorithm_h
00019 #define __itkConnectedComponentAlgorithm_h
00020 
00021 #include "itkImage.h"
00022 #include "itkConstShapedNeighborhoodIterator.h"
00023 #include "itkShapedNeighborhoodIterator.h"
00024 
00025 namespace itk
00026 {
00027 template< class TIterator >
00028 TIterator*
00029 setConnectivity( TIterator* it, bool fullyConnected=false )
00030 {
00031   typename TIterator::OffsetType offset;
00032   it->ClearActiveList();
00033   if( !fullyConnected) 
00034     {
00035     // only activate the neighbors that are face connected
00036     // to the current pixel. do not include the center pixel
00037     offset.Fill( 0 );
00038     for( unsigned int d=0; d < TIterator::Dimension; ++d )
00039       {
00040       offset[d] = -1;
00041       it->ActivateOffset( offset );
00042       offset[d] = 1;
00043       it->ActivateOffset( offset );
00044       offset[d] = 0;
00045       }
00046     }
00047   else
00048     {
00049     // activate all neighbors that are face+edge+vertex
00050     // connected to the current pixel. do not include the center pixel
00051     unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00052     for( unsigned int d=0; d < centerIndex*2 + 1; d++ )
00053       {
00054       offset = it->GetOffset( d );
00055       it->ActivateOffset( offset );
00056       }
00057     offset.Fill(0);
00058     it->DeactivateOffset( offset );
00059     }
00060   return it;
00061 }
00062 
00063 template< class TIterator >
00064 TIterator*
00065 setConnectivityPrevious( TIterator* it, bool fullyConnected=false )
00066 {
00067   // activate the "previous" neighbours
00068   typename TIterator::OffsetType offset;
00069   it->ClearActiveList();
00070   if( !fullyConnected) 
00071     {
00072     // only activate the neighbors that are face connected
00073     // to the current pixel. do not include the center pixel
00074     offset.Fill( 0 );
00075     for( unsigned int d=0; d < TIterator::Dimension; ++d )
00076       {
00077       offset[d] = -1;
00078       it->ActivateOffset( offset );
00079       offset[d] = 0;
00080       }
00081     }
00082   else
00083     {
00084     // activate all neighbors that are face+edge+vertex
00085     // connected to the current pixel. do not include the center pixel
00086     unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00087     for( unsigned int d=0; d < centerIndex; d++ )
00088       {
00089       offset = it->GetOffset( d );
00090       it->ActivateOffset( offset );
00091       }
00092     offset.Fill(0);
00093     it->DeactivateOffset( offset );
00094     }
00095   return it;
00096 }
00097 
00098 template< class TIterator >
00099 TIterator*
00100 setConnectivityLater( TIterator* it, bool fullyConnected=false )
00101 {
00102   // activate the "later" neighbours
00103   typename TIterator::OffsetType offset;
00104   it->ClearActiveList();
00105   if( !fullyConnected) 
00106     {
00107     // only activate the neighbors that are face connected
00108     // to the current pixel. do not include the center pixel
00109     offset.Fill( 0 );
00110     for( unsigned int d=0; d < TIterator::Dimension; ++d )
00111       {
00112       offset[d] = 1;
00113       it->ActivateOffset( offset );
00114       offset[d] = 0;
00115       }
00116     }
00117   else
00118     {
00119     // activate all neighbors that are face+edge+vertex
00120     // connected to the current pixel. do not include the center pixel
00121     unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00122     for( unsigned int d=centerIndex+1; d < 2*centerIndex+1; d++ )
00123       {
00124       offset = it->GetOffset( d );
00125       it->ActivateOffset( offset );
00126       }
00127     offset.Fill(0);
00128     it->DeactivateOffset( offset );
00129     }
00130   return it;
00131 }
00132 
00133 }
00134 
00135 
00136 #endif
00137 

Generated at Tue Sep 15 02:37:42 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000