ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkObjectToObjectMetric.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 itkObjectToObjectMetric_h
19 #define itkObjectToObjectMetric_h
20 
21 
23 
25 #include "itkImage.h"
26 #include "itkObject.h"
27 #include "itkPointSet.h"
28 #include "itkTransform.h"
29 
30 namespace itk
31 {
32 
87 template<unsigned int TFixedDimension, unsigned int TMovingDimension, typename TVirtualImage = Image<double, TFixedDimension>,
88  typename TParametersValueType=double>
89 class ITK_TEMPLATE_EXPORT ObjectToObjectMetric:
90  public ObjectToObjectMetricBaseTemplate<TParametersValueType>
91 {
92 public:
93  ITK_DISALLOW_COPY_AND_ASSIGN(ObjectToObjectMetric);
94 
100 
103 
105  using CoordinateRepresentationType = TParametersValueType;
106 
108  using InternalComputationValueType = TParametersValueType;
109 
111  using MeasureType = typename Superclass::MeasureType;
112 
114  using ObjectType = typename Superclass::Object;
115 
117  using DerivativeType = typename Superclass::DerivativeType;
118  using DerivativeValueType = typename Superclass::DerivativeValueType;
119 
121  using ParametersType = typename Superclass::ParametersType;
122  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
123 
124  using GradientSourceType = typename Superclass::GradientSourceType;
125 
128 
130  static constexpr DimensionType FixedDimension = TFixedDimension;
131  static constexpr DimensionType MovingDimension = TMovingDimension;
132  static constexpr DimensionType VirtualDimension = TVirtualImage::ImageDimension;
133 
135  using VirtualImageType = TVirtualImage;
147 
151 
153  using MovingTransformType = Transform<TParametersValueType,
154  TVirtualImage::ImageDimension,
155  TMovingDimension>;
156  using FixedTransformType = Transform<TParametersValueType,
157  TVirtualImage::ImageDimension,
158  TFixedDimension>;
159 
164 
169 
174 
177 
178  void Initialize() override;
179 
180  NumberOfParametersType GetNumberOfParameters() const override;
181  NumberOfParametersType GetNumberOfLocalParameters() const override;
182  void SetParameters( ParametersType & params ) override;
183  const ParametersType & GetParameters() const override;
184  bool HasLocalSupport() const override;
185  void UpdateTransformParameters( const DerivativeType & derivative, TParametersValueType factor) override;
186 
188  itkSetObjectMacro(FixedTransform, FixedTransformType);
189 
191  itkGetModifiableObjectMacro(FixedTransform, FixedTransformType);
192 
194  itkSetObjectMacro(MovingTransform, MovingTransformType);
195 
197  itkGetModifiableObjectMacro(MovingTransform, MovingTransformType);
198 
201  void SetTransform( MovingTransformType* transform );
202 
204  const MovingTransformType * GetTransform();
205 
208  itkGetConstMacro(NumberOfValidPoints, SizeValueType)
209 
210 
226  void SetVirtualDomain( const VirtualSpacingType & spacing, const VirtualOriginType & origin,
227  const VirtualDirectionType & direction, const VirtualRegionType & region );
228 
231  void SetVirtualDomainFromImage( const VirtualImageType * virtualImage);
232 
237  virtual bool SupportsArbitraryVirtualDomainSamples() const = 0;
238 
244  virtual const TimeStamp& GetVirtualDomainTimeStamp() const;
245 
248  VirtualSpacingType GetVirtualSpacing() const;
249 
252  VirtualOriginType GetVirtualOrigin() const;
253 
256  VirtualDirectionType GetVirtualDirection() const;
257 
260  const VirtualRegionType & GetVirtualRegion() const;
261 
262  itkGetModifiableObjectMacro(VirtualImage, VirtualImageType );
263 
273  OffsetValueType ComputeParameterOffsetFromVirtualIndex( const VirtualIndexType & index, const NumberOfParametersType &numberOfLocalParameters ) const;
274 
284  OffsetValueType ComputeParameterOffsetFromVirtualPoint( const VirtualPointType & point, const NumberOfParametersType & numberOfLocalParameters ) const;
285 
290  bool IsInsideVirtualDomain( const VirtualPointType & point ) const;
291  bool IsInsideVirtualDomain( const VirtualIndexType & index ) const;
293 
295 
297  MetricCategoryType GetMetricCategory() const override
298  {
299  return Superclass::OBJECT_METRIC;
300  }
301 
302 protected:
304  ~ObjectToObjectMetric() override = default;
305 
306  void PrintSelf(std::ostream & os, Indent indent) const override;
307 
310  virtual void VerifyDisplacementFieldSizeAndPhysicalSpace();
311 
312  bool TransformPhysicalPointToVirtualIndex( const VirtualPointType &, VirtualIndexType & ) const;
313  void TransformVirtualIndexToPhysicalPoint( const VirtualIndexType &, VirtualPointType & ) const;
314 
319  const MovingDisplacementFieldTransformType * GetMovingDisplacementFieldTransform() const;
320 
327  bool VerifyNumberOfValidPoints( MeasureType & value, DerivativeType & derivative ) const;
328 
332 
334 
338 
342  mutable SizeValueType m_NumberOfValidPoints{0};
343 };
344 } // end namespace itk
345 
346 #ifndef ITK_MANUAL_INSTANTIATION
347 #include "itkObjectToObjectMetric.hxx"
348 #endif
349 
350 #endif
typename Superclass::ParametersType ParametersType
Definition: itkTransform.h:119
TPixel PixelType
Definition: itkImage.h:95
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
Provides local/dense/high-dimensionaltiy transformation via a a displacement field.
typename DerivativeType::ValueType DerivativeValueType
Computes similarity between regions of two objects.
Base class for all object-to-object similarlity metrics added in ITKv4.
typename Superclass::MeasureType MeasureType
TInternalComputationValueType CoordinateRepresentationType
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
FixedTransformPointer m_FixedTransform
typename Superclass::SpacingType SpacingType
Definition: itkImage.h:143
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename Superclass::DerivativeType DerivativeType
Base class for most ITK classes.
Definition: itkObject.h:60
MovingTransformPointer m_MovingTransform
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
signed long OffsetValueType
Definition: itkIntTypes.h:94
Templated n-dimensional image class.
Definition: itkImage.h:75