1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkLandmarkTransform.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /**
16  * @class   vtkLandmarkTransform
17  * @brief   a linear transform specified by two corresponding point sets
18  *
19  * A vtkLandmarkTransform is defined by two sets of landmarks, the
20  * transform computed gives the best fit mapping one onto the other, in a
21  * least squares sense. The indices are taken to correspond, so point 1
22  * in the first set will get mapped close to point 1 in the second set,
23  * etc. Call SetSourceLandmarks and SetTargetLandmarks to specify the two
24  * sets of landmarks, ensure they have the same number of points.
25  * @warning
26  * Whenever you add, subtract, or set points you must call Modified()
27  * on the vtkPoints object, or the transformation might not update.
28  * @sa
29  * vtkLinearTransform
30  */
31 
32 #ifndef vtkLandmarkTransform_h
33 #define vtkLandmarkTransform_h
34 
35 #include "vtkCommonTransformsModule.h" // For export macro
36 #include "vtkLinearTransform.h"
37 
38 #define VTK_LANDMARK_RIGIDBODY 6
39 #define VTK_LANDMARK_SIMILARITY 7
40 #define VTK_LANDMARK_AFFINE 12
41 
42 class VTKCOMMONTRANSFORMS_EXPORT vtkLandmarkTransform : public vtkLinearTransform
43 {
44 public:
45   static vtkLandmarkTransform* New();
46 
47   vtkTypeMacro(vtkLandmarkTransform, vtkLinearTransform);
48   void PrintSelf(ostream& os, vtkIndent indent) override;
49 
50   ///@{
51   /**
52    * Specify the source and target landmark sets. The two sets must have
53    * the same number of points.  If you add or change points in these objects,
54    * you must call Modified() on them or the transformation might not update.
55    */
56   void SetSourceLandmarks(vtkPoints* source);
57   void SetTargetLandmarks(vtkPoints* target);
58   vtkGetObjectMacro(SourceLandmarks, vtkPoints);
59   vtkGetObjectMacro(TargetLandmarks, vtkPoints);
60   ///@}
61 
62   ///@{
63   /**
64    * Set the number of degrees of freedom to constrain the solution to.
65    * Rigidbody (VTK_LANDMARK_RIGIDBODY): rotation and translation only.
66    * Similarity (VTK_LANDMARK_SIMILARITY): rotation, translation and
67    * isotropic scaling.
68    * Affine (VTK_LANDMARK_AFFINE): collinearity is preserved.
69    * Ratios of distances along a line are preserved.
70    * The default is similarity.
71    */
72   vtkSetMacro(Mode, int);
SetModeToRigidBody()73   void SetModeToRigidBody() { this->SetMode(VTK_LANDMARK_RIGIDBODY); }
SetModeToSimilarity()74   void SetModeToSimilarity() { this->SetMode(VTK_LANDMARK_SIMILARITY); }
SetModeToAffine()75   void SetModeToAffine() { this->SetMode(VTK_LANDMARK_AFFINE); }
76   ///@}
77 
78   ///@{
79   /**
80    * Get the current transformation mode.
81    */
82   vtkGetMacro(Mode, int);
83   const char* GetModeAsString();
84   ///@}
85 
86   /**
87    * Invert the transformation.  This is done by switching the
88    * source and target landmarks.
89    */
90   void Inverse() override;
91 
92   /**
93    * Get the MTime.
94    */
95   vtkMTimeType GetMTime() override;
96 
97   /**
98    * Make another transform of the same type.
99    */
100   vtkAbstractTransform* MakeTransform() override;
101 
102 protected:
103   vtkLandmarkTransform();
104   ~vtkLandmarkTransform() override;
105 
106   // Update the matrix from the quaternion.
107   void InternalUpdate() override;
108 
109   /**
110    * This method does no type checking, use DeepCopy instead.
111    */
112   void InternalDeepCopy(vtkAbstractTransform* transform) override;
113 
114   vtkPoints* SourceLandmarks;
115   vtkPoints* TargetLandmarks;
116 
117   int Mode;
118 
119 private:
120   vtkLandmarkTransform(const vtkLandmarkTransform&) = delete;
121   void operator=(const vtkLandmarkTransform&) = delete;
122 };
123 
GetModeAsString()124 inline const char* vtkLandmarkTransform::GetModeAsString()
125 {
126   switch (this->Mode)
127   {
128     case VTK_LANDMARK_RIGIDBODY:
129       return "RigidBody";
130     case VTK_LANDMARK_SIMILARITY:
131       return "Similarity";
132     case VTK_LANDMARK_AFFINE:
133       return "Affine";
134     default:
135       return "Unrecognized";
136   }
137 }
138 
139 #endif
140