VTK  9.5.2
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
43
45/*
46 * @warning
47 * Currently only triangles are processed. Use vtkTriangleFilter to
48 * convert any strips or polygons to triangles.
49 */
51
53/*
54 * @cite
55 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
56 * who wrote this class.
57 * Thanks to Peter C. Everett
58 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
59 * particular, and all those who contributed to vtkOBBTree in general.
60 * The original code was contained here: https://github.com/glawlor/vtkbioeng
61 *
62 */
64
66/*
67 * @see
68 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
69 */
71
72#ifndef vtkCollisionDetectionFilter_h
73#define vtkCollisionDetectionFilter_h
74
75#include "vtkFieldData.h" // For GetContactCells
76#include "vtkFiltersModelingModule.h" // For export macro
78
79VTK_ABI_NAMESPACE_BEGIN
80class vtkOBBTree;
81class vtkPolyData;
82class vtkPoints;
83class vtkMatrix4x4;
85class vtkIdTypeArray;
86
87class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
88{
89public:
91
96 void PrintSelf(ostream& os, vtkIndent indent) override;
98
105
107
113 vtkGetMacro(CollisionMode, int);
114
119 {
120 if (this->CollisionMode == VTK_ALL_CONTACTS)
121 {
122 return "AllContacts";
123 }
124 else if (this->CollisionMode == VTK_FIRST_CONTACT)
125 {
126 return "FirstContact";
127 }
128 else
129 {
130 return "HalfContacts";
131 }
132 }
133
134
136
143 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
144 double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
146
148
151 void SetInputData(int i, vtkPolyData* model);
154
156
164
166
172
174 /* Specify the transform object used to transform models. Alternatively, matrices
175 * can be set instead.
176` */
177 void SetTransform(int i, vtkLinearTransform* transform);
178 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
180
182 /* Specify the matrix object used to transform models.
183 */
184 void SetMatrix(int i, vtkMatrix4x4* matrix);
187
189 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
190 */
191 vtkSetMacro(BoxTolerance, float);
192 vtkGetMacro(BoxTolerance, float);
194
196 /* Set and Get the cell tolerance (squared value). Default is 0.0
197 */
198 vtkSetMacro(CellTolerance, double);
199 vtkGetMacro(CellTolerance, double);
201
203 /*
204 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
205 * will be coloured from red through to blue, with collisions first determined coloured red.
206 */
207 vtkSetMacro(GenerateScalars, int);
208 vtkGetMacro(GenerateScalars, int);
209 vtkBooleanMacro(GenerateScalars, int);
211
213 /*
214 * Get the number of contacting cell pairs.
215 *
216 * @note If FirstContact mode is set, it will return either 0 or 1.
217 * @warning It is mandatory to call Update() before, otherwise -1 is returned
218 * @return -1 if internal nullptr is found, otherwise the number of contacts found
219 */
222
224 /*
225 * Get the number of box tests
226 */
227 vtkGetMacro(NumberOfBoxTests, int);
229
231 /*
232 * Set and Get the number of cells in each OBB. Default is 2
233 */
234 vtkSetMacro(NumberOfCellsPerNode, int);
235 vtkGetMacro(NumberOfCellsPerNode, int);
237
239 /*
240 * Set and Get the opacity of the polydata output when a collision takes place.
241 * Default is 1.0
242 */
243 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
244 vtkGetMacro(Opacity, float);
246
248 /*
249 * Return the MTime also considering the transform.
250 */
253
254protected:
257
258 // Usual data generation method
262
265
267
269
271
274 float Opacity;
275
277
278private:
280 void operator=(const vtkCollisionDetectionFilter&) = delete;
281};
282
283VTK_ABI_NAMESPACE_END
284#endif
Proxy object to connect input/output ports.
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)
virtual void SetCollisionMode(int)
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
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
represent and manipulate 3D points
Definition vtkPoints.h:139
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
concrete dataset represents vertices, lines, polygons, and triangle strips
vtkAlgorithmOutput * GetOutputPort()
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287