VTK  9.3.1
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 
66  static vtkIncrementalOctreeNode* New();
67 
69 
72  vtkGetMacro(NumberOfPoints, int);
74 
76 
79  vtkGetObjectMacro(PointIdSet, vtkIdList);
81 
85  void DeleteChildNodes();
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 
195  double GetDistance2ToBoundary(
196  const double point[3], vtkIncrementalOctreeNode* rootNode, int checkData);
197 
203  double GetDistance2ToBoundary(
204  const double point[3], double closest[3], vtkIncrementalOctreeNode* rootNode, int checkData);
205 
210  void ExportAllPointIdsByInsertion(vtkIdList* idList);
211 
218  void ExportAllPointIdsByDirectSet(vtkIdType* pntIdx, vtkIdList* idList);
219 
225  int GetNumberOfLevels() const;
231  int GetID() const { return this->ID; }
232  vtkIdList* GetPointIds() const { return this->PointIdSet; }
233 
234 protected:
236  ~vtkIncrementalOctreeNode() override;
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
int IsLeaf()
Determine whether or not this node is a leaf.
double * GetMaxDataBounds()
Get access to MaxDataBounds.
void GetBounds(T a, double bds[6])
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
int vtkIdType
Definition: vtkType.h:315
int vtkTypeBool
Definition: vtkABI.h:64
a simple class to control print indentation
Definition: vtkIndent.h:28
list of point or cell ids
Definition: vtkIdList.h:22
Octree node constituting incremental octree (in support of both point location and point insertion) ...
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 GetID() const
Returns the ID of this node which is the index of the node in the octree.
vtkIncrementalOctreeNode * GetChild(int i)
Get quick access to a child of this node.
double * GetMinDataBounds()
Get access to MinDataBounds.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
int GetChildIndex(const double point[3])
Determine which specific child / octant contains a given point.
represent and manipulate 3D points
Definition: vtkPoints.h:28