VTK: Filters/Modeling/vtkCollisionDetectionFilter.h Source File

| VTK 9.3.1

vtkCollisionDetectionFilter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) Goodwin Lawlor All rights reserved
3 // SPDX-License-Identifier: BSD-3-Clause
37 /*
39 * @warning
40 * Currently only triangles are processed. Use vtkTriangleFilter to
41 * convert any strips or polygons to triangles.
42 */
44
46 /*
47 * @cite
48 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
49 * who wrote this class.
50 * Thanks to Peter C. Everett
51 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
52 * particular, and all those who contributed to vtkOBBTree in general.
53 * The original code was contained here: https://github.com/glawlor/vtkbioeng
54 *
55 */
57
59 /*
60 * @see
61 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
62 */
64
65 #ifndef vtkCollisionDetectionFilter_h
66 #define vtkCollisionDetectionFilter_h
67
68 #include "vtkFieldData.h" // For GetContactCells
69 #include "vtkFiltersModelingModule.h" // For export macro
70 #include "vtkPolyDataAlgorithm.h"
71
72 VTK_ABI_NAMESPACE_BEGIN
73 class vtkOBBTree;
74 class vtkPolyData;
75 class vtkPoints;
76 class vtkMatrix4x4;
77 class vtkLinearTransform;
78 class vtkIdTypeArray;
79
80 class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
81 {
82 public:
84
87 static vtkCollisionDetectionFilter* New();
88 vtkTypeMacro(vtkCollisionDetectionFilter, vtkPolyDataAlgorithm);
89 void PrintSelf(ostream& os, vtkIndent indent) override;
91
92 enum CollisionModes
93 {
94 VTK_ALL_CONTACTS = 0,
95 VTK_FIRST_CONTACT = 1,
96 VTK_HALF_CONTACTS = 2
97 };
98
100
105 vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
106 vtkGetMacro(CollisionMode, int);
107
108 void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
109 void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
110 void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
111 const char* GetCollisionModeAsString()
112 {
113 if (this->CollisionMode == VTK_ALL_CONTACTS)
114 {
115 return "AllContacts";
116 }
117 else if (this->CollisionMode == VTK_FIRST_CONTACT)
118 {
119 return "FirstContact";
120 }
121 else
122 {
123 return "HalfContacts";
124 }
125 }
127
129
136 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
137 double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
139
141
144 void SetInputData(int i, vtkPolyData* model);
145 vtkPolyData* GetInputData(int i);
147
149
155 vtkIdTypeArray* GetContactCells(int i);
157
159
162 vtkAlgorithmOutput* GetContactsOutputPort() { return this->GetOutputPort(2); }
163 vtkPolyData* GetContactsOutput() { return this->GetOutput(2); }
165
167 /* Specify the transform object used to transform models. Alternatively, matrices
168 * can be set instead.
169 ` */
170 void SetTransform(int i, vtkLinearTransform* transform);
171 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
173
175 /* Specify the matrix object used to transform models.
176 */
177 void SetMatrix(int i, vtkMatrix4x4* matrix);
178 vtkMatrix4x4* GetMatrix(int i);
180
182 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
183 */
184 vtkSetMacro(BoxTolerance, float);
185 vtkGetMacro(BoxTolerance, float);
187
189 /* Set and Get the cell tolerance (squared value). Default is 0.0
190 */
191 vtkSetMacro(CellTolerance, double);
192 vtkGetMacro(CellTolerance, double);
194
196 /*
197 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
198 * will be coloured from red through to blue, with collisions first determined coloured red.
199 */
200 vtkSetMacro(GenerateScalars, int);
201 vtkGetMacro(GenerateScalars, int);
202 vtkBooleanMacro(GenerateScalars, int);
204
206 /*
207 * Get the number of contacting cell pairs.
208 *
209 * @note If FirstContact mode is set, it will return either 0 or 1.
210 * @warning It is mandatory to call Update() before, otherwise -1 is returned
211 * @return -1 if internal nullptr is found, otherwise the number of contacts found
212 */
213 int GetNumberOfContacts();
215
217 /*
218 * Get the number of box tests
219 */
220 vtkGetMacro(NumberOfBoxTests, int);
222
224 /*
225 * Set and Get the number of cells in each OBB. Default is 2
226 */
227 vtkSetMacro(NumberOfCellsPerNode, int);
228 vtkGetMacro(NumberOfCellsPerNode, int);
230
232 /*
233 * Set and Get the opacity of the polydata output when a collision takes place.
234 * Default is 1.0
235 */
236 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
237 vtkGetMacro(Opacity, float);
239
241 /*
242 * Return the MTime also considering the transform.
243 */
244 vtkMTimeType GetMTime() override;
246
247 protected:
248 vtkCollisionDetectionFilter();
249 ~vtkCollisionDetectionFilter() override;
250
251 // Usual data generation method
252 int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
253 vtkOBBTree* Tree0;
254 vtkOBBTree* Tree1;
255
256 vtkLinearTransform* Transform[2];
257 vtkMatrix4x4* Matrix[2];
258
259 int NumberOfBoxTests;
260
261 int NumberOfCellsPerNode;
262
263 int GenerateScalars;
264
265 float BoxTolerance;
266 float CellTolerance;
267 float Opacity;
268
269 int CollisionMode;
270
271 private:
272 vtkCollisionDetectionFilter(const vtkCollisionDetectionFilter&) = delete;
273 void operator=(const vtkCollisionDetectionFilter&) = delete;
274 };
275
276 VTK_ABI_NAMESPACE_END
277 #endif
vtkAlgorithmOutput
Proxy object to connect input/output ports.
Definition: vtkAlgorithmOutput.h:41
vtkAlgorithm::GetOutputPort
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:509
vtkCollisionDetectionFilter
performs collision determination between two polyhedral surfaces
Definition: vtkCollisionDetectionFilter.h:81
vtkCollisionDetectionFilter::NumberOfBoxTests
int NumberOfBoxTests
Definition: vtkCollisionDetectionFilter.h:259
vtkCollisionDetectionFilter::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
vtkCollisionDetectionFilter::SetCollisionModeToFirstContact
void SetCollisionModeToFirstContact()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:109
vtkCollisionDetectionFilter::GetMatrix
vtkMatrix4x4 * GetMatrix(int i)
vtkCollisionDetectionFilter::Tree1
vtkOBBTree * Tree1
Definition: vtkCollisionDetectionFilter.h:254
vtkCollisionDetectionFilter::SetTransform
void SetTransform(int i, vtkLinearTransform *transform)
vtkCollisionDetectionFilter::CellTolerance
float CellTolerance
Definition: vtkCollisionDetectionFilter.h:266
vtkCollisionDetectionFilter::GetCollisionModeAsString
const char * GetCollisionModeAsString()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:111
vtkCollisionDetectionFilter::New
static vtkCollisionDetectionFilter * New()
Standard methods for construction, type and printing.
vtkCollisionDetectionFilter::GetMTime
vtkMTimeType GetMTime() override
Return this object's modified time.
vtkCollisionDetectionFilter::BoxTolerance
float BoxTolerance
Definition: vtkCollisionDetectionFilter.h:265
vtkCollisionDetectionFilter::GetContactCells
vtkIdTypeArray * GetContactCells(int i)
Get an array of the contacting cells.
vtkCollisionDetectionFilter::GetTransform
vtkLinearTransform * GetTransform(int i)
Definition: vtkCollisionDetectionFilter.h:171
vtkCollisionDetectionFilter::CollisionModes
CollisionModes
Definition: vtkCollisionDetectionFilter.h:93
vtkCollisionDetectionFilter::GetNumberOfContacts
int GetNumberOfContacts()
vtkCollisionDetectionFilter::~vtkCollisionDetectionFilter
~vtkCollisionDetectionFilter() override
vtkCollisionDetectionFilter::SetCollisionModeToHalfContacts
void SetCollisionModeToHalfContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:110
vtkCollisionDetectionFilter::Tree0
vtkOBBTree * Tree0
Definition: vtkCollisionDetectionFilter.h:253
vtkCollisionDetectionFilter::GetInputData
vtkPolyData * GetInputData(int i)
Set and Get the input vtk polydata models.
vtkCollisionDetectionFilter::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for construction, type and printing.
vtkCollisionDetectionFilter::SetInputData
void SetInputData(int i, vtkPolyData *model)
Set and Get the input vtk polydata models.
vtkCollisionDetectionFilter::vtkCollisionDetectionFilter
vtkCollisionDetectionFilter()
vtkCollisionDetectionFilter::IntersectPolygonWithPolygon
int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], int npts2, double *pts2, double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode)
Description: Intersect two polygons, return x1 and x2 as the two points of intersection.
vtkCollisionDetectionFilter::Opacity
float Opacity
Definition: vtkCollisionDetectionFilter.h:267
vtkCollisionDetectionFilter::SetMatrix
void SetMatrix(int i, vtkMatrix4x4 *matrix)
vtkCollisionDetectionFilter::SetCollisionModeToAllContacts
void SetCollisionModeToAllContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:108
vtkCollisionDetectionFilter::GenerateScalars
int GenerateScalars
Definition: vtkCollisionDetectionFilter.h:263
vtkCollisionDetectionFilter::CollisionMode
int CollisionMode
Definition: vtkCollisionDetectionFilter.h:269
vtkCollisionDetectionFilter::NumberOfCellsPerNode
int NumberOfCellsPerNode
Definition: vtkCollisionDetectionFilter.h:261
vtkCollisionDetectionFilter::GetContactsOutputPort
vtkAlgorithmOutput * GetContactsOutputPort()
Get the output with the points where the contacting cells intersect.
Definition: vtkCollisionDetectionFilter.h:162
vtkCollisionDetectionFilter::GetContactsOutput
vtkPolyData * GetContactsOutput()
Get the output with the points where the contacting cells intersect.
Definition: vtkCollisionDetectionFilter.h:163
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:37
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:40
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:72
vtkLinearTransform
abstract superclass for linear transformations
Definition: vtkLinearTransform.h:41
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
vtkOBBTree
generate oriented bounding box (OBB) tree
Definition: vtkOBBTree.h:95
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:38
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:43
vtkPolyDataAlgorithm::GetOutput
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:89
vtkX3D::Transform
@ Transform
Definition: vtkX3D.h:41
vtkFieldData.h
vtkPolyDataAlgorithm.h
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270