VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkCellLocator.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 =========================================================================*/ 00039 #ifndef __vtkCellTreeLocator_h 00040 #define __vtkCellTreeLocator_h 00041 00042 #include "vtkFiltersGeneralModule.h" // For export macro 00043 #include "vtkAbstractCellLocator.h" 00044 #include <vector> // Needed for internal class 00045 00046 class vtkCellPointTraversal; 00047 class vtkIdTypeArray; 00048 class vtkCellArray; 00049 00050 class VTKFILTERSGENERAL_EXPORT vtkCellTreeLocator : public vtkAbstractCellLocator 00051 { 00052 public: 00053 class vtkCellTree; 00054 class vtkCellTreeNode; 00055 00056 vtkTypeMacro(vtkCellTreeLocator,vtkAbstractCellLocator); 00057 void PrintSelf(ostream& os, vtkIndent indent); 00058 00062 static vtkCellTreeLocator *New(); 00063 00065 00067 virtual vtkIdType FindCell(double pos[3], double vtkNotUsed, vtkGenericCell *cell, double pcoords[3], 00068 double* weights ); 00070 00072 00075 virtual int IntersectWithLine(double a0[3], double a1[3], double tol, 00076 double& t, double x[3], double pcoords[3], 00077 int &subId, vtkIdType &cellId, 00078 vtkGenericCell *cell); 00080 00084 virtual void FindCellsWithinBounds(double *bbox, vtkIdList *cells); 00085 00086 //BTX 00087 /* 00088 if the borland compiler is ever removed, we can use these declarations 00089 instead of reimplementaing the calls in this subclass 00090 using vtkAbstractCellLocator::IntersectWithLine; 00091 using vtkAbstractCellLocator::FindClosestPoint; 00092 using vtkAbstractCellLocator::FindClosestPointWithinRadius; 00093 */ 00094 //ETX 00096 00097 virtual int IntersectWithLine( 00098 double p1[3], double p2[3], double tol, double& t, double x[3], 00099 double pcoords[3], int &subId) 00100 { 00101 return this->Superclass::IntersectWithLine(p1, p2, tol, t, x, pcoords, subId); 00102 } 00104 00106 00111 virtual int IntersectWithLine( 00112 double p1[3], double p2[3], double tol, double &t, double x[3], 00113 double pcoords[3], int &subId, vtkIdType &cellId); 00115 00117 00118 virtual int IntersectWithLine( 00119 const double p1[3], const double p2[3], 00120 vtkPoints *points, vtkIdList *cellIds) 00121 { 00122 return this->Superclass::IntersectWithLine(p1, p2, points, cellIds); 00123 } 00125 00127 00128 virtual vtkIdType FindCell(double x[3]) 00129 { return this->Superclass::FindCell(x); } 00131 00133 00134 virtual void FreeSearchStructure(); 00135 virtual void GenerateRepresentation(int level, vtkPolyData *pd); 00136 virtual void BuildLocatorInternal(); 00137 virtual void BuildLocatorIfNeeded(); 00138 virtual void ForceBuildLocator(); 00139 virtual void BuildLocator(); 00141 00142 00143 //BTX 00145 00147 class VTKFILTERSGENERAL_EXPORT vtkCellTree 00148 { 00149 public: 00150 std::vector<vtkCellTreeNode> Nodes; 00151 std::vector<unsigned int> Leaves; 00152 friend class vtkCellPointTraversal; 00153 friend class vtkCellTreeNode; 00154 friend class vtkCellTreeBuilder; 00156 00157 public: 00158 float DataBBox[6]; // This store the bounding values of the dataset 00159 }; 00160 00162 00170 class VTKFILTERSGENERAL_EXPORT vtkCellTreeNode 00171 { 00172 public: 00174 00175 protected: 00176 unsigned int Index; 00177 float LeftMax; // left max value 00178 float RightMin; // right min value 00179 00180 unsigned int Sz; // size 00181 unsigned int St; // start 00182 00183 friend class vtkCellTree; 00184 friend class vtkCellPointTraversal; 00185 friend class vtkCellTreeBuilder; 00186 00187 public: 00188 void MakeNode( unsigned int left, unsigned int d, float b[2] ); 00189 void SetChildren( unsigned int left ); 00190 bool IsNode() const; 00191 unsigned int GetLeftChildIndex() const; 00192 unsigned int GetRightChildIndex() const; 00193 unsigned int GetDimension() const; 00194 const float& GetLeftMaxValue() const; 00195 const float& GetRightMinValue() const; 00196 void MakeLeaf( unsigned int start, unsigned int size ); 00197 bool IsLeaf() const; 00198 unsigned int Start() const; 00199 unsigned int Size() const; 00200 }; 00201 //ETX 00202 00203 protected: 00204 vtkCellTreeLocator(); 00205 ~vtkCellTreeLocator(); 00206 00207 // Test ray against node BBox : clip t values to extremes 00208 bool RayMinMaxT(const double origin[3], 00209 const double dir[3], 00210 double &rTmin, 00211 double &rTmax); 00212 00213 bool RayMinMaxT(const double bounds[6], 00214 const double origin[3], 00215 const double dir[3], 00216 double &rTmin, 00217 double &rTmax); 00218 00219 int getDominantAxis(const double dir[3]); 00220 00221 // Order nodes as near/far relative to ray 00222 void Classify(const double origin[3], 00223 const double dir[3], 00224 double &rDist, 00225 vtkCellTreeNode *&near, vtkCellTreeNode *&mid, 00226 vtkCellTreeNode *&far, int &mustCheck); 00227 00228 // From vtkModifiedBSPTRee 00229 // We provide a function which does the cell/ray test so that 00230 // it can be overriden by subclasses to perform special treatment 00231 // (Example : Particles stored in tree, have no dimension, so we must 00232 // override the cell test to return a value based on some particle size 00233 virtual int IntersectCellInternal( vtkIdType cell_ID, const double p1[3], 00234 const double p2[3], 00235 const double tol, 00236 double &t, 00237 double ipt[3], 00238 double pcoords[3], 00239 int &subId); 00240 00241 00242 int NumberOfBuckets; 00243 00244 vtkCellTree* Tree; 00245 00246 friend class vtkCellPointTraversal; 00247 friend class vtkCellTreeNode; 00248 friend class vtkCellTreeBuilder; 00249 00250 private: 00251 vtkCellTreeLocator(const vtkCellTreeLocator&); // Not implemented. 00252 void operator=(const vtkCellTreeLocator&); // Not implemented. 00253 }; 00254 00255 #endif