1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkLimiterFunctionBase_h
#define itkLimiterFunctionBase_h
#include "itkFunctionBase.h"
#include "itkMacro.h"
namespace itk
{
/**
* \class LimiterFunctionBase
* \brief Base class for all ITK limiter function objects
*
* LimiterFunctionBase is the base class for ITK limiter function objects.
* The abstract method Evaluate() should limit a function, i.e.
* it should make sure that its output is below a certain value.
* The derivative of a function that is limited also changes.
*
* In formula:
* \f[ L(y) = L(f(x)), \f]
* where \f$f(x)\f$ is the original function. and \f$L(f(x))\f$ the limited version.
* The derivative with respect to \f$x\f$ should satisfy:
* \f[ dL/dx = \frac{dL}{df} \cdot \frac{df}{dx} \f]
*
* Subclasses must override Evaluate(value) and Evaluate(value, derivative) .
*
* This class is template over the input type and the dimension of \f$x\f$.
*
* \ingroup Functions
*
*/
template <class TInput, unsigned int NDimension>
class ITK_TEMPLATE_EXPORT LimiterFunctionBase : public FunctionBase<TInput, typename NumericTraits<TInput>::RealType>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(LimiterFunctionBase);
/** Standard class typedefs. */
using Self = LimiterFunctionBase;
using Superclass = FunctionBase<TInput, typename NumericTraits<TInput>::RealType>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** Run-time type information (and related methods). */
itkTypeMacro(LimiterFunctionBase, FunctionBase);
itkStaticConstMacro(Dimension, unsigned int, NDimension);
/** Superclass' typedefs */
using typename Superclass::InputType;
using typename Superclass::OutputType;
using DerivativeValueType = OutputType;
using DerivativeType = CovariantVector<DerivativeValueType, Self::Dimension>;
/** Limit the input value. */
OutputType
Evaluate(const InputType & input) const override = 0;
/** Limit the input value and change the input function derivative accordingly */
virtual OutputType
Evaluate(const InputType & input, DerivativeType & derivative) const = 0;
/** Set/Get the upper bound that the output should respect. Make sure it is higher
* than the lower bound. */
itkSetMacro(UpperBound, OutputType);
itkGetConstMacro(UpperBound, OutputType);
/** Set/Get the lower bound that the output should respect. Make sure it is lower
* than the higher bound. */
itkSetMacro(LowerBound, OutputType);
itkGetConstMacro(LowerBound, OutputType);
/** Set the point where the limiter starts to work. Only input values above this number
* will possibly be affected. Make sure it is <= than the UpperBound. */
itkSetMacro(UpperThreshold, InputType);
itkGetConstMacro(UpperThreshold, InputType);
/** Set the point where the limiter starts to work. Only input values below this number
* will possibly be affected. Make sure it is >= than the LowerBound. */
itkSetMacro(LowerThreshold, InputType);
itkGetConstMacro(LowerThreshold, InputType);
/** Initialize the limiter */
virtual void
Initialize()
{}
protected:
LimiterFunctionBase()
{
this->m_UpperBound = itk::NumericTraits<OutputType>::One + itk::NumericTraits<OutputType>::One;
this->m_LowerBound = OutputType{};
this->m_UpperThreshold = itk::NumericTraits<InputType>::One;
this->m_LowerThreshold = itk::NumericTraits<InputType>::One;
}
~LimiterFunctionBase() override = default;
OutputType m_UpperBound{};
OutputType m_LowerBound{};
InputType m_UpperThreshold{};
InputType m_LowerThreshold{};
};
} // end namespace itk
#endif
|