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
37 /*
39  * @warning
40  * Currently only triangles are processed. Use vtkTriangleFilter to
41  * convert any strips or polygons to triangles.
42  */
44 
46 /*
47  * @cite
48  * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
49  * who wrote this class.
50  * Thanks to Peter C. Everett
51  * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
52  * particular, and all those who contributed to vtkOBBTree in general.
53  * The original code was contained here: https://github.com/glawlor/vtkbioeng
54  *
55  */
57 
59 /*
60  * @see
61  * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
62  */
64 
65 #ifndef vtkCollisionDetectionFilter_h
66 #define vtkCollisionDetectionFilter_h
67 
68 #include "vtkFieldData.h" // For GetContactCells
69 #include "vtkFiltersModelingModule.h" // For export macro
70 #include "vtkPolyDataAlgorithm.h"
71 
72 VTK_ABI_NAMESPACE_BEGIN
73 class vtkOBBTree;
74 class vtkPolyData;
75 class vtkPoints;
76 class vtkMatrix4x4;
77 class vtkLinearTransform;
78 class vtkIdTypeArray;
79 
80 class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
81 {
82 public:
84 
89  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
93  {
94  VTK_ALL_CONTACTS = 0,
95  VTK_FIRST_CONTACT = 1,
96  VTK_HALF_CONTACTS = 2
97  };
98 
100 
105  vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
106  vtkGetMacro(CollisionMode, int);
107 
108  void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
109  void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
110  void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
112  {
113  if (this->CollisionMode == VTK_ALL_CONTACTS)
114  {
115  return "AllContacts";
116  }
117  else if (this->CollisionMode == VTK_FIRST_CONTACT)
118  {
119  return "FirstContact";
120  }
121  else
122  {
123  return "HalfContacts";
124  }
125  }
127 
129 
136  int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
137  double bounds2[6], double tol2, double x1[3], double x2[3], int CollisionMode);
139 
141 
144  void SetInputData(int i, vtkPolyData* model);
147 
149 
157 
159 
163  vtkPolyData* GetContactsOutput() { return this->GetOutput(2); }
165 
167  /* Specify the transform object used to transform models. Alternatively, matrices
168  * can be set instead.
169 ` */
170  void SetTransform(int i, vtkLinearTransform* transform);
171  vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
173 
175  /* Specify the matrix object used to transform models.
176  */
177  void SetMatrix(int i, vtkMatrix4x4* matrix);
180 
182  /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
183  */
184  vtkSetMacro(BoxTolerance, float);
185  vtkGetMacro(BoxTolerance, float);
187 
189  /* Set and Get the cell tolerance (squared value). Default is 0.0
190  */
191  vtkSetMacro(CellTolerance, double);
192  vtkGetMacro(CellTolerance, double);
194 
196  /*
197  * Set and Get the the flag to visualize the contact cells. If set the contacting cells
198  * will be coloured from red through to blue, with collisions first determined coloured red.
199  */
200  vtkSetMacro(GenerateScalars, int);
201  vtkGetMacro(GenerateScalars, int);
202  vtkBooleanMacro(GenerateScalars, int);
204 
206  /*
207  * Get the number of contacting cell pairs.
208  *
209  * @note If FirstContact mode is set, it will return either 0 or 1.
210  * @warning It is mandatory to call Update() before, otherwise -1 is returned
211  * @return -1 if internal nullptr is found, otherwise the number of contacts found
212  */
215 
217  /*
218  * Get the number of box tests
219  */
220  vtkGetMacro(NumberOfBoxTests, int);
222 
224  /*
225  * Set and Get the number of cells in each OBB. Default is 2
226  */
227  vtkSetMacro(NumberOfCellsPerNode, int);
228  vtkGetMacro(NumberOfCellsPerNode, int);
230 
232  /*
233  * Set and Get the opacity of the polydata output when a collision takes place.
234  * Default is 1.0
235  */
236  vtkSetClampMacro(Opacity, float, 0.0, 1.0);
237  vtkGetMacro(Opacity, float);
239 
241  /*
242  * Return the MTime also considering the transform.
243  */
244  vtkMTimeType GetMTime() override;
246 
247 protected:
250 
251  // Usual data generation method
255 
257  vtkMatrix4x4* Matrix[2];
258 
260 
262 
264 
267  float Opacity;
268 
270 
271 private:
273  void operator=(const vtkCollisionDetectionFilter&) = delete;
274 };
275 
276 VTK_ABI_NAMESPACE_END
277 #endif
Proxy object to connect input/output ports.
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:509
performs collision determination between two polyhedral surfaces
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 ...
vtkMatrix4x4 * GetMatrix(int i)
void SetTransform(int i, vtkLinearTransform *transform)
const char * GetCollisionModeAsString()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
static vtkCollisionDetectionFilter * New()
Standard methods for construction, type and printing.
vtkMTimeType GetMTime() override
Return this object's modified time.
vtkIdTypeArray * GetContactCells(int i)
Get an array of the contacting cells.
vtkLinearTransform * GetTransform(int i)
~vtkCollisionDetectionFilter() override
void SetCollisionModeToHalfContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
vtkPolyData * GetInputData(int i)
Set and Get the input vtk polydata models.
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.
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 ...
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.
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
Definition: vtkMatrix4x4.h:40
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
@ Transform
Definition: vtkX3D.h:41
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270