File: TimePointLocators.cxx

package info (click to toggle)
paraview 5.11.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 497,236 kB
  • sloc: cpp: 3,171,290; ansic: 1,315,072; python: 134,290; xml: 103,324; sql: 65,887; sh: 5,286; javascript: 4,901; yacc: 4,383; java: 3,977; perl: 2,363; lex: 1,909; f90: 1,255; objc: 143; makefile: 119; tcl: 59; pascal: 50; fortran: 29
file content (260 lines) | stat: -rw-r--r-- 8,174 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestPointLocators.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkKdTree.h"
#include "vtkKdTreePointLocator.h"
#include "vtkMath.h"
#include "vtkOctreePointLocator.h"
#include "vtkPointLocator.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkStaticPointLocator.h"
#include "vtkTimerLog.h"

int TimePointLocators(int, char*[])
{
  int nPts = 100000;
  int nQ = nPts / 10;
  int N = 10;
  double R = 0.01;

  vtkTimerLog* timer = vtkTimerLog::New();
  double buildTime[4], cpTime[4], cnpTime[4], crpTime[4];
  for (int i = 0; i < 4; ++i)
  {
    buildTime[i] = cpTime[i] = cnpTime[i] = crpTime[i] = 0.0;
  }

  cout << "\nTiming for " << nPts << " points, " << nQ << " queries\n";

  // Populate a list of points and query locations
  vtkPoints* points = vtkPoints::New();
  points->SetDataTypeToDouble();
  points->SetNumberOfPoints(nPts);
  for (int i = 0; i < nPts; ++i)
  {
    points->SetPoint(i, vtkMath::Random(-1, 1), vtkMath::Random(-1, 1), vtkMath::Random(-1, 1));
  }

  vtkPolyData* polydata = vtkPolyData::New();
  polydata->SetPoints(points);
  points->ComputeBounds();

  // Create points array which are positions to probe data with FindClosestPoint().
  vtkPoints* qPoints = vtkPoints::New();
  qPoints->SetDataTypeToDouble();
  qPoints->SetNumberOfPoints(nQ);
  vtkMath::RandomSeed(314159);
  for (int i = 0; i < nQ; ++i)
  {
    qPoints->SetPoint(i, vtkMath::Random(-1, 1), vtkMath::Random(-1, 1), vtkMath::Random(-1, 1));
  }

  vtkIdList* closest = vtkIdList::New();

  //---------------------------------------------------------------------------
  // The simple uniform binning point locator
  vtkPointLocator* uniformLocator = vtkPointLocator::New();
  timer->StartTimer();
  uniformLocator->SetDataSet(polydata);
  uniformLocator->BuildLocator();
  timer->StopTimer();
  uniformLocator->Delete();
  buildTime[0] = timer->GetElapsedTime();

  uniformLocator = vtkPointLocator::New();
  uniformLocator->SetDataSet(polydata);
  uniformLocator->BuildLocator();
  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    uniformLocator->FindClosestPoint(qPoints->GetPoint(i));
  }
  timer->StopTimer();
  cpTime[0] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    uniformLocator->FindClosestNPoints(N, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  cnpTime[0] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    uniformLocator->FindPointsWithinRadius(R, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  crpTime[0] = timer->GetElapsedTime();
  uniformLocator->Delete();

  //---------------------------------------------------------------------------
  // The simple uniform binning point locator, this time built
  // statically and threaded (may be much faster on threaded machine).
  vtkStaticPointLocator* staticLocator = vtkStaticPointLocator::New();
  timer->StartTimer();
  staticLocator->SetDataSet(polydata);
  staticLocator->BuildLocator();
  timer->StopTimer();
  staticLocator->Delete();
  buildTime[1] = timer->GetElapsedTime();

  staticLocator = vtkStaticPointLocator::New();
  staticLocator->SetDataSet(polydata);
  staticLocator->BuildLocator();
  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    staticLocator->FindClosestPoint(qPoints->GetPoint(i));
  }
  timer->StopTimer();
  cpTime[1] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    staticLocator->FindClosestNPoints(N, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  cnpTime[1] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    staticLocator->FindPointsWithinRadius(R, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  crpTime[1] = timer->GetElapsedTime();
  staticLocator->Delete();

  //---------------------------------------------------------------------------
  // The KD Tree point locator
  vtkKdTreePointLocator* kdTreeLocator = vtkKdTreePointLocator::New();
  timer->StartTimer();
  kdTreeLocator->SetDataSet(polydata);
  kdTreeLocator->BuildLocator();
  kdTreeLocator->Delete();
  timer->StopTimer();
  buildTime[2] = timer->GetElapsedTime();

  kdTreeLocator = vtkKdTreePointLocator::New();
  kdTreeLocator->SetDataSet(polydata);
  kdTreeLocator->BuildLocator();
  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    kdTreeLocator->FindClosestPoint(qPoints->GetPoint(i));
  }
  timer->StopTimer();
  cpTime[2] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    kdTreeLocator->FindClosestNPoints(N, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  cnpTime[2] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    kdTreeLocator->FindPointsWithinRadius(R, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  crpTime[2] = timer->GetElapsedTime();
  kdTreeLocator->Delete();

  //---------------------------------------------------------------------------
  // Octree point locator
  vtkOctreePointLocator* octreeLocator = vtkOctreePointLocator::New();
  timer->StartTimer();
  octreeLocator->SetDataSet(polydata);
  octreeLocator->BuildLocator();
  octreeLocator->Delete();
  timer->StopTimer();
  buildTime[3] = timer->GetElapsedTime();

  octreeLocator = vtkOctreePointLocator::New();
  octreeLocator->SetDataSet(polydata);
  octreeLocator->BuildLocator();
  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    octreeLocator->FindClosestPoint(qPoints->GetPoint(i));
  }
  timer->StopTimer();
  cpTime[3] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    octreeLocator->FindClosestNPoints(N, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  cnpTime[3] = timer->GetElapsedTime();

  timer->StartTimer();
  for (int i = 0; i < nQ; ++i)
  {
    octreeLocator->FindPointsWithinRadius(R, qPoints->GetPoint(i), closest);
  }
  timer->StopTimer();
  crpTime[3] = timer->GetElapsedTime();
  octreeLocator->Delete();

  //---------------------------------------------------------------------------
  // Print out the statistics
  cout << "Build and delete tree\n";
  cout << "\tUniform: " << buildTime[0] << "\n";
  cout << "\tStatic: " << buildTime[1] << "\n";
  cout << "\tOctree: " << buildTime[2] << "\n";
  cout << "\tKD Tree: " << buildTime[3] << "\n";

  cout << "Closest point queries\n";
  cout << "\tUniform: " << cpTime[0] << "\n";
  cout << "\tStatic: " << cpTime[1] << "\n";
  cout << "\tOctree: " << cpTime[2] << "\n";
  cout << "\tKD Tree: " << cpTime[3] << "\n";

  cout << "Closest N points queries\n";
  cout << "\tUniform: " << cnpTime[0] << "\n";
  cout << "\tStatic: " << cnpTime[1] << "\n";
  cout << "\tOctree: " << cnpTime[2] << "\n";
  cout << "\tKD Tree: " << cnpTime[3] << "\n";

  cout << "Closest points within radius queries\n";
  cout << "\tUniform: " << crpTime[0] << "\n";
  cout << "\tStatic: " << crpTime[1] << "\n";
  cout << "\tOctree: " << crpTime[2] << "\n";
  cout << "\tKD Tree: " << crpTime[3] << "\n";

  cout << "Total time\n";
  cout << "\tUniform: " << (buildTime[0] + cpTime[0] + cnpTime[0] + crpTime[0]) << "\n";
  cout << "\tStatic: " << (buildTime[1] + cpTime[1] + cnpTime[1] + crpTime[1]) << "\n";
  cout << "\tOctree: " << (buildTime[2] + cpTime[2] + cnpTime[2] + crpTime[2]) << "\n";
  cout << "\tKD Tree: " << (buildTime[3] + cpTime[3] + cnpTime[3] + crpTime[3]) << "\n";

  timer->Delete();
  points->Delete();
  qPoints->Delete();
  polydata->Delete();
  closest->Delete();

  // Always return success, although the test infrastructure should catch
  // excessive execution times.
  return 0;
}