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