ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkPointSetToPointSetMetricv4.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 itkPointSetToPointSetMetricv4_h
19 #define itkPointSetToPointSetMetricv4_h
20 
22 
23 #include "itkFixedArray.h"
24 #include "itkPointsLocator.h"
25 #include "itkPointSet.h"
26 
27 namespace itk
28 {
69 template<typename TFixedPointSet, typename TMovingPointSet,
70  class TInternalComputationValueType = double>
71 class ITK_TEMPLATE_EXPORT PointSetToPointSetMetricv4
72 : public ObjectToObjectMetric<TFixedPointSet::PointDimension, TMovingPointSet::PointDimension,
73  Image<TInternalComputationValueType, TFixedPointSet::PointDimension>, TInternalComputationValueType>
74 {
75 public:
76  ITK_DISALLOW_COPY_AND_ASSIGN(PointSetToPointSetMetricv4);
77 
80  using Superclass = ObjectToObjectMetric<TFixedPointSet::PointDimension,
81  TMovingPointSet::PointDimension,
83  TInternalComputationValueType>;
86 
89 
91  using MeasureType = typename Superclass::MeasureType;
92 
94  using ParametersType = typename Superclass::ParametersType;
95  using ParametersValueType = typename Superclass::ParametersValueType;
96  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
97 
99  using DerivativeType = typename Superclass::DerivativeType;
100 
102  using FixedTransformType = typename Superclass::FixedTransformType;
103  using FixedTransformPointer = typename Superclass::FixedTransformPointer;
104  using FixedInputPointType = typename Superclass::FixedInputPointType;
105  using FixedOutputPointType = typename Superclass::FixedOutputPointType;
106  using FixedTransformParametersType = typename Superclass::FixedTransformParametersType;
107 
108  using MovingTransformType = typename Superclass::MovingTransformType;
109  using MovingTransformPointer = typename Superclass::MovingTransformPointer;
110  using MovingInputPointType = typename Superclass::MovingInputPointType;
111  using MovingOutputPointType = typename Superclass::MovingOutputPointType;
112  using MovingTransformParametersType = typename Superclass::MovingTransformParametersType;
113 
114  using JacobianType = typename Superclass::JacobianType;
115  using FixedTransformJacobianType = typename Superclass::FixedTransformJacobianType;
116  using MovingTransformJacobianType = typename Superclass::MovingTransformJacobianType;
117 
118  using DisplacementFieldTransformType = typename Superclass::MovingDisplacementFieldTransformType;
119 
120  using ObjectType = typename Superclass::ObjectType;
121 
123  using DimensionType = typename Superclass::DimensionType;
124 
126  using FixedPointSetType = TFixedPointSet;
128  using FixedPixelType = typename TFixedPointSet::PixelType;
129  using FixedPointsContainer = typename TFixedPointSet::PointsContainer;
130 
131  static constexpr DimensionType FixedPointDimension = Superclass::FixedDimension;
132 
134  using MovingPointSetType = TMovingPointSet;
136  using MovingPixelType = typename TMovingPointSet::PixelType;
137  using MovingPointsContainer = typename TMovingPointSet::PointsContainer;
138 
139  static constexpr DimensionType MovingPointDimension = Superclass::MovingDimension;
140 
147  static constexpr DimensionType PointDimension = Superclass::FixedDimension;
148 
151  using CoordRepType = typename PointType::CoordRepType;
153  using PointsConstIterator = typename PointsContainer::ConstIterator;
154  using PointIdentifier = typename PointsContainer::ElementIdentifier;
155 
159 
162 
163  using DerivativeValueType = typename DerivativeType::ValueType;
165 
167  using VirtualImageType = typename Superclass::VirtualImageType;
168  using VirtualImagePointer = typename Superclass::VirtualImagePointer;
169  using VirtualPixelType = typename Superclass::VirtualPixelType;
170  using VirtualRegionType = typename Superclass::VirtualRegionType;
171  using VirtualSizeType = typename Superclass::VirtualSizeType;
172  using VirtualSpacingType = typename Superclass::VirtualSpacingType;
173  using VirtualOriginType = typename Superclass::VirtualPointType;
174  using VirtualPointType = typename Superclass::VirtualPointType;
175  using VirtualDirectionType = typename Superclass::VirtualDirectionType;
176  using VirtualRadiusType = typename Superclass::VirtualSizeType;
177  using VirtualIndexType = typename Superclass::VirtualIndexType;
178  using VirtualPointSetType = typename Superclass::VirtualPointSetType;
179  using VirtualPointSetPointer = typename Superclass::VirtualPointSetPointer;
180 
182  void SetFixedObject( const ObjectType *object ) override
183  {
184  auto * pointSet = dynamic_cast<FixedPointSetType *>( const_cast<ObjectType *>( object ) );
185  if( pointSet != nullptr )
186  {
187  this->SetFixedPointSet( pointSet );
188  }
189  else
190  {
191  itkExceptionMacro( "Incorrect object type. Should be a point set." )
192  }
193  }
195 
197  void SetMovingObject( const ObjectType *object ) override
198  {
199  auto * pointSet = dynamic_cast<MovingPointSetType *>( const_cast<ObjectType *>( object ) );
200  if( pointSet != nullptr )
201  {
202  this->SetMovingPointSet( pointSet );
203  }
204  else
205  {
206  itkExceptionMacro( "Incorrect object type. Should be a point set." )
207  }
208  }
210 
212  itkSetConstObjectMacro( FixedPointSet, FixedPointSetType );
213  itkGetConstObjectMacro( FixedPointSet, FixedPointSetType );
215 
217  itkGetModifiableObjectMacro( FixedTransformedPointSet, FixedTransformedPointSetType );
218 
220  itkSetConstObjectMacro( MovingPointSet, MovingPointSetType );
221  itkGetConstObjectMacro( MovingPointSet, MovingPointSetType );
223 
225  itkGetModifiableObjectMacro( MovingTransformedPointSet, MovingTransformedPointSetType );
226 
230  SizeValueType GetNumberOfComponents() const;
231 
242  MeasureType GetValue() const override;
243 
254  void GetDerivative( DerivativeType & ) const override;
255 
266  void GetValueAndDerivative( MeasureType &, DerivativeType & ) const override;
267 
273  virtual MeasureType GetLocalNeighborhoodValue( const PointType &, const PixelType & pixel ) const = 0;
274 
279  virtual LocalDerivativeType GetLocalNeighborhoodDerivative( const PointType &, const PixelType & pixel ) const;
280 
285  virtual void GetLocalNeighborhoodValueAndDerivative( const PointType &,
286  MeasureType &, LocalDerivativeType &, const PixelType & pixel ) const = 0;
287 
292  const VirtualPointSetType * GetVirtualTransformedPointSet() const;
293 
298  void Initialize() override;
299 
301  {
302  /* An arbitrary point in the virtual domain will not always
303  * correspond to a point within either point set. */
304  return false;
305  }
306 
318  itkSetMacro( StoreDerivativeAsSparseFieldForLocalSupportTransforms, bool );
319  itkGetConstMacro( StoreDerivativeAsSparseFieldForLocalSupportTransforms, bool );
320  itkBooleanMacro( StoreDerivativeAsSparseFieldForLocalSupportTransforms );
322 
326  itkSetMacro( CalculateValueAndDerivativeInTangentSpace, bool );
327  itkGetConstMacro( CalculateValueAndDerivativeInTangentSpace, bool );
328  itkBooleanMacro( CalculateValueAndDerivativeInTangentSpace );
330 
331 protected:
333  ~PointSetToPointSetMetricv4() override = default;
334  void PrintSelf( std::ostream & os, Indent indent ) const override;
335 
336  typename FixedPointSetType::ConstPointer m_FixedPointSet;
338 
340 
341  typename MovingPointSetType::ConstPointer m_MovingPointSet;
343 
345 
348 
354 
363 
366  virtual void InitializePointSets() const;
367 
372  virtual void InitializeForIteration() const;
373 
379  virtual SizeValueType CalculateNumberOfValidFixedPoints() const;
380 
383  void CalculateValueAndDerivative( MeasureType & value, DerivativeType & derivative, bool calculateValue ) const;
384 
391  void TransformFixedAndCreateVirtualPointSet() const;
392 
399  void TransformMovingPointSet() const;
400 
405  void InitializePointsLocators() const;
406 
411  void StorePointDerivative( const VirtualPointType &, const DerivativeType &, DerivativeType & ) const;
412 
413  using MetricCategoryType = typename Superclass::MetricCategoryType;
414 
417  {
418  return Superclass::POINT_SET_METRIC;
419  }
420 
421 
422 private:
425 
426  // Flag to keep track of whether a warning has already been issued
427  // regarding the number of valid points.
429 
430  // Flag to store derivatives at fixed point locations with the rest being zero gradient
431  // (default = true).
433 
436 };
437 } // end namespace itk
438 
439 #ifndef ITK_MANUAL_INSTANTIATION
440 #include "itkPointSetToPointSetMetricv4.hxx"
441 #endif
442 
443 #endif
void SetFixedObject(const ObjectType *object) override
Light weight base class for most itk classes.
MovingPointSetType::ConstPointer m_MovingPointSet
bool SupportsArbitraryVirtualDomainSamples() const override
FixedPointSetType::ConstPointer m_FixedPointSet
unsigned long SizeValueType
Definition: itkIntTypes.h:83
TInternalComputationValueType ParametersValueType
Computes similarity between two point sets.
typename TreeType::InstanceIdentifierVectorType NeighborsIdentifierType
typename DerivativeType::ValueType DerivativeValueType
Computes similarity between regions of two objects.
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
typename Superclass::MeasureType MeasureType
Accelerate geometric searches for points.
PointsLocatorType::Pointer m_MovingTransformedPointsLocator
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
MetricCategoryType GetMetricCategory() const override
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:104
PointsLocatorType::Pointer m_FixedTransformedPointsLocator
FixedTransformedPointSetType::Pointer m_FixedTransformedPointSet
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename Superclass::DerivativeType DerivativeType
MovingTransformedPointSetType::Pointer m_MovingTransformedPointSet
Base class for most ITK classes.
Definition: itkObject.h:60
void SetMovingObject(const ObjectType *object) override
Templated n-dimensional image class.
Definition: itkImage.h:75