ITK  5.2.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  * 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 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,
29  "Histogram Size input is missing");
30 itkDeclareExceptionMacro(MissingHistogramMarginalScaleInput,
32  "Histogram marginal scale input is missing");
33 itkDeclareExceptionMacro(NullSizeHistogramInputMeasurementVectorSize,
35  "Input sample MeasurementVectorSize is zero");
36 itkDeclareExceptionMacro(MissingHistogramBinMaximumInput,
38  "Histogram Bin Maximum input is missing");
39 itkDeclareExceptionMacro(MissingHistogramBinMinimumInput,
41  "Histogram Bin Minimum input is missing");
42 itkDeclareExceptionMacro(HistogramWrongNumberOfComponents,
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 
78 
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;
91  using HistogramMeasurementType = typename HistogramType::MeasurementType;
92  using HistogramMeasurementVectorType = typename HistogramType::MeasurementVectorType;
93 
95  using DataObjectPointer = 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 
112 
115 
119 
122 
129  itkSetGetDecoratedInputMacro(HistogramSize, HistogramSizeType);
130 
134  itkSetGetDecoratedInputMacro(MarginalScale, HistogramMeasurementType);
135 
139  itkSetGetDecoratedInputMacro(HistogramBinMinimum, HistogramMeasurementVectorType);
140  itkSetGetDecoratedInputMacro(HistogramBinMaximum, HistogramMeasurementVectorType);
142 
147  itkSetGetDecoratedInputMacro(AutoMinimumMaximum, bool);
148 
151  virtual void
152  GraftOutput(DataObject * graft);
153 
154 protected:
156  ~SampleToHistogramFilter() override = default;
157 
158  void
159  PrintSelf(std::ostream & os, Indent indent) const override;
160 
168  using Superclass::MakeOutput;
170  MakeOutput(DataObjectPointerArraySizeType idx) override;
172 
173  // Where the histogram is actually computed
174  void
175  GenerateData() override;
176 
177 private:
181  {
183  {
184  auto fromMax = static_cast<MeasurementType>(NumericTraits<HistogramMeasurementType>::max());
185  auto fromMin = static_cast<MeasurementType>(NumericTraits<HistogramMeasurementType>::min());
187 
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
itk::Statistics::SampleToHistogramFilter::SafeAssign
HistogramMeasurementType SafeAssign(MeasurementType from) const
Definition: itkSampleToHistogramFilter.h:180
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
itk::SampleToHistogramFilterException
Definition: itkSampleToHistogramFilter.h:26
itk::Statistics::SampleToHistogramFilter::HistogramType
THistogram HistogramType
Definition: itkSampleToHistogramFilter.h:87
itk::HistogramWrongNumberOfComponents
Definition: itkSampleToHistogramFilter.h:44
itk::NumericTraits::min
static constexpr T min(const T &)
Definition: itkNumericTraits.h:172
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::Statistics::SampleToHistogramFilter::MeasurementVectorType
typename SampleType::MeasurementVectorType MeasurementVectorType
Definition: itkSampleToHistogramFilter.h:88
itk::MissingHistogramBinMaximumInput
Definition: itkSampleToHistogramFilter.h:38
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:193
itk::Statistics::SampleToHistogramFilter::SampleType
TSample SampleType
Definition: itkSampleToHistogramFilter.h:86
itk::MissingHistogramSizeInput
Definition: itkSampleToHistogramFilter.h:29
itk::Statistics::SampleToHistogramFilter::HistogramSizeType
typename HistogramType::SizeType HistogramSizeType
Definition: itkSampleToHistogramFilter.h:90
itk::MissingHistogramBinMinimumInput
Definition: itkSampleToHistogramFilter.h:41
itk::Statistics::SampleToHistogramFilter::MeasurementType
typename MeasurementVectorType::ValueType MeasurementType
Definition: itkSampleToHistogramFilter.h:89
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkMacro.h
itkProcessObject.h
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
itk::Statistics::SampleToHistogramFilter::HistogramMeasurementVectorType
typename HistogramType::MeasurementVectorType HistogramMeasurementVectorType
Definition: itkSampleToHistogramFilter.h:92
itk::Statistics::SampleToHistogramFilter
Computes the Histogram corresponding to a Sample.
Definition: itkSampleToHistogramFilter.h:68
itkMeasurementVectorTraits.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::NullSizeHistogramInputMeasurementVectorSize
Definition: itkSampleToHistogramFilter.h:35
itkSimpleDataObjectDecorator.h
itk::Statistics::SampleToHistogramFilter::HistogramMeasurementType
typename HistogramType::MeasurementType HistogramMeasurementType
Definition: itkSampleToHistogramFilter.h:91
itk::MissingHistogramMarginalScaleInput
Definition: itkSampleToHistogramFilter.h:32
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293