ITK  5.3.0
Insight Toolkit
itkPointSetToPointSetMetricWithIndexv4.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  * 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 itkPointSetToPointSetMetricWithIndexv4_h
19 #define itkPointSetToPointSetMetricWithIndexv4_h
20 
22 
23 #include "itkFixedArray.h"
24 #include "itkPointsLocator.h"
25 #include "itkPointSet.h"
26 
27 namespace itk
28 {
69 template <typename TFixedPointSet,
70  typename TMovingPointSet = TFixedPointSet,
71  class TInternalComputationValueType = double>
72 class ITK_TEMPLATE_EXPORT PointSetToPointSetMetricWithIndexv4
73  : public ObjectToObjectMetric<TFixedPointSet::PointDimension,
74  TMovingPointSet::PointDimension,
75  Image<TInternalComputationValueType, TFixedPointSet::PointDimension>,
76  TInternalComputationValueType>
77 {
78 public:
79  ITK_DISALLOW_COPY_AND_MOVE(PointSetToPointSetMetricWithIndexv4);
80 
83  using Superclass = ObjectToObjectMetric<TFixedPointSet::PointDimension,
84  TMovingPointSet::PointDimension,
86  TInternalComputationValueType>;
89 
92 
94  using typename Superclass::MeasureType;
95 
97  using typename Superclass::ParametersType;
98  using typename Superclass::ParametersValueType;
99  using typename Superclass::NumberOfParametersType;
100 
102  using typename Superclass::DerivativeType;
103 
105  using typename Superclass::FixedTransformType;
106  using typename Superclass::FixedTransformPointer;
107  using typename Superclass::FixedInputPointType;
108  using typename Superclass::FixedOutputPointType;
109  using typename Superclass::FixedTransformParametersType;
110 
111  using typename Superclass::MovingTransformType;
112  using typename Superclass::MovingTransformPointer;
113  using typename Superclass::MovingInputPointType;
114  using typename Superclass::MovingOutputPointType;
115  using typename Superclass::MovingTransformParametersType;
116 
117  using typename Superclass::JacobianType;
118  using typename Superclass::FixedTransformJacobianType;
119  using typename Superclass::MovingTransformJacobianType;
120 
121  using DisplacementFieldTransformType = typename Superclass::MovingDisplacementFieldTransformType;
122 
123  using ObjectType = typename Superclass::ObjectType;
124 
126  using typename Superclass::DimensionType;
127 
129  using FixedPointSetType = TFixedPointSet;
131  using FixedPixelType = typename TFixedPointSet::PixelType;
132  using FixedPointsContainer = typename TFixedPointSet::PointsContainer;
133 
134  static constexpr DimensionType FixedPointDimension = Superclass::FixedDimension;
135 
137  using MovingPointSetType = TMovingPointSet;
139  using MovingPixelType = typename TMovingPointSet::PixelType;
140  using MovingPointsContainer = typename TMovingPointSet::PointsContainer;
141 
142  static constexpr DimensionType MovingPointDimension = Superclass::MovingDimension;
143 
150  static constexpr DimensionType PointDimension = Superclass::FixedDimension;
151 
154  using CoordRepType = typename PointType::CoordRepType;
156  using PointsConstIterator = typename PointsContainer::ConstIterator;
157  using PointIdentifier = typename PointsContainer::ElementIdentifier;
158 
162 
165 
168 
170  using VirtualImageType = typename Superclass::VirtualImageType;
171  using typename Superclass::VirtualImagePointer;
172  using typename Superclass::VirtualPixelType;
173  using typename Superclass::VirtualRegionType;
174  using typename Superclass::VirtualSizeType;
175  using typename Superclass::VirtualSpacingType;
176  using VirtualOriginType = typename Superclass::VirtualPointType;
177  using typename Superclass::VirtualPointType;
178  using typename Superclass::VirtualDirectionType;
179  using VirtualRadiusType = typename Superclass::VirtualSizeType;
180  using typename Superclass::VirtualIndexType;
181  using typename Superclass::VirtualPointSetType;
182  using typename Superclass::VirtualPointSetPointer;
183 
185  void
186  SetFixedObject(const ObjectType * object) override
187  {
188  auto * pointSet = dynamic_cast<FixedPointSetType *>(const_cast<ObjectType *>(object));
189  if (pointSet != nullptr)
190  {
191  this->SetFixedPointSet(pointSet);
192  }
193  else
194  {
195  itkExceptionMacro("Incorrect object type. Should be a point set.");
196  }
197  }
199 
201  void
202  SetMovingObject(const ObjectType * object) override
203  {
204  auto * pointSet = dynamic_cast<MovingPointSetType *>(const_cast<ObjectType *>(object));
205  if (pointSet != nullptr)
206  {
207  this->SetMovingPointSet(pointSet);
208  }
209  else
210  {
211  itkExceptionMacro("Incorrect object type. Should be a point set.");
212  }
213  }
215 
217  itkSetConstObjectMacro(FixedPointSet, FixedPointSetType);
218  itkGetConstObjectMacro(FixedPointSet, FixedPointSetType);
220 
222  itkGetModifiableObjectMacro(FixedTransformedPointSet, FixedTransformedPointSetType);
223 
225  itkSetConstObjectMacro(MovingPointSet, MovingPointSetType);
226  itkGetConstObjectMacro(MovingPointSet, MovingPointSetType);
228 
230  itkGetModifiableObjectMacro(MovingTransformedPointSet, MovingTransformedPointSetType);
231 
236  GetNumberOfComponents() const;
237 
248  MeasureType
249  GetValue() const override;
250 
261  void
262  GetDerivative(DerivativeType &) const override;
263 
274  void
275  GetValueAndDerivative(MeasureType &, DerivativeType &) const override;
276 
281  const VirtualPointSetType *
282  GetVirtualTransformedPointSet() const;
283 
288  void
289  Initialize() override;
290 
291  bool
293  {
294  /* An arbitrary point in the virtual domain will not always
295  * correspond to a point within either point set. */
296  return false;
297  }
298 
310  itkSetMacro(StoreDerivativeAsSparseFieldForLocalSupportTransforms, bool);
311  itkGetConstMacro(StoreDerivativeAsSparseFieldForLocalSupportTransforms, bool);
312  itkBooleanMacro(StoreDerivativeAsSparseFieldForLocalSupportTransforms);
314 
318  itkSetMacro(CalculateValueAndDerivativeInTangentSpace, bool);
319  itkGetConstMacro(CalculateValueAndDerivativeInTangentSpace, bool);
320  itkBooleanMacro(CalculateValueAndDerivativeInTangentSpace);
322 
323 protected:
325  ~PointSetToPointSetMetricWithIndexv4() override = default;
326  void
327  PrintSelf(std::ostream & os, Indent indent) const override;
328 
329  typename FixedPointSetType::ConstPointer m_FixedPointSet;
331 
333 
334  typename MovingPointSetType::ConstPointer m_MovingPointSet;
336 
338 
341 
347 
356 
359  virtual void
360  InitializePointSets() const;
361 
366  virtual void
367  InitializeForIteration() const;
368 
374  virtual SizeValueType
375  CalculateNumberOfValidFixedPoints() const;
376 
379  void
380  CalculateValueAndDerivative(MeasureType & calculatedValue, DerivativeType & derivative, bool calculateValue) const;
381 
388  void
389  TransformFixedAndCreateVirtualPointSet() const;
390 
397  void
398  TransformMovingPointSet() const;
399 
404  void
405  InitializePointsLocators() const;
406 
411  void
412  StorePointDerivative(const VirtualPointType &, const DerivativeType &, DerivativeType &) const;
413 
414  using typename Superclass::MetricCategoryType;
415 
418  GetMetricCategory() const override
419  {
420  return MetricCategoryType::POINT_SET_METRIC;
421  }
422 
423  virtual bool
425  {
426  return true;
427  };
428 
429  virtual bool
431  {
432  return true;
433  };
434 
440  virtual MeasureType
441  GetLocalNeighborhoodValueWithIndex(const PointIdentifier &, const PointType &, const PixelType & pixel) const = 0;
442 
449  virtual LocalDerivativeType
450  GetLocalNeighborhoodDerivativeWithIndex(const PointIdentifier &, const PointType &, const PixelType & pixel) const;
451 
457  virtual void
458  GetLocalNeighborhoodValueAndDerivativeWithIndex(const PointIdentifier &,
459  const PointType &,
460  MeasureType &,
461  LocalDerivativeType &,
462  const PixelType & pixel) const = 0;
463 
464 private:
467 
468  // Flag to keep track of whether a warning has already been issued
469  // regarding the number of valid points.
471 
472  // Flag to store derivatives at fixed point locations with the rest being zero gradient
473  // (default = true).
475 
478 
479  // Create ranges over the point set for multithreaded computation of value and derivatives
480  using PointIdentifierPair = std::pair<PointIdentifier, PointIdentifier>;
481  using PointIdentifierRanges = std::vector<PointIdentifierPair>;
483  CreateRanges() const;
484 };
485 } // end namespace itk
486 
487 #ifndef ITK_MANUAL_INSTANTIATION
488 # include "itkPointSetToPointSetMetricWithIndexv4.hxx"
489 #endif
490 
491 #endif
itk::PointSetToPointSetMetricWithIndexv4::SupportsArbitraryVirtualDomainSamples
bool SupportsArbitraryVirtualDomainSamples() const override
Definition: itkPointSetToPointSetMetricWithIndexv4.h:292
itk::PointsLocator::NeighborsIdentifierType
typename TreeType::InstanceIdentifierVectorType NeighborsIdentifierType
Definition: itkPointsLocator.h:82
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PixelType
FixedPixelType PixelType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:153
itk::ObjectToObjectMetric< TPointSet ::PointDimension, TPointSet ::PointDimension, Image< TInternalComputationValueType, TPointSet ::PointDimension >, TInternalComputationValueType >::DimensionType
SizeValueType DimensionType
Definition: itkObjectToObjectMetric.h:129
itk::ObjectToObjectMetric< TPointSet ::PointDimension, TPointSet ::PointDimension, Image< TInternalComputationValueType, TPointSet ::PointDimension >, TInternalComputationValueType >::VirtualRadiusType
typename VirtualImageType::SizeType VirtualRadiusType
Definition: itkObjectToObjectMetric.h:147
itk::PointSetToPointSetMetricWithIndexv4::m_MovingTransformedPointSet
MovingTransformedPointSetType::Pointer m_MovingTransformedPointSet
Definition: itkPointSetToPointSetMetricWithIndexv4.h:335
itk::PointSet
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:82
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:102
itk::PointSetToPointSetMetricWithIndexv4::m_FixedTransformedPointSetTime
ModifiedTimeType m_FixedTransformedPointSetTime
Definition: itkPointSetToPointSetMetricWithIndexv4.h:477
itk::PointSetToPointSetMetricWithIndexv4::RequiresFixedPointsLocator
virtual bool RequiresFixedPointsLocator() const
Definition: itkPointSetToPointSetMetricWithIndexv4.h:430
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::MovingPixelType
typename TPointSet ::PixelType MovingPixelType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:139
itk::PointSetToPointSetMetricWithIndexv4::m_UsePointSetData
bool m_UsePointSetData
Definition: itkPointSetToPointSetMetricWithIndexv4.h:346
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::MovingPointsContainer
typename TPointSet ::PointsContainer MovingPointsContainer
Definition: itkPointSetToPointSetMetricWithIndexv4.h:140
itk::PointSetToPointSetMetricWithIndexv4::m_FixedPointSet
FixedPointSetType::ConstPointer m_FixedPointSet
Definition: itkPointSetToPointSetMetricWithIndexv4.h:329
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PointsContainer
FixedPointsContainer PointsContainer
Definition: itkPointSetToPointSetMetricWithIndexv4.h:155
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::PointSetToPointSetMetricWithIndexv4::m_MovingPointSet
MovingPointSetType::ConstPointer m_MovingPointSet
Definition: itkPointSetToPointSetMetricWithIndexv4.h:334
itk::PointSetToPointSetMetricWithIndexv4::m_FixedTransformedPointsLocator
PointsLocatorType::Pointer m_FixedTransformedPointsLocator
Definition: itkPointSetToPointSetMetricWithIndexv4.h:332
itk::PointSetToPointSetMetricWithIndexv4::GetMetricCategory
MetricCategoryType GetMetricCategory() const override
Definition: itkPointSetToPointSetMetricWithIndexv4.h:418
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::PointSetToPointSetMetricWithIndexv4::m_StoreDerivativeAsSparseFieldForLocalSupportTransforms
bool m_StoreDerivativeAsSparseFieldForLocalSupportTransforms
Definition: itkPointSetToPointSetMetricWithIndexv4.h:474
itk::PointsLocator
Accelerate geometric searches for points.
Definition: itkPointsLocator.h:42
itkPointsLocator.h
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::FixedPixelType
typename TPointSet ::PixelType FixedPixelType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:131
itk::ObjectToObjectMetricBaseTemplate::DerivativeValueType
typename DerivativeType::ValueType DerivativeValueType
Definition: itkObjectToObjectMetricBase.h:113
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::MovingPointSetType
TPointSet MovingPointSetType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:137
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PointIdentifierPair
std::pair< PointIdentifier, PointIdentifier > PointIdentifierPair
Definition: itkPointSetToPointSetMetricWithIndexv4.h:480
itk::PointSetToPointSetMetricWithIndexv4
Computes similarity between two point sets.
Definition: itkPointSetToPointSetMetricWithIndexv4.h:72
itk::SingleValuedCostFunctionv4Template::MeasureType
TInternalComputationValueType MeasureType
Definition: itkSingleValuedCostFunctionv4.h:67
itkObjectToObjectMetric.h
itk::ObjectToObjectMetric< TPointSet ::PointDimension, TPointSet ::PointDimension, Image< TInternalComputationValueType, TPointSet ::PointDimension >, TInternalComputationValueType >::VirtualPointSetPointer
typename VirtualPointSetType::Pointer VirtualPointSetPointer
Definition: itkObjectToObjectMetric.h:152
itk::PointSetToPointSetMetricWithIndexv4::m_FixedTransformPointLocatorsNeedInitialization
bool m_FixedTransformPointLocatorsNeedInitialization
Definition: itkPointSetToPointSetMetricWithIndexv4.h:466
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::PointSetToPointSetMetricWithIndexv4::m_MovingTransformPointLocatorsNeedInitialization
bool m_MovingTransformPointLocatorsNeedInitialization
Definition: itkPointSetToPointSetMetricWithIndexv4.h:465
itk::ObjectToObjectMetric< TPointSet ::PointDimension, TPointSet ::PointDimension, Image< TInternalComputationValueType, TPointSet ::PointDimension >, TInternalComputationValueType >::MetricCategoryType
typename Superclass::MetricCategoryEnum MetricCategoryType
Definition: itkObjectToObjectMetric.h:318
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::FixedPointType
typename TPointSet ::PointType FixedPointType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:130
itk::PointSetToPointSetMetricWithIndexv4::SetMovingObject
void SetMovingObject(const ObjectType *object) override
Definition: itkPointSetToPointSetMetricWithIndexv4.h:202
itk::PointSetToPointSetMetricWithIndexv4::m_MovingTransformedPointsLocator
PointsLocatorType::Pointer m_MovingTransformedPointsLocator
Definition: itkPointSetToPointSetMetricWithIndexv4.h:337
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::DisplacementFieldTransformType
typename Superclass::MovingDisplacementFieldTransformType DisplacementFieldTransformType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:121
itk::PointSetToPointSetMetricWithIndexv4::RequiresMovingPointsLocator
virtual bool RequiresMovingPointsLocator() const
Definition: itkPointSetToPointSetMetricWithIndexv4.h:424
itkFixedArray.h
itk::PointSetToPointSetMetricWithIndexv4::m_FixedTransformedPointSet
FixedTransformedPointSetType::Pointer m_FixedTransformedPointSet
Definition: itkPointSetToPointSetMetricWithIndexv4.h:330
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PointsConstIterator
typename PointsContainer::ConstIterator PointsConstIterator
Definition: itkPointSetToPointSetMetricWithIndexv4.h:156
itk::ObjectToObjectMetric< TPointSet ::PointDimension, TPointSet ::PointDimension, Image< TInternalComputationValueType, TPointSet ::PointDimension >, TInternalComputationValueType >::VirtualOriginType
typename VirtualImageType::PointType VirtualOriginType
Definition: itkObjectToObjectMetric.h:144
itk::PointSetToPointSetMetricWithIndexv4::m_HaveWarnedAboutNumberOfValidPoints
bool m_HaveWarnedAboutNumberOfValidPoints
Definition: itkPointSetToPointSetMetricWithIndexv4.h:470
itk::ObjectToObjectMetric< TPointSet ::PointDimension, TPointSet ::PointDimension, Image< TInternalComputationValueType, TPointSet ::PointDimension >, TInternalComputationValueType >::VirtualPointType
typename VirtualImageType::PointType VirtualPointType
Definition: itkObjectToObjectMetric.h:145
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::PointSetToPointSetMetricWithIndexv4::m_CalculateValueAndDerivativeInTangentSpace
bool m_CalculateValueAndDerivativeInTangentSpace
Definition: itkPointSetToPointSetMetricWithIndexv4.h:355
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::MovingPointType
typename TPointSet ::PointType MovingPointType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:138
itk::PointSetToPointSetMetricWithIndexv4::m_VirtualTransformedPointSet
VirtualPointSetPointer m_VirtualTransformedPointSet
Definition: itkPointSetToPointSetMetricWithIndexv4.h:340
itk::Array< TInternalComputationValueType >::ValueType
TInternalComputationValueType ValueType
Definition: itkArray.h:52
itk::PointSetToPointSetMetricWithIndexv4::SetFixedObject
void SetFixedObject(const ObjectType *object) override
Definition: itkPointSetToPointSetMetricWithIndexv4.h:186
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::NeighborsIdentifierType
typename PointsLocatorType::NeighborsIdentifierType NeighborsIdentifierType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:161
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::FixedPointsContainer
typename TPointSet ::PointsContainer FixedPointsContainer
Definition: itkPointSetToPointSetMetricWithIndexv4.h:132
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::FixedPointSetType
TPointSet FixedPointSetType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:129
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PointIdentifierRanges
std::vector< PointIdentifierPair > PointIdentifierRanges
Definition: itkPointSetToPointSetMetricWithIndexv4.h:481
itk::Array< TInternalComputationValueType >
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ObjectToObjectMetric
Computes similarity between regions of two objects.
Definition: itkObjectToObjectMetric.h:92
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itkPointSet.h
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PointIdentifier
typename PointsContainer::ElementIdentifier PointIdentifier
Definition: itkPointSetToPointSetMetricWithIndexv4.h:157
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::CoordRepType
typename PointType::CoordRepType CoordRepType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:154
itk::PointSetToPointSetMetricWithIndexv4::m_MovingTransformedPointSetTime
ModifiedTimeType m_MovingTransformedPointSetTime
Definition: itkPointSetToPointSetMetricWithIndexv4.h:476
itk::PointSetToPointSetMetricWithIndexv4< TPointSet, TPointSet, TInternalComputationValueType >::PointType
FixedPointType PointType
Definition: itkPointSetToPointSetMetricWithIndexv4.h:152
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83