ITK  5.4.0
Insight Toolkit
itkHistogramThresholdCalculator.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
19#ifndef itkHistogramThresholdCalculator_h
20#define itkHistogramThresholdCalculator_h
21
22#include "itkObject.h"
23#include "itkObjectFactory.h"
24#include "itkNumericTraits.h"
26#include "itkProgressReporter.h"
27
28namespace itk
29{
30
45template <typename THistogram, typename TOutput>
47{
48public:
49 ITK_DISALLOW_COPY_AND_MOVE(HistogramThresholdCalculator);
50
56
58 itkNewMacro(Self);
59
61 itkOverrideGetNameOfClassMacro(HistogramThresholdCalculator);
62
64 using HistogramType = THistogram;
65
67 using OutputType = TOutput;
69
70 void
71 SetInput(const HistogramType * input)
72 {
73 // Process object is not const-correct so the const_cast is required here
74 this->ProcessObject::SetNthInput(0, const_cast<HistogramType *>(input));
75 }
76
77 const HistogramType *
78 GetInput() const
79 {
80 if (this->GetNumberOfInputs() < 1)
81 {
82 return nullptr;
83 }
84 return static_cast<const HistogramType *>(this->ProcessObject::GetInput(0));
85 }
86
89 {
90 if (this->GetNumberOfOutputs() < 1)
91 {
92 return nullptr;
93 }
94 return static_cast<DecoratedOutputType *>(this->ProcessObject::GetOutput(0));
95 }
96
99 {
101 }
102
103 const OutputType &
105 {
106 if (this->GetNumberOfOutputs() < 1)
107 {
108 itkExceptionMacro("No output available.");
109 }
110 return static_cast<DecoratedOutputType *>(this->ProcessObject::GetOutput(0))->Get();
111 }
112
113protected:
115 {
117 this->ProcessObject::SetNthOutput(0, this->MakeOutput(0));
118 }
119 ~HistogramThresholdCalculator() override = default;
121};
122
123} // end namespace itk
124
125#endif
Base class to compute a threshold value based on the histogram of an image.
SimpleDataObjectDecorator< OutputType > DecoratedOutputType
~HistogramThresholdCalculator() override=default
DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType) override
Make a DataObject of the correct type to used as the specified output.
void SetInput(const HistogramType *input)
Light weight base class for most itk classes.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
virtual void SetInput(const DataObjectIdentifierType &key, DataObject *input)
Protected method for setting indexed and named inputs.
DataObject * GetOutput(const DataObjectIdentifierType &key)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObjectPointerArraySizeType GetNumberOfInputs() const
Get the size of the input container.
virtual void SetNumberOfRequiredOutputs(DataObjectPointerArraySizeType _arg)
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
DataObjectPointerArraySizeType GetNumberOfOutputs() const
Get the size of the output container.
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
virtual void SetNthOutput(DataObjectPointerArraySizeType idx, DataObject *output)
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
ObjectType * GetPointer() const noexcept
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....