VMTK
Loading...
Searching...
No Matches
vtkvmtkIterativeClosestPointTransform Class Reference

Implements the ICP algorithm, with a FarThreshold variant. More...

#include <vtkvmtkIterativeClosestPointTransform.h>

Inheritance diagram for vtkvmtkIterativeClosestPointTransform:
[legend]
Collaboration diagram for vtkvmtkIterativeClosestPointTransform:
[legend]

Public Types

typedef vtkIterativeClosestPointTransform Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkIterativeClosestPointTransform * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetFarThreshold (double)
virtual double GetFarThreshold ()
virtual void SetUseFarThreshold (int)
virtual int GetUseFarThreshold ()
virtual void UseFarThresholdOn ()
virtual void UseFarThresholdOff ()

Static Public Member Functions

static vtkvmtkIterativeClosestPointTransform * New ()
static int IsTypeOf (const char *type)
static vtkvmtkIterativeClosestPointTransform * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkIterativeClosestPointTransform ()
 ~vtkvmtkIterativeClosestPointTransform ()
void InternalUpdate () override

Protected Attributes

double FarThreshold
int UseFarThreshold

Detailed Description

Implements the ICP algorithm, with a FarThreshold variant.

This class extends VTK's vtkIterativeClosestPointTransform (rigid/similarity registration of a source point set onto a target point set by iteratively matching closest points and solving a landmark transform) with an optional far-point rejection step. When UseFarThreshold is on, source points whose closest target point is farther than FarThreshold are excluded from the landmark correspondences used to update the transform at each iteration; this makes the registration robust to partially overlapping surfaces, where forcing every source point to match some target point would bias the result.

This is the transform behind the vmtkicpregistration pype script, used to rigidly align a surface onto a reference surface (e.g. two segmentations of the same vessel from different imaging sessions).

Definition at line 41 of file vtkvmtkIterativeClosestPointTransform.h.

Member Typedef Documentation

◆ Superclass

typedef vtkIterativeClosestPointTransform vtkvmtkIterativeClosestPointTransform::Superclass

Definition at line 45 of file vtkvmtkIterativeClosestPointTransform.h.

Constructor & Destructor Documentation

◆ vtkvmtkIterativeClosestPointTransform()

vtkvmtkIterativeClosestPointTransform::vtkvmtkIterativeClosestPointTransform ( )
protected

◆ ~vtkvmtkIterativeClosestPointTransform()

vtkvmtkIterativeClosestPointTransform::~vtkvmtkIterativeClosestPointTransform ( )
protected

Definition at line 42 of file vtkvmtkIterativeClosestPointTransform.cxx.

43{
44}

Member Function Documentation

◆ New()

vtkvmtkIterativeClosestPointTransform * vtkvmtkIterativeClosestPointTransform::New ( )
static

◆ IsTypeOf()

int vtkvmtkIterativeClosestPointTransform::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkIterativeClosestPointTransform::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkIterativeClosestPointTransform * vtkvmtkIterativeClosestPointTransform::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkIterativeClosestPointTransform::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkIterativeClosestPointTransform * vtkvmtkIterativeClosestPointTransform::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkIterativeClosestPointTransform::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 272 of file vtkvmtkIterativeClosestPointTransform.cxx.

273{
274 this->Superclass::PrintSelf(os,indent);
275
276 os << indent << "FarThreshold: " << this->FarThreshold << "\n";
277 os << indent << "UseFarThreshold: " << this->UseFarThreshold << "\n";
278}

◆ SetFarThreshold()

virtual void vtkvmtkIterativeClosestPointTransform::SetFarThreshold ( double )
virtual

Set/Get the threshold to declare a point to not have a corresponding point in the other point set. This value is only used if UseFarThreshold is True (not the default). This is useful to align partially overlapping surfaces. If this value is negative, all points are considered to have a corresponding point in the other point set. The default is 1.0.

◆ GetFarThreshold()

virtual double vtkvmtkIterativeClosestPointTransform::GetFarThreshold ( )
virtual

Set/Get the threshold to declare a point to not have a corresponding point in the other point set. This value is only used if UseFarThreshold is True (not the default). This is useful to align partially overlapping surfaces. If this value is negative, all points are considered to have a corresponding point in the other point set. The default is 1.0.

◆ SetUseFarThreshold()

virtual void vtkvmtkIterativeClosestPointTransform::SetUseFarThreshold ( int )
virtual

Determine whether or not to use the FarThreshold. The default is 0.

◆ GetUseFarThreshold()

virtual int vtkvmtkIterativeClosestPointTransform::GetUseFarThreshold ( )
virtual

Determine whether or not to use the FarThreshold. The default is 0.

◆ UseFarThresholdOn()

virtual void vtkvmtkIterativeClosestPointTransform::UseFarThresholdOn ( )
virtual

Determine whether or not to use the FarThreshold. The default is 0.

◆ UseFarThresholdOff()

virtual void vtkvmtkIterativeClosestPointTransform::UseFarThresholdOff ( )
virtual

Determine whether or not to use the FarThreshold. The default is 0.

◆ InternalUpdate()

void vtkvmtkIterativeClosestPointTransform::InternalUpdate ( )
overrideprotected

Definition at line 46 of file vtkvmtkIterativeClosestPointTransform.cxx.

47{
48 // Check source, target
49
50 if (this->Source == NULL || !this->Source->GetNumberOfPoints())
51 {
52 vtkErrorMacro(<<"Can't execute with NULL or empty input");
53 return;
54 }
55
56 if (this->Target == NULL || !this->Target->GetNumberOfPoints())
57 {
58 vtkErrorMacro(<<"Can't execute with NULL or empty target");
59 return;
60 }
61
62 // Create locator
63
64 this->CreateDefaultLocator();
65 this->Locator->SetDataSet(this->Target);
66 this->Locator->SetNumberOfCellsPerBucket(1);
67 this->Locator->BuildLocator();
68
69 // Create two sets of points to handle iteration
70
71 int step = 1;
72 if (this->Source->GetNumberOfPoints() > this->MaximumNumberOfLandmarks)
73 {
74 step = this->Source->GetNumberOfPoints() / this->MaximumNumberOfLandmarks;
75 vtkDebugMacro(<< "Landmarks step is now : " << step);
76 }
77
78 vtkIdType nb_points = this->Source->GetNumberOfPoints() / step;
79
80 // Allocate some points.
81 // - closestp is used so that the internal state of LandmarkTransform remains
82 // correct whenever the iteration process is stopped (hence its source
83 // and landmark points might be used in a vtkThinPlateSplineTransform).
84 // - points2 could have been avoided, but do not ask me why
85 // InternalTransformPoint is not working correctly on my computer when
86 // in and out are the same pointer.
87
88 vtkPoints *points1 = vtkPoints::New();
89 points1->SetNumberOfPoints(nb_points);
90
91 vtkPoints *closestp = vtkPoints::New();
92 closestp->SetNumberOfPoints(nb_points);
93
94 vtkPoints *points2 = vtkPoints::New();
95 points2->SetNumberOfPoints(nb_points);
96
97 // Fill with initial positions (sample dataset using step)
98
99 vtkTransform *accumulate = vtkTransform::New();
100 accumulate->PostMultiply();
101
102 vtkIdType i;
103 int j;
104 double p1[3], p2[3];
105
106 if (StartByMatchingCentroids)
107 {
108 double source_centroid[3] = {0,0,0};
109 for (i = 0; i < this->Source->GetNumberOfPoints(); i++)
110 {
111 this->Source->GetPoint(i, p1);
112 source_centroid[0] += p1[0];
113 source_centroid[1] += p1[1];
114 source_centroid[2] += p1[2];
115 }
116 source_centroid[0] /= this->Source->GetNumberOfPoints();
117 source_centroid[1] /= this->Source->GetNumberOfPoints();
118 source_centroid[2] /= this->Source->GetNumberOfPoints();
119
120 double target_centroid[3] = {0,0,0};
121 for (i = 0; i < this->Target->GetNumberOfPoints(); i++)
122 {
123 this->Target->GetPoint(i, p2);
124 target_centroid[0] += p2[0];
125 target_centroid[1] += p2[1];
126 target_centroid[2] += p2[2];
127 }
128 target_centroid[0] /= this->Target->GetNumberOfPoints();
129 target_centroid[1] /= this->Target->GetNumberOfPoints();
130 target_centroid[2] /= this->Target->GetNumberOfPoints();
131
132 accumulate->Translate(target_centroid[0] - source_centroid[0],
133 target_centroid[1] - source_centroid[1],
134 target_centroid[2] - source_centroid[2]);
135 accumulate->Update();
136
137 for (i = 0, j = 0; i < nb_points; i++, j += step)
138 {
139 double outPoint[3];
140 accumulate->InternalTransformPoint(this->Source->GetPoint(j),
141 outPoint);
142 points1->SetPoint(i, outPoint);
143 }
144 }
145 else
146 {
147 for (i = 0, j = 0; i < nb_points; i++, j += step)
148 {
149 points1->SetPoint(i, this->Source->GetPoint(j));
150 }
151 }
152
153 // Go
154
155 vtkIdType cell_id;
156 int sub_id;
157 double dist2, totaldist = 0;
158 double outPoint[3];
159
160 vtkPoints *temp, *a = points1, *b = points2;
161
162 this->NumberOfIterations = 0;
163
164 double tooFarThreshold2 = this->FarThreshold * this->FarThreshold;
165 do
166 {
167 // Fill points with the closest points to each vertex in input
168 if (!this->UseFarThreshold)
169 {
170 closestp->SetNumberOfPoints(nb_points); // It was set above, but at this point it should be removed from there
171 for(i = 0; i < nb_points; i++)
172 {
173 this->Locator->FindClosestPoint(a->GetPoint(i),
174 outPoint,
175 cell_id,
176 sub_id,
177 dist2);
178 closestp->SetPoint(i, outPoint);
179 }
180 this->LandmarkTransform->SetSourceLandmarks(a);
181 }
182 else //use a FarThreshold
183 {
184 vtkPoints* sourceLandmarks = vtkPoints::New();
185 closestp->Initialize();
186 for(i = 0; i < nb_points; i++)
187 {
188 this->Locator->FindClosestPoint(a->GetPoint(i),
189 outPoint,
190 cell_id,
191 sub_id,
192 dist2);
193 if(dist2 < tooFarThreshold2)
194 {
195 closestp->InsertNextPoint(outPoint);
196 sourceLandmarks->InsertNextPoint(a->GetPoint(i));
197 }
198 }
199 this->LandmarkTransform->SetSourceLandmarks(sourceLandmarks);
200 sourceLandmarks->Delete();
201 }
202 // Build the landmark transform
203
204 this->LandmarkTransform->SetTargetLandmarks(closestp);
205 this->LandmarkTransform->Update();
206
207 this->NumberOfIterations++;
208 vtkDebugMacro(<< "Iteration: " << this->NumberOfIterations);
209 if (this->NumberOfIterations > this->MaximumNumberOfIterations)
210 {
211 break;
212 }
213
214 // Concatenate (can't use this->Concatenate directly)
215 accumulate->Concatenate(this->LandmarkTransform->GetMatrix());
216
217 // Move mesh and compute mean distance if needed
218
219 if (this->CheckMeanDistance)
220 {
221 totaldist = 0.0;
222 }
223
224 for(i = 0; i < nb_points; i++)
225 {
226 a->GetPoint(i, p1);
227 this->LandmarkTransform->InternalTransformPoint(p1, p2);
228 b->SetPoint(i, p2);
229 if (this->CheckMeanDistance)
230 {
231 if (this->MeanDistanceMode == VTK_ICP_MODE_RMS)
232 {
233 totaldist += vtkMath::Distance2BetweenPoints(p1, p2);
234 } else {
235 totaldist += sqrt(vtkMath::Distance2BetweenPoints(p1, p2));
236 }
237 }
238 }
239
240 if (this->CheckMeanDistance)
241 {
242 if (this->MeanDistanceMode == VTK_ICP_MODE_RMS)
243 {
244 this->MeanDistance = sqrt(totaldist / (double)nb_points);
245 } else {
246 this->MeanDistance = totaldist / (double)nb_points;
247 }
248 vtkDebugMacro("Mean distance: " << this->MeanDistance);
249 if (this->MeanDistance <= this->MaximumMeanDistance)
250 {
251 break;
252 }
253 }
254
255 temp = a;
256 a = b;
257 b = temp;
258
259 }
260 while (1);
261
262 // Now recover accumulated result
263
264 this->Matrix->DeepCopy(accumulate->GetMatrix());
265
266 accumulate->Delete();
267 points1->Delete();
268 closestp->Delete();
269 points2->Delete();
270}

Member Data Documentation

◆ FarThreshold

double vtkvmtkIterativeClosestPointTransform::FarThreshold
protected

Definition at line 75 of file vtkvmtkIterativeClosestPointTransform.h.

◆ UseFarThreshold

int vtkvmtkIterativeClosestPointTransform::UseFarThreshold
protected

Definition at line 76 of file vtkvmtkIterativeClosestPointTransform.h.


The documentation for this class was generated from the following files: