ITK  5.4.0
Insight Toolkit
itkSampleToHistogramFilter.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 itkSampleToHistogramFilter_h
19 #define itkSampleToHistogramFilter_h
20 
21 #include "itkMacro.h"
22 #include "itkProcessObject.h"
25 
26 itkDeclareExceptionMacro(SampleToHistogramFilterException, ExceptionObject, "Histogram-related Exception");
27 itkDeclareExceptionMacro(MissingHistogramSizeInput,
28  SampleToHistogramFilterException,
29  "Histogram Size input is missing");
30 itkDeclareExceptionMacro(MissingHistogramMarginalScaleInput,
31  SampleToHistogramFilterException,
32  "Histogram marginal scale input is missing");
33 itkDeclareExceptionMacro(NullSizeHistogramInputMeasurementVectorSize,
34  SampleToHistogramFilterException,
35  "Input sample MeasurementVectorSize is zero");
36 itkDeclareExceptionMacro(MissingHistogramBinMaximumInput,
37  SampleToHistogramFilterException,
38  "Histogram Bin Maximum input is missing");
39 itkDeclareExceptionMacro(MissingHistogramBinMinimumInput,
40  SampleToHistogramFilterException,
41  "Histogram Bin Minimum input is missing");
42 itkDeclareExceptionMacro(HistogramWrongNumberOfComponents,
43  SampleToHistogramFilterException,
44  "Histogram has wrong number of components");
45 
46 namespace itk
47 {
48 namespace Statistics
49 {
50 
67 template <typename TSample, typename THistogram>
68 class ITK_TEMPLATE_EXPORT SampleToHistogramFilter : public ProcessObject
69 {
70 public:
71  ITK_DISALLOW_COPY_AND_MOVE(SampleToHistogramFilter);
72 
74  using Self = SampleToHistogramFilter;
75  using Superclass = ProcessObject;
76  using Pointer = SmartPointer<Self>;
77  using ConstPointer = SmartPointer<const Self>;
78 
80  itkOverrideGetNameOfClassMacro(SampleToHistogramFilter);
81 
83  itkNewMacro(Self);
84 
86  using SampleType = TSample;
87  using HistogramType = THistogram;
88  using MeasurementVectorType = typename SampleType::MeasurementVectorType;
89  using MeasurementType = typename MeasurementVectorType::ValueType;
90  using HistogramSizeType = typename HistogramType::SizeType;
91  using HistogramMeasurementType = typename HistogramType::MeasurementType;
92  using HistogramMeasurementVectorType = typename HistogramType::MeasurementVectorType;
93 
95  using typename Superclass::DataObjectPointer;
96 
97  using Superclass::SetInput;
98 
100  virtual void
101  SetInput(const SampleType * sample);
102 
103  virtual const SampleType *
104  GetInput() const;
105 
107  const HistogramType *
108  GetOutput() const;
109 
111  using InputHistogramSizeObjectType = SimpleDataObjectDecorator<HistogramSizeType>;
112 
114  using InputHistogramMeasurementObjectType = SimpleDataObjectDecorator<HistogramMeasurementType>;
115 
118  using InputHistogramMeasurementVectorObjectType = SimpleDataObjectDecorator<HistogramMeasurementVectorType>;
119 
121  using InputBooleanObjectType = SimpleDataObjectDecorator<bool>;
122 
129  itkSetGetDecoratedInputMacro(HistogramSize, HistogramSizeType);
130 
134  itkSetGetDecoratedInputMacro(MarginalScale, HistogramMeasurementType);
135 
139  itkSetGetDecoratedInputMacro(HistogramBinMinimum, HistogramMeasurementVectorType);
140  itkSetGetDecoratedInputMacro(HistogramBinMaximum, HistogramMeasurementVectorType);
147  itkSetGetDecoratedInputMacro(AutoMinimumMaximum, bool);
148 
151  virtual void
152  GraftOutput(DataObject * graft);
153 
154 protected:
155  SampleToHistogramFilter();
156  ~SampleToHistogramFilter() override = default;
157 
158  void
159  PrintSelf(std::ostream & os, Indent indent) const override;
160 
167  using DataObjectPointerArraySizeType = ProcessObject::DataObjectPointerArraySizeType;
168  using Superclass::MakeOutput;
169  DataObjectPointer
170  MakeOutput(DataObjectPointerArraySizeType idx) override;
173  // Where the histogram is actually computed
174  void
175  GenerateData() override;
176 
177 private:
179  HistogramMeasurementType
180  SafeAssign(MeasurementType from) const
181  {
182  if (NumericTraits<HistogramMeasurementType>::is_integer)
183  {
184  auto fromMax = static_cast<MeasurementType>(NumericTraits<HistogramMeasurementType>::max());
185  auto fromMin = static_cast<MeasurementType>(NumericTraits<HistogramMeasurementType>::min());
188  if (from >= fromMax)
189  {
191  }
192  else if (from <= fromMin)
193  {
195  }
196  }
197  return static_cast<HistogramMeasurementType>(from);
198  }
199 
200 }; // end of class
201 } // end of namespace Statistics
202 } // end of namespace itk
203 
204 #ifndef ITK_MANUAL_INSTANTIATION
205 # include "itkSampleToHistogramFilter.hxx"
206 #endif
207 
208 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::NumericTraits::min
static constexpr T min(const T &)
Definition: itkNumericTraits.h:173
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:194
itkMacro.h
itkProcessObject.h
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:168
itkMeasurementVectorTraits.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itkSimpleDataObjectDecorator.h
AddImageFilter
Definition: itkAddImageFilter.h:81
Superclass
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
Definition: itkAddImageFilter.h:90