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