ITK  6.0.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 * https://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
27namespace itk
28{
69template <typename TFixedPointSet,
70 typename TMovingPointSet = TFixedPointSet,
71 class TInternalComputationValueType = double>
72class ITK_TEMPLATE_EXPORT PointSetToPointSetMetricWithIndexv4
73 : public ObjectToObjectMetric<TFixedPointSet::PointDimension,
74 TMovingPointSet::PointDimension,
75 Image<TInternalComputationValueType, TFixedPointSet::PointDimension>,
76 TInternalComputationValueType>
77{
78public:
79 ITK_DISALLOW_COPY_AND_MOVE(PointSetToPointSetMetricWithIndexv4);
80
83 using Superclass = ObjectToObjectMetric<TFixedPointSet::PointDimension,
84 TMovingPointSet::PointDimension,
86 TInternalComputationValueType>;
89
91 itkOverrideGetNameOfClassMacro(PointSetToPointSetMetricWithIndexv4);
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 }
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 }
217 itkSetConstObjectMacro(FixedPointSet, FixedPointSetType);
218 itkGetConstObjectMacro(FixedPointSet, FixedPointSetType);
222 itkGetModifiableObjectMacro(FixedTransformedPointSet, FixedTransformedPointSetType);
223
225 itkSetConstObjectMacro(MovingPointSet, MovingPointSetType);
226 itkGetConstObjectMacro(MovingPointSet, MovingPointSetType);
230 itkGetModifiableObjectMacro(MovingTransformedPointSet, MovingTransformedPointSetType);
231
237
249 GetValue() const override;
250
261 void
262 GetDerivative(DerivativeType &) const override;
263
274 void
276
281 const VirtualPointSetType *
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);
318 itkSetMacro(CalculateValueAndDerivativeInTangentSpace, bool);
319 itkGetConstMacro(CalculateValueAndDerivativeInTangentSpace, bool);
320 itkBooleanMacro(CalculateValueAndDerivativeInTangentSpace);
323protected:
326 void
327 PrintSelf(std::ostream & os, Indent indent) const override;
328
329 typename FixedPointSetType::ConstPointer m_FixedPointSet{};
330 mutable typename FixedTransformedPointSetType::Pointer m_FixedTransformedPointSet{};
331
332 mutable typename PointsLocatorType::Pointer m_FixedTransformedPointsLocator{};
333
334 typename MovingPointSetType::ConstPointer m_MovingPointSet{};
335 mutable typename MovingTransformedPointSetType::Pointer m_MovingTransformedPointSet{};
336
337 mutable typename PointsLocatorType::Pointer m_MovingTransformedPointsLocator{};
338
340 mutable VirtualPointSetPointer m_VirtualTransformedPointSet{};
341
346 bool m_UsePointSetData{};
347
355 bool m_CalculateValueAndDerivativeInTangentSpace{};
356
359 virtual void
361
366 virtual void
368
374 virtual SizeValueType
376
379 void
380 CalculateValueAndDerivative(MeasureType & calculatedValue, DerivativeType & derivative, bool calculateValue) const;
381
388 void
390
397 void
399
404 void
406
411 void
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
451
457 virtual void
459 const PointType &,
460 MeasureType &,
462 const PixelType & pixel) const = 0;
463
464private:
465 mutable bool m_MovingTransformPointLocatorsNeedInitialization{};
466 mutable bool m_FixedTransformPointLocatorsNeedInitialization{};
467
468 // Flag to keep track of whether a warning has already been issued
469 // regarding the number of valid points.
470 mutable bool m_HaveWarnedAboutNumberOfValidPoints{};
471
472 // Flag to store derivatives at fixed point locations with the rest being zero gradient
473 // (default = true).
474 bool m_StoreDerivativeAsSparseFieldForLocalSupportTransforms{};
475
476 mutable ModifiedTimeType m_MovingTransformedPointSetTime{};
477 mutable ModifiedTimeType m_FixedTransformedPointSetTime{};
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>;
484};
485} // end namespace itk
486
487#ifndef ITK_MANUAL_INSTANTIATION
488# include "itkPointSetToPointSetMetricWithIndexv4.hxx"
489#endif
490
491#endif
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
Templated n-dimensional image class.
Definition: itkImage.h:89
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Computes similarity between regions of two objects.
const PointIdentifierRanges CreateRanges() const
typename PointsContainer::ElementIdentifier PointIdentifier
virtual void InitializeForIteration() const
virtual SizeValueType CalculateNumberOfValidFixedPoints() const
void GetDerivative(DerivativeType &) const override
~PointSetToPointSetMetricWithIndexv4() override=default
const VirtualPointSetType * GetVirtualTransformedPointSet() const
typename TMovingPointSet::PointsContainer MovingPointsContainer
virtual void GetLocalNeighborhoodValueAndDerivativeWithIndex(const PointIdentifier &, const PointType &, MeasureType &, LocalDerivativeType &, const PixelType &pixel) const =0
void CalculateValueAndDerivative(MeasureType &calculatedValue, DerivativeType &derivative, bool calculateValue) const
virtual LocalDerivativeType GetLocalNeighborhoodDerivativeWithIndex(const PointIdentifier &, const PointType &, const PixelType &pixel) const
MeasureType GetValue() const override
SizeValueType GetNumberOfComponents() const
void StorePointDerivative(const VirtualPointType &, const DerivativeType &, DerivativeType &) const
typename Superclass::MovingDisplacementFieldTransformType DisplacementFieldTransformType
std::pair< PointIdentifier, PointIdentifier > PointIdentifierPair
void GetValueAndDerivative(MeasureType &, DerivativeType &) const override
virtual MeasureType GetLocalNeighborhoodValueWithIndex(const PointIdentifier &, const PointType &, const PixelType &pixel) const =0
void PrintSelf(std::ostream &os, Indent indent) const override
typename PointsContainer::ConstIterator PointsConstIterator
typename TFixedPointSet::PointsContainer FixedPointsContainer
typename PointsLocatorType::NeighborsIdentifierType NeighborsIdentifierType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:82
Accelerate geometric searches for points.
typename TreeType::InstanceIdentifierVectorType NeighborsIdentifierType
SmartPointer< const Self > ConstPointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:105
unsigned long SizeValueType
Definition: itkIntTypes.h:86