VTK  9.0.1
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 
75 
77 
80  vtkGetMacro(NumberOfPoints, int);
82 
84 
87  vtkGetObjectMacro(PointIdSet, vtkIdList);
89 
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 
183  vtkPoints* points, const double newPnt[3], int maxPts, vtkIdType* pntId, int ptMode);
184 
190  double GetDistance2ToInnerBoundary(const double point[3], vtkIncrementalOctreeNode* rootNode);
191 
198  const double point[3], vtkIncrementalOctreeNode* rootNode, int checkData);
199 
206  const double point[3], double closest[3], vtkIncrementalOctreeNode* rootNode, int checkData);
207 
213 
221 
222 protected:
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
list of point or cell ids
Definition: vtkIdList.h:31
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.
int InsertPoint(vtkPoints *points, const double newPnt[3], int maxPts, vtkIdType *pntId, int ptMode)
This function is called after a successful point-insertion check and only applies to a leaf node.
void GetBounds(double bounds[6]) const
Get the spatial bounding box of the node.
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:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
represent and manipulate 3D points
Definition: vtkPoints.h:34
@ point
Definition: vtkX3D.h:242
@ points
Definition: vtkX3D.h:452
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:338