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: 2006/12/14 10:27:37 $
00007   Version:   $Revision: 1.2 $
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] = 1;
00080 //       it->ActivateOffset( offset );
00081       offset[d] = 0;
00082       }
00083     }
00084   else
00085     {
00086     // activate all neighbors that are face+edge+vertex
00087     // connected to the current pixel. do not include the center pixel
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   // activate the "later" neighbours
00105   typename TIterator::OffsetType offset;
00106   it->ClearActiveList();
00107   if( !fullyConnected) 
00108     {
00109     // only activate the neighbors that are face connected
00110     // to the current pixel. do not include the center pixel
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     // activate all neighbors that are face+edge+vertex
00122     // connected to the current pixel. do not include the center pixel
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 

Generated at Tue Jul 29 19:37:06 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000