ITK  5.4.0
Insight Toolkit
itkMembershipFunctionBase.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 #ifndef itkMembershipFunctionBase_h
19 #define itkMembershipFunctionBase_h
20 
21 #include "itkFunctionBase.h"
24 
25 namespace itk
26 {
27 namespace Statistics
28 {
57 template <typename TVector>
58 class ITK_TEMPLATE_EXPORT MembershipFunctionBase : public FunctionBase<TVector, double>
59 {
60 public:
61  ITK_DISALLOW_COPY_AND_MOVE(MembershipFunctionBase);
62 
68 
70  itkTypeMacro(MembershipFunctionBase, FunctionBase);
71 
73  using MeasurementVectorType = TVector;
74 
76  using MeasurementVectorSizeType = unsigned int;
77 
81  double
82  Evaluate(const MeasurementVectorType & x) const override = 0;
83 
91  virtual void
93  {
94  // Test whether the vector type is resizable or not
95  if (MeasurementVectorTraits::IsResizable<MeasurementVectorType>({}))
96  {
97  // then this is a resizable vector type
98  //
99  // if the new size is the same as the previous size, just return
100  if (s == this->m_MeasurementVectorSize)
101  {
102  return;
103  }
104  else
105  {
106  this->m_MeasurementVectorSize = s;
107  this->Modified();
108  }
109  }
110  else
111  {
112  // If this is a non-resizable vector type
114  // and the new length is different from the default one, then throw an
115  // exception
116  if (defaultLength != s)
117  {
118  itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
119  }
120  }
121  }
125  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
126 
127 protected:
129  {
131  }
132 
133  ~MembershipFunctionBase() override = default;
134 
135  void
136  PrintSelf(std::ostream & os, Indent indent) const override
137  {
138  Superclass::PrintSelf(os, indent);
139  os << indent << "Length of measurement vectors: " << m_MeasurementVectorSize << std::endl;
140  }
141 
142 private:
144 
145 }; // end of class
146 } // end of namespace Statistics
147 } // end namespace itk
148 
149 #endif
itk::Statistics::MembershipFunctionBase::MembershipFunctionBase
MembershipFunctionBase()
Definition: itkMembershipFunctionBase.h:128
itk::Statistics::MembershipFunctionBase
MembershipFunctionBase defines common interfaces for membership functions.
Definition: itkMembershipFunctionBase.h:58
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::MembershipFunctionBase::m_MeasurementVectorSize
MeasurementVectorSizeType m_MeasurementVectorSize
Definition: itkMembershipFunctionBase.h:143
itkFunctionBase.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkNumericTraitsCovariantVectorPixel.h
itk::Statistics::MembershipFunctionBase< TMeasurementVector >::MeasurementVectorType
TMeasurementVector MeasurementVectorType
Definition: itkMembershipFunctionBase.h:73
itk::Statistics::MembershipFunctionBase::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkMembershipFunctionBase.h:136
itk::FunctionBase
Base class for all ITK function objects.
Definition: itkFunctionBase.h:44
itkMeasurementVectorTraits.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:209
itk::Statistics::MembershipFunctionBase< TMeasurementVector >::MeasurementVectorSizeType
unsigned int MeasurementVectorSizeType
Definition: itkMembershipFunctionBase.h:76
itk::Statistics::MembershipFunctionBase::SetMeasurementVectorSize
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition: itkMembershipFunctionBase.h:92