VTK  9.2.6
vtkIncrementalOctreeNode.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkIncrementalOctreeNode.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
62 #ifndef vtkIncrementalOctreeNode_h
63 #define vtkIncrementalOctreeNode_h
64 
65 #include "vtkCommonDataModelModule.h" // For export macro
66 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
67 #include "vtkObject.h"
68 
69 class vtkPoints;
70 class vtkIdList;
71 
72 class VTKCOMMONDATAMODEL_EXPORT vtkIncrementalOctreeNode : public vtkObject
73 {
74 public:
76  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
78  static vtkIncrementalOctreeNode* New();
79 
81 
84  vtkGetMacro(NumberOfPoints, int);
86 
88 
91  vtkGetObjectMacro(PointIdSet, vtkIdList);
93 
97  void DeleteChildNodes();
98 
103  void SetBounds(double x1, double x2, double y1, double y2, double z1, double z2);
104 
109  void GetBounds(double bounds[6]) const;
110 
112 
115  vtkGetVector3Macro(MinBounds, double);
117 
119 
122  vtkGetVector3Macro(MaxBounds, double);
124 
130  {
131  return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds;
132  }
133 
139  {
140  return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds;
141  }
142 
146  int IsLeaf() { return (this->Children == nullptr) ? 1 : 0; }
147 
153  int GetChildIndex(const double point[3]);
154 
159  vtkIncrementalOctreeNode* GetChild(int i) { return this->Children[i]; }
160 
165  vtkTypeBool ContainsPoint(const double pnt[3]);
166 
171  vtkTypeBool ContainsPointByData(const double pnt[3]);
172 
174 
191  VTK_DEPRECATED_IN_9_1_0("Use the version with numberOfNodes parameter instead.")
192  int InsertPoint(
193  vtkPoints* points, const double newPnt[3], int maxPts, vtkIdType* pntId, int ptMode);
194  int InsertPoint(vtkPoints* points, const double newPnt[3], int maxPts, vtkIdType* pntId,
195  int ptMode, int& numberOfNodes);
197 
203  double GetDistance2ToInnerBoundary(const double point[3], vtkIncrementalOctreeNode* rootNode);
204 
210  double GetDistance2ToBoundary(
211  const double point[3], vtkIncrementalOctreeNode* rootNode, int checkData);
212 
218  double GetDistance2ToBoundary(
219  const double point[3], double closest[3], vtkIncrementalOctreeNode* rootNode, int checkData);
220 
225  void ExportAllPointIdsByInsertion(vtkIdList* idList);
226 
233  void ExportAllPointIdsByDirectSet(vtkIdType* pntIdx, vtkIdList* idList);
235 
240  int GetNumberOfLevels() const;
246  int GetID() const { return this->ID; }
247  vtkIdList* GetPointIds() const { return this->PointIdSet; }
248 
249 protected:
251  ~vtkIncrementalOctreeNode() override;
252 
253 private:
257  int NumberOfPoints;
258 
262  double MinBounds[3];
263 
267  double MaxBounds[3];
268 
274  double MinDataBounds[3];
275 
281  double MaxDataBounds[3];
282 
287  vtkIdList* PointIdSet;
288 
294  int ID;
295 
299  vtkIncrementalOctreeNode* Parent;
300 
304  vtkIncrementalOctreeNode** Children;
305 
309  virtual void SetParent(vtkIncrementalOctreeNode*);
310 
314  virtual void SetPointIdSet(vtkIdList*);
315 
334  int CreateChildNodes(vtkPoints* points, vtkIdList* pntIds, const double newPnt[3],
335  vtkIdType* pntIdx, int maxPts, int ptMode, int& numberOfNodes);
336 
341  void CreatePointIdSet(int initSize, int growSize);
342 
346  void DeletePointIdSet();
347 
353  void UpdateCounterAndDataBounds(const double point[3]);
354 
364  int UpdateCounterAndDataBounds(const double point[3], int nHits, int updateData);
365 
376  int UpdateCounterAndDataBoundsRecursively(
377  const double point[3], int nHits, int updateData, vtkIncrementalOctreeNode* endNode);
378 
385  int ContainsDuplicatePointsOnly(const double pnt[3]);
386 
400  void SeperateExactlyDuplicatePointsFromNewInsertion(vtkPoints* points, vtkIdList* pntIds,
401  const double newPnt[3], vtkIdType* pntIdx, int maxPts, int ptMode);
402 
410  double GetDistance2ToBoundary(const double point[3], double closest[3], int innerOnly,
411  vtkIncrementalOctreeNode* rootNode, int checkData = 0);
412 
414  void operator=(const vtkIncrementalOctreeNode&) = delete;
415 };
416 
417 // In-lined for performance
419 {
420  // Children[0]->MaxBounds[] is exactly the center point of this node.
421  return int(point[0] > this->Children[0]->MaxBounds[0]) +
422  ((int(point[1] > this->Children[0]->MaxBounds[1])) << 1) +
423  ((int(point[2] > this->Children[0]->MaxBounds[2])) << 2);
424 }
425 
426 // In-lined for performance
428 {
429  return (
430  (this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] && this->MinBounds[1] < pnt[1] &&
431  pnt[1] <= this->MaxBounds[1] && this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2])
432  ? 1
433  : 0);
434 }
435 
436 // In-lined for performance
438 {
439  return ((this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
440  this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
441  this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2])
442  ? 1
443  : 0);
444 }
445 
446 // In-lined for performance
447 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly(const double pnt[3])
448 {
449  return ((this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
450  this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
451  this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2])
452  ? 1
453  : 0);
454 }
455 
456 // In-lined for performance
457 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds(const double point[3])
458 {
459  this->NumberOfPoints++;
460 
461  this->MinDataBounds[0] = (point[0] < this->MinDataBounds[0]) ? point[0] : this->MinDataBounds[0];
462  this->MinDataBounds[1] = (point[1] < this->MinDataBounds[1]) ? point[1] : this->MinDataBounds[1];
463  this->MinDataBounds[2] = (point[2] < this->MinDataBounds[2]) ? point[2] : this->MinDataBounds[2];
464  this->MaxDataBounds[0] = (point[0] > this->MaxDataBounds[0]) ? point[0] : this->MaxDataBounds[0];
465  this->MaxDataBounds[1] = (point[1] > this->MaxDataBounds[1]) ? point[1] : this->MaxDataBounds[1];
466  this->MaxDataBounds[2] = (point[2] > this->MaxDataBounds[2]) ? point[2] : this->MaxDataBounds[2];
467 }
468 
469 // In-lined for performance
470 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively(
471  const double point[3], int nHits, int updateData, vtkIncrementalOctreeNode* endNode)
472 {
473  int updated = this->UpdateCounterAndDataBounds(point, nHits, updateData);
474 
475  return ((this->Parent == endNode)
476  ? updated
477  : this->Parent->UpdateCounterAndDataBoundsRecursively(point, nHits, updated, endNode));
478 }
479 #endif
int IsLeaf()
Determine whether or not this node is a leaf.
double * GetMaxDataBounds()
Get access to MaxDataBounds.
#define VTK_DEPRECATED_IN_9_1_0(reason)
void GetBounds(T a, double bds[6])
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:332
int vtkTypeBool
Definition: vtkABI.h:69
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:33
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]...
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:39