VTK
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,
100  double y2, double z1, double z2 );
101 
106  void GetBounds( double bounds[6] ) const;
107 
109 
112  vtkGetVector3Macro( MinBounds, double );
114 
116 
119  vtkGetVector3Macro( MaxBounds, double );
121 
126  double * GetMinDataBounds()
127  { return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds; }
128 
133  double * GetMaxDataBounds()
134  { return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds; }
135 
139  int IsLeaf() { return ( this->Children == nullptr ) ? 1 : 0; }
140 
146  int GetChildIndex( const double point[3] );
147 
152  vtkIncrementalOctreeNode * GetChild( int i ) { return this->Children[i]; }
153 
158  vtkTypeBool ContainsPoint( const double pnt[3] );
159 
164  vtkTypeBool ContainsPointByData( const double pnt[3] );
165 
179  int InsertPoint( vtkPoints * points, const double newPnt[3],
180  int maxPts, vtkIdType * pntId, int ptMode );
181 
187  double GetDistance2ToInnerBoundary( const double point[3],
188  vtkIncrementalOctreeNode * rootNode );
189 
195  double GetDistance2ToBoundary( const double point[3],
196  vtkIncrementalOctreeNode * rootNode, int checkData );
197 
203  double GetDistance2ToBoundary( const double point[3], double closest[3],
204  vtkIncrementalOctreeNode * rootNode, int checkData );
205 
210  void ExportAllPointIdsByInsertion( vtkIdList * idList );
211 
218  void ExportAllPointIdsByDirectSet( vtkIdType * pntIdx, vtkIdList * idList );
219 
220 protected:
221 
223  ~vtkIncrementalOctreeNode() override;
224 
225 private:
226 
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,
300  const double newPnt[3], 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
330  ( const double point[3], int nHits, int updateData );
331 
342  int UpdateCounterAndDataBoundsRecursively( const double point[3], int nHits,
343  int updateData, vtkIncrementalOctreeNode * endNode );
344 
351  int ContainsDuplicatePointsOnly( const double pnt[3] );
352 
366  void SeperateExactlyDuplicatePointsFromNewInsertion( vtkPoints * points,
367  vtkIdList * pntIds, const double newPnt[3],
368  vtkIdType * pntIdx, int maxPts, int ptMode );
369 
377  double GetDistance2ToBoundary( const double point[3], double closest[3],
378  int innerOnly, vtkIncrementalOctreeNode* rootNode, int checkData = 0 );
379 
381  void operator = ( const vtkIncrementalOctreeNode & ) = delete;
382 
383 };
384 
385 // In-lined for performance
386 inline int vtkIncrementalOctreeNode::GetChildIndex( const double point[3] )
387 {
388  // Children[0]->MaxBounds[] is exactly the center point of this node.
389  return int( point[0] > this->Children[0]->MaxBounds[0] ) +
390  ( ( int( point[1] > this->Children[0]->MaxBounds[1] ) ) << 1 ) +
391  ( ( int( point[2] > this->Children[0]->MaxBounds[2] ) ) << 2 );
392 }
393 
394 // In-lined for performance
396 {
397  return (
398  ( this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] &&
399  this->MinBounds[1] < pnt[1] && pnt[1] <= this->MaxBounds[1] &&
400  this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2]
401  ) ? 1 : 0
402  );
403 }
404 
405 // In-lined for performance
407 {
408  return
409  (
410  ( this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
411  this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
412  this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2]
413  ) ? 1 : 0
414  );
415 }
416 
417 // In-lined for performance
418 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly
419  ( const double pnt[3] )
420 {
421  return
422  (
423  ( this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
424  this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
425  this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2]
426  ) ? 1 : 0
427  );
428 }
429 
430 // In-lined for performance
431 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds
432  ( const double point[3] )
433 {
434  this->NumberOfPoints ++;
435 
436  this->MinDataBounds[0] = ( point[0] < this->MinDataBounds[0] )
437  ? point[0] : this->MinDataBounds[0];
438  this->MinDataBounds[1] = ( point[1] < this->MinDataBounds[1] )
439  ? point[1] : this->MinDataBounds[1];
440  this->MinDataBounds[2] = ( point[2] < this->MinDataBounds[2] )
441  ? point[2] : this->MinDataBounds[2];
442  this->MaxDataBounds[0] = ( point[0] > this->MaxDataBounds[0] )
443  ? point[0] : this->MaxDataBounds[0];
444  this->MaxDataBounds[1] = ( point[1] > this->MaxDataBounds[1] )
445  ? point[1] : this->MaxDataBounds[1];
446  this->MaxDataBounds[2] = ( point[2] > this->MaxDataBounds[2] )
447  ? point[2] : this->MaxDataBounds[2];
448 }
449 
450 // In-lined for performance
451 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively
452  ( const double point[3], int nHits, int updateData,
453  vtkIncrementalOctreeNode * endNode )
454 {
455  int updated = this->UpdateCounterAndDataBounds
456  ( point, nHits, updateData );
457 
458  return ( ( this->Parent == endNode )
459  ? updated
460  : this->Parent->UpdateCounterAndDataBoundsRecursively
461  ( point, nHits, updated, endNode )
462  );
463 }
464 #endif
int IsLeaf()
Determine whether or not this node is a leaf.
double * GetMaxDataBounds()
Get access to MaxDataBounds.
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:347
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:36
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