VTK
|
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 "vtkCommonDataModelModule.h" // For export macro 00062 #include "vtkObject.h" 00063 00064 class vtkPoints; 00065 class vtkIdList; 00066 00067 class VTKCOMMONDATAMODEL_EXPORT vtkIncrementalOctreeNode : public vtkObject 00068 { 00069 public: 00070 vtkTypeMacro( vtkIncrementalOctreeNode, vtkObject ); 00071 void PrintSelf( ostream & os, vtkIndent indent ); 00072 00073 static vtkIncrementalOctreeNode * New(); 00074 00076 00077 vtkGetMacro( NumberOfPoints, int ); 00079 00081 00082 vtkGetObjectMacro( PointIdSet, vtkIdList ); 00084 00086 void DeleteChildNodes(); 00087 00089 00091 void SetBounds( double x1, double x2, double y1, 00092 double y2, double z1, double z2 ); 00094 00097 void GetBounds( double bounds[6] ) const; 00098 00100 00101 vtkGetVector3Macro( MinBounds, double ); 00103 00105 00106 vtkGetVector3Macro( MaxBounds, double ); 00108 00110 00112 double * GetMinDataBounds() 00113 { return this->NumberOfPoints ? this->MinDataBounds : this->MinBounds; } 00115 00117 00119 double * GetMaxDataBounds() 00120 { return this->NumberOfPoints ? this->MaxDataBounds : this->MaxBounds; } 00122 00124 int IsLeaf() { return ( this->Children == NULL ) ? 1 : 0; } 00125 00129 int GetChildIndex( const double point[3] ); 00130 00134 vtkIncrementalOctreeNode * GetChild( int i ) { return this->Children[i]; } 00135 00139 int ContainsPoint( const double pnt[3] ); 00140 00143 int ContainsPointByData( const double pnt[3] ); 00144 00146 00158 int InsertPoint( vtkPoints * points, const double newPnt[3], 00159 int maxPts, vtkIdType * pntId, int ptMode ); 00161 00163 00166 double GetDistance2ToInnerBoundary( const double point[3], 00167 vtkIncrementalOctreeNode * rootNode ); 00169 00171 00174 double GetDistance2ToBoundary( const double point[3], 00175 vtkIncrementalOctreeNode * rootNode, int checkData ); 00177 00179 00183 double GetDistance2ToBoundary( const double point[3], double closest[3], 00184 vtkIncrementalOctreeNode * rootNode, int checkData ); 00186 00190 void ExportAllPointIdsByInsertion( vtkIdList * idList ); 00191 00196 void ExportAllPointIdsByDirectSet( vtkIdType * pntIdx, vtkIdList * idList ); 00197 00198 //BTX 00199 protected: 00200 00201 vtkIncrementalOctreeNode(); 00202 ~vtkIncrementalOctreeNode(); 00203 00204 private: 00205 00207 int NumberOfPoints; 00208 00210 double MinBounds[3]; 00211 00213 double MaxBounds[3]; 00214 00219 double MinDataBounds[3]; 00220 00225 double MaxDataBounds[3]; 00226 00229 vtkIdList * PointIdSet; 00230 00232 vtkIncrementalOctreeNode * Parent; 00233 00235 vtkIncrementalOctreeNode ** Children; 00236 00238 virtual void SetParent( vtkIncrementalOctreeNode * ); 00239 00241 virtual void SetPointIdSet( vtkIdList * ); 00242 00244 00261 int CreateChildNodes( vtkPoints * points, vtkIdList * pntIds, 00262 const double newPnt[3], vtkIdType * pntIdx, int maxPts, int ptMode ); 00264 00267 void CreatePointIdSet( int initSize, int growSize ); 00268 00270 void DeletePointIdSet(); 00271 00275 void UpdateCounterAndDataBounds( const double point[3] ); 00276 00278 00286 int UpdateCounterAndDataBounds 00287 ( const double point[3], int nHits, int updateData ); 00289 00291 00300 int UpdateCounterAndDataBoundsRecursively( const double point[3], int nHits, 00301 int updateData, vtkIncrementalOctreeNode * endNode ); 00303 00308 int ContainsDuplicatePointsOnly( const double pnt[3] ); 00309 00311 00323 void SeperateExactlyDuplicatePointsFromNewInsertion( vtkPoints * points, 00324 vtkIdList * pntIds, const double newPnt[3], 00325 vtkIdType * pntIdx, int maxPts, int ptMode ); 00327 00329 00334 double GetDistance2ToBoundary( const double point[3], double closest[3], 00335 int innerOnly, vtkIncrementalOctreeNode* rootNode, int checkData = 0 ); 00337 00338 vtkIncrementalOctreeNode( const vtkIncrementalOctreeNode & );// Not implemented 00339 void operator = ( const vtkIncrementalOctreeNode & ); // Not implemented 00340 //ETX 00341 }; 00342 00343 // In-lined for performance 00344 inline int vtkIncrementalOctreeNode::GetChildIndex( const double point[3] ) 00345 { 00346 // Children[0]->MaxBounds[] is exactly the center point of this node. 00347 return int( point[0] > this->Children[0]->MaxBounds[0] ) + 00348 ( ( int( point[1] > this->Children[0]->MaxBounds[1] ) ) << 1 ) + 00349 ( ( int( point[2] > this->Children[0]->MaxBounds[2] ) ) << 2 ); 00350 } 00351 00352 // In-lined for performance 00353 inline int vtkIncrementalOctreeNode::ContainsPoint( const double pnt[3] ) 00354 { 00355 return ( 00356 ( this->MinBounds[0] < pnt[0] && pnt[0] <= this->MaxBounds[0] && 00357 this->MinBounds[1] < pnt[1] && pnt[1] <= this->MaxBounds[1] && 00358 this->MinBounds[2] < pnt[2] && pnt[2] <= this->MaxBounds[2] 00359 ) ? 1 : 0 00360 ); 00361 } 00362 00363 // In-lined for performance 00364 inline int vtkIncrementalOctreeNode::ContainsPointByData( const double pnt[3] ) 00365 { 00366 return 00367 ( 00368 ( this->MinDataBounds[0] <= pnt[0] && pnt[0] <= this->MaxDataBounds[0] && 00369 this->MinDataBounds[1] <= pnt[1] && pnt[1] <= this->MaxDataBounds[1] && 00370 this->MinDataBounds[2] <= pnt[2] && pnt[2] <= this->MaxDataBounds[2] 00371 ) ? 1 : 0 00372 ); 00373 } 00374 00375 // In-lined for performance 00376 inline int vtkIncrementalOctreeNode::ContainsDuplicatePointsOnly 00377 ( const double pnt[3] ) 00378 { 00379 return 00380 ( 00381 ( this->MinDataBounds[0] == pnt[0] && pnt[0] == this->MaxDataBounds[0] && 00382 this->MinDataBounds[1] == pnt[1] && pnt[1] == this->MaxDataBounds[1] && 00383 this->MinDataBounds[2] == pnt[2] && pnt[2] == this->MaxDataBounds[2] 00384 ) ? 1 : 0 00385 ); 00386 } 00387 00388 // In-lined for performance 00389 inline void vtkIncrementalOctreeNode::UpdateCounterAndDataBounds 00390 ( const double point[3] ) 00391 { 00392 this->NumberOfPoints ++; 00393 00394 this->MinDataBounds[0] = ( point[0] < this->MinDataBounds[0] ) 00395 ? point[0] : this->MinDataBounds[0]; 00396 this->MinDataBounds[1] = ( point[1] < this->MinDataBounds[1] ) 00397 ? point[1] : this->MinDataBounds[1]; 00398 this->MinDataBounds[2] = ( point[2] < this->MinDataBounds[2] ) 00399 ? point[2] : this->MinDataBounds[2]; 00400 this->MaxDataBounds[0] = ( point[0] > this->MaxDataBounds[0] ) 00401 ? point[0] : this->MaxDataBounds[0]; 00402 this->MaxDataBounds[1] = ( point[1] > this->MaxDataBounds[1] ) 00403 ? point[1] : this->MaxDataBounds[1]; 00404 this->MaxDataBounds[2] = ( point[2] > this->MaxDataBounds[2] ) 00405 ? point[2] : this->MaxDataBounds[2]; 00406 } 00407 00408 // In-lined for performance 00409 inline int vtkIncrementalOctreeNode::UpdateCounterAndDataBoundsRecursively 00410 ( const double point[3], int nHits, int updateData, 00411 vtkIncrementalOctreeNode * endNode ) 00412 { 00413 int updated = this->UpdateCounterAndDataBounds 00414 ( point, nHits, updateData ); 00415 00416 return ( ( this->Parent == endNode ) 00417 ? updated 00418 : this->Parent->UpdateCounterAndDataBoundsRecursively 00419 ( point, nHits, updated, endNode ) 00420 ); 00421 } 00422 #endif