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 #ifndef __itkConnectedComponentAlgorithm_h
00002 #define __itkConnectedComponentAlgorithm_h
00003 
00004 #include "itkImage.h"
00005 #include "itkConstShapedNeighborhoodIterator.h"
00006 #include "itkShapedNeighborhoodIterator.h"
00007 
00008 namespace itk
00009 {
00010 template< class TIterator >
00011 TIterator*
00012 setConnectivity( TIterator* it, bool fullyConnected=false )
00013 {
00014   typename TIterator::OffsetType offset;
00015   it->ClearActiveList();
00016   if( !fullyConnected) 
00017     {
00018     // only activate the neighbors that are face connected
00019     // to the current pixel. do not include the center pixel
00020     offset.Fill( 0 );
00021     for( unsigned int d=0; d < TIterator::Dimension; ++d )
00022       {
00023       offset[d] = -1;
00024       it->ActivateOffset( offset );
00025       offset[d] = 1;
00026       it->ActivateOffset( offset );
00027       offset[d] = 0;
00028       }
00029     }
00030   else
00031     {
00032     // activate all neighbors that are face+edge+vertex
00033     // connected to the current pixel. do not include the center pixel
00034     unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00035     for( unsigned int d=0; d < centerIndex*2 + 1; d++ )
00036       {
00037       offset = it->GetOffset( d );
00038       it->ActivateOffset( offset );
00039       }
00040     offset.Fill(0);
00041     it->DeactivateOffset( offset );
00042     }
00043   return it;
00044 }
00045 
00046 template< class TIterator >
00047 TIterator*
00048 setConnectivityPrev( TIterator* it, bool fullyConnected=false )
00049 {
00050   // activate the "previous" neighbours
00051   typename TIterator::OffsetType offset;
00052   it->ClearActiveList();
00053   if( !fullyConnected) 
00054     {
00055     // only activate the neighbors that are face connected
00056     // to the current pixel. do not include the center pixel
00057     offset.Fill( 0 );
00058     for( unsigned int d=0; d < TIterator::Dimension; ++d )
00059       {
00060       offset[d] = -1;
00061       it->ActivateOffset( offset );
00062 //       offset[d] = 1;
00063 //       it->ActivateOffset( offset );
00064       offset[d] = 0;
00065       }
00066     }
00067   else
00068     {
00069     // activate all neighbors that are face+edge+vertex
00070     // connected to the current pixel. do not include the center pixel
00071     unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00072     for( unsigned int d=0; d < centerIndex; d++ )
00073       {
00074       offset = it->GetOffset( d );
00075       it->ActivateOffset( offset );
00076       }
00077     offset.Fill(0);
00078     it->DeactivateOffset( offset );
00079     }
00080   return it;
00081 }
00082 
00083 template< class TIterator >
00084 TIterator*
00085 setConnectivityLater( TIterator* it, bool fullyConnected=false )
00086 {
00087   // activate the "later" neighbours
00088   typename TIterator::OffsetType offset;
00089   it->ClearActiveList();
00090   if( !fullyConnected) 
00091     {
00092     // only activate the neighbors that are face connected
00093     // to the current pixel. do not include the center pixel
00094     offset.Fill( 0 );
00095     for( unsigned int d=0; d < TIterator::Dimension; ++d )
00096       {
00097        offset[d] = 1;
00098        it->ActivateOffset( offset );
00099        offset[d] = 0;
00100       }
00101     }
00102   else
00103     {
00104     // activate all neighbors that are face+edge+vertex
00105     // connected to the current pixel. do not include the center pixel
00106     unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00107     for( unsigned int d=centerIndex+1; d < 2*centerIndex+1; d++ )
00108       {
00109       offset = it->GetOffset( d );
00110       it->ActivateOffset( offset );
00111       }
00112     offset.Fill(0);
00113     it->DeactivateOffset( offset );
00114     }
00115   return it;
00116 }
00117 
00118 }
00119 
00120 
00121 #endif
00122 

Generated at Sat Sep 2 20:16:50 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000