GenericRegistrationFilter.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2017 Imperial College London
5  * Copyright 2013-2017 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_GenericRegistrationFilter_H
21 #define MIRTK_GenericRegistrationFilter_H
22 
23 #include "mirtk/RegistrationFilter.h"
24 
25 #include "mirtk/Math.h"
26 #include "mirtk/Point.h"
27 #include "mirtk/Vector3D.h"
28 #include "mirtk/EventDelegate.h"
29 
30 #include "mirtk/BaseImage.h"
31 #include "mirtk/GenericImage.h"
32 #include "mirtk/RegisteredImage.h"
33 #include "mirtk/InterpolationMode.h"
34 #include "mirtk/ExtrapolationMode.h"
35 
36 #include "mirtk/SimilarityMeasure.h"
37 #include "mirtk/PointSetDistanceMeasure.h"
38 #include "mirtk/ConstraintMeasure.h"
39 
40 #include "mirtk/LocalOptimizer.h"
41 #include "mirtk/RegistrationEnergy.h"
42 
43 #include "mirtk/Transformation.h"
44 #include "mirtk/TransformationModel.h"
45 
46 #include "mirtk/RegistrationConfig.h"
47 #if MIRTK_Registration_WITH_PointSet
48 # include "vtkSmartPointer.h"
49 # include "vtkPointSet.h"
50 #else
51 class vtkPointSet;
52 #endif
53 
54 
55 namespace mirtk {
56 
57 
58 class RegisteredPointSet;
59 class RegistrationEnergyParser;
60 class GenericRegistrationLogger;
61 class GenericRegistrationDebugger;
62 class HomogeneousTransformation;
63 class FreeFormTransformation;
64 
65 
66 const int MAX_NO_RESOLUTIONS = 10;
67 
68 
69 /**
70  * Generic registration filter
71  */
73 {
74  mirtkObjectMacro(GenericRegistrationFilter);
75 
76  friend class RegistrationEnergyParser;
77  friend class GenericRegistrationLogger;
78  friend class GenericRegistrationDebugger;
79 
80  // ---------------------------------------------------------------------------
81  // Types
82 public:
83 
84  /// Type of resolution pyramid images
86 
87  /// List type storing images for one resolution pyramid level
88  typedef Array<ResampledImageType> ResampledImageList;
89 
90  /// Scalar type of resolution pyramid images
92 
93  /// Type of cached displacement field
95 
96  /// Structure storing information about transformation instance
98  {
99  double _Exponent;
100 
101  TransformationInfo(double e = .0) : _Exponent(e) {}
102 
103  bool operator ==(const TransformationInfo &other) const
104  {
105  return fequal(_Exponent, other._Exponent, 1e-3);
106  }
107 
108  bool operator !=(const TransformationInfo &other) const
109  {
110  return !(*this == other);
111  }
112 
113  static TransformationInfo Identity()
114  {
115  return TransformationInfo(.0);
116  }
117 
118  static TransformationInfo Full()
119  {
120  return TransformationInfo(1.0);
121  }
122 
123  static TransformationInfo Inverse()
124  {
125  return TransformationInfo(-1.0);
126  }
127 
128  bool IsForwardTransformation() const
129  {
130  return _Exponent > .0;
131  }
132 
133  bool IsBackwardTransformation() const
134  {
135  return _Exponent < .0;
136  }
137 
138  bool IsIdentity() const
139  {
140  return fequal(_Exponent, .0, 1e-3);
141  }
142 
143  operator bool() const
144  {
145  return !IsIdentity();
146  }
147  };
148 
149  /// Structure storing information of a used image similarity term parsed
150  /// from the registration energy function string
152  {
153  SimilarityMeasure _Measure; ///< Type of similarity measure
154  bool _DefaultSign; ///< Whether to use default sign of similarity
155  string _Name; ///< Name of similarity term
156  double _Weight; ///< Weight of similarity term
157  int _TargetIndex; ///< Index of target image
158  TransformationInfo _TargetTransformation; ///< Target transformation identifier
159  int _SourceIndex; ///< Index of source image
160  TransformationInfo _SourceTransformation; ///< Source transformation identifier
161 
162  bool IsSymmetric() const
163  {
164  return _TargetTransformation && _SourceTransformation;
165  }
166  };
167 
168  /// Structure storing information of a used point set distance term parsed
169  /// from the registration energy function string
171  {
172  PointSetDistanceMeasure _Measure; ///< Measure of polydata distance
173  bool _DefaultSign; ///< Whether to use default sign of distance measure
174  string _Name; ///< Name of polydata distance term
175  double _Weight; ///< Weight of polydata distance term
176  int _TargetIndex; ///< Index of target data set
177  TransformationInfo _TargetTransformation; ///< Target transformation identifier
178  int _SourceIndex; ///< Index of source data set
179  TransformationInfo _SourceTransformation; ///< Source transformation identifier
180 
181  bool IsSymmetric() const
182  {
183  return _TargetTransformation && _SourceTransformation;
184  }
185  };
186 
187  /// Structure storing information of a used point set constraint term parsed
188  /// from the registration energy function string
190  {
191  EnergyMeasure _Measure; ///< Type of internal forces
192  string _Name; ///< Name of constraint
193  double _Weight; ///< Weight of constraint
194  int _PointSetIndex; ///< Index of input point set object
195  int _RefImageIndex;
196  int _RefPointSetIndex;
197  TransformationInfo _Transformation; ///< Point set transformation identifier
198  };
199 
200  /// Structure storing information of a used constraint term parsed from the
201  /// registration energy function string
203  {
204  ConstraintMeasure _Measure; ///< Type of constraint
205  string _Name; ///< Name of constraint
206  double _Weight; ///< Weight of constraint
207  };
208 
209  /// Structure storing information about cached displacements
211  {
212  int _DispIndex; ///< Index of cached displacement field
213  double _InputTime; ///< Time of untransformed data
214  ImageAttributes _Domain; ///< Domain on which it is defined
215  const Transformation *_Transformation; ///< Corresponding transformation instance
216  };
217 
218  /// Structure storing information about transformed output point set
220  {
221  int _InputIndex;
222  bool _InitialUpdate;
224  };
225 
226  // ---------------------------------------------------------------------------
227  // Attributes
228 
229  /// Number of resolution levels
230  mirtkPublicAttributeMacro(int, NumberOfLevels);
231 
232  /// Level at which to stop multi-resolution optimization
233  mirtkPublicAttributeMacro(int, FinalLevel);
234 
235  /// Multi-level transformation mode
236  mirtkPublicAttributeMacro(MFFDMode, MultiLevelMode);
237 
238  /// Transformation model
239  mirtkPublicAttributeMacro(Array<enum TransformationModel>, TransformationModel);
240 
241  /// Default image interpolation mode
243 
244  /// Default image extrapolation mode
245  mirtkPublicAttributeMacro(enum ExtrapolationMode, DefaultExtrapolationMode);
246 
247  /// Rescale input image intensities from [imin, imax] to [0, omax]
248  ///
249  /// Here [imin, imax] is the intensity range of the respective input image
250  /// excluding the background (if specified) and omax is the maximum intensity
251  /// of the rescaled intensities. This maximum value influences the relative
252  /// weighting of image similarity gradient vs. the gradient of constraint terms
253  /// such as the bending energy.
254  ///
255  /// This normalization ensures that the magnitude of image derivatives used
256  /// for energy gradient computation have comparable magnitude in order to
257  /// prevent one image to have stronger influence than another. This is more
258  /// important for symmetric, inverse consistent, or multi-modal settings.
259  ///
260  /// By default, this parameter is set to inf and no rescaling is done.
261  mirtkPublicAttributeMacro(double, MaxRescaledIntensity);
262 
263  /// Whether to precompute image derivatives or compute them on the fly
264  mirtkPublicAttributeMacro(bool, PrecomputeDerivatives);
265 
266  /// Default similarity measure
268 
269  /// Default polydata distance measure
271 
272  /// Optimization method
274 
275  /// Normalize weights of energy function terms
276  mirtkPublicAttributeMacro(bool, NormalizeWeights);
277 
278  /// Initial guess of optimal transformation
279  mirtkPublicAggregateMacro(const Transformation, InitialGuess);
280 
281  /// Target transformation to be approximated by output transformation
282  mirtkPublicAggregateMacro(const Transformation, TargetTransformation);
283 
284  /// Name of target transformation MSDE term
285  mirtkPublicAttributeMacro(string, TargetTransformationErrorName);
286 
287  /// Weight of target transformation MSDE term
288  mirtkPublicAttributeMacro(double, TargetTransformationErrorWeight);
289 
290  /// Whether to merge initial global transformation into (local) transformation
291  mirtkPublicAttributeMacro(bool, MergeGlobalAndLocalTransformation);
292 
293  /// Whether to allow x coordinate transformation
294  mirtkPublicAttributeMacro(bool, RegisterX);
295 
296  /// Whether to allow y coordinate transformation
297  mirtkPublicAttributeMacro(bool, RegisterY);
298 
299  /// Whether to allow z coordinate transformation
300  mirtkPublicAttributeMacro(bool, RegisterZ);
301 
302  /// Enforce Dirichlet boundary condition on FFD transformations
303  ///
304  /// When this option is enabled, the status of control points at the
305  /// boundary of the finite FFD lattice is set to Passive and the parameters
306  /// of these control points set to zero. This is always the case for FFDs
307  /// whose parameters are control point displacements. In case of FFDs
308  /// parameterized by (stationary) velocities, the default extrapolation
309  /// mode is nearest neighbor, however, and a layer of passive CPs with
310  /// constant value is needed if the velocity should be forced to zero
311  /// outside the finite domain on which the velocity field is defined.
312  /// Alternatively, FFD extrapolation mode "Const" can be used.
313  mirtkPublicAttributeMacro(bool, DirichletBoundaryCondition);
314 
315  /// Mask which defines where to evaluate the energy function
317 
318  /// Whether to adaptively remesh surfaces before each gradient step
319  mirtkPublicAttributeMacro(bool, AdaptiveRemeshing);
320 
321 protected:
322 
323  /// Common attributes of (untransformed) input target data sets
324  ///
325  /// These attributes are in particular used to initialize the control point
326  /// grid of a free-form deformation such that the grid is large enough to
327  /// be valid for every target point for which the transformation will be
328  /// evaluated. It is therefore computed from the attributes of the input
329  /// data sets rather than the downsampled data. If a _Domain mask is set,
330  /// the attributes of this mask are copied instead.
332 
333  Array<Point> _Centroid; ///< Centroids of images
334  Point _TargetOffset; ///< Target origin offset
335  Point _SourceOffset; ///< Source origin offset
336  Array<const BaseImage *> _Input; ///< Input images
337  Array<ResampledImageList> _Image; ///< Resolution pyramid
338  Array<BinaryImage *> _Mask; ///< Domain on which to evaluate similarity
339  Transformation *_Transformation; ///< Current estimate
340  Array<TransformationInfo> _TransformationInfo; ///< Meta-data of partial transformation
341  Array<Transformation *> _TransformationInstance; ///< Partial transformations
342  Array<enum InterpolationMode> _InterpolationMode; ///< Interpolation mode of each input image
343  Array<enum ExtrapolationMode> _ExtrapolationMode; ///< Extrapolation mode of each input image
344  RegistrationEnergy _Energy; ///< Registration energy
345  LocalOptimizer *_Optimizer; ///< Used optimizer
346  enum TransformationModel _CurrentModel; ///< Current transformation model
347  int _CurrentLevel; ///< Current resolution level
348  EventDelegate _EventDelegate; ///< Forwards optimization events to observers
349  string _EnergyFormula; ///< Registration energy formula as string
350  Array<ImageSimilarityInfo> _ImageSimilarityInfo; ///< Parsed similarity measure(s)
351  Array<ConstraintInfo> _ConstraintInfo; ///< Parsed constraint(s)
352  Array<Vector3D<double> > _Resolution[MAX_NO_RESOLUTIONS]; ///< Image resolution in mm
353  Array<double> _MinEdgeLength[MAX_NO_RESOLUTIONS]; ///< Minimum edge length in mm
354  Array<double> _MaxEdgeLength[MAX_NO_RESOLUTIONS]; ///< Maximum edge length in mm
355  int _UseGaussianResolutionPyramid; ///< Whether resolution levels correspond to a Gaussian pyramid
356  Array<double> _Blurring[MAX_NO_RESOLUTIONS]; ///< Image blurring value
357  double _DefaultBackground; ///< Default background value
358  Array<double> _Background; ///< Image background value
359  bool _DownsampleWithPadding; ///< Whether to take background into account
360  ///< during initialization of the image pyramid
361  bool _CropPadImages; ///< Whether to crop/pad input images
362  int _CropPadFFD; ///< Whether to crop/pad FFD lattice
363 
364 #if MIRTK_Registration_WITH_PointSet
365  Array<double> _PointSetTime; ///< Time point of input points, curves, and/or surfaces
366  Array<vtkSmartPointer<vtkPointSet> > _PointSetInput; ///< Input points, curves, and/or surfaces
367  Array<Array<vtkSmartPointer<vtkPointSet> > > _PointSet; ///< Remeshed/-sampled points, curves, and/or surfaces
368  Array<RegisteredPointSet *> _PointSetOutput; ///< Output points, curves, and/or surfaces
369  Array<PointSetOutputInfo> _PointSetOutputInfo; ///< Meta-data of output points, curves, and/or surfaces
370  Array<PointSetDistanceInfo> _PointSetDistanceInfo; ///< Parsed point set distance measure(s)
371  Array<PointSetConstraintInfo> _PointSetConstraintInfo; ///< Parsed point set constraint measure(s)
372 #else // MIRTK_Registration_WITH_PointSet
373  Array<double> _PointSetTime; ///< Unused
374  Array<void *> _PointSetInput; ///< Unused
375  Array<Array<void *> > _PointSet; ///< Unused
376  Array<void *> _PointSetOutput; ///< Unused
377  Array<PointSetOutputInfo> _PointSetOutputInfo; ///< Unused
378  Array<PointSetDistanceInfo> _PointSetDistanceInfo; ///< Unused
379  Array<PointSetConstraintInfo> _PointSetConstraintInfo; ///< Unused
380 #endif // MIRTK_Registration_WITH_PointSet
381 
382  int _Centering [MAX_NO_RESOLUTIONS]; ///< Whether to center foreground (if applicable)
383  double _MinControlPointSpacing[MAX_NO_RESOLUTIONS][4]; ///< Control point spacing for FFDs
384  double _MaxControlPointSpacing[MAX_NO_RESOLUTIONS][4]; ///< Control point spacing for FFDs
385  bool _Subdivide [MAX_NO_RESOLUTIONS][4]; ///< Whether to subdivide FFD
386 
387  /// Parameters not considered by the registration filter itself
388  ///
389  /// These parameters are passed on to the sub-modules of the registration
390  /// filter such as the image similarity measure(s), the registration
391  /// constraint(s), and the optimizer. This way, the registration filter does
392  /// not need to know which parameters its sub-modules accept and is better
393  /// decoupled from the implementation of the respective image similarities,
394  /// constraints, and optimizers.
395  ParameterList _Parameter[MAX_NO_RESOLUTIONS];
396 
397  /// Delegate of pre-update function
399 
400  /// Info of cached displacement fields
401  Array<DisplacementInfo> _DisplacementInfo;
402  Array<DisplacementImageType *> _DisplacementField;
403 
404  // ---------------------------------------------------------------------------
405  // Access to managed data objects and their attributes
406 
407 protected:
408 
409  /// Determine number of temporal frames and temporal sampling attributes
410  virtual int NumberOfFrames(double * = NULL, double * = NULL, double * = NULL) const;
411 
412  /// Get attributes of n-th input image at specified resolution level
413  virtual struct ImageAttributes ImageAttributes(int, int = -1) const;
414 
415  /// Common attributes of (untransformed) input target data sets at specified resolution level
416  virtual struct ImageAttributes RegistrationDomain(int = -1) const;
417 
418  /// Average resolution of (untransformed) target data sets at given level
419  virtual Vector3D<double> AverageOutputResolution(int = -1) const;
420 
421  /// Get (partial/inverse) output transformation
423 
424  /// Initialize output image corresponding to registered (transformed) image
425  virtual void SetInputOf(RegisteredImage *, const struct ImageAttributes &, int, TransformationInfo);
426 
427  /// Get (new) registered output point set
428  ///
429  /// \note Use only when MIRTK_Registration_WITH_PointSet is 1.
431 
432  // ---------------------------------------------------------------------------
433  // Construction/Destruction
434 private:
435 
436  /// Copy constructor
437  /// \note Intentionally not implemented
439 
440  /// Assignment operator
441  /// \note Intentionally not implemented
442  void operator =(const GenericRegistrationFilter &);
443 
444 public:
445 
446  /// Constructor
448 
449  /// Reset filter settings, but keep input
450  virtual void Reset();
451 
452  /// Reset filter settings and input
453  virtual void Clear();
454 
455  /// Destructor
456  virtual ~GenericRegistrationFilter();
457 
458  // ---------------------------------------------------------------------------
459  // Input images
460 
461  /// Set input images of the registration filter
462  void Input(const BaseImage *, const BaseImage *);
463 
464  /// Set input images of the registration filter
465  void Input(int, const BaseImage **);
466 
467  /// Set input images of the registration filter
468  template <class TVoxel> void Input(int, const GenericImage<TVoxel> **);
469 
470  /// Add filter input image
471  ///
472  /// For registration filters which support multiple target/source images
473  /// such as multiple channels and/or frames of a temporal image sequence.
474  /// How the transformation is applied to which inputs depends on the
475  /// respective transformation model and image registration method.
476  void AddInput(const BaseImage *);
477 
478  /// Number of input images
479  int NumberOfImages() const;
480 
481  /// Number of required input images
482  /// \note Only valid after ParseEnergyFormula has been called!
483  int NumberOfRequiredImages() const;
484 
485  /// Determine whether the specified input image either remains untransformed,
486  /// or is transformed by the inverse transformation or a part of it such
487  /// as in case of an inverse consistent and/or symmetric energy function.
488  bool IsTargetImage(int) const;
489 
490  /// Determine whether the specified input image will be transformed by the
491  /// forward transformation or part of it such as in case of a symmetric energy.
492  bool IsSourceImage(int) const;
493 
494  /// Determine whether the specified input image remains untransformed.
495  bool IsFixedImage(int) const;
496 
497  /// Determine whether the specified input image will be transformed.
498  bool IsMovingImage(int) const;
499 
500  /// Set common/default interpolation mode for all input images
502 
503  /// Set interpolation mode of n-th input image
504  void InterpolationMode(int, enum InterpolationMode);
505 
506  /// Get interpolation mode of n-th input image or default mode, respectively
507  enum InterpolationMode InterpolationMode(int = -1) const;
508 
509  /// Set common/default extrapolation mode for all input images
511 
512  /// Set extrapolation mode of n-th input image
513  void ExtrapolationMode(int, enum ExtrapolationMode);
514 
515  /// Get extrapolation mode of n-th input image or default mode, respectively
516  enum ExtrapolationMode ExtrapolationMode(int = -1) const;
517 
518  /// Get background value of n-th input image (after registration done)
519  double BackgroundValue(int) const;
520 
521  // ---------------------------------------------------------------------------
522  // Input simplicial complexes (points, curves, surfaces, tetrahedral meshes)
523 
524  /// Set input point sets of the registration filter
525  ///
526  /// \note Use only when MIRTK_Registration_WITH_PointSet is 1.
527  void Input(vtkPointSet *, vtkPointSet *, double = .0, double = 1.0);
528 
529  /// Set input point set of the registration filter
530  ///
531  /// \note Use only when MIRTK_Registration_WITH_PointSet is 1.
532  void Input(int, vtkPointSet **, double * = NULL);
533 
534  /// Add filter input point set
535  ///
536  /// \note Use only when MIRTK_Registration_WITH_PointSet is 1.
537  void AddInput(vtkPointSet *, double = .0);
538 
539  /// Number of input point sets
540  int NumberOfPointSets() const;
541 
542  /// Number of required input point sets
543  /// \note Only valid after ParseEnergyFormula has been called!
544  int NumberOfRequiredPointSets() const;
545 
546  /// Determine whether the specified input point set will be transformed by the
547  /// forward transformation or part of it such as in case of a symmetric energy.
548  bool IsTargetPointSet(int) const;
549 
550  /// Determine whether the specified input point set either remains untransformed,
551  /// or is transformed by the inverse transformation or a part of it such
552  /// as in case of an inverse consistent and/or symmetric energy function.
553  bool IsSourcePointSet(int) const;
554 
555  /// Determine whether the specified input point set remains untransformed.
556  bool IsFixedPointSet(int) const;
557 
558  /// Determine whether the specified input point set will be transformed.
559  bool IsMovingPointSet(int) const;
560 
561  // ---------------------------------------------------------------------------
562  // Parameter
563 
566 
567  /// Set (single) transformation model
568  virtual void TransformationModel(enum TransformationModel);
569 
570  /// Parse registration energy function
571  /// \note Optional to call explicitly as this method is called by GuessParameter.
572  virtual void ParseEnergyFormula(int = -1, int = -1, int = -1);
573 
574  /// Guess proper setting for any yet unset parameter
575  /// \note Optional to call explicitly as this method is called by Run.
576  virtual void GuessParameter();
577 
578  /// Read registration parameters from input stream
579  virtual bool Read(istream &, bool = false);
580 
581  /// Set named parameter from value as string
582  virtual bool Set(const char *, const char *);
583 
584  /// Set named parameter from value as string
585  virtual bool Set(const char *, const char *, int);
586 
587  /// Get parameters as key/value as string map
588  virtual ParameterList Parameter() const;
589 
590  /// Get parameters as key/value as string map
591  virtual ParameterList Parameter(int) const;
592 
593  /// Write registration parameters to file
594  virtual void Write(const char *) const;
595 
596  // ---------------------------------------------------------------------------
597  // Execution
598 
599  /// Make an initial guess of the (global) output transformation
600  virtual Transformation *MakeInitialGuess();
601 
602  /// Run the multi-level registration
603  virtual void Run();
604 
605  // ---------------------------------------------------------------------------
606  // Implementation - the following functions can be overridden in subclasses
607 
608 protected:
609 
610  /// Whether current level is the initial resolution level
611  bool AtInitialLevel() const;
612 
613  /// Whether current level is the final resolution level
614  bool AtFinalLevel() const;
615 
616  /// Run multi-resolution registration
617  virtual void MultiResolutionOptimization();
618 
619  /// Initialize registration at current resolution
620  virtual void Initialize();
621 
622  /// Initialize image resolution pyramid
623  virtual void InitializePyramid();
624 
625  /// Remesh/-sample input point sets
626  virtual void InitializePointSets();
627 
628  /// Type of output transformation of sub-registration at current resolution
629  virtual enum TransformationType TransformationType();
630 
631  /// Initialize new transformation instance
632  virtual void InitializeTransformation();
633 
634  /// Initialize transformation parameters using provided initial guess
635  virtual void ApplyInitialGuess();
636 
637  /// Initialize status of linear parameters
639 
640  /// Initialize status of FFD parameters
642 
643  /// Initialize status of transformation parameters
644  virtual void InitializeStatus();
645 
646  /// Initialize transformation for sub-registration at current resolution
647  virtual void InitializeOutput();
648 
649  /// Instantiate new image similarity term for energy function
650  /// \note The individual energy terms are destroyed by the energy function!
651  virtual void AddImageSimilarityTerm();
652 
653  /// Instantiate new point set distance term for energy function
654  /// \note The individual energy terms are destroyed by the energy function!
655  virtual void AddPointSetDistanceTerm();
656 
657  /// Instantiate new point set constraint term for energy function
658  /// \note The individual energy terms are destroyed by the energy function!
659  virtual void AddPointSetConstraintTerm();
660 
661  /// Instantiate new regularization term for energy function
662  /// \note The individual energy terms are destroyed by the energy function!
663  virtual void AddPenaltyTerm();
664 
665  /// Initialize registration energy of registration at current resolution
666  virtual void InitializeEnergy();
667 
668  /// Initialize optimizer used to solve registration problem
669  virtual void InitializeOptimizer();
670 
671  /// Finalize registration at current resolution
672  virtual void Finalize();
673 
674  /// Callback function called by _Energy->Update(bool)
675  void PreUpdateCallback(bool);
676 
677 };
678 
679 ////////////////////////////////////////////////////////////////////////////////
680 // Inline/template definitions
681 ////////////////////////////////////////////////////////////////////////////////
682 
683 // -----------------------------------------------------------------------------
684 template <class TVoxel>
686 {
687  _Input.clear();
688  for (int n = 0; n < num; ++n) AddInput(image[n]);
689 }
690 
691 
692 } // namespace mirtk
693 
694 #endif // MIRTK_GenericRegistrationFilter_H
RegisteredPointSet * OutputPointSet(int, double, TransformationInfo)
void ExtrapolationMode(enum ExtrapolationMode)
Set common/default extrapolation mode for all input images.
TransformationInfo _TargetTransformation
Target transformation identifier.
GenericRegistrationFilter()
Constructor.
virtual bool Set(const char *, const char *)
Set named parameter from value as string.
Array< DisplacementInfo > _DisplacementInfo
Info of cached displacement fields.
bool IsFixedImage(int) const
Determine whether the specified input image remains untransformed.
int NumberOfImages() const
Number of input images.
bool _CropPadImages
Whether to crop/pad input images.
double _MaxControlPointSpacing[MAX_NO_RESOLUTIONS][4]
Control point spacing for FFDs.
Array< Vector3D< double > > _Resolution[MAX_NO_RESOLUTIONS]
Image resolution in mm.
virtual void InitializeOutput()
Initialize transformation for sub-registration at current resolution.
TransformationInfo _Transformation
Point set transformation identifier.
bool IsMovingImage(int) const
Determine whether the specified input image will be transformed.
TransformationInfo _SourceTransformation
Source transformation identifier.
virtual void InitializeEnergy()
Initialize registration energy of registration at current resolution.
RegisteredImage::InputImageType ResampledImageType
Type of resolution pyramid images.
int _Centering[MAX_NO_RESOLUTIONS]
Whether to center foreground (if applicable)
virtual struct ImageAttributes RegistrationDomain(int=-1) const
Common attributes of (untransformed) input target data sets at specified resolution level...
RegisteredImage::DisplacementImageType DisplacementImageType
Type of cached displacement field.
MFFDMode
Enumeration of available multi-level transformation modes.
bool AtFinalLevel() const
Whether current level is the final resolution level.
mirtkPublicAttributeMacro(int, NumberOfLevels)
Number of resolution levels.
virtual void AddPointSetConstraintTerm()
virtual void InitializePointSets()
Remesh/-sample input point sets.
Point _SourceOffset
Source origin offset.
TransformationInfo _SourceTransformation
Source transformation identifier.
virtual void InitializeStatus()
Initialize status of transformation parameters.
Array< ResampledImageList > _Image
Resolution pyramid.
Array< ResampledImageType > ResampledImageList
List type storing images for one resolution pyramid level.
int NumberOfPointSets() const
Number of input point sets.
virtual Transformation * OutputTransformation(TransformationInfo)
Get (partial/inverse) output transformation.
Transformation * _Transformation
Current estimate.
virtual void MultiResolutionOptimization()
Run multi-resolution registration.
Structure storing information about cached displacements.
ImageAttributes _Domain
Domain on which it is defined.
EventDelegate _EventDelegate
Forwards optimization events to observers.
enum TransformationModel _CurrentModel
Current transformation model.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
InterpolationMode DefaultInterpolationMode()
Get default interpolation mode.
Array< enum ExtrapolationMode > _ExtrapolationMode
Extrapolation mode of each input image.
bool IsMovingPointSet(int) const
Determine whether the specified input point set will be transformed.
bool _DefaultSign
Whether to use default sign of similarity.
string _EnergyFormula
Registration energy formula as string.
Array< ConstraintInfo > _ConstraintInfo
Parsed constraint(s)
virtual Vector3D< double > AverageOutputResolution(int=-1) const
Average resolution of (untransformed) target data sets at given level.
InterpolationMode
Image interpolation modes.
const Transformation * _Transformation
Corresponding transformation instance.
mirtkPublicAggregateMacro(const Transformation, InitialGuess)
Initial guess of optimal transformation.
Structure storing information about transformation instance.
void PreUpdateCallback(bool)
Callback function called by _Energy->Update(bool)
Structure storing information about transformed output point set.
MIRTKCU_API bool fequal(double a, double b, double tol=1e-12)
Definition: Math.h:138
int _UseGaussianResolutionPyramid
Whether resolution levels correspond to a Gaussian pyramid.
Definition: IOConfig.h:41
virtual void ApplyInitialGuess()
Initialize transformation parameters using provided initial guess.
TransformationInfo _TargetTransformation
Target transformation identifier.
Array< PointSetOutputInfo > _PointSetOutputInfo
Unused.
void AddInput(const BaseImage *)
virtual void ParseEnergyFormula(int=-1, int=-1, int=-1)
virtual enum TransformationType TransformationType()
Type of output transformation of sub-registration at current resolution.
ParameterList _Parameter[MAX_NO_RESOLUTIONS]
void Input(const BaseImage *, const BaseImage *)
Set input images of the registration filter.
virtual void Finalize()
Finalize registration at current resolution.
Array< TransformationInfo > _TransformationInfo
Meta-data of partial transformation.
double BackgroundValue(int) const
Get background value of n-th input image (after registration done)
Array< BinaryImage * > _Mask
Domain on which to evaluate similarity.
virtual bool Read(const char *, bool=false)
Read registration parameters from input stream.
Array< Array< void * > > _PointSet
Unused.
int _CurrentLevel
Current resolution level.
bool IsFixedPointSet(int) const
Determine whether the specified input point set remains untransformed.
bool AtInitialLevel() const
Whether current level is the initial resolution level.
Array< PointSetConstraintInfo > _PointSetConstraintInfo
Unused.
Array< double > _Background
Image background value.
ResampledImageType::VoxelType VoxelType
Scalar type of resolution pyramid images.
virtual void Run()
Run the multi-level registration.
virtual void TransformationModel(enum TransformationModel)
Set (single) transformation model.
virtual bool Read(istream &, bool=false)
Read registration parameters from input stream.
LocalOptimizer * _Optimizer
Used optimizer.
Array< double > _MinEdgeLength[MAX_NO_RESOLUTIONS]
Minimum edge length in mm.
int _CropPadFFD
Whether to crop/pad FFD lattice.
Point _TargetOffset
Target origin offset.
virtual void Clear()
Reset filter settings and input.
ExtrapolationMode
Image extrapolation modes.
EnergyMeasure
Enumeration of all available energy terms.
Definition: EnergyMeasure.h:31
virtual void InitializeOptimizer()
Initialize optimizer used to solve registration problem.
virtual Transformation * MakeInitialGuess()
Make an initial guess of the (global) output transformation.
Array< PointSetDistanceInfo > _PointSetDistanceInfo
Unused.
FastDelegate1< bool > PreUpdateFunctionType
Type of pre-update function delegate.
virtual void InitializePyramid()
Initialize image resolution pyramid.
bool _Subdivide[MAX_NO_RESOLUTIONS][4]
Whether to subdivide FFD.
RegistrationEnergy _Energy
Registration energy.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
Definition: Object.h:139
Array< double > _MaxEdgeLength[MAX_NO_RESOLUTIONS]
Maximum edge length in mm.
RegistrationEnergy::PreUpdateFunctionType _PreUpdateDelegate
Delegate of pre-update function.
virtual int NumberOfFrames(double *=NULL, double *=NULL, double *=NULL) const
Determine number of temporal frames and temporal sampling attributes.
Array< enum InterpolationMode > _InterpolationMode
Interpolation mode of each input image.
virtual void AddPointSetDistanceTerm()
Array< Point > _Centroid
Centroids of images.
Array< const BaseImage * > _Input
Input images.
void InterpolationMode(enum InterpolationMode)
Set common/default interpolation mode for all input images.
virtual void Write(const char *) const
Write registration parameters to file.
virtual void Reset()
Reset filter settings, but keep input.
SimilarityMeasure _Measure
Type of similarity measure.
double _MinControlPointSpacing[MAX_NO_RESOLUTIONS][4]
Control point spacing for FFDs.
double _DefaultBackground
Default background value.
Array< Transformation * > _TransformationInstance
Partial transformations.
OptimizationMethod
Enumeration of available optimization methods.
virtual void Initialize()
Initialize registration at current resolution.
Array< double > _Blurring[MAX_NO_RESOLUTIONS]
Image blurring value.
PointSetDistanceMeasure _Measure
Measure of polydata distance.
int _DispIndex
Index of cached displacement field.
bool _DefaultSign
Whether to use default sign of distance measure.
TVoxel VoxelType
Voxel type.
Definition: GenericImage.h:52
virtual void SetInputOf(RegisteredImage *, const struct ImageAttributes &, int, TransformationInfo)
Initialize output image corresponding to registered (transformed) image.
Array< ImageSimilarityInfo > _ImageSimilarityInfo
Parsed similarity measure(s)
virtual ~GenericRegistrationFilter()
Destructor.
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
virtual void InitializeTransformation()
Initialize new transformation instance.