ITK  5.2.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  * 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 
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 
28 namespace itk
29 {
30 
45 template <typename THistogram, typename TOutput>
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_MOVE(HistogramThresholdCalculator);
50 
56 
58  itkNewMacro(Self);
59 
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 
113 protected:
115  {
117  this->ProcessObject::SetNthOutput(0, this->MakeOutput(0));
118  }
119  ~HistogramThresholdCalculator() override = default;
121 };
122 
123 } // end namespace itk
124 
125 #endif
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
itkObjectFactory.h
itk::HistogramThresholdCalculator::GetInput
const HistogramType * GetInput() const
Definition: itkHistogramThresholdCalculator.h:78
itk::HistogramThresholdCalculator::HistogramThresholdCalculator
HistogramThresholdCalculator()
Definition: itkHistogramThresholdCalculator.h:114
itk::HistogramThresholdCalculator::HistogramType
THistogram HistogramType
Definition: itkHistogramThresholdCalculator.h:64
itkProgressReporter.h
itk::ProcessObject::GetOutput
DataObject * GetOutput(const DataObjectIdentifierType &key)
itk::SmartPointer< Self >
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:193
itk::ProcessObject::SetInput
virtual void SetInput(const DataObjectIdentifierType &key, DataObject *input)
Protected method for setting indexed and named inputs.
itk::ProcessObject::ProcessObject
ProcessObject()
itk::HistogramThresholdCalculator::DecoratedOutputType
SimpleDataObjectDecorator< OutputType > DecoratedOutputType
Definition: itkHistogramThresholdCalculator.h:68
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::SimpleDataObjectDecorator::New
static Pointer New()
itk::HistogramThresholdCalculator::~HistogramThresholdCalculator
~HistogramThresholdCalculator() override=default
itk::SmartPointer::GetPointer
ObjectType * GetPointer() const noexcept
Definition: itkSmartPointer.h:132
itk::HistogramThresholdCalculator::MakeOutput
DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType) override
Make a DataObject of the correct type to used as the specified output.
Definition: itkHistogramThresholdCalculator.h:98
itk::HistogramThresholdCalculator::OutputType
TOutput OutputType
Definition: itkHistogramThresholdCalculator.h:67
itk::ProcessObject::GetNumberOfOutputs
DataObjectPointerArraySizeType GetNumberOfOutputs() const
Get the size of the output container.
itk::HistogramThresholdCalculator::SetInput
void SetInput(const HistogramType *input)
Definition: itkHistogramThresholdCalculator.h:71
itk::HistogramThresholdCalculator
Base class to compute a threshold value based on the histogram of an image.
Definition: itkHistogramThresholdCalculator.h:46
itkObject.h
itk::ProcessObject::GetNumberOfInputs
DataObjectPointerArraySizeType GetNumberOfInputs() const
Get the size of the input container.
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject::SetNthOutput
virtual void SetNthOutput(DataObjectPointerArraySizeType idx, DataObject *output)
itk::ProcessObject::SetNthInput
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ProcessObject::MakeOutput
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
itk::HistogramThresholdCalculator::GetOutput
DecoratedOutputType * GetOutput()
Definition: itkHistogramThresholdCalculator.h:88
itk::HistogramThresholdCalculator::GetThreshold
const OutputType & GetThreshold()
Definition: itkHistogramThresholdCalculator.h:104
itkNumericTraits.h
itkSimpleDataObjectDecorator.h
itk::ProcessObject::SetNumberOfRequiredOutputs
virtual void SetNumberOfRequiredOutputs(DataObjectPointerArraySizeType _arg)
itk::ProcessObject::GetInput
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.