VTK  9.4.20241114
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
47
48/*
49 * @warning
50 * Currently only triangles are processed. Use vtkTriangleFilter to
51 * convert any strips or polygons to triangles.
52 */
54
56/*
57 * @cite
58 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
59 * who wrote this class.
60 * Thanks to Peter C. Everett
61 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
62 * particular, and all those who contributed to vtkOBBTree in general.
63 * The original code was contained here: https://github.com/glawlor/vtkbioeng
64 *
65 */
67
69/*
70 * @see
71 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
72 */
74
75#ifndef vtkCollisionDetectionFilter_h
76#define vtkCollisionDetectionFilter_h
77
78#include "vtkFieldData.h" // For GetContactCells
79#include "vtkFiltersModelingModule.h" // For export macro
81
82VTK_ABI_NAMESPACE_BEGIN
83class vtkOBBTree;
84class vtkPolyData;
85class vtkPoints;
86class vtkMatrix4x4;
88class vtkIdTypeArray;
89
90class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
91{
92public:
94
99 void PrintSelf(ostream& os, vtkIndent indent) override;
101
103 {
104 VTK_ALL_CONTACTS = 0,
105 VTK_FIRST_CONTACT = 1,
106 VTK_HALF_CONTACTS = 2
107 };
108
110
115 vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
116 vtkGetMacro(CollisionMode, int);
117
118 void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
119 void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
120 void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
122 {
123 if (this->CollisionMode == VTK_ALL_CONTACTS)
124 {
125 return "AllContacts";
126 }
127 else if (this->CollisionMode == VTK_FIRST_CONTACT)
128 {
129 return "FirstContact";
130 }
131 else
132 {
133 return "HalfContacts";
134 }
135 }
137
139
146 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
147 double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
149
151
154 void SetInputData(int i, vtkPolyData* model);
157
159
167
169
172 vtkAlgorithmOutput* GetContactsOutputPort() { return this->GetOutputPort(2); }
173 vtkPolyData* GetContactsOutput() { return this->GetOutput(2); }
175
177 /* Specify the transform object used to transform models. Alternatively, matrices
178 * can be set instead.
179` */
180 void SetTransform(int i, vtkLinearTransform* transform);
181 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
183
185 /* Specify the matrix object used to transform models.
186 */
187 void SetMatrix(int i, vtkMatrix4x4* matrix);
190
192 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
193 */
194 vtkSetMacro(BoxTolerance, float);
195 vtkGetMacro(BoxTolerance, float);
197
199 /* Set and Get the cell tolerance (squared value). Default is 0.0
200 */
201 vtkSetMacro(CellTolerance, double);
202 vtkGetMacro(CellTolerance, double);
204
206 /*
207 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
208 * will be coloured from red through to blue, with collisions first determined coloured red.
209 */
210 vtkSetMacro(GenerateScalars, int);
211 vtkGetMacro(GenerateScalars, int);
212 vtkBooleanMacro(GenerateScalars, int);
214
216 /*
217 * Get the number of contacting cell pairs.
218 *
219 * @note If FirstContact mode is set, it will return either 0 or 1.
220 * @warning It is mandatory to call Update() before, otherwise -1 is returned
221 * @return -1 if internal nullptr is found, otherwise the number of contacts found
222 */
225
227 /*
228 * Get the number of box tests
229 */
230 vtkGetMacro(NumberOfBoxTests, int);
232
234 /*
235 * Set and Get the number of cells in each OBB. Default is 2
236 */
237 vtkSetMacro(NumberOfCellsPerNode, int);
238 vtkGetMacro(NumberOfCellsPerNode, int);
240
242 /*
243 * Set and Get the opacity of the polydata output when a collision takes place.
244 * Default is 1.0
245 */
246 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
247 vtkGetMacro(Opacity, float);
249
251 /*
252 * Return the MTime also considering the transform.
253 */
256
257protected:
260
261 // Usual data generation method
265
266 vtkLinearTransform* Transform[2];
267 vtkMatrix4x4* Matrix[2];
268
270
272
274
277 float Opacity;
278
280
281private:
283 void operator=(const vtkCollisionDetectionFilter&) = delete;
284};
285
286VTK_ABI_NAMESPACE_END
287#endif
Proxy object to connect input/output ports.
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:108
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:165
represent and manipulate 3D points
Definition vtkPoints.h:139
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270