Orfeo Toolbox  3.16
ITK/Code/BasicFilters/itkConnectedComponentAlgorithm.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkConnectedComponentAlgorithm.h,v $
5  Language: C++
6  Date: $Date: 2008-10-13 18:54:27 $
7  Version: $Revision: 1.3 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __itkConnectedComponentAlgorithm_h
19 #define __itkConnectedComponentAlgorithm_h
20 
21 #include "itkImage.h"
24 
25 namespace itk
26 {
27 template< class TIterator >
28 TIterator*
29 setConnectivity( TIterator* it, bool fullyConnected=false )
30 {
31  typename TIterator::OffsetType offset;
32  it->ClearActiveList();
33  if( !fullyConnected)
34  {
35  // only activate the neighbors that are face connected
36  // to the current pixel. do not include the center pixel
37  offset.Fill( 0 );
38  for( unsigned int d=0; d < TIterator::Dimension; ++d )
39  {
40  offset[d] = -1;
41  it->ActivateOffset( offset );
42  offset[d] = 1;
43  it->ActivateOffset( offset );
44  offset[d] = 0;
45  }
46  }
47  else
48  {
49  // activate all neighbors that are face+edge+vertex
50  // connected to the current pixel. do not include the center pixel
51  unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
52  for( unsigned int d=0; d < centerIndex*2 + 1; d++ )
53  {
54  offset = it->GetOffset( d );
55  it->ActivateOffset( offset );
56  }
57  offset.Fill(0);
58  it->DeactivateOffset( offset );
59  }
60  return it;
61 }
62 
63 template< class TIterator >
64 TIterator*
65 setConnectivityPrevious( TIterator* it, bool fullyConnected=false )
66 {
67  // activate the "previous" neighbours
68  typename TIterator::OffsetType offset;
69  it->ClearActiveList();
70  if( !fullyConnected)
71  {
72  // only activate the neighbors that are face connected
73  // to the current pixel. do not include the center pixel
74  offset.Fill( 0 );
75  for( unsigned int d=0; d < TIterator::Dimension; ++d )
76  {
77  offset[d] = -1;
78  it->ActivateOffset( offset );
79  offset[d] = 0;
80  }
81  }
82  else
83  {
84  // activate all neighbors that are face+edge+vertex
85  // connected to the current pixel. do not include the center pixel
86  unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
87  for( unsigned int d=0; d < centerIndex; d++ )
88  {
89  offset = it->GetOffset( d );
90  it->ActivateOffset( offset );
91  }
92  offset.Fill(0);
93  it->DeactivateOffset( offset );
94  }
95  return it;
96 }
97 
98 template< class TIterator >
99 TIterator*
100 setConnectivityLater( TIterator* it, bool fullyConnected=false )
101 {
102  // activate the "later" neighbours
103  typename TIterator::OffsetType offset;
104  it->ClearActiveList();
105  if( !fullyConnected)
106  {
107  // only activate the neighbors that are face connected
108  // to the current pixel. do not include the center pixel
109  offset.Fill( 0 );
110  for( unsigned int d=0; d < TIterator::Dimension; ++d )
111  {
112  offset[d] = 1;
113  it->ActivateOffset( offset );
114  offset[d] = 0;
115  }
116  }
117  else
118  {
119  // activate all neighbors that are face+edge+vertex
120  // connected to the current pixel. do not include the center pixel
121  unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
122  for( unsigned int d=centerIndex+1; d < 2*centerIndex+1; d++ )
123  {
124  offset = it->GetOffset( d );
125  it->ActivateOffset( offset );
126  }
127  offset.Fill(0);
128  it->DeactivateOffset( offset );
129  }
130  return it;
131 }
132 
133 }
134 
135 
136 #endif

Generated at Sat May 18 2013 23:34:20 for Orfeo Toolbox with doxygen 1.8.3.1