VTK
vtkCellTreeLocator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellLocator.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 =========================================================================*/
39 #ifndef __vtkCellTreeLocator_h
40 #define __vtkCellTreeLocator_h
41 
42 #include "vtkAbstractCellLocator.h"
43 #include <vector> // Needed for internal class
44 
45 class vtkCellPointTraversal;
46 class vtkIdTypeArray;
47 class vtkCellArray;
48 
50 {
51  public:
52  class vtkCellTree;
54 
56  void PrintSelf(ostream& os, vtkIndent indent);
57 
61  static vtkCellTreeLocator *New();
62 
64 
66  virtual vtkIdType FindCell(double pos[3], double vtkNotUsed, vtkGenericCell *cell, double pcoords[3],
67  double* weights );
69 
71 
74  virtual int IntersectWithLine(double a0[3], double a1[3], double tol,
75  double& t, double x[3], double pcoords[3],
76  int &subId, vtkIdType &cellId,
77  vtkGenericCell *cell);
79 
83  virtual void FindCellsWithinBounds(double *bbox, vtkIdList *cells);
84 
85  //BTX
86  /*
87  if the borland compiler is ever removed, we can use these declarations
88  instead of reimplementaing the calls in this subclass
89  using vtkAbstractCellLocator::IntersectWithLine;
90  using vtkAbstractCellLocator::FindClosestPoint;
91  using vtkAbstractCellLocator::FindClosestPointWithinRadius;
92  */
93  //ETX
95 
96  virtual int IntersectWithLine(
97  double p1[3], double p2[3], double tol, double& t, double x[3],
98  double pcoords[3], int &subId)
99  {
100  return this->Superclass::IntersectWithLine(p1, p2, tol, t, x, pcoords, subId);
101  }
103 
105 
110  virtual int IntersectWithLine(
111  double p1[3], double p2[3], double tol, double &t, double x[3],
112  double pcoords[3], int &subId, vtkIdType &cellId);
114 
116 
117  virtual int IntersectWithLine(
118  const double p1[3], const double p2[3],
119  vtkPoints *points, vtkIdList *cellIds)
120  {
121  return this->Superclass::IntersectWithLine(p1, p2, points, cellIds);
122  }
124 
126 
127  virtual vtkIdType FindCell(double x[3])
128  { return this->Superclass::FindCell(x); }
130 
132 
133  virtual void FreeSearchStructure();
134  virtual void GenerateRepresentation(int level, vtkPolyData *pd);
135  virtual void BuildLocatorInternal();
136  virtual void BuildLocatorIfNeeded();
137  virtual void ForceBuildLocator();
138  virtual void BuildLocator();
140 
141 
142 //BTX
144 
147  {
148  public:
149  std::vector<vtkCellTreeNode> Nodes;
150  std::vector<unsigned int> Leaves;
151  friend class vtkCellPointTraversal;
152  friend class vtkCellTreeNode;
153  friend class vtkCellTreeBuilder;
155 
156  public:
157  float DataBBox[6]; // This store the bounding values of the dataset
158  };
159 
161 
170  {
171  public:
173 
174  protected:
175  unsigned int Index;
176  float LeftMax; // left max value
177  float RightMin; // right min value
178 
179  unsigned int Sz; // size
180  unsigned int St; // start
181 
182  friend class vtkCellTree;
183  friend class vtkCellPointTraversal;
184  friend class vtkCellTreeBuilder;
185 
186  public:
187  void MakeNode( unsigned int left, unsigned int d, float b[2] );
188  void SetChildren( unsigned int left );
189  bool IsNode() const;
190  unsigned int GetLeftChildIndex() const;
191  unsigned int GetRightChildIndex() const;
192  unsigned int GetDimension() const;
193  const float& GetLeftMaxValue() const;
194  const float& GetRightMinValue() const;
195  void MakeLeaf( unsigned int start, unsigned int size );
196  bool IsLeaf() const;
197  unsigned int Start() const;
198  unsigned int Size() const;
199  };
200 //ETX
201 
202 protected:
205 
206  // Test ray against node BBox : clip t values to extremes
207  bool RayMinMaxT(const double origin[3],
208  const double dir[3],
209  double &rTmin,
210  double &rTmax);
211 
212  bool RayMinMaxT(const double bounds[6],
213  const double origin[3],
214  const double dir[3],
215  double &rTmin,
216  double &rTmax);
217 
218  int getDominantAxis(const double dir[3]);
219 
220  // Order nodes as near/far relative to ray
221  void Classify(const double origin[3],
222  const double dir[3],
223  double &rDist,
224  vtkCellTreeNode *&near, vtkCellTreeNode *&mid,
225  vtkCellTreeNode *&far, int &mustCheck);
226 
227  // From vtkModifiedBSPTRee
228  // We provide a function which does the cell/ray test so that
229  // it can be overriden by subclasses to perform special treatment
230  // (Example : Particles stored in tree, have no dimension, so we must
231  // override the cell test to return a value based on some particle size
232  virtual int IntersectCellInternal( vtkIdType cell_ID, const double p1[3],
233  const double p2[3],
234  const double tol,
235  double &t,
236  double ipt[3],
237  double pcoords[3],
238  int &subId);
239 
240 
242 
244 
245  friend class vtkCellPointTraversal;
246  friend class vtkCellTreeNode;
247  friend class vtkCellTreeBuilder;
248 
249 private:
250  vtkCellTreeLocator(const vtkCellTreeLocator&); // Not implemented.
251  void operator=(const vtkCellTreeLocator&); // Not implemented.
252 };
253 
254 #endif