ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkDistanceMetric.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 itkDistanceMetric_h
19 #define itkDistanceMetric_h
20 
21 #include "itkFunctionBase.h"
23 
24 namespace itk
25 {
26 namespace Statistics
27 {
46 template< typename TVector >
47 class ITK_TEMPLATE_EXPORT DistanceMetric:public FunctionBase< TVector, double >
48 {
49 public:
55 
57  using MeasurementVectorType = TVector;
58 
63  using MeasurementVectorSizeType = unsigned int;
64 
66  itkTypeMacro(DistanceMetric, FunctionBase);
67 
69 
76  void SetOrigin(const OriginType & x);
77 
78  itkGetConstReferenceMacro(Origin, OriginType);
79 
82  double Evaluate(const MeasurementVectorType & x) const override = 0;
83 
89  virtual double Evaluate(const MeasurementVectorType & x1,
90  const MeasurementVectorType & x2) const = 0;
91 
94  {
95  // Test whether the vector type is resizable or not
97 
99  {
100  // then this is a resizable vector type
101  //
102  // if the new size is the same as the previou size, just return
103  if ( s == this->m_MeasurementVectorSize )
104  {
105  return;
106  }
107  else
108  {
109  this->m_MeasurementVectorSize = s;
110  this->Modified();
111  }
112  }
113  else
114  {
115  // If this is a non-resizable vector type
117  MeasurementVectorSizeType defaultLength =
119  // and the new length is different from the default one, then throw an
120  // exception
121  if ( defaultLength != s )
122  {
123  itkExceptionMacro(
124  "Attempting to change the measurement \
125  vector size of a non-resizable vector type" );
126  }
127  }
128  }
129 
131  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
132 
133 protected:
134  DistanceMetric();
135  ~DistanceMetric() override = default;
136  void PrintSelf(std::ostream & os, Indent indent) const override;
137 
138 private:
139 
141 
144 }; // end of class
145 } // end of namespace Statistics
146 } // end of namespace itk
147 
148 #ifndef ITK_MANUAL_INSTANTIATION
149 #include "itkDistanceMetric.hxx"
150 #endif
151 
152 #endif
Light weight base class for most itk classes.
Define numeric traits for std::vector.
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
this class declares common interfaces for distance functions.
static bool IsResizable(const TVectorType &)
MeasurementVectorSizeType m_MeasurementVectorSize
Base class for all ITK function objects.
Control indentation during Print() invocation.
Definition: itkIndent.h:49