VTK  9.6.20260216
vtkVoronoiCore2D.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
105
106#ifndef vtkVoronoiCore2D_h
107#define vtkVoronoiCore2D_h
108
109#include "vtkAnnularBinIterator.h" // Iteration over the bins of the locator
110#include "vtkLocatorInterface.h" // Interface to spatial locators
111#include "vtkPoints.h" // for input points
112#include "vtkSMPTools.h" // SMP parallel processing
113#include "vtkStaticPointLocator2D.h" // for locating nearby points
114#include "vtkVoronoiCore.h" // Core includes
115#include "vtkVoronoiTile.h" // Generate Voronoi convex tiles
116
117VTK_ABI_NAMESPACE_BEGIN
118
134
147{
148 // Optional regions ids for point classification.
149 const int* Regions;
150
151 // Constructors
153 : Regions(nullptr)
154 {
155 }
156 vtkVoronoiClassifier2D(const int* regions)
157 : Regions(regions)
158 {
159 }
160
161 // Method required by vtkVoronoiCore2D.
163 {
164 if (c)
165 {
166 this->Regions = c->Regions;
167 }
168 }
169
170 // Method required by vtkVoronoiCore2D.
172 vtkVoronoiSpokesType& spokes, int& numSpokes, int& maxPoints);
173
174 // Method required by vtkVoronoiCore2D. By default, any region id >= 0 is
175 // considered a valid inside region (<0 region values are reserved for
176 // algorithm use). If no region ids have been specified, and the point id
177 // is ptId >=0, then the point ptId is inside an interior region.
179 {
180 if (!this->Regions)
181 {
182 return (ptId >= 0);
183 }
184 else
185 {
186 return (ptId >= 0 && this->Regions[ptId] >= 0);
187 }
188 }
189
190 // Method required by vtkVoronoiCore2D. Determine if the two points
191 // ptId and neiId (which form a spoke) are in the same region. It is
192 // assumed that both (ptId,neiId >= 0), i.e., inside.
194 {
195 return (!this->Regions || this->Regions[ptId] == this->Regions[neiId]);
196 }
197}; // vtkVoronoiClassifier2D
198
203template <class TCompositor, class TClassifier>
205{
206 vtkIdType ThreadId; // assign a thread id [0,NumThreadsUsed)
207 int MaxPoints; // the maximum number of points in any tile
208 int NumPrunes; // total number of pruning operations
209 vtkBatchIdsType LocalBatches; // list of batches processed by this thread
210 vtkVoronoiSpokesType LocalSpokes; // connecting edges/spokes for each tile
211 vtkAnnularBinIterator BIter; // iterator over static point locator bins
212 vtkVoronoiTile Tile; // computational 2D Voronoi tile algorithm
213 typename TCompositor::LocalData Compositor; // gather data from compositing operations
214 TClassifier Classifier; // Used to classify spokes (based on regions)
215
217 : ThreadId(-1)
218 , MaxPoints(0)
219 , NumPrunes(0)
220 {
221 this->LocalBatches.reserve(2048);
222 this->LocalSpokes.reserve(2048);
223 }
224}; // vtkVoronoi2DLocalData
225
230template <class TCompositor, class TClassifier>
231using ThreadMapType = std::vector<vtkVoronoi2DLocalData<TCompositor, TClassifier>*>;
232
245template <class TCompositor, class TClassifier = vtkVoronoiClassifier2D>
247{
248public:
265 static std::unique_ptr<vtkVoronoiCore2D<TCompositor, TClassifier>> Execute(vtkAlgorithm* filter,
266 unsigned int batchSize, vtkStaticPointLocator2D* loc, vtkPoints* inPts, double padding,
267 vtkIdType maxClips, bool validate, double pruneTol, TCompositor* comp, TClassifier* cl);
268
270
275 int GetNumberOfThreads() { return this->NumberOfThreads; }
277 {
278 return this->ThreadMap[threadNum];
279 }
280
281
283
289 int GetMaximumNumberOfPoints() { return this->MaximumNumberOfPoints; }
290 int GetNumberOfPrunes() { return this->NumberOfPrunes; }
292
298
304 vtkStaticPointLocator2D* loc, vtkPoints* inPts, double padding, vtkIdType maxClips,
305 bool validate, double pruneTol, TCompositor* comp, TClassifier* c);
306
308
316 void operator()(vtkIdType batchId, vtkIdType endBatchId);
317 void Reduce();
319
327 TCompositor Compositor;
328
334 TClassifier Classifier;
335
342
349
354 vtkIdType GetNumberOfPoints() { return this->NPts; }
355 const double* GetPoints() { return this->Points; }
356
362
363private:
364 vtkIdType NPts; // The number of input points
365 vtkPoints* InPoints; // Input points as data array
366 const double* Points; // Input points as pointer to x-y-z AOS doubles
367 vtkStaticPointLocator2D* Locator; // Used to (quickly) find nearby points
368 double Padding; // The padding distance around the bounding box
369 double Bounds[6]; // locator bounds
370 double PaddedBounds[6]; // the domain over which Voronoi is calculated
371 vtkIdType MaxClips; // Limit the number of half-space clips
372
373 // Enable pruning of spokes (equivalent to deletion of a degenerate tile edges)
374 bool Validate; // Indicate whether to explicitly validate the mesh
375 vtkIdType NumberOfPrunes; // If pruning is on, keep track of the number of prunes
376 double PruneTolerance; // Specify the square spoke prune tolerance
377
378 // High-level information captured during processing
379 int NumberOfThreads; // Keep track of the number of threads used durinf processing
380 int MaximumNumberOfPoints; // Maximum number of points in a generated Voronoi tile (this
381 // equals the maximum number of edges).
382
383 // Storage local to each thread, as well as working/scratch arrays. We
384 // don't want to allocate working arrays on every thread invocation. Thread
385 // local storage saves lots of new/delete (e.g. the locator tuples).
388
393 using vtkBinIterator = vtkAnnularBinIterator;
394 bool BuildTile(vtkVoronoiTile& tile, vtkBinIterator* biter, const double* pts, vtkIdType maxClips,
395 vtkDist2TupleArray& results, int& numPrunes);
396
397public:
407 {
410 void operator()(vtkIdType threadId, vtkIdType endThreadId);
411
412 // Invoke the production of wheels and spokes
414 }; // ProduceWheelsAndSpokes
415
429 {
432
433 vtkMergeTuples2DType MergeTuples; // temporary array for merging points
434 vtkMergeMapType MergeMap; // maps tile/hull point ids to merged point ids
435 vtkIdType NumMergedPts; // after merging, the number of points remaining
436
443 vtkIdType GetNumberOfMergedPoints() { return this->NumMergedPts; }
444
445 // Core Voronoi methods in support of vtkSMPTools
446 void Initialize() {}
447 void operator()(vtkIdType threadId, vtkIdType endThreadId);
448 void Reduce();
449
450 // Execute the topological point merge to produce a merge map.
451 static std::unique_ptr<TopologicalMerge> Execute(
453 }; // TopologicalMerge
454
455}; // vtkVoronoiCore2D
456
461
470{
476 void Finalize() {}
477
482 {
484 void AddData(vtkVoronoiTile&, int vtkNotUsed(numSpokes), const vtkVoronoiSpoke*) {}
485 };
486}; // vtkEmptyVoronoi2DCompositor
487
488// Minimal classifier - just records the tile's number of points and edges. It
489// still supports region classification.
491{
492 // Optional regions ids for point classification.
493 const int* Regions;
494
495 // Constructor
497 : Regions(nullptr)
498 {
499 }
500 vtkEmptyVoronoi2DClassifier(const int* regions)
501 : Regions(regions)
502 {
503 }
504
505 // Initialize
507 {
508 if (c)
509 {
510 this->Regions = c->Regions;
511 }
512 }
513
514 // Method required by vtkVoronoiCore2D. This vtkEmptyClassifier provides
515 // the minimum information needed.
517 vtkVoronoiSpokesType& vtkNotUsed(spokes), int& numSpokes, int& maxPoints)
518 {
519 int numPts = tile.GetNumberOfPoints();
520 wheels[tile.GetGeneratorPointId()] = numPts; // numEdges == numSpokes == numPts
521 maxPoints = (numPts > maxPoints ? numPts : maxPoints);
522 numSpokes = 0;
523 return nullptr;
524 }
525
526 // Method required by vtkVoronoiCore2D. By default, any region id >= 0 is
527 // considered a valid inside region (<0 region values are reserved for
528 // algorithm use). If no region ids have been specified, and the point id
529 // is ptId >=0, then the point ptId is inside an interior region.
531 {
532 if (!this->Regions)
533 {
534 return (ptId >= 0);
535 }
536 else
537 {
538 return (ptId >= 0 && this->Regions[ptId] >= 0);
539 }
540 }
541
542 // Method required by vtkVoronoiCore2D. Determine if the two points
543 // ptId and neiId (which form a spoke) are in the same region. It is
544 // assumed that both (ptId,neiId >= 0), i.e., inside.
546 {
547 return (!this->Regions || this->Regions[ptId] == this->Regions[neiId]);
548 }
549}; // vtkEmptyVoronoi2DClassifier
550
551VTK_ABI_NAMESPACE_END
552#include "vtkVoronoiCore2D.txx"
553
554#endif
555// VTK-HeaderTest-Exclude: vtkVoronoiCore2D.h
A fast, lightweight class for iterating over the bins of a 2D vtkStaticPointLocator2D.
represent and manipulate 3D points
Definition vtkPoints.h:140
Thread local storage for VTK objects.
quickly locate points in 2-space
int GetNumberOfPrunes()
Obtain information about the execution of the Voronoi algorithm.
static std::unique_ptr< vtkVoronoiCore2D< TCompositor, TClassifier > > Execute(vtkAlgorithm *filter, unsigned int batchSize, vtkStaticPointLocator2D *loc, vtkPoints *inPts, double padding, vtkIdType maxClips, bool validate, double pruneTol, TCompositor *comp, TClassifier *cl)
A factory method to conveniently instantiate and execute the algorithm.
TClassifier Classifier
This templated class is used to extend the API of this vtkVoronoiCore2D class, to implement the spoke...
ThreadMapType< TCompositor, TClassifier > ThreadMap
vtkVoronoiAdjacencyGraph Graph
This is used to create the spokes and wheels adjacency graph used to validate the tessellation and pr...
int GetMaximumNumberOfPoints()
Obtain information about the execution of the Voronoi algorithm.
vtkVoronoiAdjacencyGraph & GetAdjacencyGraph()
Obtain the adjacency graph (wheel & spokes data structure).
TCompositor Compositor
The compositor enables this vtkVoronoiCore2D templated class to be used in different applications.
vtkVoronoiCore2D(vtkAlgorithm *filter, vtkVoronoiBatchManager &batcher, vtkStaticPointLocator2D *loc, vtkPoints *inPts, double padding, vtkIdType maxClips, bool validate, double pruneTol, TCompositor *comp, TClassifier *c)
Constructor.
vtkVoronoi2DLocalData< TCompositor, TClassifier > * GetThreadData(int threadNum)
Access the local thread data produced by execution of the filter.
vtkIdType GetNumberOfPoints()
Convenience methods to retrieve the number of input points, and the raw double* points array.
const double * GetPoints()
void Reduce()
Core vtkSMPTools methods to process tiles in parallel, and produce thread local output data.
int GetNumberOfThreads()
Access the local thread data produced by execution of the filter.
vtkAlgorithm * Filter
Used for controlling filter abort and accessing filter information.
void Initialize()
Core vtkSMPTools methods to process tiles in parallel, and produce thread local output data.
vtkVoronoiBatchManager Batcher
Controls processing of batches of generating points.
void operator()(vtkIdType batchId, vtkIdType endBatchId)
Core vtkSMPTools methods to process tiles in parallel, and produce thread local output data.
The convex polygon tile class proper.
vtkIdType GetNumberOfPoints()
vtkIdType GetGeneratorPointId()
Obtain information about the generated tile.
Represent an array of vtkDist2Tuples.
const vtkVoronoiSpoke * AddAdjacencyInformation(vtkVoronoiTile &tile, vtkVoronoiWheelsType &wheels, vtkVoronoiSpokesType &spokes, int &numSpokes, int &maxPoints)
bool IsSameRegion(vtkIdType ptId, vtkIdType neiId)
vtkEmptyVoronoi2DClassifier(const int *regions)
bool IsInsideRegion(vtkIdType ptId)
void Initialize(vtkEmptyVoronoi2DClassifier *c)
Thread local data may be needed.
void AddData(vtkVoronoiTile &, int numSpokes, const vtkVoronoiSpoke *)
void Initialize(vtkEmptyVoronoi2DCompositor *)
These are convenience/demonstration classes for configuring the templated 2D Voronoi classes.
void Initialize(vtkIdType numPts, vtkEmptyVoronoi2DCompositor *)
Prepare to accumulate compositing information: specify the total number of generating points to be pr...
The following thread local data is used to process and keep track of information on a per-thread basi...
vtkBatchIdsType LocalBatches
vtkAnnularBinIterator BIter
TCompositor::LocalData Compositor
vtkVoronoiSpokesType LocalSpokes
The adjacency graph, a collection of wheels and spokes, is a topological construct that connects Voro...
Class to manage batches of points.
bool IsInsideRegion(vtkIdType ptId)
bool IsSameRegion(vtkIdType ptId, vtkIdType neiId)
void Initialize(vtkVoronoiClassifier2D *c)
const vtkVoronoiSpoke * AddAdjacencyInformation(vtkVoronoiTile &tile, vtkVoronoiWheelsType &wheels, vtkVoronoiSpokesType &spokes, int &numSpokes, int &maxPoints)
vtkVoronoiClassifier2D(const int *regions)
ProduceWheelsAndSpokes(vtkVoronoiCore2D< TCompositor, TClassifier > *vc)
static void Execute(vtkVoronoiCore2D< TCompositor, TClassifier > *vc)
vtkVoronoiCore2D< TCompositor, TClassifier > * VC
void operator()(vtkIdType threadId, vtkIdType endThreadId)
vtkIdType GetNumberOfMergedPoints()
Methods related to merging coincident points.
static std::unique_ptr< TopologicalMerge > Execute(vtkVoronoiCore2D< TCompositor, TClassifier > *vc)
TopologicalMerge(vtkVoronoiCore2D< TCompositor, TClassifier > *vc)
vtkVoronoiCore2D< TCompositor, TClassifier > * VC
void operator()(vtkIdType threadId, vtkIdType endThreadId)
Typedefs and classes in support of the adjacency graph.
int vtkIdType
Definition vtkType.h:363
std::vector< vtkVoronoi2DLocalData< TCompositor, TClassifier > * > ThreadMapType
The thread map keeps track of the thread local data across all computing threads.
std::vector< vtkIdType > vtkBatchIdsType
Keep track of batches of generating points.
std::vector< vtkIdType > vtkMergeMapType
When merging points, the merge map is a vector that maps global tile/hull vertex ids (which contain d...
std::vector< vtkIdType > vtkVoronoiWheelsType
std::vector< vtkVoronoiSpoke > vtkVoronoiSpokesType
The vtkVoronoiWheelsType vector is used to keep track of the number of spokes (and equivalently,...
std::vector< vtkVoronoiMergeTuple2D > vtkMergeTuples2DType
#define vtkAlgorithm