ITK  6.0.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
26itkDeclareExceptionMacro(SampleToHistogramFilterException, ExceptionObject, "Histogram-related Exception");
27itkDeclareExceptionMacro(MissingHistogramSizeInput,
28 SampleToHistogramFilterException,
29 "Histogram Size input is missing");
30itkDeclareExceptionMacro(MissingHistogramMarginalScaleInput,
31 SampleToHistogramFilterException,
32 "Histogram marginal scale input is missing");
33itkDeclareExceptionMacro(NullSizeHistogramInputMeasurementVectorSize,
34 SampleToHistogramFilterException,
35 "Input sample MeasurementVectorSize is zero");
36itkDeclareExceptionMacro(MissingHistogramBinMaximumInput,
37 SampleToHistogramFilterException,
38 "Histogram Bin Maximum input is missing");
39itkDeclareExceptionMacro(MissingHistogramBinMinimumInput,
40 SampleToHistogramFilterException,
41 "Histogram Bin Minimum input is missing");
42itkDeclareExceptionMacro(HistogramWrongNumberOfComponents,
43 SampleToHistogramFilterException,
44 "Histogram has wrong number of components");
45
46namespace itk
47{
48namespace Statistics
49{
50
67template <typename TSample, typename THistogram>
68class ITK_TEMPLATE_EXPORT SampleToHistogramFilter : public ProcessObject
69{
70public:
71 ITK_DISALLOW_COPY_AND_MOVE(SampleToHistogramFilter);
72
74 using Self = SampleToHistogramFilter;
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
154protected:
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
177private:
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
Pixel-wise addition of two images.
static constexpr T max(const T &)
static constexpr T min(const T &)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
SmartPointer< const Self > ConstPointer
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41