VTK  9.3.20240418
vtkIncrementalOctreeNode.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
50 #ifndef vtkIncrementalOctreeNode_h
51 #define vtkIncrementalOctreeNode_h
52 
53 #include "vtkCommonDataModelModule.h" // For export macro
54 #include "vtkObject.h"
55 
56 VTK_ABI_NAMESPACE_BEGIN
57 class vtkPoints;
58 class vtkIdList;
59 
60 class VTKCOMMONDATAMODEL_EXPORT vtkIncrementalOctreeNode : public vtkObject
61 {
62 public:
64  void PrintSelf(ostream& os, vtkIndent indent) override;
65 
67 
69 
72  vtkGetMacro(NumberOfPoints, int);
74 
76 
79  vtkGetObjectMacro(PointIdSet, vtkIdList);
81 
86 
91  void SetBounds(double x1, double x2, double y1, double y2, double z1, double z2);
92 
97  void GetBounds(double bounds[6]) const;
98 
100 
103  vtkGetVector3Macro(MinBounds, double);
105 
107 
110  vtkGetVector3Macro(MaxBounds, double);
112 
118  {
119  return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds;
120  }
121 
127  {
128  return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds;
129  }
130 
134  int IsLeaf() { return (this->Children == nullptr) ? 1 : 0; }
135 
141  int GetChildIndex(const double point[3]);
142 
147  vtkIncrementalOctreeNode* GetChild(int i) { return this->Children[i]; }
148 
153  vtkTypeBool ContainsPoint(const double pnt[3]);
154 
159  vtkTypeBool ContainsPointByData(const double pnt[3]);
160 
162 
179  int InsertPoint(vtkPoints* points, const double newPnt[3], int maxPts, vtkIdType* pntId,
180  int ptMode, int& numberOfNodes);
182 
188  double GetDistance2ToInnerBoundary(const double point[3], vtkIncrementalOctreeNode* rootNode);
189 
196  const double point[3], vtkIncrementalOctreeNode* rootNode, int checkData);
197 
204  const double point[3], double closest[3], vtkIncrementalOctreeNode* rootNode, int checkData);
205 
211 
219 
225  int GetNumberOfLevels() const;
231  int GetID() const { return this->ID; }
232  vtkIdList* GetPointIds() const { return this->PointIdSet; }
233 
234 protected:
237 
238 private:
242  int NumberOfPoints;
243 
247  double MinBounds[3];
248 
252  double MaxBounds[3];
253 
259  double MinDataBounds[3];
260 
266  double MaxDataBounds[3];
267 
272  vtkIdList* PointIdSet;
273 
279  int ID;
280 
284  vtkIncrementalOctreeNode* Parent;
285 
289  vtkIncrementalOctreeNode** Children;
290 
294  virtual void SetParent(vtkIncrementalOctreeNode*);
295 
299  virtual void SetPointIdSet(vtkIdList*);
300 
319  int CreateChildNodes(vtkPoints* points, vtkIdList* pntIds, const double newPnt[3],
320  vtkIdType* pntIdx, int maxPts, int ptMode, int& numberOfNodes);
321 
326  void CreatePointIdSet(int initSize, int growSize);
327 
331  void DeletePointIdSet();
332 
338  void UpdateCounterAndDataBounds(const double point[3]);
339 
349  int UpdateCounterAndDataBounds(const double point[3], int nHits, int updateData);
350 
361  int UpdateCounterAndDataBoundsRecursively(
362  const double point[3], int nHits, int updateData, vtkIncrementalOctreeNode* endNode);
363 
370  int ContainsDuplicatePointsOnly(const double pnt[3]);
371 
385  void SeperateExactlyDuplicatePointsFromNewInsertion(vtkPoints* points, vtkIdList* pntIds,
386  const double newPnt[3], vtkIdType* pntIdx, int maxPts, int ptMode);
387 
395  double GetDistance2ToBoundary(const double point[3], double closest[3], int innerOnly,
396  vtkIncrementalOctreeNode* rootNode, int checkData = 0);
397 
399  void operator=(const vtkIncrementalOctreeNode&) = delete;
400 };
401 
402 // In-lined for performance
404 {
405  // Children[0]->MaxBounds[] is exactly the center point of this node.
406  return int(point[0] > this->Children[0]->MaxBounds[0]) +
407  ((int(point[1] > this->Children[0]->MaxBounds[1])) << 1) +
408  ((int(point[2] > this->Children[0]->MaxBounds[2])) << 2);
409 }
410 
411 // In-lined for performance
413 {
414  return (
415  (this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] && this->MinBounds[1] < pnt[1] &&
416  pnt[1] <= this->MaxBounds[1] && this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2])
417  ? 1
418  : 0);
419 }
420 
421 // In-lined for performance
423 {
424  return ((this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
425  this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
426  this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2])
427  ? 1
428  : 0);
429 }
430 
431 // In-lined for performance
432 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly(const double pnt[3])
433 {
434  return ((this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
435  this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
436  this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2])
437  ? 1
438  : 0);
439 }
440 
441 // In-lined for performance
442 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds(const double point[3])
443 {
444  this->NumberOfPoints++;
445 
446  this->MinDataBounds[0] = (point[0] < this->MinDataBounds[0]) ? point[0] : this->MinDataBounds[0];
447  this->MinDataBounds[1] = (point[1] < this->MinDataBounds[1]) ? point[1] : this->MinDataBounds[1];
448  this->MinDataBounds[2] = (point[2] < this->MinDataBounds[2]) ? point[2] : this->MinDataBounds[2];
449  this->MaxDataBounds[0] = (point[0] > this->MaxDataBounds[0]) ? point[0] : this->MaxDataBounds[0];
450  this->MaxDataBounds[1] = (point[1] > this->MaxDataBounds[1]) ? point[1] : this->MaxDataBounds[1];
451  this->MaxDataBounds[2] = (point[2] > this->MaxDataBounds[2]) ? point[2] : this->MaxDataBounds[2];
452 }
453 
454 // In-lined for performance
455 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively(
456  const double point[3], int nHits, int updateData, vtkIncrementalOctreeNode* endNode)
457 {
458  int updated = this->UpdateCounterAndDataBounds(point, nHits, updateData);
459 
460  return ((this->Parent == endNode)
461  ? updated
462  : this->Parent->UpdateCounterAndDataBoundsRecursively(point, nHits, updated, endNode));
463 }
464 VTK_ABI_NAMESPACE_END
465 #endif
list of point or cell ids
Definition: vtkIdList.h:133
Octree node constituting incremental octree (in support of both point location and point insertion)
double GetDistance2ToBoundary(const double point[3], double closest[3], vtkIncrementalOctreeNode *rootNode, int checkData)
Compute the minimum squared distance from a point to this node, with all six boundaries considered.
void GetBounds(double bounds[6]) const
Get the spatial bounding box of the node.
int InsertPoint(vtkPoints *points, const double newPnt[3], int maxPts, vtkIdType *pntId, int ptMode, int &numberOfNodes)
This function is called after a successful point-insertion check and only applies to a leaf node.
int GetNumberOfLevels() const
Computes and returns the maximum level of the tree.
int GetID() const
Returns the ID of this node which is the index of the node in the octree.
void ExportAllPointIdsByInsertion(vtkIdList *idList)
Export all the indices of the points (contained in or under this node) by inserting them to an alloca...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
double GetDistance2ToInnerBoundary(const double point[3], vtkIncrementalOctreeNode *rootNode)
Given a point inside this node, get the minimum squared distance to all inner boundaries.
double GetDistance2ToBoundary(const double point[3], vtkIncrementalOctreeNode *rootNode, int checkData)
Compute the minimum squared distance from a point to this node, with all six boundaries considered.
static vtkIncrementalOctreeNode * New()
void DeleteChildNodes()
Delete the eight child nodes.
void SetBounds(double x1, double x2, double y1, double y2, double z1, double z2)
Set the spatial bounding box of the node.
~vtkIncrementalOctreeNode() override
vtkIncrementalOctreeNode * GetChild(int i)
Get quick access to a child of this node.
vtkTypeBool ContainsPointByData(const double pnt[3])
A point is in a node, in terms of data, if and only if MinDataBounds[i] <= p[i] <= MaxDataBounds[i].
int GetChildIndex(const double point[3])
Determine which specific child / octant contains a given point.
int IsLeaf()
Determine whether or not this node is a leaf.
vtkTypeBool ContainsPoint(const double pnt[3])
A point is in a node if and only if MinBounds[i] < p[i] <= MaxBounds[i], which allows a node to be di...
double * GetMaxDataBounds()
Get access to MaxDataBounds.
double * GetMinDataBounds()
Get access to MinDataBounds.
void ExportAllPointIdsByDirectSet(vtkIdType *pntIdx, vtkIdList *idList)
Export all the indices of the points (contained in or under this node) by directly setting them in an...
a simple class to control print indentation
Definition: vtkIndent.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:162
represent and manipulate 3D points
Definition: vtkPoints.h:139
@ point
Definition: vtkX3D.h:236
@ points
Definition: vtkX3D.h:446
int vtkTypeBool
Definition: vtkABI.h:64
int vtkIdType
Definition: vtkType.h:315