13 #ifndef vtkStaticPointLocator2DPrivate_h
14 #define vtkStaticPointLocator2DPrivate_h
30 VTK_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]);
72 if (min[i] <= center[i] && center[i] <= max[i])
74 dmin += std::min(a, b);
77 return (!(dmin <= r2 && r2 <= dmax));
94 struct NeighborBuckets2D;
124 this->NumPts = numPts;
125 this->NumBuckets = numBuckets;
126 this->BatchSize = 10000;
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);
174 vtkIdType tmp0 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[0] -
bX) * fX);
175 vtkIdType tmp1 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[1] -
bY) * fY);
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);
231 template <
typename TIds>
244 this->Map[numPts].
Bucket = numBuckets;
245 this->Offsets =
new TIds[numBuckets + 1];
246 this->Offsets[numBuckets] = numPts;
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);
293 int IntersectWithLine(
double a0[3],
double a1[3],
double tol,
double& t,
double lineX[3],
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>
348 auto x = vtk::DataArrayTupleRange<3>(this->
Points, ptId, end).begin();
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;
556 MapPointsArrayWorker worker;
578 int numBatches =
static_cast<int>(ceil(static_cast<double>(this->
NumPts) / this->
BatchSize));
579 MapOffsets<TIds> offMapper(
this);
584 VTK_ABI_NAMESPACE_END
585 #endif // vtkStaticPointLocator2DPrivate_h
void FindClosestNPoints(int N, const double x[3], vtkIdList *result)
void operator()(vtkIdType batch, vtkIdType batchEnd)
virtual vtkPoints * GetPoints()
If the subclass has (implicit/explicit) points, then return them.
void operator()(vtkIdType ptId, vtkIdType end)
bool BucketInsideCircle(int i, int j, const double center[3], double r2)
void GetOverlappingBuckets(NeighborBuckets2D *buckets, const double x[3], const int ij[2], double dist, int level)
const vtkLocatorTuple< TIds > * GetIds(vtkIdType bucketNum)
virtual ~vtkBucketList2D()=default
void GetBucketCenter(int i, int j, double center[3])
void GenerateFace(int face, int i, int j, int k, vtkPoints *pts, vtkCellArray *polys)
void GetIds(vtkIdType bucketNum, vtkIdList *bList)
abstract class to specify dataset behavior
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
MapDataSet(BucketList2D< T > *blist, vtkDataSet *ds)
BucketList2D< T > * BList
vtkIdType GetNumberOfIds(vtkIdType bucketNum)
virtual double * GetSpacing()
Provide an accessor to the bucket spacing.
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.
bool BucketIntersectsCircle(int i, int j, const double center[3], double R2)
concrete dataset represents vertices, lines, polygons, and triangle strips
MapOffsets(BucketList2D< T > *blist)
vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double inputDataLength, double &dist2)
BucketList2D< T > * BList
static vtkDoubleArray * SafeDownCast(vtkObjectBase *o)
dynamic, self-adjusting array of double
MergeClose(BucketList2D< T > *blist, double tol, vtkIdType *mergeMap)
virtual int * GetDivisions()
Set the number of divisions in x-y directions.
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.
void GetBucketIndices(const double *x, int ij[2]) const
vtkIdType GetId(vtkIdType i)
Return the id at location i.
void SetId(vtkIdType i, vtkIdType id)
Set the id at location i.
virtual vtkDataSet * GetDataSet()
Build the locator from the points/cells defining this dataset.
int IntersectWithLine(double a0[3], double a1[3], double tol, double &t, double lineX[3], double ptX[3], vtkIdType &ptId)
vtkIdType GetBucketIndex(const double *x) const
list of point or cell ids
void MergePoints(double tol, vtkIdType *pointMap)
void GetBucketNeighbors(NeighborBuckets2D *buckets, const int ij[2], const int ndivs[2], int level)
vtkLocatorTuple< TIds > * Map
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
vtkSMPThreadLocalObject< vtkIdList > PIds
BucketList2D< T > * BList
void GetBounds(double *bounds) override
Provide an accessor to the bounds.
Private declarations for 2D binned spatial locator.
double Distance2ToBucket(const double x[3], const int nei[3])
void GenerateRepresentation(int level, vtkPolyData *pd)
vtkStaticPointLocator2D * Locator
vtkTypeBool Reserve(vtkIdType size)
Reserve the id list to the requested number of ids and preserve data.
object to represent cell connectivity
double FindNPointsInAnnulus(int N, const double x[3], vtkDist2TupleArray &results, double minDist2=(-0.1), bool sort=true, vtkDoubleArray *petals=nullptr)
Represent an array of vtkDist2Tuples.
double Distance2ToBounds(const double x[3], const double bounds[6])
BucketList2D(vtkStaticPointLocator2D *loc, vtkIdType numPts, int numBuckets)
BucketList2D< T > * BList
BucketList2D< T > * BList
vtkIdType FindClosestPoint(const double x[3])
void GetBucketBounds(int i, int j, double min[3], double max[3])
void FindPointsWithinRadius(double R, const double x[3], vtkIdList *result)
virtual double * GetPoint(vtkIdType ptId)=0
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
double FindCloseNBoundedPoints(int N, const double x[3], vtkIdList *result)
MergePrecise(BucketList2D< T > *blist, vtkIdType *mergeMap)
T *& Local()
Returns an object local to the current thread.
void operator()(vtkIdType bucket, vtkIdType endBucket)
void BuildLocator() override
void operator()(vtkIdType ptId, vtkIdType end)
void operator()(vtkIdType ptId, vtkIdType endPtId)
MapPointsArray(BucketList2D< T > *blist, TPointsArray *pts)
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
represent and manipulate 3D points
Dispatch a single array against all array types mentioned in the ArrayList template parameter...
vtkBucketList2D(vtkStaticPointLocator2D *loc, vtkIdType numPts, int numBuckets)
quickly locate points in 2-space
virtual void BuildLocator()=0
STL-compatible iterable ranges that provide access to vtkDataArray elements.
void operator()(TPointsArray *points, BucketList2D *blist)