13#ifndef vtkStaticPointLocatorPrivate_h
14#define vtkStaticPointLocatorPrivate_h
29VTK_ABI_NAMESPACE_BEGIN
46struct NeighborBuckets;
76 this->NumPts = numPts;
77 this->NumBuckets = numBuckets;
78 this->BatchSize = 10000;
83 double spacing[3], bounds[6];
87 this->hX = this->H[0] = spacing[0];
88 this->hY = this->H[1] = spacing[1];
89 this->hZ = this->H[2] = spacing[2];
90 this->hX2 = this->hX / 2.0;
91 this->hY2 = this->hY / 2.0;
92 this->hZ2 = this->hZ / 2.0;
93 this->fX = 1.0 / spacing[0];
94 this->fY = 1.0 / spacing[1];
95 this->fZ = 1.0 / spacing[2];
96 this->bX = this->Bounds[0] = bounds[0];
97 this->Bounds[1] = bounds[1];
98 this->bY = this->Bounds[2] = bounds[2];
99 this->Bounds[3] = bounds[3];
100 this->bZ = this->Bounds[4] = bounds[4];
101 this->Bounds[5] = bounds[5];
102 this->xD = this->Divisions[0];
103 this->yD = this->Divisions[1];
104 this->zD = this->Divisions[2];
105 this->xyD = this->Divisions[0] * this->Divisions[1];
107 this->FastPoints =
nullptr;
108 this->BinRadius = sqrt(
hX *
hX +
hY *
hY +
hZ *
hZ) / 2.0;
109 this->MaxLevel = std::max({ this->xD, this->yD, this->zD });
118 NeighborBuckets* buckets,
const int ijk[3],
const int ndivs[3],
int level);
133 ijk[0] = tmp0 < 0 ? 0 : std::min(
xD - 1, tmp0);
134 ijk[1] = tmp1 < 0 ? 0 : std::min(
yD - 1, tmp1);
135 ijk[2] = tmp2 < 0 ? 0 : std::min(
zD - 1, tmp2);
143 return ijk[0] + ijk[1] *
xD + ijk[2] *
xyD;
150 center[0] = this->bX + this->hX2 + i * this->hX;
151 center[1] = this->bY + this->hY2 + j * this->hY;
152 center[2] = this->bZ + this->hZ2 + k * this->hZ;
159 min[0] = this->bX + i * this->hX;
160 min[1] = this->bY + j * this->hY;
161 min[2] = this->bZ + k * this->hZ;
162 max[0] = min[0] + this->hX;
163 max[1] = min[1] + this->hY;
164 max[2] = min[2] + this->hZ;
172 double min[3],
max[3];
173 min[0] = this->bX + i * this->hX;
174 min[1] = this->bY + j * this->hY;
175 min[2] = this->bZ + k * this->hZ;
187template <
typename TIds>
200 this->Map[numPts].
Bucket = numBuckets;
201 this->Offsets =
new TIds[numBuckets + 1];
202 this->Offsets[numBuckets] = numPts;
209 delete[] this->Offsets;
216 return (this->Offsets[bucketNum + 1] - this->Offsets[bucketNum]);
222 return this->Map + this->Offsets[bucketNum];
231 for (
int i = 0; i < numIds; i++)
233 bList->
SetId(i, ids[i].PtId);
240 double radius,
const double x[3],
double inputDataLength,
double& dist2);
243 double minDist2 = (-0.1),
bool sort =
true,
vtkDoubleArray* petals =
nullptr);
253 NeighborBuckets* buckets,
const double x[3],
const int ijk[3],
double dist,
int level);
255 int prevMinLevel[3],
int prevMaxLevel[3]);
258 template <
typename T>
275 for (; ptId < end; ++ptId, ++t)
285 template <
typename T,
typename TPts>
300 const TPts* x = this->Points + 3 * ptId;
303 for (; ptId < end; ++ptId, x += 3, ++t)
305 p[0] =
static_cast<double>(x[0]);
306 p[1] =
static_cast<double>(x[1]);
307 p[2] =
static_cast<double>(x[2]);
318 template <
typename T>
329 this->NumPts = this->BList->
NumPts;
335 T* offsets = this->BList->
Offsets;
340 endBatchPt = (endBatchPt > endPt ? endPt : endBatchPt);
345 if (curPt == this->BList->
Map)
347 prevPt = this->BList->
Map;
348 std::fill_n(offsets, curPt->
Bucket + 1, 0);
363 for (curPt = prevPt; curPt < endBatchPt;)
365 for (; curPt->
Bucket == prevPt->
Bucket && curPt <= endBatchPt; ++curPt)
371 offsets + prevPt->
Bucket + 1, curPt->
Bucket - prevPt->
Bucket, curPt - this->BList->Map);
379 template <
typename T>
390 this->DataSet = blist->
DataSet;
402 for (; bucket < endBucket; ++bucket)
406 ids = bList->
GetIds(bucket);
407 for (i = 0; i < numIds; i++)
410 if (mergeMap[ptId] < 0)
412 mergeMap[ptId] = ptId;
414 for (j = i + 1; j < numIds; j++)
417 if (mergeMap[ptId2] < 0)
420 if (p[0] == p2[0] && p[1] == p2[1] && p[2] == p2[2])
422 mergeMap[ptId2] = ptId;
440 template <
typename T>
455 this->DataSet = blist->
DataSet;
464 if (mergeMap[ptId] < 0)
466 mergeMap[ptId] = ptId;
473 for (
auto i = 0; i < numIds; ++i)
476 if (mergeMap[nearId] < 0)
478 mergeMap[nearId] = ptId;
498 template <
typename T>
514 for (
vtkIdType ptId = 0; ptId < numPts; ++ptId)
538 template <
typename T>
553 double hMin = std::min({ bl->
hX, bl->
hY, bl->
hZ });
554 this->CheckerboardDimension =
560 for (
auto i = 0; i < 3; ++i)
563 static_cast<double>(bl->
Divisions[i]) /
static_cast<double>(this->CheckerboardDimension);
565 this->NumBlocks *= this->BlockDims[i];
575 this->CheckerboardIndex[0] = 0;
576 this->CheckerboardIndex[1] = 0;
577 this->CheckerboardIndex[2] = 0;
578 return this->CheckerboardIndex;
592 for (
auto i = 0; i < 3; ++i)
594 ijk[i] = ijk[i] * this->CheckerboardDimension + cIdx[i];
595 if (ijk[i] >= this->
BList->Divisions[i])
602 return (ijk[0] + ijk[1] * this->
BList->Divisions[0] +
603 ijk[2] * this->BList->Divisions[0] * this->BList->Divisions[1]);
612 for (; blockId < endBlockId; ++blockId)
617 if (bin >= 0 && (numIds = this->
BList->GetNumberOfIds(bin)) > 0)
620 for (
auto i = 0; i < numIds; ++i)
640 int cDim = this->CheckerboardDimension;
645 for (cIdx[2] = 0; cIdx[2] < cDim; ++cIdx[2])
647 for (cIdx[1] = 0; cIdx[1] < cDim; ++cIdx[1])
649 for (cIdx[0] = 0; cIdx[0] < cDim; ++cIdx[0])
662 template <
typename T>
677 this->DataSet = blist->
DataSet;
682 for (
auto i = 0; i < tupleSize; ++i)
695 this->Tuple.
Local().resize(numComp);
696 this->Tuple2.
Local().resize(numComp);
707 int tupleSize =
static_cast<int>(this->Tuple.
Local().size());
708 double* t = this->Tuple.
Local().data();
709 double*
t2 = this->Tuple2.
Local().data();
711 for (; bucket < endBucket; ++bucket)
715 ids = bList->
GetIds(bucket);
716 for (i = 0; i < numIds; i++)
719 if (mergeMap[ptId] < 0)
721 mergeMap[ptId] = ptId;
724 for (j = i + 1; j < numIds; j++)
727 if (mergeMap[ptId2] < 0)
730 if (p[0] == p2[0] && p[1] == p2[1] && p[2] == p2[2])
735 mergeMap[ptId2] = ptId;
785 int numBatches =
static_cast<int>(ceil(
static_cast<double>(this->
NumPts) / this->
BatchSize));
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
static bool InsideSphere(const double min[3], const double max[3], const double center[3], double r2)
Performant method to determine if box if fully inside a sphere.
object to represent cell connectivity
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
abstract class to specify dataset behavior
virtual double * GetPoint(vtkIdType ptId)=0
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
dynamic, self-adjusting array of double
list of point or cell ids
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
int Allocate(vtkIdType sz, int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
void SetId(vtkIdType i, vtkIdType vtkid)
Set the id at location i.
vtkIdType GetId(vtkIdType i)
Return the id at location i.
virtual vtkDataSet * GetDataSet()
Build the locator from the points/cells defining this dataset.
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
concrete class for storing a set of points
static vtkPointSet * SafeDownCast(vtkObjectBase *o)
Standard methods for type information and printing.
vtkPoints * GetPoints() override
Specify point array to define point coordinates.
represent and manipulate 3D points
void * GetVoidPointer(const int id)
Return a void pointer.
virtual int GetDataType() const
Return the underlying data type.
concrete dataset represents vertices, lines, polygons, and triangle strips
Thread local storage for VTK objects.
T *& Local()
Returns an object local to the current thread.
Thread local storage for VTK objects.
T & Local()
This needs to be called mainly within a threaded execution path.
quickly locate points in 3-space
virtual double * GetBounds()
Provide an accessor to the bounds.
virtual double * GetSpacing()
Provide an accessor to the bucket spacing.
virtual int * GetDivisions()
Set the number of divisions in x-y-z directions.
static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a pointId and grid dimensions 'dim', get the structured coordinates (i-j-k).
MapDataSet(BucketList< T > *blist, vtkDataSet *ds)
void operator()(vtkIdType ptId, vtkIdType end)
void operator()(vtkIdType batch, vtkIdType batchEnd)
MapOffsets(BucketList< T > *blist)
MapPointsArray(BucketList< T > *blist, const TPts *pts)
void operator()(vtkIdType ptId, vtkIdType end)
void operator()(vtkIdType blockId, vtkIdType endBlockId)
MergeBinOrder(BucketList< T > *blist, double tol, vtkIdType *mergeMap)
int * InitializeCheckerboardIndex()
vtkIdType GetCurrentBin(int blockId, int cIdx[3])
int CheckerboardDimension
vtkSMPThreadLocalObject< vtkIdList > PIds
void MergePoint(vtkIdType ptId, vtkIdList *nearby)
MergeClose(BucketList< T > *blist, double tol, vtkIdType *mergeMap)
void operator()(vtkIdType numPts)
MergePointOrder(BucketList< T > *blist, double tol, vtkIdType *mergeMap)
MergePointsAndData(BucketList< T > *blist, vtkDataArray *da, vtkIdType *mergeMap)
bool TuplesEqual(int tupleSize, double *t1, double *t2)
vtkSMPThreadLocal< std::vector< double > > Tuple
void operator()(vtkIdType bucket, vtkIdType endBucket)
vtkSMPThreadLocal< std::vector< double > > Tuple2
MergePrecise(BucketList< T > *blist, vtkIdType *mergeMap)
void operator()(vtkIdType bucket, vtkIdType endBucket)
void GetIds(vtkIdType bucketNum, vtkIdList *bList)
BucketList(vtkStaticPointLocator *loc, vtkIdType numPts, int numBuckets)
void GetOverlappingBuckets(NeighborBuckets *buckets, const double x[3], double dist, int prevMinLevel[3], int prevMaxLevel[3])
double FindNPointsInShell(int N, const double x[3], vtkDist2TupleArray &results, double minDist2=(-0.1), bool sort=true, vtkDoubleArray *petals=nullptr)
void GenerateRepresentation(int level, vtkPolyData *pd)
void MergePointsWithData(vtkDataArray *data, vtkIdType *pointMap)
vtkIdType FindClosestPoint(const double x[3])
vtkIdType GetNumberOfIds(vtkIdType bucketNum)
void FindPointsWithinRadius(double R, const double x[3], vtkIdList *result)
vtkLocatorTuple< TIds > * Map
void BuildLocator() override
const vtkLocatorTuple< TIds > * GetIds(vtkIdType bucketNum)
vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double inputDataLength, double &dist2)
int IntersectWithLine(double a0[3], double a1[3], double tol, double &t, double lineX[3], double ptX[3], vtkIdType &ptId)
void GetOverlappingBuckets(NeighborBuckets *buckets, const double x[3], const int ijk[3], double dist, int level)
void MergePoints(double tol, vtkIdType *pointMap, int orderingMode)
void FindClosestNPoints(int N, const double x[3], vtkIdList *result)
void GenerateFace(int face, int i, int j, int k, vtkPoints *pts, vtkCellArray *polys)
vtkIdType GetBucketIndex(const double *x) const
virtual void BuildLocator()=0
void GetBucketNeighbors(NeighborBuckets *buckets, const int ijk[3], const int ndivs[3], int level)
vtkBucketList(vtkStaticPointLocator *loc, vtkIdType numPts, int numBuckets)
double Distance2ToBucket(const double x[3], const int nei[3])
virtual ~vtkBucketList()=default
vtkStaticPointLocator * Locator
double Distance2ToBounds(const double x[3], const double bounds[6])
bool BucketInsideSphere(int i, int j, int k, double center[3], double r2)
void GetBucketIndices(const double *x, int ijk[3]) const
void GetBucketBounds(int i, int j, int k, double min[3], double max[3])
void GetBucketCenter(int i, int j, int k, double center[3])
Represent an array of vtkDist2Tuples.