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)
310 template <
typename T,
typename TPo
intsArray>
327 for (; ptId < end; ++ptId, ++x, ++t)
338 template <
typename TPo
intsArray>
350 template <
typename T>
360 this->NumPts = this->BList->
NumPts;
367 T* offsets = this->BList->
Offsets;
372 endBatchPt = (endBatchPt > endPt ? endPt : endBatchPt);
377 if (curPt == this->BList->
Map)
379 prevPt = this->BList->
Map;
380 std::fill_n(offsets, curPt->
Bucket + 1, 0);
395 for (curPt = prevPt; curPt < endBatchPt;)
397 for (; curPt->
Bucket == prevPt->
Bucket && curPt <= endBatchPt; ++curPt)
403 offsets + prevPt->
Bucket + 1, curPt->
Bucket - prevPt->
Bucket, curPt - this->BList->Map);
411 template <
typename T>
422 this->DataSet = blist->
DataSet;
434 for (; bucket < endBucket; ++bucket)
438 ids = bList->
GetIds(bucket);
439 for (i = 0; i < numIds; i++)
442 if (mergeMap[ptId] < 0)
444 mergeMap[ptId] = ptId;
446 for (j = i + 1; j < numIds; j++)
449 if (mergeMap[ptId2] < 0)
452 if (p[0] == p2[0] && p[1] == p2[1])
454 mergeMap[ptId2] = ptId;
469 template <
typename T>
484 this->DataSet = blist->
DataSet;
503 for (; ptId < endPtId; ++ptId)
505 if (mergeMap[ptId] < 0)
507 mergeMap[ptId] = ptId;
512 for (i = 0; i < numIds; i++)
514 nearId = nearby->
GetId(i);
515 if (ptId < nearId && (mergeMap[nearId] < 0 || ptId < mergeMap[nearId]))
517 mergeMap[nearId] = ptId;
532 auto points = this->
DataSet->GetPoints()->GetData();
535 points, worker,
this))
537 worker(points,
this);
549 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.
represent and manipulate 3D points
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.
VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr &array, TupleIdType start=-1, TupleIdType end=-1) -> typename detail::SelectTupleRange< ArrayTypePtr, TupleSize >::type
Generate an stl and for-range compatible range of tuple iterators from a vtkDataArray.
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)
void operator()(TPointsArray *points, BucketList2D *blist)
BucketList2D< T > * BList
void operator()(vtkIdType ptId, vtkIdType end)
MapPointsArray(BucketList2D< T > *blist, TPointsArray *pts)
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)
Dispatch a single array against all array types mentioned in the ArrayList template parameter.
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.
STL-compatible iterable ranges that provide access to vtkDataArray elements.
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.