ITK  4.13.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 
79  typedef ObjectToObjectMetric<TFixedPointSet::PointDimension,
80  TMovingPointSet::PointDimension,
82  TInternalComputationValueType> Superclass;
85 
88 
90  typedef typename Superclass::MeasureType MeasureType;
91 
93  typedef typename Superclass::ParametersType ParametersType;
94  typedef typename Superclass::ParametersValueType ParametersValueType;
95  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
96 
98  typedef typename Superclass::DerivativeType DerivativeType;
99 
101  typedef typename Superclass::FixedTransformType FixedTransformType;
102  typedef typename Superclass::FixedTransformPointer FixedTransformPointer;
103  typedef typename Superclass::FixedInputPointType FixedInputPointType;
104  typedef typename Superclass::FixedOutputPointType FixedOutputPointType;
105  typedef typename Superclass::FixedTransformParametersType FixedTransformParametersType;
106 
107  typedef typename Superclass::MovingTransformType MovingTransformType;
108  typedef typename Superclass::MovingTransformPointer MovingTransformPointer;
109  typedef typename Superclass::MovingInputPointType MovingInputPointType;
110  typedef typename Superclass::MovingOutputPointType MovingOutputPointType;
111  typedef typename Superclass::MovingTransformParametersType MovingTransformParametersType;
112 
113  typedef typename Superclass::JacobianType JacobianType;
114  typedef typename Superclass::FixedTransformJacobianType FixedTransformJacobianType;
115  typedef typename Superclass::MovingTransformJacobianType MovingTransformJacobianType;
116 
117  typedef typename Superclass::MovingDisplacementFieldTransformType DisplacementFieldTransformType;
118 
119  typedef typename Superclass::ObjectType ObjectType;
120 
122  typedef typename Superclass::DimensionType DimensionType;
123 
125  typedef TFixedPointSet FixedPointSetType;
127  typedef typename TFixedPointSet::PixelType FixedPixelType;
128  typedef typename TFixedPointSet::PointsContainer FixedPointsContainer;
129 
130  itkStaticConstMacro( FixedPointDimension, DimensionType, Superclass::FixedDimension );
131 
133  typedef TMovingPointSet MovingPointSetType;
135  typedef typename TMovingPointSet::PixelType MovingPixelType;
136  typedef typename TMovingPointSet::PointsContainer MovingPointsContainer;
137 
138  itkStaticConstMacro( MovingPointDimension, DimensionType, Superclass::MovingDimension );
139 
146  itkStaticConstMacro( PointDimension, DimensionType, Superclass::FixedDimension );
147 
150  typedef typename PointType::CoordRepType CoordRepType;
152  typedef typename PointsContainer::ConstIterator PointsConstIterator;
153  typedef typename PointsContainer::ElementIdentifier PointIdentifier;
154 
158 
161 
164 
166  typedef typename Superclass::VirtualImageType VirtualImageType;
167  typedef typename Superclass::VirtualImagePointer VirtualImagePointer;
168  typedef typename Superclass::VirtualPixelType VirtualPixelType;
169  typedef typename Superclass::VirtualRegionType VirtualRegionType;
170  typedef typename Superclass::VirtualSizeType VirtualSizeType;
171  typedef typename Superclass::VirtualSpacingType VirtualSpacingType;
172  typedef typename Superclass::VirtualPointType VirtualOriginType;
173  typedef typename Superclass::VirtualPointType VirtualPointType;
174  typedef typename Superclass::VirtualDirectionType VirtualDirectionType;
175  typedef typename Superclass::VirtualSizeType VirtualRadiusType;
176  typedef typename Superclass::VirtualIndexType VirtualIndexType;
177  typedef typename Superclass::VirtualPointSetType VirtualPointSetType;
178  typedef typename Superclass::VirtualPointSetPointer VirtualPointSetPointer;
179 
181  virtual void SetFixedObject( const ObjectType *object ) ITK_OVERRIDE
182  {
183  FixedPointSetType *pointSet = dynamic_cast<FixedPointSetType *>( const_cast<ObjectType *>( object ) );
184  if( pointSet != ITK_NULLPTR )
185  {
186  this->SetFixedPointSet( pointSet );
187  }
188  else
189  {
190  itkExceptionMacro( "Incorrect object type. Should be a point set." )
191  }
192  }
194 
196  virtual void SetMovingObject( const ObjectType *object ) ITK_OVERRIDE
197  {
198  MovingPointSetType *pointSet = dynamic_cast<MovingPointSetType *>( const_cast<ObjectType *>( object ) );
199  if( pointSet != ITK_NULLPTR )
200  {
201  this->SetMovingPointSet( pointSet );
202  }
203  else
204  {
205  itkExceptionMacro( "Incorrect object type. Should be a point set." )
206  }
207  }
209 
211  itkSetConstObjectMacro( FixedPointSet, FixedPointSetType );
212  itkGetConstObjectMacro( FixedPointSet, FixedPointSetType );
214 
216  itkGetModifiableObjectMacro( FixedTransformedPointSet, FixedTransformedPointSetType );
217 
219  itkSetConstObjectMacro( MovingPointSet, MovingPointSetType );
220  itkGetConstObjectMacro( MovingPointSet, MovingPointSetType );
222 
224  itkGetModifiableObjectMacro( MovingTransformedPointSet, MovingTransformedPointSetType );
225 
229  SizeValueType GetNumberOfComponents() const;
230 
241  virtual MeasureType GetValue() const ITK_OVERRIDE;
242 
253  virtual void GetDerivative( DerivativeType & ) const ITK_OVERRIDE;
254 
265  virtual void GetValueAndDerivative( MeasureType &, DerivativeType & ) const ITK_OVERRIDE;
266 
272  virtual MeasureType GetLocalNeighborhoodValue( const PointType &, const PixelType & pixel ) const = 0;
273 
278  virtual LocalDerivativeType GetLocalNeighborhoodDerivative( const PointType &, const PixelType & pixel ) const;
279 
284  virtual void GetLocalNeighborhoodValueAndDerivative( const PointType &,
285  MeasureType &, LocalDerivativeType &, const PixelType & pixel ) const = 0;
286 
291  const VirtualPointSetType * GetVirtualTransformedPointSet() const;
292 
297  virtual void Initialize( void ) ITK_OVERRIDE;
298 
299  virtual bool SupportsArbitraryVirtualDomainSamples( void ) const ITK_OVERRIDE
300  {
301  /* An arbitrary point in the virtual domain will not always
302  * correspond to a point within either point set. */
303  return false;
304  }
305 
317  itkSetMacro( StoreDerivativeAsSparseFieldForLocalSupportTransforms, bool );
318  itkGetConstMacro( StoreDerivativeAsSparseFieldForLocalSupportTransforms, bool );
319  itkBooleanMacro( StoreDerivativeAsSparseFieldForLocalSupportTransforms );
321 
325  itkSetMacro( CalculateValueAndDerivativeInTangentSpace, bool );
326  itkGetConstMacro( CalculateValueAndDerivativeInTangentSpace, bool );
327  itkBooleanMacro( CalculateValueAndDerivativeInTangentSpace );
329 
330 protected:
332  virtual ~PointSetToPointSetMetricv4() ITK_OVERRIDE;
333  void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
334 
335  typename FixedPointSetType::ConstPointer m_FixedPointSet;
336  mutable typename FixedTransformedPointSetType::Pointer m_FixedTransformedPointSet;
337 
338  mutable typename PointsLocatorType::Pointer m_FixedTransformedPointsLocator;
339 
340  typename MovingPointSetType::ConstPointer m_MovingPointSet;
341  mutable typename MovingTransformedPointSetType::Pointer m_MovingTransformedPointSet;
342 
343  mutable typename PointsLocatorType::Pointer m_MovingTransformedPointsLocator;
344 
346  mutable VirtualPointSetPointer m_VirtualTransformedPointSet;
347 
352  bool m_UsePointSetData;
353 
361  bool m_CalculateValueAndDerivativeInTangentSpace;
362 
365  virtual void InitializePointSets() const;
366 
371  virtual void InitializeForIteration() const;
372 
378  virtual SizeValueType CalculateNumberOfValidFixedPoints() const;
379 
382  void CalculateValueAndDerivative( MeasureType & value, DerivativeType & derivative, bool calculateValue ) const;
383 
390  void TransformFixedAndCreateVirtualPointSet() const;
391 
398  void TransformMovingPointSet() const;
399 
404  void InitializePointsLocators() const;
405 
410  void StorePointDerivative( const VirtualPointType &, const DerivativeType &, DerivativeType & ) const;
411 
413 
415  virtual MetricCategoryType GetMetricCategory() const ITK_OVERRIDE
416  {
417  return Superclass::POINT_SET_METRIC;
418  }
419 
420 
421 private:
422  ITK_DISALLOW_COPY_AND_ASSIGN(PointSetToPointSetMetricv4);
423 
426 
427  // Flag to keep track of whether a warning has already been issued
428  // regarding the number of valid points.
430 
431  // Flag to store derivatives at fixed point locations with the rest being zero gradient
432  // (default = true).
434 
437 };
438 } // end namespace itk
439 
440 #ifndef ITK_MANUAL_INSTANTIATION
441 #include "itkPointSetToPointSetMetricv4.hxx"
442 #endif
443 
444 #endif
PointsContainer::ConstIterator PointsConstIterator
TInternalComputationValueType ValueType
Definition: itkArray.h:55
Superclass::VirtualImageType VirtualImageType
Light weight base class for most itk classes.
PointSet< FixedPixelType, itkGetStaticConstMacro(PointDimension)> FixedTransformedPointSetType
PointsContainer::ElementIdentifier PointIdentifier
PointsLocatorType::NeighborsIdentifierType NeighborsIdentifierType
PointSet< MovingPixelType, itkGetStaticConstMacro(PointDimension)> MovingTransformedPointSetType
ObjectToObjectMetric< TFixedPointSet::PointDimension, TMovingPointSet::PointDimension, Image< TInternalComputationValueType, TFixedPointSet::PointDimension >, TInternalComputationValueType > Superclass
Superclass::FixedTransformParametersType FixedTransformParametersType
Superclass::VirtualPointSetType VirtualPointSetType
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
Computes similarity between two point sets.
Superclass::MovingInputPointType MovingInputPointType
PointsLocator< PointsContainer > PointsLocatorType
Superclass::MovingOutputPointType MovingOutputPointType
Computes similarity between regions of two objects.
Superclass::VirtualPixelType VirtualPixelType
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Superclass::VirtualSpacingType VirtualSpacingType
TFixedPointSet::PointsContainer FixedPointsContainer
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
Superclass::VirtualImagePointer VirtualImagePointer
Superclass::VirtualPointType VirtualPointType
Accelerate geometric searches for points.
Superclass::VirtualIndexType VirtualIndexType
FixedArray< DerivativeValueType, itkGetStaticConstMacro(PointDimension)> LocalDerivativeType
Superclass::VirtualSizeType VirtualRadiusType
Superclass::FixedOutputPointType FixedOutputPointType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
Superclass::FixedTransformPointer FixedTransformPointer
Superclass::MovingDisplacementFieldTransformType DisplacementFieldTransformType
Superclass::FixedTransformJacobianType FixedTransformJacobianType
TMovingPointSet::PointsContainer MovingPointsContainer
TreeType::InstanceIdentifierVectorType NeighborsIdentifierType
Superclass::MovingTransformType MovingTransformType
Superclass::VirtualRegionType VirtualRegionType
Superclass::VirtualPointType VirtualOriginType
Superclass::MovingTransformPointer MovingTransformPointer
Superclass::MovingTransformJacobianType MovingTransformJacobianType
virtual void SetFixedObject(const ObjectType *object) override
virtual void SetMovingObject(const ObjectType *object) override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:59
Superclass::FixedInputPointType FixedInputPointType
Superclass::FixedTransformType FixedTransformType
Superclass::VirtualPointSetPointer VirtualPointSetPointer
Superclass::ParametersValueType ParametersValueType
Superclass::NumberOfParametersType NumberOfParametersType
Templated n-dimensional image class.
Definition: itkImage.h:75
Superclass::MovingTransformParametersType MovingTransformParametersType
Superclass::VirtualDirectionType VirtualDirectionType