ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMembershipFunctionBase.h
Go to the documentation of this file.
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 itkMembershipFunctionBase_h
19 #define itkMembershipFunctionBase_h
20 
21 #include "itkFunctionBase.h"
24 
25 namespace itk
26 {
27 namespace Statistics
28 {
56 template< typename TVector >
57 class ITK_TEMPLATE_EXPORT MembershipFunctionBase:
58  public FunctionBase< TVector, double >
59 {
60 public:
61  ITK_DISALLOW_COPY_AND_ASSIGN(MembershipFunctionBase);
62 
68 
70  itkTypeMacro(MembershipFunctionBase, FunctionBase);
71 
73  using MeasurementVectorType = TVector;
74 
76  using MeasurementVectorSizeType = unsigned int;
77 
81  double Evaluate(const MeasurementVectorType & x) const override = 0;
82 
91  {
92  // Test whether the vector type is resizable or not
94 
96  {
97  // then this is a resizable vector type
98  //
99  // if the new size is the same as the previou 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  MeasurementVectorSizeType defaultLength =
116  // and the new length is different from the default one, then throw an
117  // exception
118  if ( defaultLength != s )
119  {
120  itkExceptionMacro(
121  "Attempting to change the measurement vector size of a non-resizable vector type" );
122  }
123  }
124  }
125 
127  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
128 
129 protected:
131  {
132  m_MeasurementVectorSize = NumericTraits<MeasurementVectorType>::GetLength(
134  }
135 
136  ~MembershipFunctionBase() override = default;
137 
138  void PrintSelf(std::ostream & os, Indent indent) const override
139  {
140  Superclass::PrintSelf(os, indent);
141  os << indent << "Length of measurement vectors: "
142  << m_MeasurementVectorSize << std::endl;
143  }
144 
145 private:
147 
148 }; // end of class
149 } // end of namespace Statistics
150 } // end namespace itk
151 
152 #endif
Light weight base class for most itk classes.
Define numeric traits for std::vector.
void PrintSelf(std::ostream &os, Indent indent) const override
static bool IsResizable(const TVectorType &)
Base class for all ITK function objects.
MembershipFunctionBase defines common interfaces for membership functions.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)