ITK  6.0.0
Insight Toolkit
itkStatisticsLabelMapFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkStatisticsLabelMapFilter_h
19 #define itkStatisticsLabelMapFilter_h
20 
21 #include "itkShapeLabelMapFilter.h"
22 
23 namespace itk
24 {
40 template <typename TImage, typename TFeatureImage>
41 class ITK_TEMPLATE_EXPORT StatisticsLabelMapFilter
42  : public ShapeLabelMapFilter<TImage, Image<typename TImage::PixelType, TImage::ImageDimension>>
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_MOVE(StatisticsLabelMapFilter);
46 
52 
54  using ImageType = TImage;
55  using ImagePointer = typename ImageType::Pointer;
57  using PixelType = typename ImageType::PixelType;
58  using IndexType = typename ImageType::IndexType;
59  using PointType = typename ImageType::PointType;
60  using LabelObjectType = typename ImageType::LabelObjectType;
61  using MatrixType = typename LabelObjectType::MatrixType;
63 
64  using FeatureImageType = TFeatureImage;
67  using FeatureImagePixelType = typename FeatureImageType::PixelType;
68 
70  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
71 
73  itkNewMacro(Self);
74 
76  itkOverrideGetNameOfClassMacro(StatisticsLabelMapFilter);
77 
78 #ifdef ITK_USE_CONCEPT_CHECKING
79  // Begin concept checking
80 /* itkConceptMacro(InputEqualityComparableCheck,
81  (Concept::EqualityComparable<InputImagePixelType>));
82  itkConceptMacro(IntConvertibleToInputCheck,
83  (Concept::Convertible<int, InputImagePixelType>));
84  itkConceptMacro(InputOStreamWritableCheck,
85  (Concept::OStreamWritable<InputImagePixelType>));*/
86 // End concept checking
87 #endif
88 
90  void
91  SetFeatureImage(const TFeatureImage * input)
92  {
93  // Process object is not const-correct so the const casting is required.
94  this->SetNthInput(1, const_cast<TFeatureImage *>(input));
95  }
96 
98  FeatureImageType *
100  {
101  return static_cast<FeatureImageType *>(const_cast<DataObject *>(this->ProcessObject::GetInput(1)));
102  }
103 
105  void
106  SetInput1(TImage * input)
107  {
108  this->SetInput(input);
109  }
110 
112  void
113  SetInput2(const TFeatureImage * input)
114  {
115  this->SetFeatureImage(input);
116  }
117 
124  itkSetMacro(ComputeHistogram, bool);
125  itkGetConstReferenceMacro(ComputeHistogram, bool);
126  itkBooleanMacro(ComputeHistogram);
134  itkSetMacro(NumberOfBins, unsigned int);
135  itkGetConstReferenceMacro(NumberOfBins, unsigned int);
138  // Set the default number of bins to match the number of values for 8 or 16-bit integers; otherwise 128
139  static constexpr unsigned int
141  {
142  constexpr size_t bitsShift = std::min(8 * sizeof(FeatureImagePixelType), 8 * sizeof(m_NumberOfBins) - 1);
143 
144  return std::is_integral_v<FeatureImagePixelType> && sizeof(FeatureImagePixelType) <= 2 ? 1u << bitsShift : 128u;
145  }
146 
147 protected:
149  ~StatisticsLabelMapFilter() override = default;
150 
151  void
152  ThreadedProcessLabelObject(LabelObjectType * labelObject) override;
153 
154  void
155  BeforeThreadedGenerateData() override;
156 
157  void
158  PrintSelf(std::ostream & os, Indent indent) const override;
159 
160 private:
163  unsigned int m_NumberOfBins{ GetDefaultNumberOfBins() };
164  bool m_ComputeHistogram{ true };
165 }; // end of class
166 } // end namespace itk
167 
168 #ifndef ITK_MANUAL_INSTANTIATION
169 # include "itkStatisticsLabelMapFilter.hxx"
170 #endif
171 
172 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::StatisticsLabelMapFilter
The valuator class for the StatisticsLabelObject.
Definition: itkStatisticsLabelMapFilter.h:41
itk::StatisticsLabelMapFilter::ImageType
TImage ImageType
Definition: itkStatisticsLabelMapFilter.h:54
itk::StatisticsLabelMapFilter::ImageConstPointer
typename ImageType::ConstPointer ImageConstPointer
Definition: itkStatisticsLabelMapFilter.h:56
itk::StatisticsLabelMapFilter::SetInput2
void SetInput2(const TFeatureImage *input)
Definition: itkStatisticsLabelMapFilter.h:113
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::StatisticsLabelMapFilter::PointType
typename ImageType::PointType PointType
Definition: itkStatisticsLabelMapFilter.h:59
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ShapeLabelMapFilter
The valuator class for the ShapeLabelObject.
Definition: itkShapeLabelMapFilter.h:53
itk::StatisticsLabelMapFilter::FeatureImageConstPointer
typename FeatureImageType::ConstPointer FeatureImageConstPointer
Definition: itkStatisticsLabelMapFilter.h:66
itk::StatisticsLabelMapFilter::GetDefaultNumberOfBins
static constexpr unsigned int GetDefaultNumberOfBins()
Definition: itkStatisticsLabelMapFilter.h:140
itk::StatisticsLabelMapFilter::GetFeatureImage
FeatureImageType * GetFeatureImage()
Definition: itkStatisticsLabelMapFilter.h:99
itk::StatisticsLabelMapFilter::FeatureImagePixelType
typename FeatureImageType::PixelType FeatureImagePixelType
Definition: itkStatisticsLabelMapFilter.h:67
itkShapeLabelMapFilter.h
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::StatisticsLabelMapFilter::IndexType
typename ImageType::IndexType IndexType
Definition: itkStatisticsLabelMapFilter.h:58
itk::StatisticsLabelMapFilter::SetInput1
void SetInput1(TImage *input)
Definition: itkStatisticsLabelMapFilter.h:106
itk::StatisticsLabelMapFilter::VectorType
typename LabelObjectType::VectorType VectorType
Definition: itkStatisticsLabelMapFilter.h:62
itk::StatisticsLabelMapFilter::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkStatisticsLabelMapFilter.h:55
itk::StatisticsLabelMapFilter::LabelObjectType
typename ImageType::LabelObjectType LabelObjectType
Definition: itkStatisticsLabelMapFilter.h:60
itk::StatisticsLabelMapFilter::MatrixType
typename LabelObjectType::MatrixType MatrixType
Definition: itkStatisticsLabelMapFilter.h:61
itk::StatisticsLabelMapFilter::FeatureImageType
TFeatureImage FeatureImageType
Definition: itkStatisticsLabelMapFilter.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::StatisticsLabelMapFilter::PixelType
typename ImageType::PixelType PixelType
Definition: itkStatisticsLabelMapFilter.h:57
itk::StatisticsLabelMapFilter::FeatureImagePointer
typename FeatureImageType::Pointer FeatureImagePointer
Definition: itkStatisticsLabelMapFilter.h:65
itk::StatisticsLabelMapFilter::SetFeatureImage
void SetFeatureImage(const TFeatureImage *input)
Definition: itkStatisticsLabelMapFilter.h:91
itk::ProcessObject::GetInput
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.