ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkBinaryContourImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkBinaryContourImageFilter_h
19 #define __itkBinaryContourImageFilter_h
20 
21 #include "itkInPlaceImageFilter.h"
22 #include "itkConceptChecking.h"
23 #include "itkBarrier.h"
24 #include <vector>
25 
26 namespace itk
27 {
53 template< class TInputImage, class TOutputImage >
54 class ITK_EXPORT BinaryContourImageFilter:
55  public InPlaceImageFilter< TInputImage, TOutputImage >
56 {
57 public:
65 
70 
74  itkNewMacro(Self);
75 
79  typedef TInputImage InputImageType;
80  typedef typename InputImageType::Pointer InputImagePointer;
81  typedef typename InputImageType::ConstPointer InputImageConstPointer;
82  typedef typename InputImageType::IndexType IndexType;
83  typedef typename InputImageType::SizeType SizeType;
84  typedef typename InputImageType::OffsetType OffsetType;
85  typedef typename InputImageType::PixelType InputImagePixelType;
86  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
87 
88  typedef TOutputImage OutputImageType;
89  typedef typename OutputImageType::Pointer OutputImagePointer;
90  typedef typename OutputImageType::RegionType RegionType;
91  typedef typename OutputImageType::IndexType OutputIndexType;
92  typedef typename OutputImageType::SizeType OutputSizeType;
93  typedef typename OutputImageType::OffsetType OutputOffsetType;
94  typedef typename OutputImageType::PixelType OutputImagePixelType;
95  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
96 
97  itkStaticConstMacro(ImageDimension, unsigned int,
98  OutputImageType::ImageDimension);
99 
100 #ifdef ITK_USE_CONCEPT_CHECKING
101  itkStaticConstMacro(InputImageDimension, unsigned int,
102  InputImageType::ImageDimension);
103 
104  // Concept checking -- input and output dimensions must be the same
105  itkConceptMacro( SameDimension,
106  ( Concept::SameDimension< itkGetStaticConstMacro(ImageDimension),
107  itkGetStaticConstMacro(OutputImageDimension) > ) );
108 #endif
109 
116  itkSetMacro(FullyConnected, bool);
117  itkGetConstReferenceMacro(FullyConnected, bool);
118  itkBooleanMacro(FullyConnected);
120 
125  itkSetMacro(BackgroundValue, OutputImagePixelType);
126  itkGetConstMacro(BackgroundValue, OutputImagePixelType);
128 
133  itkSetMacro(ForegroundValue, InputImagePixelType);
134  itkGetConstMacro(ForegroundValue, InputImagePixelType);
136 
137 protected:
138 
141 
142  void PrintSelf(std::ostream & os, Indent indent) const;
143 
147  void BeforeThreadedGenerateData();
148 
149  void AfterThreadedGenerateData();
150 
151  void ThreadedGenerateData(const RegionType & outputRegionForThread,
152  ThreadIdType threadId);
153 
157  void GenerateInputRequestedRegion();
158 
163  void EnlargeOutputRequestedRegion( DataObject * itkNotUsed(output) );
164 
165 private:
166  BinaryContourImageFilter(const Self &); //Purposefully not implemented
167  void operator = ( const Self &); //Purposefully not implemented
168 
169  // types to support the run length encoding of lines
170  struct runLength
171  {
172  runLength( const OffsetValueType& iLength, const IndexType& iWhere ) :
173  m_Length( iLength ), m_Where( iWhere ) {}
174 
175  // run length information - may be a more type safe way of doing this
177 
178  // Index of the start of the run
180  };
181 
182  typedef std::vector< runLength > LineEncodingType;
183  typedef typename LineEncodingType::iterator LineEncodingIterator;
184  typedef typename LineEncodingType::const_iterator LineEncodingConstIterator;
185 
186  // the map storing lines
187  typedef std::vector< LineEncodingType > LineMapType;
188 
189  typedef std::vector< OffsetValueType > OffsetVec;
190 
191  bool CheckNeighbors(const OutputIndexType & A,
192  const OutputIndexType & B);
193 
194  void CompareLines(LineEncodingType & current,
195  const LineEncodingType & Neighbour);
196 
197  void SetupLineOffsets(OffsetVec & LineOffsets);
198 
199  void Wait();
200 
202 
206 
210 };
211 } // end namespace itk
212 
213 #ifndef ITK_MANUAL_INSTANTIATION
214 #include "itkBinaryContourImageFilter.hxx"
215 #endif
216 
217 #endif
218