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
34
35/*
36 * @warning
37 * Currently only triangles are processed. Use vtkTriangleFilter to
38 * convert any strips or polygons to triangles.
39 */
41
43/*
44 * @cite
45 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
46 * who wrote this class.
47 * Thanks to Peter C. Everett
48 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
49 * particular, and all those who contributed to vtkOBBTree in general.
50 * The original code was contained here: https://github.com/glawlor/vtkbioeng
51 *
52 */
54
56/*
57 * @see
58 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
59 */
61
62#ifndef vtkCollisionDetectionFilter_h
63#define vtkCollisionDetectionFilter_h
64
65#include "vtkFieldData.h" // For GetContactCells
66#include "vtkFiltersModelingModule.h" // For export macro
68
69VTK_ABI_NAMESPACE_BEGIN
70class vtkOBBTree;
71class vtkPolyData;
72class vtkPoints;
73class vtkMatrix4x4;
75class vtkIdTypeArray;
76
77class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
78{
79public:
81
86 void PrintSelf(ostream& os, vtkIndent indent) override;
88
90 {
91 VTK_ALL_CONTACTS = 0,
92 VTK_FIRST_CONTACT = 1,
93 VTK_HALF_CONTACTS = 2
94 };
95
97
102 vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
103 vtkGetMacro(CollisionMode, int);
104
105 void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
106 void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
107 void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
109 {
110 if (this->CollisionMode == VTK_ALL_CONTACTS)
111 {
112 return "AllContacts";
113 }
114 else if (this->CollisionMode == VTK_FIRST_CONTACT)
115 {
116 return "FirstContact";
117 }
118 else
119 {
120 return "HalfContacts";
121 }
122 }
124
126
133 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
134 double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
136
138
141 void SetInputData(int i, vtkPolyData* model);
144
146
154
156
162
164 /* Specify the transform object used to transform models. Alternatively, matrices
165 * can be set instead.
166` */
167 void SetTransform(int i, vtkLinearTransform* transform);
168 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
170
172 /* Specify the matrix object used to transform models.
173 */
174 void SetMatrix(int i, vtkMatrix4x4* matrix);
177
179 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
180 */
181 vtkSetMacro(BoxTolerance, float);
182 vtkGetMacro(BoxTolerance, float);
184
186 /* Set and Get the cell tolerance (squared value). Default is 0.0
187 */
188 vtkSetMacro(CellTolerance, double);
189 vtkGetMacro(CellTolerance, double);
191
193 /*
194 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
195 * will be coloured from red through to blue, with collisions first determined coloured red.
196 */
197 vtkSetMacro(GenerateScalars, int);
198 vtkGetMacro(GenerateScalars, int);
199 vtkBooleanMacro(GenerateScalars, int);
201
203 /*
204 * Get the number of contacting cell pairs.
205 *
206 * @note If FirstContact mode is set, it will return either 0 or 1.
207 * @warning It is mandatory to call Update() before, otherwise -1 is returned
208 * @return -1 if internal nullptr is found, otherwise the number of contacts found
209 */
212
214 /*
215 * Get the number of box tests
216 */
217 vtkGetMacro(NumberOfBoxTests, int);
219
221 /*
222 * Set and Get the number of cells in each OBB. Default is 2
223 */
224 vtkSetMacro(NumberOfCellsPerNode, int);
225 vtkGetMacro(NumberOfCellsPerNode, int);
227
229 /*
230 * Set and Get the opacity of the polydata output when a collision takes place.
231 * Default is 1.0
232 */
233 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
234 vtkGetMacro(Opacity, float);
236
238 /*
239 * Return the MTime also considering the transform.
240 */
243
244protected:
247
248 // Usual data generation method
252
253 vtkLinearTransform* Transform[2];
254 vtkMatrix4x4* Matrix[2];
255
257
259
261
264 float Opacity;
265
267
268private:
270 void operator=(const vtkCollisionDetectionFilter&) = delete;
271};
272
273VTK_ABI_NAMESPACE_END
274#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:38
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:95
represent and manipulate 3D points
Definition vtkPoints.h:38
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:89
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270