Orfeo Toolbox  3.16
InsightJournal/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: 2006/12/14 10:27:37 $
7  Version: $Revision: 1.2 $
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] = 1;
80 // it->ActivateOffset( offset );
81  offset[d] = 0;
82  }
83  }
84  else
85  {
86  // activate all neighbors that are face+edge+vertex
87  // connected to the current pixel. do not include the center pixel
88  unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
89  for( unsigned int d=0; d < centerIndex; d++ )
90  {
91  offset = it->GetOffset( d );
92  it->ActivateOffset( offset );
93  }
94  offset.Fill(0);
95  it->DeactivateOffset( offset );
96  }
97  return it;
98 }
99 
100 template< class TIterator >
101 TIterator*
102 setConnectivityLater( TIterator* it, bool fullyConnected=false )
103 {
104  // activate the "later" neighbours
105  typename TIterator::OffsetType offset;
106  it->ClearActiveList();
107  if( !fullyConnected)
108  {
109  // only activate the neighbors that are face connected
110  // to the current pixel. do not include the center pixel
111  offset.Fill( 0 );
112  for( unsigned int d=0; d < TIterator::Dimension; ++d )
113  {
114  offset[d] = 1;
115  it->ActivateOffset( offset );
116  offset[d] = 0;
117  }
118  }
119  else
120  {
121  // activate all neighbors that are face+edge+vertex
122  // connected to the current pixel. do not include the center pixel
123  unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
124  for( unsigned int d=centerIndex+1; d < 2*centerIndex+1; d++ )
125  {
126  offset = it->GetOffset( d );
127  it->ActivateOffset( offset );
128  }
129  offset.Fill(0);
130  it->DeactivateOffset( offset );
131  }
132  return it;
133 }
134 
135 }
136 
137 
138 #endif

Generated at Sat Feb 2 2013 23:33:03 for Orfeo Toolbox with doxygen 1.8.1.1