VTK  9.0.20200605
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 =========================================================================*/
59 #ifndef vtkIncrementalOctreeNode_h
60 #define vtkIncrementalOctreeNode_h
61 
62 #include "vtkCommonDataModelModule.h" // For export macro
63 #include "vtkObject.h"
64 
65 class vtkPoints;
66 class vtkIdList;
67 
68 class VTKCOMMONDATAMODEL_EXPORT vtkIncrementalOctreeNode : public vtkObject
69 {
70 public:
72  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
74  static vtkIncrementalOctreeNode* New();
75 
77 
80  vtkGetMacro(NumberOfPoints, int);
82 
84 
87  vtkGetObjectMacro(PointIdSet, vtkIdList);
89 
93  void DeleteChildNodes();
94 
99  void SetBounds(double x1, double x2, double y1, double y2, double z1, double z2);
100 
105  void GetBounds(double bounds[6]) const;
106 
108 
111  vtkGetVector3Macro(MinBounds, double);
113 
115 
118  vtkGetVector3Macro(MaxBounds, double);
120 
126  {
127  return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds;
128  }
129 
135  {
136  return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds;
137  }
138 
142  int IsLeaf() { return (this->Children == nullptr) ? 1 : 0; }
143 
149  int GetChildIndex(const double point[3]);
150 
155  vtkIncrementalOctreeNode* GetChild(int i) { return this->Children[i]; }
156 
161  vtkTypeBool ContainsPoint(const double pnt[3]);
162 
167  vtkTypeBool ContainsPointByData(const double pnt[3]);
168 
182  int InsertPoint(
183  vtkPoints* points, const double newPnt[3], int maxPts, vtkIdType* pntId, int ptMode);
184 
190  double GetDistance2ToInnerBoundary(const double point[3], vtkIncrementalOctreeNode* rootNode);
191 
197  double GetDistance2ToBoundary(
198  const double point[3], vtkIncrementalOctreeNode* rootNode, int checkData);
199 
205  double GetDistance2ToBoundary(
206  const double point[3], double closest[3], vtkIncrementalOctreeNode* rootNode, int checkData);
207 
212  void ExportAllPointIdsByInsertion(vtkIdList* idList);
213 
220  void ExportAllPointIdsByDirectSet(vtkIdType* pntIdx, vtkIdList* idList);
221 
222 protected:
224  ~vtkIncrementalOctreeNode() override;
225 
226 private:
230  int NumberOfPoints;
231 
235  double MinBounds[3];
236 
240  double MaxBounds[3];
241 
247  double MinDataBounds[3];
248 
254  double MaxDataBounds[3];
255 
260  vtkIdList* PointIdSet;
261 
265  vtkIncrementalOctreeNode* Parent;
266 
270  vtkIncrementalOctreeNode** Children;
271 
275  virtual void SetParent(vtkIncrementalOctreeNode*);
276 
280  virtual void SetPointIdSet(vtkIdList*);
281 
299  int CreateChildNodes(vtkPoints* points, vtkIdList* pntIds, const double newPnt[3],
300  vtkIdType* pntIdx, int maxPts, int ptMode);
301 
306  void CreatePointIdSet(int initSize, int growSize);
307 
311  void DeletePointIdSet();
312 
318  void UpdateCounterAndDataBounds(const double point[3]);
319 
329  int UpdateCounterAndDataBounds(const double point[3], int nHits, int updateData);
330 
341  int UpdateCounterAndDataBoundsRecursively(
342  const double point[3], int nHits, int updateData, vtkIncrementalOctreeNode* endNode);
343 
350  int ContainsDuplicatePointsOnly(const double pnt[3]);
351 
365  void SeperateExactlyDuplicatePointsFromNewInsertion(vtkPoints* points, vtkIdList* pntIds,
366  const double newPnt[3], vtkIdType* pntIdx, int maxPts, int ptMode);
367 
375  double GetDistance2ToBoundary(const double point[3], double closest[3], int innerOnly,
376  vtkIncrementalOctreeNode* rootNode, int checkData = 0);
377 
379  void operator=(const vtkIncrementalOctreeNode&) = delete;
380 };
381 
382 // In-lined for performance
384 {
385  // Children[0]->MaxBounds[] is exactly the center point of this node.
386  return int(point[0] > this->Children[0]->MaxBounds[0]) +
387  ((int(point[1] > this->Children[0]->MaxBounds[1])) << 1) +
388  ((int(point[2] > this->Children[0]->MaxBounds[2])) << 2);
389 }
390 
391 // In-lined for performance
393 {
394  return (
395  (this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] && this->MinBounds[1] < pnt[1] &&
396  pnt[1] <= this->MaxBounds[1] && this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2])
397  ? 1
398  : 0);
399 }
400 
401 // In-lined for performance
403 {
404  return ((this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
405  this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
406  this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2])
407  ? 1
408  : 0);
409 }
410 
411 // In-lined for performance
412 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly(const double pnt[3])
413 {
414  return ((this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
415  this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
416  this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2])
417  ? 1
418  : 0);
419 }
420 
421 // In-lined for performance
422 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds(const double point[3])
423 {
424  this->NumberOfPoints++;
425 
426  this->MinDataBounds[0] = (point[0] < this->MinDataBounds[0]) ? point[0] : this->MinDataBounds[0];
427  this->MinDataBounds[1] = (point[1] < this->MinDataBounds[1]) ? point[1] : this->MinDataBounds[1];
428  this->MinDataBounds[2] = (point[2] < this->MinDataBounds[2]) ? point[2] : this->MinDataBounds[2];
429  this->MaxDataBounds[0] = (point[0] > this->MaxDataBounds[0]) ? point[0] : this->MaxDataBounds[0];
430  this->MaxDataBounds[1] = (point[1] > this->MaxDataBounds[1]) ? point[1] : this->MaxDataBounds[1];
431  this->MaxDataBounds[2] = (point[2] > this->MaxDataBounds[2]) ? point[2] : this->MaxDataBounds[2];
432 }
433 
434 // In-lined for performance
435 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively(
436  const double point[3], int nHits, int updateData, vtkIncrementalOctreeNode* endNode)
437 {
438  int updated = this->UpdateCounterAndDataBounds(point, nHits, updateData);
439 
440  return ((this->Parent == endNode)
441  ? updated
442  : this->Parent->UpdateCounterAndDataBoundsRecursively(point, nHits, updated, endNode));
443 }
444 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkIncrementalOctreeNode::IsLeaf
int IsLeaf()
Determine whether or not this node is a leaf.
Definition: vtkIncrementalOctreeNode.h:142
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkIncrementalOctreeNode::ContainsPointByData
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].
Definition: vtkIncrementalOctreeNode.h:402
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkIncrementalOctreeNode::GetChild
vtkIncrementalOctreeNode * GetChild(int i)
Get quick access to a child of this node.
Definition: vtkIncrementalOctreeNode.h:155
vtkIncrementalOctreeNode::GetMinDataBounds
double * GetMinDataBounds()
Get access to MinDataBounds.
Definition: vtkIncrementalOctreeNode.h:125
vtkX3D::points
Definition: vtkX3D.h:452
vtkX3D::point
Definition: vtkX3D.h:242
vtkBlockSortHelper::GetBounds
void GetBounds(T a, double bds[6])
Definition: vtkBlockSortHelper.h:37
vtkIncrementalOctreeNode::GetMaxDataBounds
double * GetMaxDataBounds()
Get access to MaxDataBounds.
Definition: vtkIncrementalOctreeNode.h:134
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIncrementalOctreeNode
Octree node constituting incremental octree (in support of both point location and point insertion)
Definition: vtkIncrementalOctreeNode.h:68
vtkIncrementalOctreeNode::GetChildIndex
int GetChildIndex(const double point[3])
Determine which specific child / octant contains a given point.
Definition: vtkIncrementalOctreeNode.h:383
vtkIncrementalOctreeNode::ContainsPoint
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...
Definition: vtkIncrementalOctreeNode.h:392
vtkObject.h
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69