VTK  9.7.20261105
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 "vtkAbstractPointLocator.h" // for locating nearby points
110#include "vtkLocatorInterface.h" // Interface to spatial locators
111#include "vtkPoints.h" // for input points
112#include "vtkSMPTools.h" // SMP parallel processing
113#include "vtkVoronoiCore.h" // Core includes
114#include "vtkVoronoiTile.h" // Generate Voronoi convex tiles
115
116VTK_ABI_NAMESPACE_BEGIN
117
133
146{
147 // Optional regions ids for point classification.
148 const int* Regions;
149
150 // Constructors
152 : Regions(nullptr)
153 {
154 }
155 vtkVoronoiClassifier2D(const int* regions)
156 : Regions(regions)
157 {
158 }
159
160 // Method required by vtkVoronoiCore2D.
162 {
163 if (c)
164 {
165 this->Regions = c->Regions;
166 }
167 }
168
169 // Method required by vtkVoronoiCore2D.
171 vtkVoronoiSpokesType& spokes, int& numSpokes, int& maxPoints);
172
173 // Method required by vtkVoronoiCore2D. By default, any region id >= 0 is
174 // considered a valid inside region (<0 region values are reserved for
175 // algorithm use). If no region ids have been specified, and the point id
176 // is ptId >=0, then the point ptId is inside an interior region.
178 {
179 if (!this->Regions)
180 {
181 return (ptId >= 0);
182 }
183 else
184 {
185 return (ptId >= 0 && this->Regions[ptId] >= 0);
186 }
187 }
188
189 // Method required by vtkVoronoiCore2D. Determine if the two points
190 // ptId and neiId (which form a spoke) are in the same region. It is
191 // assumed that both (ptId,neiId >= 0), i.e., inside.
193 {
194 return (!this->Regions || this->Regions[ptId] == this->Regions[neiId]);
195 }
196}; // vtkVoronoiClassifier2D
197
202template <class TCompositor, class TClassifier>
204{
205 vtkIdType ThreadId; // assign a thread id [0,NumThreadsUsed)
206 int MaxPoints; // the maximum number of points in any tile
207 int NumPrunes; // total number of pruning operations
208 vtkBatchIdsType LocalBatches; // list of batches processed by this thread
209 vtkVoronoiSpokesType LocalSpokes; // connecting edges/spokes for each tile
210 vtkVoronoiNeighborIterator<2> BIter; // iterator over the neighbors of a generator
211 vtkVoronoiTile Tile; // computational 2D Voronoi tile algorithm
212 typename TCompositor::LocalData Compositor; // gather data from compositing operations
213 TClassifier Classifier; // Used to classify spokes (based on regions)
214
216 : ThreadId(-1)
217 , MaxPoints(0)
218 , NumPrunes(0)
219 {
220 this->LocalBatches.reserve(2048);
221 this->LocalSpokes.reserve(2048);
222 }
223}; // vtkVoronoi2DLocalData
224
229template <class TCompositor, class TClassifier>
230using ThreadMapType = std::vector<vtkVoronoi2DLocalData<TCompositor, TClassifier>*>;
231
244template <class TCompositor, class TClassifier = vtkVoronoiClassifier2D>
246{
247public:
264 static std::unique_ptr<vtkVoronoiCore2D<TCompositor, TClassifier>> Execute(vtkAlgorithm* filter,
265 unsigned int batchSize, vtkAbstractPointLocator* loc, vtkPoints* inPts, double padding,
266 vtkIdType maxClips, bool validate, double pruneTol, TCompositor* comp, TClassifier* cl);
267
269
274 int GetNumberOfThreads() { return this->NumberOfThreads; }
276 {
277 return this->ThreadMap[threadNum];
278 }
279
280
282
288 int GetMaximumNumberOfPoints() { return this->MaximumNumberOfPoints; }
289 int GetNumberOfPrunes() { return this->NumberOfPrunes; }
291
297
303 vtkAbstractPointLocator* loc, vtkPoints* inPts, double padding, vtkIdType maxClips,
304 bool validate, double pruneTol, TCompositor* comp, TClassifier* c);
305
307
315 void operator()(vtkIdType batchId, vtkIdType endBatchId);
316 void Reduce();
318
326 TCompositor Compositor;
327
333 TClassifier Classifier;
334
341
348
353 vtkIdType GetNumberOfPoints() { return this->NPts; }
354 const double* GetPoints() { return this->Points; }
355
361
362private:
363 vtkIdType NPts; // The number of input points
364 vtkPoints* InPoints; // Input points as data array
365 const double* Points; // Input points as pointer to x-y-z AOS doubles
366 vtkAbstractPointLocator* Locator; // Used to (quickly) find nearby points
367 double Padding; // The padding distance around the bounding box
368 double Bounds[6]; // locator bounds
369 double PaddedBounds[6]; // the domain over which Voronoi is calculated
370 vtkIdType MaxClips; // Limit the number of half-space clips
371
372 // Enable pruning of spokes (equivalent to deletion of a degenerate tile edges)
373 bool Validate; // Indicate whether to explicitly validate the mesh
374 vtkIdType NumberOfPrunes; // If pruning is on, keep track of the number of prunes
375 double PruneTolerance; // Specify the square spoke prune tolerance
376
377 // High-level information captured during processing
378 int NumberOfThreads; // Keep track of the number of threads used durinf processing
379 int MaximumNumberOfPoints; // Maximum number of points in a generated Voronoi tile (this
380 // equals the maximum number of edges).
381
382 // Storage local to each thread, as well as working/scratch arrays. We
383 // don't want to allocate working arrays on every thread invocation. Thread
384 // local storage saves lots of new/delete (e.g. the locator tuples).
387
392 using vtkBinIterator = vtkVoronoiNeighborIterator<2>;
393 bool BuildTile(vtkVoronoiTile& tile, vtkBinIterator* biter, const double* pts, vtkIdType maxClips,
394 vtkDist2TupleArray& results, int& numPrunes);
395
396public:
406 {
409 void operator()(vtkIdType threadId, vtkIdType endThreadId);
410
411 // Invoke the production of wheels and spokes
413 }; // ProduceWheelsAndSpokes
414
428 {
431
432 vtkMergeTuples2DType MergeTuples; // temporary array for merging points
433 vtkMergeMapType MergeMap; // maps tile/hull point ids to merged point ids
434 vtkIdType NumMergedPts; // after merging, the number of points remaining
435
442 vtkIdType GetNumberOfMergedPoints() { return this->NumMergedPts; }
443
444 // Core Voronoi methods in support of vtkSMPTools
445 void Initialize() {}
446 void operator()(vtkIdType threadId, vtkIdType endThreadId);
447 void Reduce();
448
449 // Execute the topological point merge to produce a merge map.
450 static std::unique_ptr<TopologicalMerge> Execute(
452 }; // TopologicalMerge
453
454}; // vtkVoronoiCore2D
455
460
469{
475 void Finalize() {}
476
481 {
483 void AddData(vtkVoronoiTile&, int vtkNotUsed(numSpokes), const vtkVoronoiSpoke*) {}
484 };
485}; // vtkEmptyVoronoi2DCompositor
486
487// Minimal classifier - just records the tile's number of points and edges. It
488// still supports region classification.
490{
491 // Optional regions ids for point classification.
492 const int* Regions;
493
494 // Constructor
496 : Regions(nullptr)
497 {
498 }
499 vtkEmptyVoronoi2DClassifier(const int* regions)
500 : Regions(regions)
501 {
502 }
503
504 // Initialize
506 {
507 if (c)
508 {
509 this->Regions = c->Regions;
510 }
511 }
512
513 // Method required by vtkVoronoiCore2D. This vtkEmptyClassifier provides
514 // the minimum information needed.
516 vtkVoronoiSpokesType& vtkNotUsed(spokes), int& numSpokes, int& maxPoints)
517 {
518 int numPts = tile.GetNumberOfPoints();
519 wheels[tile.GetGeneratorPointId()] = numPts; // numEdges == numSpokes == numPts
520 maxPoints = (numPts > maxPoints ? numPts : maxPoints);
521 numSpokes = 0;
522 return nullptr;
523 }
524
525 // Method required by vtkVoronoiCore2D. By default, any region id >= 0 is
526 // considered a valid inside region (<0 region values are reserved for
527 // algorithm use). If no region ids have been specified, and the point id
528 // is ptId >=0, then the point ptId is inside an interior region.
530 {
531 if (!this->Regions)
532 {
533 return (ptId >= 0);
534 }
535 else
536 {
537 return (ptId >= 0 && this->Regions[ptId] >= 0);
538 }
539 }
540
541 // Method required by vtkVoronoiCore2D. Determine if the two points
542 // ptId and neiId (which form a spoke) are in the same region. It is
543 // assumed that both (ptId,neiId >= 0), i.e., inside.
545 {
546 return (!this->Regions || this->Regions[ptId] == this->Regions[neiId]);
547 }
548}; // vtkEmptyVoronoi2DClassifier
549
550VTK_ABI_NAMESPACE_END
551#include "vtkVoronoiCore2D.txx"
552
553#endif
554// VTK-HeaderTest-Exclude: vtkVoronoiCore2D.h
abstract class to quickly locate points in 3-space
represent and manipulate 3D points
Definition vtkPoints.h:140
Thread local storage for VTK objects.
int GetNumberOfPrunes()
Obtain information about the execution of the Voronoi algorithm.
TClassifier Classifier
This templated class is used to extend the API of this vtkVoronoiCore2D class, to implement the spoke...
vtkVoronoiCore2D(vtkAlgorithm *filter, vtkVoronoiBatchManager &batcher, vtkAbstractPointLocator *loc, vtkPoints *inPts, double padding, vtkIdType maxClips, bool validate, double pruneTol, TCompositor *comp, TClassifier *c)
Constructor.
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.
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.
static std::unique_ptr< vtkVoronoiCore2D< TCompositor, TClassifier > > Execute(vtkAlgorithm *filter, unsigned int batchSize, vtkAbstractPointLocator *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.
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
vtkVoronoiNeighborIterator< 2 > 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)
Iterate over the neighbors of a Voronoi generator in spherical shells (the annuli of a 2D tile),...
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