3D Human Airway Tree
Program generuje ludzkie drzewo oskrzelowe
vtkCollisionDetectionFilter.h
Idź do dokumentacji tego pliku.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCollisionDetectionFilter.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 =========================================================================*/
15 // .NAME vtkCollisionDetectionFilter - performs collision determination between two polyhedral surfaces
16 // .SECTION Description
17 // vtkCollisionDetectionFilter performs collision determination between two polyhedral surfaces using
18 // two instances of vtkOBBTree. Set the polydata inputs, the tolerance and transforms or matrices. If
19 // CollisionMode is set to AllContacts, the Contacts output will be lines of contact.
20 // If CollisionMode is FirstContact or HalfContacts then the Contacts output will be vertices.
21 // See below for an explanation of these options.
22 //
23 // This class can be used to clip one polydata surface with another, using the Contacts output as a loop
24 // set in vtkSelectPolyData
25 
26 // .SECTION Caveats
27 // Currently only triangles are processed. Use vtkTriangleFilter to
28 // convert any strips or polygons to triangles.
29 
30 // .SECTION Thanks
31 // Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin, who wrote this class.
32 // Thanks to Peter C. Everett <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in particular,
33 // and all those who contributed to vtkOBBTree in general.
34 
35 
36 // .SECTION See Also
37 // vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
38 
39 #ifndef __vtkCollisionDetectionFilter_h
40 #define __vtkCollisionDetectionFilter_h
41 
42 #include "vtkPolyDataAlgorithm.h"
43 #include "vtkLinearTransform.h"
44 #include "vtkIdTypeArray.h"
45 #include "vtkFieldData.h"
46 
47 // Forward declarations
48 class vtkOBBTree;
49 class vtkPolyData;
50 class vtkPoints;
51 class vtkMatrix4x4;
52 
53 #ifndef WINNT
54 class VTK_GRAPHICS_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
55 #else
56 class __declspec(dllexport) VTK_GRAPHICS_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
57 #endif
58 {
59 public:
60  vtkTypeMacro(vtkCollisionDetectionFilter, vtkPolyDataAlgorithm);
61  void PrintSelf(ostream& os, vtkIndent indent);
62 
63 //BTX
65  {
66  VTK_ALL_CONTACTS = 0,
67  VTK_FIRST_CONTACT = 1,
68  VTK_HALF_CONTACTS = 2
69  };
70 //ETX
71 
72  // Description:
73  // Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with
74  // two points per collision, or VTK_HALF_CONTACTS to find all the contacting cell pairs
75  // with one point per collision, or VTK_FIRST_CONTACT to quickly find the first contact
76  // point.
77  vtkSetClampMacro(CollisionMode,int,VTK_ALL_CONTACTS,VTK_HALF_CONTACTS);
78  vtkGetMacro(CollisionMode,int);
79  void SetCollisionModeToAllContacts() {this->SetCollisionMode(VTK_ALL_CONTACTS);};
80  void SetCollisionModeToFirstContact() {this->SetCollisionMode(VTK_FIRST_CONTACT);};
81  void SetCollisionModeToHalfContacts() {this->SetCollisionMode(VTK_HALF_CONTACTS);};
82  const char *GetCollisionModeAsString();
83 
84  // Description:
85  // Constructs with initial values.
87 
88  // Description:
89  // Intersect two polygons, return x1 and x2 as the twp points of intersection. If
90  // CollisionMode = VTK_ALL_CONTACTS, both contact points are found. If
91  // CollisionMode = VTK_FIRST_CONTACT or VTK_HALF_CONTACTS, only
92  // one contact point is found.
93  int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6],
94  int npts2, double *pts2,
95  double bounds2[6], double tol2,
96  double x1[2], double x2[3],
97  int CollisionMode);
98 
99  // Description:
100  // Set and Get the input vtk polydata models
101  void SetInput(int i, vtkPolyData *model);
102  vtkPolyData *GetInput(int i);
103 
104 
105  // Description:
106  // Get an array of the contacting cells. This is a convenience method to access
107  // the "ContactCells" field array in outputs 0 and 1. These arrays index contacting
108  // cells (eg) index 50 of array 0 points to a cell (triangle) which contacts/intersects
109  // a cell at index 50 of array 1. This method is equivalent to
110  // GetOutput(i)->GetFieldData()->GetArray("ContactCells")
111  vtkIdTypeArray *GetContactCells(int i);
112 
113  // Description:
114  // Get the output with the points where the contacting cells intersect. This method is
115  // is equivalent to GetOutputPort(2)/GetOutput(2)
116  vtkAlgorithmOutput *GetContactsOutputPort() {return this->GetOutputPort(2);}
117  vtkPolyData *GetContactsOutput() {return this->GetOutput(2);}
118 
119  // Description:
120  // Specify the transform object used to transform models. Alternatively, matrices
121  // can be set instead.
122  void SetTransform(int i, vtkLinearTransform *transform);
123  vtkLinearTransform *GetTransform(int i) {return this->Transform[i];}
124 
125  // Description:
126  // Specify the matrix object used to transform models.
127  void SetMatrix(int i, vtkMatrix4x4 *matrix);
128  vtkMatrix4x4 *GetMatrix(int i);
129 
130  //Description:
131  // Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
132  vtkSetMacro(BoxTolerance, float);
133  vtkGetMacro(BoxTolerance, float);
134 
135  //Description:
136  // Set and Get the cell tolerance (squared value). Default is 0.0
137  vtkSetMacro(CellTolerance, double);
138  vtkGetMacro(CellTolerance, double);
139 
140  //Description:
141  // Set and Get the the flag to visualize the contact cells. If set the contacting cells
142  // will be coloured from red through to blue, with collisions first determined coloured red.
143  vtkSetMacro(GenerateScalars, int);
144  vtkGetMacro(GenerateScalars, int);
145  vtkBooleanMacro(GenerateScalars,int);
146 
147  //Description:
148  // Get the number of contacting cell pairs
150  {return this->GetOutput(0)->GetFieldData()->GetArray("ContactCells")->GetNumberOfTuples();}
151 
152  //Description:
153  // Get the number of box tests
154  vtkGetMacro(NumberOfBoxTests, int);
155 
156  //Description:
157  // Set and Get the number of cells in each OBB. Default is 2
158  vtkSetMacro(NumberOfCellsPerNode, int);
159  vtkGetMacro(NumberOfCellsPerNode, int);
160 
161  //Description:
162  // Set and Get the opacity of the polydata output when a collision takes place.
163  // Default is 1.0
164  vtkSetClampMacro(Opacity, float, 0.0, 1.0);
165  vtkGetMacro(Opacity, float);
166 
167  // Description:
168  // Return the MTime also considering the transform.
169  unsigned long GetMTime();
170 
171 protected:
174 
175  // Usual data generation method
176  virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
177 
178  vtkOBBTree *tree0;
179  vtkOBBTree *tree1;
180 
181  vtkLinearTransform *Transform[2];
182  vtkMatrix4x4 *Matrix[2];
183 
185 
187 
189 
192  float Opacity;
193 
195 
196 private:
197 
198  vtkCollisionDetectionFilter(const vtkCollisionDetectionFilter&); // Not implemented.
199  void operator=(const vtkCollisionDetectionFilter&); // Not implemented.
200 };
201 
202 //BTX
203 
205 {
206  if ( this->CollisionMode == VTK_ALL_CONTACTS )
207  {
208  return (char *)"AllContacts";
209  }
210  else if (this->CollisionMode == VTK_FIRST_CONTACT)
211  {
212  return (char *)"FirstContact";
213  }
214  else
215  {
216  return (char *)"HalfContacts";
217  }
218 }
219 
220 //ETX
221 #endif