13#ifndef vtkStaticPointLocator2DPrivate_h
14#define vtkStaticPointLocator2DPrivate_h
30VTK_ABI_NAMESPACE_BEGIN
32#define Distance2BetweenPoints2D(p1, p2) \
33 ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]))
41 const double min[2],
const double max[2],
const double center[2],
double r2)
44 for (
int i = 0; i < 2; ++i)
46 if (center[i] < min[i])
48 d2 += (center[i] - min[i]) * (center[i] - min[i]);
50 else if (center[i] >
max[i])
52 d2 += (center[i] -
max[i]) * (center[i] -
max[i]);
64 const double min[2],
const double max[2],
const double center[2],
double r2)
66 double dmin = 0.0, dmax = 0.0;
67 for (
int i = 0; i < 2; ++i)
69 double a = (center[i] - min[i]) * (center[i] - min[i]);
70 double b = (center[i] -
max[i]) * (center[i] -
max[i]);
71 dmax += std::max(a, b);
72 if (min[i] <= center[i] && center[i] <=
max[i])
74 dmin += std::min(a, b);
77 return (!(dmin <=
r2 &&
r2 <= dmax));
94struct NeighborBuckets2D;
124 this->NumPts = numPts;
125 this->NumBuckets = numBuckets;
126 this->BatchSize = 10000;
131 double spacing[3], bounds[6];
135 this->hX = this->H[0] = spacing[0];
136 this->hY = this->H[1] = spacing[1];
137 this->hX2 = this->hX / 2.0;
138 this->hY2 = this->hY / 2.0;
139 this->fX = 1.0 / spacing[0];
140 this->fY = 1.0 / spacing[1];
141 this->bX = this->Bounds[0] = bounds[0];
142 this->Bounds[1] = bounds[1];
143 this->bY = this->Bounds[2] = bounds[2];
144 this->Bounds[3] = bounds[3];
145 this->xD = this->Divisions[0];
146 this->yD = this->Divisions[1];
149 this->FastPoints =
nullptr;
150 this->BinRadius = sqrt(
hX *
hX +
hY *
hY) / 2.0;
151 this->MaxLevel = std::max({ this->xD, this->yD, this->zD });
160 NeighborBuckets2D* buckets,
const int ij[2],
const int ndivs[2],
int level);
177 ij[0] = std::min(std::max<vtkIdType>(tmp0, 0),
xD - 1);
178 ij[1] = std::min(std::max<vtkIdType>(tmp1, 0),
yD - 1);
186 return ij[0] + ij[1] *
xD;
194 center[0] = this->bX + this->hX2 + i * this->hX;
195 center[1] = this->bY + this->hY2 + j * this->hY;
203 min[0] = this->bX + i * this->hX;
204 min[1] = this->bY + j * this->hY;
206 max[0] = min[0] + this->hX;
207 max[1] = min[1] + this->hY;
216 double xMin = this->bX + i * this->hX;
217 double xMax = xMin + this->hX;
218 double yMin = this->bY + j * this->hY;
219 double yMax = yMin + this->hY;
220 double dx0 = center[0] - xMin, dx1 = center[0] - xMax;
221 double dy0 = center[1] - yMin, dy1 = center[1] - yMax;
222 double dmax2 = std::max(dx0 * dx0, dx1 * dx1) + std::max(dy0 * dy0, dy1 * dy1);
231template <
typename TIds>
244 this->Map[numPts].
Bucket = numBuckets;
245 this->Offsets =
new TIds[numBuckets + 1];
246 this->Offsets[numBuckets] = numPts;
253 delete[] this->Offsets;
260 if (bucketNum < 0 || bucketNum >= this->
NumBuckets)
264 return (this->Offsets[bucketNum + 1] - this->Offsets[bucketNum]);
270 return this->Map + this->Offsets[bucketNum];
279 for (
int i = 0; i < numIds; i++)
281 bList->
SetId(i, ids[i].PtId);
288 double radius,
const double x[3],
double inputDataLength,
double& dist2);
291 double minDist2 = (-0.1),
bool sort =
true,
vtkDoubleArray* petals =
nullptr);
303 NeighborBuckets2D* buckets,
const double x[3],
const int ij[2],
double dist,
int level);
305 int prevMinLevel[2],
int prevMaxLevel[2]);
308 template <
typename T>
324 for (; ptId < end; ++ptId, ++t)
333 template <
typename T,
typename TPo
intsArray>
350 for (; ptId < end; ++ptId, ++x, ++t)
361 template <
typename TPo
intsArray>
373 template <
typename T>
383 this->NumPts = this->BList->
NumPts;
390 T* offsets = this->BList->
Offsets;
395 endBatchPt = (endBatchPt > endPt ? endPt : endBatchPt);
400 if (curPt == this->BList->
Map)
402 prevPt = this->BList->
Map;
403 std::fill_n(offsets, curPt->
Bucket + 1, 0);
418 for (curPt = prevPt; curPt < endBatchPt;)
420 for (; curPt->
Bucket == prevPt->
Bucket && curPt <= endBatchPt; ++curPt)
426 offsets + prevPt->
Bucket + 1, curPt->
Bucket - prevPt->
Bucket, curPt - this->BList->Map);
434 template <
typename T>
445 this->DataSet = blist->
DataSet;
457 for (; bucket < endBucket; ++bucket)
461 ids = bList->
GetIds(bucket);
462 for (i = 0; i < numIds; i++)
465 if (mergeMap[ptId] < 0)
467 mergeMap[ptId] = ptId;
469 for (j = i + 1; j < numIds; j++)
472 if (mergeMap[ptId2] < 0)
475 if (p[0] == p2[0] && p[1] == p2[1])
477 mergeMap[ptId2] = ptId;
492 template <
typename T>
507 this->DataSet = blist->
DataSet;
526 for (; ptId < endPtId; ++ptId)
528 if (mergeMap[ptId] < 0)
530 mergeMap[ptId] = ptId;
535 for (i = 0; i < numIds; i++)
537 nearId = nearby->
GetId(i);
538 if (ptId < nearId && (mergeMap[nearId] < 0 || ptId < mergeMap[nearId]))
540 mergeMap[nearId] = ptId;
555 auto points = this->
DataSet->GetPoints()->GetData();
558 points, worker,
this))
560 worker(points,
this);
578 int numBatches =
static_cast<int>(ceil(
static_cast<double>(this->
NumPts) / this->
BatchSize));
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
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
static vtkDoubleArray * SafeDownCast(vtkObjectBase *o)
list of point or cell ids
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
vtkIdType GetId(vtkIdType i)
Return the id at location i.
void SetId(vtkIdType i, vtkIdType id)
Set the id at location i.
vtkTypeBool Reserve(vtkIdType size)
Reserve the id list to the requested number of ids and preserve data.
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.
A SafeCastFromDouble(double value)
Cast from double, and clamp to output type limits to avoid overlow.
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
bool BucketInsideCircle(int i, int j, const double center[3], double r2)
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.