ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLabelMapFilter.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkLabelMapFilter_h
29 #define itkLabelMapFilter_h
30 
31 #include "itkImageToImageFilter.h"
32 #include <mutex>
33 
34 namespace itk
35 {
56 template< typename TInputImage, typename TOutputImage >
57 class ITK_TEMPLATE_EXPORT LabelMapFilter:
58  public
59  ImageToImageFilter< TInputImage, TOutputImage >
60 {
61 public:
62  ITK_DISALLOW_COPY_AND_ASSIGN(LabelMapFilter);
63 
69 
71  itkTypeMacro(LabelMapFilter, ImageToImageFilter);
72 
74  itkNewMacro(Self);
75 
77  using InputImageType = typename Superclass::InputImageType;
78  using InputImagePointer = typename Superclass::InputImagePointer;
79  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
80  using InputImageRegionType = typename Superclass::InputImageRegionType;
81  using InputImagePixelType = typename Superclass::InputImagePixelType;
82  using LabelObjectType = typename InputImageType::LabelObjectType;
83 
84  using OutputImageType = TOutputImage;
85  using OutputImagePointer = typename OutputImageType::Pointer;
86  using OutputImageConstPointer = typename OutputImageType::ConstPointer;
88  using OutputImagePixelType = typename OutputImageType::PixelType;
89 
91  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
92  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
93 
97  void GenerateInputRequestedRegion() override;
98 
100  void EnlargeOutputRequestedRegion( DataObject * itkNotUsed(output) ) override;
101 
102 protected:
103  LabelMapFilter();
104  ~LabelMapFilter() override = default;
105 
106  void BeforeThreadedGenerateData() override;
107 
108  void AfterThreadedGenerateData() override;
109 
110  void DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
111 
112  //derived classes call this as inherited so we must delegate to DynamicThreadedGenerateData
113  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType) override
114  {
115  Self::DynamicThreadedGenerateData(outputRegionForThread);
116  }
117 
118  virtual void ThreadedProcessLabelObject(LabelObjectType *labelObject);
119 
125  {
126  return static_cast< InputImageType * >( const_cast< DataObject * >( this->ProcessObject::GetInput(0) ) );
127  }
128 
130 
131 private:
132  typename InputImageType::Iterator m_LabelObjectIterator;
133  float m_InverseNumberOfLabelObjects{ 1.0f };
134  SizeValueType m_NumberOfLabelObjectsProcessed{ 1 };
135 };
136 } // end namespace itk
137 
138 #ifndef ITK_MANUAL_INSTANTIATION
139 #include "itkLabelMapFilter.hxx"
140 #endif
141 
142 #endif
typename OutputImageType::Pointer OutputImagePointer
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename InputImageType::LabelObjectType LabelObjectType
typename OutputImageType::ConstPointer OutputImageConstPointer
typename OutputImageType::PixelType OutputImagePixelType
typename InputImageType::PixelType InputImagePixelType
virtual InputImageType * GetLabelMap()
typename InputImageType::Pointer InputImagePointer
std::mutex m_LabelObjectContainerLock
typename OutputImageType::RegionType OutputImageRegionType
Base class for filters that take an image as input and overwrite that image as the output...
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType) override
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
InputImageType::Iterator m_LabelObjectIterator
typename InputImageType::RegionType InputImageRegionType
Base class for filters that take an image as input and produce an image as output.
typename InputImageType::ConstPointer InputImageConstPointer
Base class for all data objects in ITK.