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
28
29/*
30 * @warning
31 * Currently only triangles are processed. Use vtkTriangleFilter to
32 * convert any strips or polygons to triangles.
33 */
35
37/*
38 * @cite
39 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
40 * who wrote this class.
41 * Thanks to Peter C. Everett
42 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
43 * particular, and all those who contributed to vtkOBBTree in general.
44 * The original code was contained here: https://github.com/glawlor/vtkbioeng
45 *
46 */
48
50/*
51 * @see
52 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
53 */
55
56#ifndef vtkCollisionDetectionFilter_h
57#define vtkCollisionDetectionFilter_h
58
59#include "vtkFieldData.h" // For GetContactCells
60#include "vtkFiltersModelingModule.h" // For export macro
62
63VTK_ABI_NAMESPACE_BEGIN
64class vtkOBBTree;
65class vtkPolyData;
66class vtkPoints;
67class vtkMatrix4x4;
69class vtkIdTypeArray;
70
71class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
72{
73public:
75
80 void PrintSelf(ostream& os, vtkIndent indent) override;
82
84 {
85 VTK_ALL_CONTACTS = 0,
86 VTK_FIRST_CONTACT = 1,
87 VTK_HALF_CONTACTS = 2
88 };
89
91
96 vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
97 vtkGetMacro(CollisionMode, int);
98
99 void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
100 void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
101 void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
103 {
104 if (this->CollisionMode == VTK_ALL_CONTACTS)
105 {
106 return "AllContacts";
107 }
108 else if (this->CollisionMode == VTK_FIRST_CONTACT)
109 {
110 return "FirstContact";
111 }
112 else
113 {
114 return "HalfContacts";
115 }
116 }
118
120
127 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
128 double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
130
132
135 void SetInputData(int i, vtkPolyData* model);
138
140
148
150
156
158 /* Specify the transform object used to transform models. Alternatively, matrices
159 * can be set instead.
160` */
161 void SetTransform(int i, vtkLinearTransform* transform);
162 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
164
166 /* Specify the matrix object used to transform models.
167 */
168 void SetMatrix(int i, vtkMatrix4x4* matrix);
171
173 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
174 */
175 vtkSetMacro(BoxTolerance, float);
176 vtkGetMacro(BoxTolerance, float);
178
180 /* Set and Get the cell tolerance (squared value). Default is 0.0
181 */
182 vtkSetMacro(CellTolerance, double);
183 vtkGetMacro(CellTolerance, double);
185
187 /*
188 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
189 * will be coloured from red through to blue, with collisions first determined coloured red.
190 */
191 vtkSetMacro(GenerateScalars, int);
192 vtkGetMacro(GenerateScalars, int);
193 vtkBooleanMacro(GenerateScalars, int);
195
197 /*
198 * Get the number of contacting cell pairs.
199 *
200 * @note If FirstContact mode is set, it will return either 0 or 1.
201 * @warning It is mandatory to call Update() before, otherwise -1 is returned
202 * @return -1 if internal nullptr is found, otherwise the number of contacts found
203 */
206
208 /*
209 * Get the number of box tests
210 */
211 vtkGetMacro(NumberOfBoxTests, int);
213
215 /*
216 * Set and Get the number of cells in each OBB. Default is 2
217 */
218 vtkSetMacro(NumberOfCellsPerNode, int);
219 vtkGetMacro(NumberOfCellsPerNode, int);
221
223 /*
224 * Set and Get the opacity of the polydata output when a collision takes place.
225 * Default is 1.0
226 */
227 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
228 vtkGetMacro(Opacity, float);
230
232 /*
233 * Return the MTime also considering the transform.
234 */
237
238protected:
241
242 // Usual data generation method
246
247 vtkLinearTransform* Transform[2];
248 vtkMatrix4x4* Matrix[2];
249
251
253
255
258 float Opacity;
259
261
262private:
264 void operator=(const vtkCollisionDetectionFilter&) = delete;
265};
266
267VTK_ABI_NAMESPACE_END
268#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