1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 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 itkBinaryThresholdSpatialFunction_h 19 #define itkBinaryThresholdSpatialFunction_h 20 21 #include "itkSpatialFunction.h" 22 #include "itkImageBase.h" 23 24 namespace itk 25 { 26 /** \class BinaryThresholdSpatialFunction 27 * \brief A spatial functions that returns if the internal spatial function 28 * is within user specified thresholds. 29 * 30 * BinaryThresholdSpatialFunction is a wrapper class for an internal 31 * spatial function and returns true if it is within user specified 32 * thresholds and false otherwise. 33 * 34 * This class is templated over the internal spatial function type. 35 * 36 * \sa SpatialFunction 37 * 38 * 39 * \ingroup ITKCommon 40 */ 41 template< typename TFunction > 42 class ITK_TEMPLATE_EXPORT BinaryThresholdSpatialFunction: 43 public SpatialFunction< bool, 44 TFunction::ImageDimension, 45 typename TFunction::InputType > 46 { 47 public: 48 ITK_DISALLOW_COPY_AND_ASSIGN(BinaryThresholdSpatialFunction); 49 50 /** Standard class type aliases. */ 51 using Self = BinaryThresholdSpatialFunction; 52 using Superclass = SpatialFunction< bool, 53 TFunction::ImageDimension, 54 typename TFunction::InputType >; 55 56 using Pointer = SmartPointer< Self >; 57 using ConstPointer = SmartPointer< const Self >; 58 59 /** Run-time type information (and related methods). */ 60 itkTypeMacro(BinaryThresholdSpatialFunction, SpatialFunction); 61 62 /** New macro for creation of through the object factory. */ 63 itkNewMacro(Self); 64 65 /** OutputType type alias support. */ 66 using OutputType = typename Superclass::OutputType; 67 68 /** InputType type alias support. */ 69 using InputType = typename TFunction::InputType; 70 71 /** Underlying function type. */ 72 using FunctionType = TFunction; 73 74 /** Underlying function output type. */ 75 using FunctionOutputType = typename TFunction::OutputType; 76 77 /** Set/Get the lower threshold. */ 78 itkSetMacro(LowerThreshold, FunctionOutputType); 79 itkGetConstReferenceMacro(LowerThreshold, FunctionOutputType); 80 81 /** Set/Get the upper threshold. */ 82 itkSetMacro(UpperThreshold, FunctionOutputType); 83 itkGetConstReferenceMacro(UpperThreshold, FunctionOutputType); 84 85 /** Set/Get the underlying function. */ 86 itkSetObjectMacro(Function, FunctionType); 87 itkGetModifiableObjectMacro(Function, FunctionType); 88 89 /** Evaluate the function at a given position. */ 90 OutputType Evaluate(const InputType & point) const override; 91 92 protected: 93 94 BinaryThresholdSpatialFunction(); 95 ~BinaryThresholdSpatialFunction() override = default; 96 void PrintSelf(std::ostream & os, Indent indent) const override; 97 98 FunctionOutputType m_LowerThreshold; 99 FunctionOutputType m_UpperThreshold; 100 101 typename FunctionType::Pointer m_Function; 102 }; 103 } // end namespace itk 104 105 #ifndef ITK_MANUAL_INSTANTIATION 106 #include "itkBinaryThresholdSpatialFunction.hxx" 107 #endif 108 109 #endif 110