Go to the documentation of this file.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 offset[d] = 0;
00080 }
00081 }
00082 else
00083 {
00084
00085
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
00103 typename TIterator::OffsetType offset;
00104 it->ClearActiveList();
00105 if( !fullyConnected)
00106 {
00107
00108
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
00120
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