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 =========================================================================*/
58 #ifndef vtkIncrementalOctreeNode_h
59 #define vtkIncrementalOctreeNode_h
60 
61 #include "vtkCommonDataModelModule.h" // For export macro
62 #include "vtkObject.h"
63 
64 class vtkPoints;
65 class vtkIdList;
66 
68 {
69 public:
71  void PrintSelf( ostream & os, vtkIndent indent );
72 
73  static vtkIncrementalOctreeNode * New();
74 
76 
77  vtkGetMacro( NumberOfPoints, int );
79 
81 
82  vtkGetObjectMacro( PointIdSet, vtkIdList );
84 
86  void DeleteChildNodes();
87 
89 
91  void SetBounds( double x1, double x2, double y1,
92  double y2, double z1, double z2 );
94 
97  void GetBounds( double bounds[6] ) const;
98 
100 
101  vtkGetVector3Macro( MinBounds, double );
103 
105 
106  vtkGetVector3Macro( MaxBounds, double );
108 
110 
112  double * GetMinDataBounds()
113  { return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds; }
115 
117 
119  double * GetMaxDataBounds()
120  { return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds; }
122 
124  int IsLeaf() { return ( this->Children == NULL ) ? 1 : 0; }
125 
129  int GetChildIndex( const double point[3] );
130 
134  vtkIncrementalOctreeNode * GetChild( int i ) { return this->Children[i]; }
135 
139  int ContainsPoint( const double pnt[3] );
140 
143  int ContainsPointByData( const double pnt[3] );
144 
146 
158  int InsertPoint( vtkPoints * points, const double newPnt[3],
159  int maxPts, vtkIdType * pntId, int ptMode );
161 
163 
166  double GetDistance2ToInnerBoundary( const double point[3],
167  vtkIncrementalOctreeNode * rootNode );
169 
171 
174  double GetDistance2ToBoundary( const double point[3],
175  vtkIncrementalOctreeNode * rootNode, int checkData );
177 
179 
183  double GetDistance2ToBoundary( const double point[3], double closest[3],
184  vtkIncrementalOctreeNode * rootNode, int checkData );
186 
190  void ExportAllPointIdsByInsertion( vtkIdList * idList );
191 
196  void ExportAllPointIdsByDirectSet( vtkIdType * pntIdx, vtkIdList * idList );
197 
198 //BTX
199 protected:
200 
203 
204 private:
205 
207  int NumberOfPoints;
208 
210  double MinBounds[3];
211 
213  double MaxBounds[3];
214 
219  double MinDataBounds[3];
220 
225  double MaxDataBounds[3];
226 
229  vtkIdList * PointIdSet;
230 
232  vtkIncrementalOctreeNode * Parent;
233 
235  vtkIncrementalOctreeNode ** Children;
236 
238  virtual void SetParent( vtkIncrementalOctreeNode * );
239 
241  virtual void SetPointIdSet( vtkIdList * );
242 
244 
261  int CreateChildNodes( vtkPoints * points, vtkIdList * pntIds,
262  const double newPnt[3], vtkIdType * pntIdx, int maxPts, int ptMode );
264 
267  void CreatePointIdSet( int initSize, int growSize );
268 
270  void DeletePointIdSet();
271 
275  void UpdateCounterAndDataBounds( const double point[3] );
276 
278 
286  int UpdateCounterAndDataBounds
287  ( const double point[3], int nHits, int updateData );
289 
291 
300  int UpdateCounterAndDataBoundsRecursively( const double point[3], int nHits,
301  int updateData, vtkIncrementalOctreeNode * endNode );
303 
308  int ContainsDuplicatePointsOnly( const double pnt[3] );
309 
311 
323  void SeperateExactlyDuplicatePointsFromNewInsertion( vtkPoints * points,
324  vtkIdList * pntIds, const double newPnt[3],
325  vtkIdType * pntIdx, int maxPts, int ptMode );
327 
329 
334  double GetDistance2ToBoundary( const double point[3], double closest[3],
335  int innerOnly, vtkIncrementalOctreeNode* rootNode, int checkData = 0 );
337 
338  vtkIncrementalOctreeNode( const vtkIncrementalOctreeNode & );// Not implemented
339  void operator = ( const vtkIncrementalOctreeNode & ); // Not implemented
340 //ETX
341 };
342 
343 // In-lined for performance
344 inline int vtkIncrementalOctreeNode::GetChildIndex( const double point[3] )
345 {
346  // Children[0]->MaxBounds[] is exactly the center point of this node.
347  return int( point[0] > this->Children[0]->MaxBounds[0] ) +
348  ( ( int( point[1] > this->Children[0]->MaxBounds[1] ) ) << 1 ) +
349  ( ( int( point[2] > this->Children[0]->MaxBounds[2] ) ) << 2 );
350 }
351 
352 // In-lined for performance
353 inline int vtkIncrementalOctreeNode::ContainsPoint( const double pnt[3] )
354 {
355  return (
356  ( this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] &&
357  this->MinBounds[1] < pnt[1] && pnt[1] <= this->MaxBounds[1] &&
358  this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2]
359  ) ? 1 : 0
360  );
361 }
362 
363 // In-lined for performance
364 inline int vtkIncrementalOctreeNode::ContainsPointByData( const double pnt[3] )
365 {
366  return
367  (
368  ( this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
369  this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
370  this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2]
371  ) ? 1 : 0
372  );
373 }
374 
375 // In-lined for performance
376 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly
377  ( const double pnt[3] )
378 {
379  return
380  (
381  ( this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
382  this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
383  this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2]
384  ) ? 1 : 0
385  );
386 }
387 
388 // In-lined for performance
389 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds
390  ( const double point[3] )
391 {
392  this->NumberOfPoints ++;
393 
394  this->MinDataBounds[0] = ( point[0] < this->MinDataBounds[0] )
395  ? point[0] : this->MinDataBounds[0];
396  this->MinDataBounds[1] = ( point[1] < this->MinDataBounds[1] )
397  ? point[1] : this->MinDataBounds[1];
398  this->MinDataBounds[2] = ( point[2] < this->MinDataBounds[2] )
399  ? point[2] : this->MinDataBounds[2];
400  this->MaxDataBounds[0] = ( point[0] > this->MaxDataBounds[0] )
401  ? point[0] : this->MaxDataBounds[0];
402  this->MaxDataBounds[1] = ( point[1] > this->MaxDataBounds[1] )
403  ? point[1] : this->MaxDataBounds[1];
404  this->MaxDataBounds[2] = ( point[2] > this->MaxDataBounds[2] )
405  ? point[2] : this->MaxDataBounds[2];
406 }
407 
408 // In-lined for performance
409 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively
410  ( const double point[3], int nHits, int updateData,
411  vtkIncrementalOctreeNode * endNode )
412 {
413  int updated = this->UpdateCounterAndDataBounds
414  ( point, nHits, updateData );
415 
416  return ( ( this->Parent == endNode )
417  ? updated
418  : this->Parent->UpdateCounterAndDataBoundsRecursively
419  ( point, nHits, updated, endNode )
420  );
421 }
422 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:61
int ContainsPoint(const double pnt[3])
int ContainsPointByData(const double pnt[3])
int vtkIdType
Definition: vtkType.h:275
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
list of point or cell ids
Definition: vtkIdList.h:35
Octree node constituting incremental octree (in support of both point location and point insertion) ...
vtkIncrementalOctreeNode * GetChild(int i)
static vtkObject * New()
int GetChildIndex(const double point[3])
#define VTKCOMMONDATAMODEL_EXPORT
represent and manipulate 3D points
Definition: vtkPoints.h:38