1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkIterativeClosestPointTransform.h,v $
6 Date: $Date: 2002/01/22 15:30:32 $
7 Version: $Revision: 1.8 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
19 // .NAME vtkIterativeClosestPointTransform - Implementation of the ICP algorithm.
20 // .SECTION Description
21 // Match two surfaces using the iterative closest point (ICP) algorithm.
22 // The core of the algorithm is to match each vertex in one surface with
23 // the closest surface point on the other, then apply the transformation
24 // that modify one surface to best match the other (in a least square sense).
25 // This has to be iterated to get proper convergence of the surfaces.
27 // Use vtkTransformPolyDataFilter to apply the resulting ICP transform to
28 // your data. You might also set it to your actor's user transform.
30 // This class makes use of vtkLandmarkTransform internally to compute the
31 // best fit. Use the GetLandmarkTransform member to get a pointer to that
32 // transform and set its parameters. You might, for example, constrain the
33 // number of degrees of freedom of the solution (i.e. rigid body, similarity,
34 // etc.) by checking the vtkLandmarkTransform documentation for its SetMode
37 // vtkLandmarkTransform
40 #ifndef __vtkIterativeClosestPointTransform_h
41 #define __vtkIterativeClosestPointTransform_h
43 #include "vtkLinearTransform.h"
45 #define VTK_ICP_MODE_RMS 0
46 #define VTK_ICP_MODE_AV 1
49 class vtkLandmarkTransform;
52 class VTK_HYBRID_EXPORT vtkIterativeClosestPointTransform : public vtkLinearTransform
55 static vtkIterativeClosestPointTransform *New();
56 vtkTypeRevisionMacro(vtkIterativeClosestPointTransform,vtkLinearTransform);
57 void PrintSelf(ostream& os, vtkIndent indent);
60 // Specify the source and target data sets.
61 void SetSource(vtkDataSet *source);
62 void SetTarget(vtkDataSet *target);
63 vtkGetObjectMacro(Source, vtkDataSet);
64 vtkGetObjectMacro(Target, vtkDataSet);
67 // Set/Get a spatial locator for speeding up the search process.
68 // An instance of vtkCellLocator is used by default.
69 void SetLocator(vtkCellLocator *locator);
70 vtkGetObjectMacro(Locator,vtkCellLocator);
73 // Set/Get the maximum number of iterations
74 vtkSetMacro(MaximumNumberOfIterations, int);
75 vtkGetMacro(MaximumNumberOfIterations, int);
78 // Get the number of iterations since the last update
79 vtkGetMacro(NumberOfIterations, int);
82 // Force the algorithm to check the mean distance between two iteration.
83 vtkSetMacro(CheckMeanDistance, int);
84 vtkGetMacro(CheckMeanDistance, int);
85 vtkBooleanMacro(CheckMeanDistance, int);
88 // Specify the mean distance mode. This mode expresses how the mean
89 // distance is computed. The RMS mode is the square root of the average
90 // of the sum of squares of the closest point distances. The Absolute
91 // Value mode is the mean of the sum of absolute values of the closest
93 vtkSetClampMacro(MeanDistanceMode,int,
94 VTK_ICP_MODE_RMS,VTK_ICP_MODE_AV);
95 vtkGetMacro(MeanDistanceMode,int);
96 void SetMeanDistanceModeToRMS()
97 {this->SetMeanDistanceMode(VTK_ICP_MODE_RMS);}
98 void SetMeanDistanceModeToAbsoluteValue()
99 {this->SetMeanDistanceMode(VTK_ICP_MODE_AV);}
100 const char *GetMeanDistanceModeAsString();
103 // Set/Get the maximum mean distance between two iteration. If the mean
104 // distance is lower than this, the convergence stops.
105 vtkSetMacro(MaximumMeanDistance, float);
106 vtkGetMacro(MaximumMeanDistance, float);
109 // Get the mean distance between the last two iterations.
110 vtkGetMacro(MeanDistance, float);
113 // Set/Get the maximum number of landmarks sampled in your dataset.
114 // If your dataset is dense, then you will typically not need all the
115 // points to compute the ICP transform.
116 vtkSetMacro(MaximumNumberOfLandmarks, int);
117 vtkGetMacro(MaximumNumberOfLandmarks, int);
120 // Starts the process by translating source centroid to target centroid.
121 vtkSetMacro(StartByMatchingCentroids, int);
122 vtkGetMacro(StartByMatchingCentroids, int);
123 vtkBooleanMacro(StartByMatchingCentroids, int);
126 // Get the internal landmark transform. Use it to constrain the number of
127 // degrees of freedom of the solution (i.e. rigid body, similarity, etc.).
128 vtkGetObjectMacro(LandmarkTransform,vtkLandmarkTransform);
131 // Invert the transformation. This is done by switching the
132 // source and target.
136 // Make another transform of the same type.
137 vtkAbstractTransform *MakeTransform();
142 // Release source and target
143 void ReleaseSource(void);
144 void ReleaseTarget(void);
148 void ReleaseLocator(void);
151 // Create default locator. Used to create one when none is specified.
152 void CreateDefaultLocator(void);
155 // Get the MTime of this object also considering the locator.
156 unsigned long int GetMTime();
158 vtkIterativeClosestPointTransform();
159 ~vtkIterativeClosestPointTransform();
161 void InternalUpdate();
164 // This method does no type checking, use DeepCopy instead.
165 void InternalDeepCopy(vtkAbstractTransform *transform);
169 vtkCellLocator *Locator;
170 int MaximumNumberOfIterations;
171 int CheckMeanDistance;
172 int MeanDistanceMode;
173 float MaximumMeanDistance;
174 int MaximumNumberOfLandmarks;
175 int StartByMatchingCentroids;
177 int NumberOfIterations;
179 vtkLandmarkTransform *LandmarkTransform;
181 vtkIterativeClosestPointTransform(const vtkIterativeClosestPointTransform&); // Not implemented.
182 void operator=(const vtkIterativeClosestPointTransform&); // Not implemented.