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 /*
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
61 #include "vtkPolyDataAlgorithm.h"
62 
63 VTK_ABI_NAMESPACE_BEGIN
64 class vtkOBBTree;
65 class vtkPolyData;
66 class vtkPoints;
67 class vtkMatrix4x4;
68 class vtkLinearTransform;
69 class vtkIdTypeArray;
70 
71 class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
72 {
73 public:
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);
136  vtkPolyData* GetInputData(int i);
138 
140 
146  vtkIdTypeArray* GetContactCells(int i);
148 
150 
154  vtkPolyData* GetContactsOutput() { return this->GetOutput(2); }
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);
169  vtkMatrix4x4* GetMatrix(int i);
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  */
204  int GetNumberOfContacts();
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  */
235  vtkMTimeType GetMTime() override;
237 
238 protected:
240  ~vtkCollisionDetectionFilter() override;
241 
242  // Usual data generation method
246 
248  vtkMatrix4x4* Matrix[2];
249 
251 
253 
255 
258  float Opacity;
259 
261 
262 private:
264  void operator=(const vtkCollisionDetectionFilter&) = delete;
265 };
266 
267 VTK_ABI_NAMESPACE_END
268 #endif
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:500
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
void SetCollisionModeToHalfContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
vtkPolyData * GetContactsOutput()
Get the output with the points where the contacting cells intersect.
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
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 ...
dynamic, self-adjusting array of vtkIdType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
void SetCollisionModeToAllContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
generate oriented bounding box (OBB) tree
Definition: vtkOBBTree.h:85
Proxy object to connect input/output ports.
const char * GetCollisionModeAsString()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
static vtkPolyDataAlgorithm * New()
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual vtkMTimeType GetMTime()
Return this object's modified time.
void SetInputData(vtkDataObject *)
Assign a data object as input.
performs collision determination between two polyhedral surfaces
vtkLinearTransform * GetTransform(int i)
Store zero or more vtkInformation instances.
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
vtkAlgorithmOutput * GetContactsOutputPort()
Get the output with the points where the contacting cells intersect.
represent and manipulate 3D points
Definition: vtkPoints.h:28
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
abstract superclass for linear transformations