VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtkOBBTree.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOBBTree.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 =========================================================================*/
55 #ifndef __vtkOBBTree_h
56 #define __vtkOBBTree_h
57 
58 #include "vtkFiltersGeneralModule.h" // For export macro
59 #include "vtkAbstractCellLocator.h"
60 
61 class vtkMatrix4x4;
62 
63 // Special class defines node for the OBB tree
64 //
65 //BTX
66 //
67 class VTKFILTERSGENERAL_EXPORT vtkOBBNode { //;prevent man page generation
68 public:
69  vtkOBBNode();
70  ~vtkOBBNode();
71 
72  double Corner[3]; //center point of this node
73  double Axes[3][3]; //the axes defining the OBB - ordered from long->short
74  vtkOBBNode *Parent; //parent node; NULL if root
75  vtkOBBNode **Kids; //two children of this node; NULL if leaf
76  vtkIdList *Cells; //list of cells in node
77  void DebugPrintTree( int level, double *leaf_vol, int *minCells,
78  int *maxCells );
79 };
80 //ETX
81 //
82 
83 class VTKFILTERSGENERAL_EXPORT vtkOBBTree : public vtkAbstractCellLocator
84 {
85 public:
86  vtkTypeMacro(vtkOBBTree,vtkAbstractCellLocator);
87  void PrintSelf(ostream& os, vtkIndent indent);
88 
91  static vtkOBBTree *New();
92 
93 //BTX
94 /*
95  if the borland compiler is ever removed, we can use these declarations
96  instead of reimplementaing the calls in this subclass
97  using vtkAbstractCellLocator::IntersectWithLine;
98  using vtkAbstractCellLocator::FindClosestPoint;
99  using vtkAbstractCellLocator::FindClosestPointWithinRadius;
100 */
101 //ETX
102 
104 
105  virtual int IntersectWithLine(
106  double a0[3], double a1[3], double tol,
107  double& t, double x[3], double pcoords[3],
108  int &subId)
109  {
110  return Superclass::
111  IntersectWithLine(a0, a1, tol,t, x, pcoords, subId);
112  }
114 
116 
117  virtual int IntersectWithLine(
118  double a0[3], double a1[3], double tol,
119  double& t, double x[3], double pcoords[3],
120  int &subId, vtkIdType &cellId)
121  {
122  return Superclass::
123  IntersectWithLine(a0, a1, tol,t, x, pcoords, subId, cellId);
124  }
126 
128 
136  int IntersectWithLine(const double a0[3], const double a1[3],
137  vtkPoints *points, vtkIdList *cellIds);
139 
141 
144  int IntersectWithLine(double a0[3], double a1[3], double tol,
145  double& t, double x[3], double pcoords[3],
146  int &subId, vtkIdType &cellId, vtkGenericCell *cell);
148 
150 
159  virtual void FindClosestPoint(
160  double x[3], double closestPoint[3],
161  vtkIdType &cellId, int &subId, double& dist2)
162  {
163  Superclass::
164  FindClosestPoint(x, closestPoint, cellId, subId, dist2);
165  }
167 
169 
170  virtual void FindClosestPoint(
171  double x[3], double closestPoint[3],
172  vtkGenericCell *cell, vtkIdType &cellId,
173  int &subId, double& dist2)
174  {
175  Superclass::
176  FindClosestPoint(x, closestPoint, cell, cellId, subId, dist2);
177  }
179 
181 
182  virtual vtkIdType FindClosestPointWithinRadius(
183  double x[3], double radius,
184  double closestPoint[3], vtkIdType &cellId,
185  int &subId, double& dist2)
186  {
187  return Superclass::FindClosestPointWithinRadius
188  (x, radius, closestPoint, cellId, subId, dist2);
189  }
191 
193 
194  virtual vtkIdType FindClosestPointWithinRadius(
195  double x[3], double radius,
196  double closestPoint[3],
197  vtkGenericCell *cell, vtkIdType &cellId,
198  int &subId, double& dist2)
199  {
200  return Superclass::FindClosestPointWithinRadius
201  (x, radius, closestPoint, cell, cellId, subId, dist2);
202  }
204 
206 
207  virtual vtkIdType FindClosestPointWithinRadius(
208  double x[3], double radius, double closestPoint[3],
209  vtkGenericCell *cell, vtkIdType &cellId,
210  int &subId, double& dist2, int &inside)
211  {
212  return Superclass::FindClosestPointWithinRadius
213  (x, radius, closestPoint, cell, cellId, subId, dist2, inside);
214  }
216 
218 
221  static void ComputeOBB(vtkPoints *pts, double corner[3], double max[3],
222  double mid[3], double min[3], double size[3]);
224 
226 
230  void ComputeOBB(vtkDataSet *input, double corner[3], double max[3],
231  double mid[3], double min[3], double size[3]);
233 
238  int InsideOrOutside(const double point[3]);
239 
240  //BTX
241 
243 
245  int DisjointOBBNodes( vtkOBBNode *nodeA, vtkOBBNode *nodeB,
246  vtkMatrix4x4 *XformBtoA );
248 
250  int LineIntersectsNode( vtkOBBNode *pA, double b0[3], double b1[3] );
251 
253 
254  int TriangleIntersectsNode( vtkOBBNode *pA,
255  double p0[3], double p1[3],
256  double p2[3], vtkMatrix4x4 *XformBtoA );
258 
260 
262  int IntersectWithOBBTree( vtkOBBTree *OBBTreeB, vtkMatrix4x4 *XformBtoA,
263  int(*function)( vtkOBBNode *nodeA,
264  vtkOBBNode *nodeB,
265  vtkMatrix4x4 *Xform,
266  void *arg ),
267  void *data_arg );
268  //ETX
270 
272 
273  void FreeSearchStructure();
274  void BuildLocator();
276 
285  void GenerateRepresentation(int level, vtkPolyData *pd);
286 
287  //BTX
288 protected:
289  vtkOBBTree();
290  ~vtkOBBTree();
291 
292  // Compute an OBB from the list of cells given. This used to be
293  // public but should not have been. A public call has been added
294  // so that the functionality can be accessed.
295  void ComputeOBB(vtkIdList *cells, double corner[3], double max[3],
296  double mid[3], double min[3], double size[3]);
297 
299  void BuildTree(vtkIdList *cells, vtkOBBNode *parent, int level);
300  vtkPoints *PointsList;
302  int OBBCount;
303 
304  void DeleteTree(vtkOBBNode *OBBptr);
305  void GeneratePolygons(vtkOBBNode *OBBptr, int level, int repLevel,
306  vtkPoints* pts, vtkCellArray *polys);
307 
308  //ETX
309 private:
310  vtkOBBTree(const vtkOBBTree&); // Not implemented.
311  void operator=(const vtkOBBTree&); // Not implemented.
312 };
313 
314 #endif
vtkOBBNode * Parent
Definition: vtkOBBTree.h:74
virtual void FindClosestPoint(double x[3], double closestPoint[3], vtkIdType &cellId, int &subId, double &dist2)
Definition: vtkOBBTree.h:159
vtkOBBNode ** Kids
Definition: vtkOBBTree.h:75
virtual vtkIdType FindClosestPointWithinRadius(double x[3], double radius, double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2, int &inside)
Definition: vtkOBBTree.h:207
int * InsertedPoints
Definition: vtkOBBTree.h:301
virtual vtkIdType FindClosestPointWithinRadius(double x[3], double radius, double closestPoint[3], vtkIdType &cellId, int &subId, double &dist2)
Definition: vtkOBBTree.h:182
vtkIdList * Cells
Definition: vtkOBBTree.h:76
generate oriented bounding box (OBB) tree
Definition: vtkOBBTree.h:83
vtkOBBNode * Tree
Definition: vtkOBBTree.h:298
virtual int IntersectWithLine(double a0[3], double a1[3], double tol, double &t, double x[3], double pcoords[3], int &subId, vtkIdType &cellId)
Definition: vtkOBBTree.h:117
int OBBCount
Definition: vtkOBBTree.h:302
vtkPoints * PointsList
Definition: vtkOBBTree.h:300
virtual void FindClosestPoint(double x[3], double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2)
Definition: vtkOBBTree.h:170
virtual vtkIdType FindClosestPointWithinRadius(double x[3], double radius, double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2)
Definition: vtkOBBTree.h:194
virtual int IntersectWithLine(double a0[3], double a1[3], double tol, double &t, double x[3], double pcoords[3], int &subId)
Definition: vtkOBBTree.h:105