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 "vtkObject.h"
62 
63 class vtkPoints;
64 class vtkIdList;
65 
67 {
68 public:
70  void PrintSelf( ostream & os, vtkIndent indent );
71 
72  static vtkIncrementalOctreeNode * New();
73 
75 
76  vtkGetMacro( NumberOfPoints, int );
78 
80 
81  vtkGetObjectMacro( PointIdSet, vtkIdList );
83 
85  void DeleteChildNodes();
86 
88 
90  void SetBounds( double x1, double x2, double y1,
91  double y2, double z1, double z2 );
93 
96  void GetBounds( double bounds[6] ) const;
97 
99 
100  vtkGetVector3Macro( MinBounds, double );
102 
104 
105  vtkGetVector3Macro( MaxBounds, double );
107 
109 
111  double * GetMinDataBounds()
112  { return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds; }
114 
116 
118  double * GetMaxDataBounds()
119  { return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds; }
121 
123  int IsLeaf() { return ( this->Children == NULL ) ? 1 : 0; }
124 
128  int GetChildIndex( const double point[3] );
129 
133  vtkIncrementalOctreeNode * GetChild( int i ) { return this->Children[i]; }
134 
138  int ContainsPoint( const double pnt[3] );
139 
142  int ContainsPointByData( const double pnt[3] );
143 
145 
157  int InsertPoint( vtkPoints * points, const double newPnt[3],
158  int maxPts, vtkIdType * pntId, int ptMode );
160 
162 
165  double GetDistance2ToInnerBoundary( const double point[3],
166  vtkIncrementalOctreeNode * rootNode );
168 
170 
173  double GetDistance2ToBoundary( const double point[3],
174  vtkIncrementalOctreeNode * rootNode, int checkData );
176 
178 
182  double GetDistance2ToBoundary( const double point[3], double closest[3],
183  vtkIncrementalOctreeNode * rootNode, int checkData );
185 
189  void ExportAllPointIdsByInsertion( vtkIdList * idList );
190 
195  void ExportAllPointIdsByDirectSet( vtkIdType * pntIdx, vtkIdList * idList );
196 
197 //BTX
198 protected:
199 
202 
203 private:
204 
206  int NumberOfPoints;
207 
209  double MinBounds[3];
210 
212  double MaxBounds[3];
213 
218  double MinDataBounds[3];
219 
224  double MaxDataBounds[3];
225 
228  vtkIdList * PointIdSet;
229 
231  vtkIncrementalOctreeNode * Parent;
232 
234  vtkIncrementalOctreeNode ** Children;
235 
237  virtual void SetParent( vtkIncrementalOctreeNode * );
238 
240  virtual void SetPointIdSet( vtkIdList * );
241 
243 
260  int CreateChildNodes( vtkPoints * points, vtkIdList * pntIds,
261  const double newPnt[3], vtkIdType * pntIdx, int maxPts, int ptMode );
263 
266  void CreatePointIdSet( int initSize, int growSize );
267 
269  void DeletePointIdSet();
270 
274  void UpdateCounterAndDataBounds( const double point[3] );
275 
277 
285  int UpdateCounterAndDataBounds
286  ( const double point[3], int nHits, int updateData );
288 
290 
299  int UpdateCounterAndDataBoundsRecursively( const double point[3], int nHits,
300  int updateData, vtkIncrementalOctreeNode * endNode );
302 
307  int ContainsDuplicatePointsOnly( const double pnt[3] );
308 
310 
322  void SeperateExactlyDuplicatePointsFromNewInsertion( vtkPoints * points,
323  vtkIdList * pntIds, const double newPnt[3],
324  vtkIdType * pntIdx, int maxPts, int ptMode );
326 
328 
333  double GetDistance2ToBoundary( const double point[3], double closest[3],
334  int innerOnly, vtkIncrementalOctreeNode* rootNode, int checkData = 0 );
336 
337  vtkIncrementalOctreeNode( const vtkIncrementalOctreeNode & );// Not implemented
338  void operator = ( const vtkIncrementalOctreeNode & ); // Not implemented
339 //ETX
340 };
341 
342 // In-lined for performance
343 inline int vtkIncrementalOctreeNode::GetChildIndex( const double point[3] )
344 {
345  // Children[0]->MaxBounds[] is exactly the center point of this node.
346  return int( point[0] > this->Children[0]->MaxBounds[0] ) +
347  ( ( int( point[1] > this->Children[0]->MaxBounds[1] ) ) << 1 ) +
348  ( ( int( point[2] > this->Children[0]->MaxBounds[2] ) ) << 2 );
349 }
350 
351 // In-lined for performance
352 inline int vtkIncrementalOctreeNode::ContainsPoint( const double pnt[3] )
353 {
354  return (
355  ( this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] &&
356  this->MinBounds[1] < pnt[1] && pnt[1] <= this->MaxBounds[1] &&
357  this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2]
358  ) ? 1 : 0
359  );
360 }
361 
362 // In-lined for performance
363 inline int vtkIncrementalOctreeNode::ContainsPointByData( const double pnt[3] )
364 {
365  return
366  (
367  ( this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
368  this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
369  this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2]
370  ) ? 1 : 0
371  );
372 }
373 
374 // In-lined for performance
375 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly
376  ( const double pnt[3] )
377 {
378  return
379  (
380  ( this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
381  this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
382  this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2]
383  ) ? 1 : 0
384  );
385 }
386 
387 // In-lined for performance
388 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds
389  ( const double point[3] )
390 {
391  this->NumberOfPoints ++;
392 
393  this->MinDataBounds[0] = ( point[0] < this->MinDataBounds[0] )
394  ? point[0] : this->MinDataBounds[0];
395  this->MinDataBounds[1] = ( point[1] < this->MinDataBounds[1] )
396  ? point[1] : this->MinDataBounds[1];
397  this->MinDataBounds[2] = ( point[2] < this->MinDataBounds[2] )
398  ? point[2] : this->MinDataBounds[2];
399  this->MaxDataBounds[0] = ( point[0] > this->MaxDataBounds[0] )
400  ? point[0] : this->MaxDataBounds[0];
401  this->MaxDataBounds[1] = ( point[1] > this->MaxDataBounds[1] )
402  ? point[1] : this->MaxDataBounds[1];
403  this->MaxDataBounds[2] = ( point[2] > this->MaxDataBounds[2] )
404  ? point[2] : this->MaxDataBounds[2];
405 }
406 
407 // In-lined for performance
408 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively
409  ( const double point[3], int nHits, int updateData,
410  vtkIncrementalOctreeNode * endNode )
411 {
412  int updated = this->UpdateCounterAndDataBounds
413  ( point, nHits, updateData );
414 
415  return ( ( this->Parent == endNode )
416  ? updated
417  : this->Parent->UpdateCounterAndDataBoundsRecursively
418  ( point, nHits, updated, endNode )
419  );
420 }
421 #endif