00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00036
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
00050
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
00068 typename TIterator::OffsetType offset;
00069 it->ClearActiveList();
00070 if( !fullyConnected)
00071 {
00072
00073
00074 offset.Fill( 0 );
00075 for( unsigned int d=0; d < TIterator::Dimension; ++d )
00076 {
00077 offset[d] = -1;
00078 it->ActivateOffset( offset );
00079
00080
00081 offset[d] = 0;
00082 }
00083 }
00084 else
00085 {
00086
00087
00088 unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00089 for( unsigned int d=0; d < centerIndex; d++ )
00090 {
00091 offset = it->GetOffset( d );
00092 it->ActivateOffset( offset );
00093 }
00094 offset.Fill(0);
00095 it->DeactivateOffset( offset );
00096 }
00097 return it;
00098 }
00099
00100 template< class TIterator >
00101 TIterator*
00102 setConnectivityLater( TIterator* it, bool fullyConnected=false )
00103 {
00104
00105 typename TIterator::OffsetType offset;
00106 it->ClearActiveList();
00107 if( !fullyConnected)
00108 {
00109
00110
00111 offset.Fill( 0 );
00112 for( unsigned int d=0; d < TIterator::Dimension; ++d )
00113 {
00114 offset[d] = 1;
00115 it->ActivateOffset( offset );
00116 offset[d] = 0;
00117 }
00118 }
00119 else
00120 {
00121
00122
00123 unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
00124 for( unsigned int d=centerIndex+1; d < 2*centerIndex+1; d++ )
00125 {
00126 offset = it->GetOffset( d );
00127 it->ActivateOffset( offset );
00128 }
00129 offset.Fill(0);
00130 it->DeactivateOffset( offset );
00131 }
00132 return it;
00133 }
00134
00135 }
00136
00137
00138 #endif
00139