13#ifndef vtkStaticPointLocator2DPrivate_h
14#define vtkStaticPointLocator2DPrivate_h
29VTK_ABI_NAMESPACE_BEGIN
31#define Distance2BetweenPoints2D(p1, p2) \
32 ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]))
40 const double min[2],
const double max[2],
const double center[2],
double r2)
43 for (
int i = 0; i < 2; ++i)
45 if (center[i] < min[i])
47 d2 += (center[i] - min[i]) * (center[i] - min[i]);
49 else if (center[i] >
max[i])
51 d2 += (center[i] -
max[i]) * (center[i] -
max[i]);
63 const double min[2],
const double max[2],
const double center[2],
double r2)
65 double dmin = 0.0, dmax = 0.0;
66 for (
int i = 0; i < 2; ++i)
68 double a = (center[i] - min[i]) * (center[i] - min[i]);
69 double b = (center[i] -
max[i]) * (center[i] -
max[i]);
70 dmax += std::max(a, b);
71 if (min[i] <= center[i] && center[i] <=
max[i])
73 dmin += std::min(a, b);
76 return (!(dmin <=
r2 &&
r2 <= dmax));
93struct NeighborBuckets2D;
123 this->NumPts = numPts;
124 this->NumBuckets = numBuckets;
125 this->BatchSize = 10000;
130 double spacing[3], bounds[6];
134 this->hX = this->H[0] = spacing[0];
135 this->hY = this->H[1] = spacing[1];
136 this->hX2 = this->hX / 2.0;
137 this->hY2 = this->hY / 2.0;
138 this->fX = 1.0 / spacing[0];
139 this->fY = 1.0 / spacing[1];
140 this->bX = this->Bounds[0] = bounds[0];
141 this->Bounds[1] = bounds[1];
142 this->bY = this->Bounds[2] = bounds[2];
143 this->Bounds[3] = bounds[3];
144 this->xD = this->Divisions[0];
145 this->yD = this->Divisions[1];
148 this->FastPoints =
nullptr;
149 this->BinRadius = sqrt(
hX *
hX +
hY *
hY) / 2.0;
150 this->MaxLevel = std::max({ this->xD, this->yD, this->zD });
159 NeighborBuckets2D* buckets,
const int ij[2],
const int ndivs[2],
int level);
173 ij[0] = std::min(std::max<vtkIdType>(tmp0, 0),
xD - 1);
174 ij[1] = std::min(std::max<vtkIdType>(tmp1, 0),
yD - 1);
182 return ij[0] + ij[1] *
xD;
190 center[0] = this->bX + this->hX2 + i * this->hX;
191 center[1] = this->bY + this->hY2 + j * this->hY;
199 min[0] = this->bX + i * this->hX;
200 min[1] = this->bY + j * this->hY;
202 max[0] = min[0] + this->hX;
203 max[1] = min[1] + this->hY;
212template <
typename TIds>
225 this->Map[numPts].
Bucket = numBuckets;
226 this->Offsets =
new TIds[numBuckets + 1];
227 this->Offsets[numBuckets] = numPts;
234 delete[] this->Offsets;
241 return (this->Offsets[bucketNum + 1] - this->Offsets[bucketNum]);
247 return this->Map + this->Offsets[bucketNum];
256 for (
int i = 0; i < numIds; i++)
258 bList->
SetId(i, ids[i].PtId);
265 double radius,
const double x[3],
double inputDataLength,
double& dist2);
268 double minDist2 = (-0.1),
bool sort =
true,
vtkDoubleArray* petals =
nullptr);
280 NeighborBuckets2D* buckets,
const double x[3],
const int ij[2],
double dist,
int level);
282 int prevMinLevel[2],
int prevMaxLevel[2]);
285 template <
typename T>
301 for (; ptId < end; ++ptId, ++t)
311 template <
typename T,
typename TPts>
326 const TPts* x = this->Points + 3 * ptId;
328 for (; ptId < end; ++ptId, x += 3, ++t)
330 p[0] =
static_cast<double>(x[0]);
331 p[1] =
static_cast<double>(x[1]);
342 template <
typename T>
352 this->NumPts = this->BList->
NumPts;
359 T* offsets = this->BList->
Offsets;
364 endBatchPt = (endBatchPt > endPt ? endPt : endBatchPt);
369 if (curPt == this->BList->
Map)
371 prevPt = this->BList->
Map;
372 std::fill_n(offsets, curPt->
Bucket + 1, 0);
387 for (curPt = prevPt; curPt < endBatchPt;)
389 for (; curPt->
Bucket == prevPt->
Bucket && curPt <= endBatchPt; ++curPt)
395 offsets + prevPt->
Bucket + 1, curPt->
Bucket - prevPt->
Bucket, curPt - this->BList->Map);
403 template <
typename T>
414 this->DataSet = blist->
DataSet;
426 for (; bucket < endBucket; ++bucket)
430 ids = bList->
GetIds(bucket);
431 for (i = 0; i < numIds; i++)
434 if (mergeMap[ptId] < 0)
436 mergeMap[ptId] = ptId;
438 for (j = i + 1; j < numIds; j++)
441 if (mergeMap[ptId2] < 0)
444 if (p[0] == p2[0] && p[1] == p2[1])
446 mergeMap[ptId2] = ptId;
461 template <
typename T>
476 this->DataSet = blist->
DataSet;
495 for (; ptId < endPtId; ++ptId)
497 if (mergeMap[ptId] < 0)
499 mergeMap[ptId] = ptId;
504 for (i = 0; i < numIds; i++)
506 nearId = nearby->
GetId(i);
507 if (ptId < nearId && (mergeMap[nearId] < 0 || ptId < mergeMap[nearId]))
509 mergeMap[nearId] = ptId;
558 int numBatches =
static_cast<int>(ceil(
static_cast<double>(this->
NumPts) / this->
BatchSize));
object to represent cell connectivity
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.
concrete class for storing a set of points
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.
quickly locate points in 2-space
void GetBounds(double *bounds) override
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 directions.
MapDataSet(BucketList2D< T > *blist, vtkDataSet *ds)
void operator()(vtkIdType ptId, vtkIdType end)
BucketList2D< T > * BList
MapOffsets(BucketList2D< T > *blist)
BucketList2D< T > * BList
void operator()(vtkIdType batch, vtkIdType batchEnd)
MapPointsArray(BucketList2D< T > *blist, const TPts *pts)
BucketList2D< T > * BList
void operator()(vtkIdType ptId, vtkIdType end)
BucketList2D< T > * BList
MergeClose(BucketList2D< T > *blist, double tol, vtkIdType *mergeMap)
vtkSMPThreadLocalObject< vtkIdList > PIds
void operator()(vtkIdType ptId, vtkIdType endPtId)
BucketList2D< T > * BList
void operator()(vtkIdType bucket, vtkIdType endBucket)
MergePrecise(BucketList2D< T > *blist, vtkIdType *mergeMap)
void FindClosestNPoints(int N, const double x[3], vtkIdList *result)
double FindCloseNBoundedPoints(int N, const double x[3], vtkIdList *result)
const vtkLocatorTuple< TIds > * GetIds(vtkIdType bucketNum)
BucketList2D(vtkStaticPointLocator2D *loc, vtkIdType numPts, int numBuckets)
void MergePoints(double tol, vtkIdType *pointMap)
void GetOverlappingBuckets(NeighborBuckets2D *buckets, const double x[3], const int ij[2], double dist, int level)
void GetOverlappingBuckets(NeighborBuckets2D *buckets, const double x[3], double dist, int prevMinLevel[2], int prevMaxLevel[2])
void BuildLocator() override
vtkLocatorTuple< TIds > * Map
void FindPointsWithinRadius(double R, const double x[3], vtkIdList *result)
int IntersectWithLine(double a0[3], double a1[3], double tol, double &t, double lineX[3], double ptX[3], vtkIdType &ptId)
vtkIdType GetNumberOfIds(vtkIdType bucketNum)
bool BucketIntersectsCircle(int i, int j, const double center[3], double R2)
void GetIds(vtkIdType bucketNum, vtkIdList *bList)
vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double inputDataLength, double &dist2)
vtkIdType FindClosestPoint(const double x[3])
double FindNPointsInAnnulus(int N, const double x[3], vtkDist2TupleArray &results, double minDist2=(-0.1), bool sort=true, vtkDoubleArray *petals=nullptr)
void GenerateRepresentation(int level, vtkPolyData *pd)
double Distance2ToBucket(const double x[3], const int nei[3])
void GetBucketBounds(int i, int j, double min[3], double max[3])
double Distance2ToBounds(const double x[3], const double bounds[6])
void GetBucketIndices(const double *x, int ij[2]) const
void GenerateFace(int face, int i, int j, int k, vtkPoints *pts, vtkCellArray *polys)
vtkIdType GetBucketIndex(const double *x) const
virtual ~vtkBucketList2D()=default
vtkStaticPointLocator2D * Locator
virtual void BuildLocator()=0
void GetBucketCenter(int i, int j, double center[3])
void GetBucketNeighbors(NeighborBuckets2D *buckets, const int ij[2], const int ndivs[2], int level)
vtkBucketList2D(vtkStaticPointLocator2D *loc, vtkIdType numPts, int numBuckets)
Represent an array of vtkDist2Tuples.
bool InsideCircle(const double min[2], const double max[2], const double center[2], double r2)
Performant method to determine if a box if fully inside a circle.
bool IntersectsCircle(const double min[2], const double max[2], const double center[2], double r2)
Performant method to intersect a box with a circle.