VTK
dox/Filtering/vtkIncrementalOctreeNode.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkIncrementalOctreeNode.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013  
00014 =========================================================================*/
00058 #ifndef __vtkIncrementalOctreeNode_h
00059 #define __vtkIncrementalOctreeNode_h
00060 
00061 #include "vtkObject.h"
00062 
00063 class vtkPoints;
00064 class vtkIdList;
00065 
00066 class VTK_FILTERING_EXPORT vtkIncrementalOctreeNode : public vtkObject
00067 {
00068 public:
00069   vtkTypeMacro( vtkIncrementalOctreeNode, vtkObject );
00070   void PrintSelf( ostream & os, vtkIndent indent );
00071 
00072   static vtkIncrementalOctreeNode * New();
00073   
00075 
00076   vtkGetMacro( NumberOfPoints, int );
00078   
00080 
00081   vtkGetObjectMacro( PointIdSet, vtkIdList );
00083   
00085   void DeleteChildNodes();
00086   
00088 
00090   void SetBounds( double x1, double x2, double y1, 
00091                   double y2, double z1, double z2 );
00093   
00096   void GetBounds( double bounds[6] ) const;
00097                      
00099 
00100   vtkGetVector3Macro( MinBounds, double );
00102   
00104 
00105   vtkGetVector3Macro( MaxBounds, double );
00107   
00109 
00111   double * GetMinDataBounds()
00112   { return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds; }
00114   
00116 
00118   double * GetMaxDataBounds()
00119   { return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds; }
00121                     
00123   int IsLeaf() { return ( this->Children == NULL ) ? 1 : 0; }
00124   
00128   int GetChildIndex( const double point[3] );
00129   
00133   vtkIncrementalOctreeNode * GetChild( int i ) { return this->Children[i]; }
00134   
00138   int  ContainsPoint( const double pnt[3] );
00139   
00142   int  ContainsPointByData( const double pnt[3] );
00143   
00145 
00157   int InsertPoint( vtkPoints * points, const double newPnt[3], 
00158                    int maxPts, vtkIdType * pntId, int ptMode );
00160  
00162 
00165   double GetDistance2ToInnerBoundary( const double point[3], 
00166                                       vtkIncrementalOctreeNode * rootNode );
00168                                       
00170 
00173   double GetDistance2ToBoundary( const double point[3],
00174     vtkIncrementalOctreeNode * rootNode, int checkData );
00176     
00178 
00182   double GetDistance2ToBoundary( const double point[3], double closest[3],
00183     vtkIncrementalOctreeNode * rootNode, int checkData );
00185   
00189   void ExportAllPointIdsByInsertion( vtkIdList * idList );
00190   
00195   void ExportAllPointIdsByDirectSet( vtkIdType * pntIdx, vtkIdList * idList );
00196 
00197 //BTX
00198 protected:
00199 
00200   vtkIncrementalOctreeNode();
00201   ~vtkIncrementalOctreeNode();
00202 
00203 private:
00204 
00206   int  NumberOfPoints;
00207   
00209   double MinBounds[3];
00210 
00212   double MaxBounds[3];
00213   
00218   double MinDataBounds[3];   
00219 
00224   double MaxDataBounds[3];
00225   
00228   vtkIdList * PointIdSet;
00229   
00231   vtkIncrementalOctreeNode *  Parent;
00232   
00234   vtkIncrementalOctreeNode ** Children;
00235   
00237   virtual void SetParent( vtkIncrementalOctreeNode * );
00238   
00240   virtual void SetPointIdSet( vtkIdList * );
00241   
00243 
00260   int CreateChildNodes( vtkPoints * points, vtkIdList * pntIds,
00261     const double newPnt[3], vtkIdType * pntIdx, int maxPts, int ptMode );
00263     
00266   void CreatePointIdSet( int initSize, int growSize );
00267   
00269   void DeletePointIdSet();
00270   
00274   void UpdateCounterAndDataBounds( const double point[3] );
00275   
00277 
00285   int UpdateCounterAndDataBounds
00286     ( const double point[3], int nHits, int updateData );
00288 
00290 
00299   int UpdateCounterAndDataBoundsRecursively( const double point[3], int nHits,
00300     int updateData, vtkIncrementalOctreeNode * endNode );
00302     
00307   int  ContainsDuplicatePointsOnly( const double pnt[3] );
00308   
00310 
00322   void SeperateExactlyDuplicatePointsFromNewInsertion( vtkPoints * points, 
00323     vtkIdList * pntIds, const double newPnt[3], 
00324     vtkIdType * pntIdx, int maxPts, int ptMode );
00326                    
00328 
00333   double GetDistance2ToBoundary( const double point[3], double closest[3],
00334     int innerOnly, vtkIncrementalOctreeNode* rootNode, int checkData = 0 );
00336 
00337   vtkIncrementalOctreeNode( const vtkIncrementalOctreeNode & );// Not implemented
00338   void operator = ( const vtkIncrementalOctreeNode & );        // Not implemented
00339 //ETX
00340 };
00341 
00342 // In-lined for performance
00343 inline int vtkIncrementalOctreeNode::GetChildIndex( const double point[3] )
00344 { 
00345   // Children[0]->MaxBounds[] is exactly the center point of this node.
00346   return int( point[0] > this->Children[0]->MaxBounds[0] ) +
00347     (  ( int( point[1] > this->Children[0]->MaxBounds[1] ) ) << 1  ) +
00348     (  ( int( point[2] > this->Children[0]->MaxBounds[2] ) ) << 2  );
00349 }
00350 
00351 // In-lined for performance 
00352 inline int vtkIncrementalOctreeNode::ContainsPoint( const double pnt[3] )
00353 {
00354   return (
00355             ( this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] &&
00356               this->MinBounds[1] < pnt[1] && pnt[1] <= this->MaxBounds[1] &&
00357               this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2]
00358             ) ? 1 : 0
00359          );
00360 }
00361 
00362 // In-lined for performance 
00363 inline int vtkIncrementalOctreeNode::ContainsPointByData( const double pnt[3] )
00364 {
00365   return
00366   (
00367      ( this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] &&
00368        this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] &&
00369        this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2]
00370      ) ? 1 : 0
00371   );
00372 }
00373 
00374 // In-lined for performance
00375 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly
00376   ( const double pnt[3] )
00377 {
00378   return
00379   (
00380      ( this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] &&
00381        this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] &&
00382        this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2]
00383      ) ? 1 : 0
00384   );  
00385 }
00386 
00387 // In-lined for performance
00388 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds
00389   ( const double point[3] )
00390 {
00391   this->NumberOfPoints ++;
00392   
00393   this->MinDataBounds[0] = ( point[0] < this->MinDataBounds[0] ) 
00394                            ? point[0] : this->MinDataBounds[0];
00395   this->MinDataBounds[1] = ( point[1] < this->MinDataBounds[1] ) 
00396                            ? point[1] : this->MinDataBounds[1];
00397   this->MinDataBounds[2] = ( point[2] < this->MinDataBounds[2] ) 
00398                            ? point[2] : this->MinDataBounds[2];
00399   this->MaxDataBounds[0] = ( point[0] > this->MaxDataBounds[0] ) 
00400                            ? point[0] : this->MaxDataBounds[0];
00401   this->MaxDataBounds[1] = ( point[1] > this->MaxDataBounds[1] ) 
00402                            ? point[1] : this->MaxDataBounds[1];
00403   this->MaxDataBounds[2] = ( point[2] > this->MaxDataBounds[2] ) 
00404                            ? point[2] : this->MaxDataBounds[2];
00405 }
00406 
00407 // In-lined for performance 
00408 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively
00409   ( const double point[3], int nHits, int updateData, 
00410     vtkIncrementalOctreeNode * endNode )
00411 {
00412   int  updated = this->UpdateCounterAndDataBounds
00413                        ( point, nHits, updateData );
00414   
00415   return (    ( this->Parent == endNode )
00416            ?  updated 
00417            :  this->Parent->UpdateCounterAndDataBoundsRecursively
00418                             ( point, nHits, updated, endNode ) 
00419          );
00420 }
00421 #endif