VTK  9.3.0
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
25
26/*
27 * @warning
28 * Currently only triangles are processed. Use vtkTriangleFilter to
29 * convert any strips or polygons to triangles.
30 */
32
34/*
35 * @cite
36 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
37 * who wrote this class.
38 * Thanks to Peter C. Everett
39 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
40 * particular, and all those who contributed to vtkOBBTree in general.
41 * The original code was contained here: https://github.com/glawlor/vtkbioeng
42 *
43 */
45
47/*
48 * @see
49 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
50 */
52
53#ifndef vtkCollisionDetectionFilter_h
54#define vtkCollisionDetectionFilter_h
55
56#include "vtkFieldData.h" // For GetContactCells
57#include "vtkFiltersModelingModule.h" // For export macro
59
60VTK_ABI_NAMESPACE_BEGIN
61class vtkOBBTree;
62class vtkPolyData;
63class vtkPoints;
64class vtkMatrix4x4;
66class vtkIdTypeArray;
67
68class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
69{
70public:
72
77 void PrintSelf(ostream& os, vtkIndent indent) override;
79
81 {
82 VTK_ALL_CONTACTS = 0,
83 VTK_FIRST_CONTACT = 1,
84 VTK_HALF_CONTACTS = 2
85 };
86
88
93 vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
94 vtkGetMacro(CollisionMode, int);
95
96 void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
97 void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
98 void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
100 {
101 if (this->CollisionMode == VTK_ALL_CONTACTS)
102 {
103 return "AllContacts";
104 }
105 else if (this->CollisionMode == VTK_FIRST_CONTACT)
106 {
107 return "FirstContact";
108 }
109 else
110 {
111 return "HalfContacts";
112 }
113 }
115
117
124 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
125 double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
127
129
132 void SetInputData(int i, vtkPolyData* model);
135
137
145
147
153
155 /* Specify the transform object used to transform models. Alternatively, matrices
156 * can be set instead.
157` */
158 void SetTransform(int i, vtkLinearTransform* transform);
159 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
161
163 /* Specify the matrix object used to transform models.
164 */
165 void SetMatrix(int i, vtkMatrix4x4* matrix);
168
170 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
171 */
172 vtkSetMacro(BoxTolerance, float);
173 vtkGetMacro(BoxTolerance, float);
175
177 /* Set and Get the cell tolerance (squared value). Default is 0.0
178 */
179 vtkSetMacro(CellTolerance, double);
180 vtkGetMacro(CellTolerance, double);
182
184 /*
185 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
186 * will be coloured from red through to blue, with collisions first determined coloured red.
187 */
188 vtkSetMacro(GenerateScalars, int);
189 vtkGetMacro(GenerateScalars, int);
190 vtkBooleanMacro(GenerateScalars, int);
192
194 /*
195 * Get the number of contacting cell pairs.
196 *
197 * @note If FirstContact mode is set, it will return either 0 or 1.
198 * @warning It is mandatory to call Update() before, otherwise -1 is returned
199 * @return -1 if internal nullptr is found, otherwise the number of contacts found
200 */
203
205 /*
206 * Get the number of box tests
207 */
208 vtkGetMacro(NumberOfBoxTests, int);
210
212 /*
213 * Set and Get the number of cells in each OBB. Default is 2
214 */
215 vtkSetMacro(NumberOfCellsPerNode, int);
216 vtkGetMacro(NumberOfCellsPerNode, int);
218
220 /*
221 * Set and Get the opacity of the polydata output when a collision takes place.
222 * Default is 1.0
223 */
224 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
225 vtkGetMacro(Opacity, float);
227
229 /*
230 * Return the MTime also considering the transform.
231 */
234
235protected:
238
239 // Usual data generation method
243
244 vtkLinearTransform* Transform[2];
245 vtkMatrix4x4* Matrix[2];
246
248
250
252
255 float Opacity;
256
258
259private:
261 void operator=(const vtkCollisionDetectionFilter&) = delete;
262};
263
264VTK_ABI_NAMESPACE_END
265#endif
Proxy object to connect input/output ports.
vtkAlgorithmOutput * GetOutputPort()
performs collision determination between two polyhedral surfaces
vtkAlgorithmOutput * GetContactsOutputPort()
Get the output with the points where the contacting cells intersect.
vtkPolyData * GetContactsOutput()
Get the output with the points where the contacting cells intersect.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
void SetCollisionModeToFirstContact()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
void SetTransform(int i, vtkLinearTransform *transform)
vtkIdTypeArray * GetContactCells(int i)
Get an array of the contacting cells.
vtkPolyData * GetInputData(int i)
Set and Get the input vtk polydata models.
vtkMTimeType GetMTime() override
Return this object's modified time.
vtkMatrix4x4 * GetMatrix(int i)
static vtkCollisionDetectionFilter * New()
Standard methods for construction, type and printing.
~vtkCollisionDetectionFilter() override
void SetCollisionModeToHalfContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for construction, type and printing.
void SetInputData(int i, vtkPolyData *model)
Set and Get the input vtk polydata models.
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.
const char * GetCollisionModeAsString()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
void SetMatrix(int i, vtkMatrix4x4 *matrix)
void SetCollisionModeToAllContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
vtkLinearTransform * GetTransform(int i)
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract superclass for linear transformations
represent and manipulate 4x4 transformation matrices
generate oriented bounding box (OBB) tree
Definition vtkOBBTree.h:86
represent and manipulate 3D points
Definition vtkPoints.h:29
Superclass for algorithms that produce only polydata as output.
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:80
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270