VTK  9.1.0
vtkCollisionDetectionFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCollisionDetection.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14  Copyright (c) Goodwin Lawlor All rights reserved.
15  BSD 3-Clause License
16 
17  Redistribution and use in source and binary forms, with or without
18  modification, are permitted provided that the following conditions are
19  met:
20 
21  Redistributions of source code must retain the above copyright notice,
22  this list of conditions and the following disclaimer.
23 
24  Redistributions in binary form must reproduce the above copyright
25  notice, this list of conditions and the following disclaimer in the
26  documentation and/or other materials provided with the distribution.
27 
28  Neither the name of the copyright holder nor the names of its
29  contributors may be used to endorse or promote products derived from
30  this software without specific prior written permission.
31 
32  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 =========================================================================*/
44 
88 /*
90  * @warning
91  * Currently only triangles are processed. Use vtkTriangleFilter to
92  * convert any strips or polygons to triangles.
93  */
95 
97 /*
98  * @cite
99  * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
100  * who wrote this class.
101  * Thanks to Peter C. Everett
102  * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
103  * particular, and all those who contributed to vtkOBBTree in general.
104  * The original code was contained here: https://github.com/glawlor/vtkbioeng
105  *
106  */
108 
110 /*
111  * @see
112  * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
113  */
115 
116 #ifndef vtkCollisionDetectionFilter_h
117 #define vtkCollisionDetectionFilter_h
118 
119 #include "vtkFieldData.h" // For GetContactCells
120 #include "vtkFiltersModelingModule.h" // For export macro
121 #include "vtkPolyDataAlgorithm.h"
122 
123 class vtkOBBTree;
124 class vtkPolyData;
125 class vtkPoints;
126 class vtkMatrix4x4;
127 class vtkLinearTransform;
128 class vtkIdTypeArray;
129 
130 class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
131 {
132 public:
134 
139  void PrintSelf(ostream& os, vtkIndent indent) override;
141 
143  {
144  VTK_ALL_CONTACTS = 0,
145  VTK_FIRST_CONTACT = 1,
146  VTK_HALF_CONTACTS = 2
147  };
148 
150 
155  vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
156  vtkGetMacro(CollisionMode, int);
157 
158  void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
159  void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
160  void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
161  const char* GetCollisionModeAsString(void)
162  {
163  if (this->CollisionMode == VTK_ALL_CONTACTS)
164  {
165  return "AllContacts";
166  }
167  else if (this->CollisionMode == VTK_FIRST_CONTACT)
168  {
169  return "FirstContact";
170  }
171  else
172  {
173  return "HalfContacts";
174  }
175  }
177 
179 
186  int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
187  double bounds2[6], double tol2, double x1[2], double x2[3], int CollisionMode);
189 
191 
194  void SetInputData(int i, vtkPolyData* model);
197 
199 
207 
209 
213  vtkPolyData* GetContactsOutput() { return this->GetOutput(2); }
215 
217  /* Specify the transform object used to transform models. Alternatively, matrices
218  * can be set instead.
219 ` */
220  void SetTransform(int i, vtkLinearTransform* transform);
221  vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
223 
225  /* Specify the matrix object used to transform models.
226  */
227  void SetMatrix(int i, vtkMatrix4x4* matrix);
230 
232  /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
233  */
234  vtkSetMacro(BoxTolerance, float);
235  vtkGetMacro(BoxTolerance, float);
237 
239  /* Set and Get the cell tolerance (squared value). Default is 0.0
240  */
241  vtkSetMacro(CellTolerance, double);
242  vtkGetMacro(CellTolerance, double);
244 
246  /*
247  * Set and Get the the flag to visualize the contact cells. If set the contacting cells
248  * will be coloured from red through to blue, with collisions first determined coloured red.
249  */
250  vtkSetMacro(GenerateScalars, int);
251  vtkGetMacro(GenerateScalars, int);
252  vtkBooleanMacro(GenerateScalars, int);
254 
256  /*
257  * Get the number of contacting cell pairs.
258  *
259  * @note If FirstContact mode is set, it will return either 0 or 1.
260  * @warning It is mandatory to call Update() before, otherwise -1 is returned
261  * @return -1 if internal nullptr is found, otherwise the number of contacts found
262  */
265 
267  /*
268  * Get the number of box tests
269  */
270  vtkGetMacro(NumberOfBoxTests, int);
272 
274  /*
275  * Set and Get the number of cells in each OBB. Default is 2
276  */
277  vtkSetMacro(NumberOfCellsPerNode, int);
278  vtkGetMacro(NumberOfCellsPerNode, int);
280 
282  /*
283  * Set and Get the opacity of the polydata output when a collision takes place.
284  * Default is 1.0
285  */
286  vtkSetClampMacro(Opacity, float, 0.0, 1.0);
287  vtkGetMacro(Opacity, float);
289 
291  /*
292  * Return the MTime also considering the transform.
293  */
294  vtkMTimeType GetMTime() override;
296 
297 protected:
300 
301  // Usual data generation method
305 
307  vtkMatrix4x4* Matrix[2];
308 
310 
312 
314 
317  float Opacity;
318 
320 
321 private:
323  void operator=(const vtkCollisionDetectionFilter&) = delete;
324 };
325 
326 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:143
vtkCollisionDetectionFilter::CollisionMode
int CollisionMode
Definition: vtkCollisionDetectionFilter.h:319
vtkCollisionDetectionFilter::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for construction, type and printing.
vtkCollisionDetectionFilter::SetCollisionModeToHalfContacts
void SetCollisionModeToHalfContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:160
vtkCollisionDetectionFilter::vtkCollisionDetectionFilter
vtkCollisionDetectionFilter()
vtkCollisionDetectionFilter::GetTransform
vtkLinearTransform * GetTransform(int i)
Definition: vtkCollisionDetectionFilter.h:221
vtkCollisionDetectionFilter::SetMatrix
void SetMatrix(int i, vtkMatrix4x4 *matrix)
vtkAlgorithm::GetOutputPort
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:538
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:145
vtkCollisionDetectionFilter::CellTolerance
float CellTolerance
Definition: vtkCollisionDetectionFilter.h:316
vtkCollisionDetectionFilter::GenerateScalars
int GenerateScalars
Definition: vtkCollisionDetectionFilter.h:313
vtkOBBTree
generate oriented bounding box (OBB) tree
Definition: vtkOBBTree.h:165
vtkCollisionDetectionFilter::GetContactsOutput
vtkPolyData * GetContactsOutput()
Get the output with the points where the contacting cells intersect.
Definition: vtkCollisionDetectionFilter.h:213
vtkCollisionDetectionFilter::GetMatrix
vtkMatrix4x4 * GetMatrix(int i)
vtkX3D::Transform
@ Transform
Definition: vtkX3D.h:47
vtkLinearTransform
abstract superclass for linear transformations
Definition: vtkLinearTransform.h:69
vtkFieldData.h
vtkPolyDataAlgorithm.h
vtkCollisionDetectionFilter::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
vtkCollisionDetectionFilter::Tree1
vtkOBBTree * Tree1
Definition: vtkCollisionDetectionFilter.h:304
vtkCollisionDetectionFilter::Tree0
vtkOBBTree * Tree0
Definition: vtkCollisionDetectionFilter.h:303
vtkCollisionDetectionFilter::GetContactCells
vtkIdTypeArray * GetContactCells(int i)
Get an array of the contacting cells.
vtkCollisionDetectionFilter::~vtkCollisionDetectionFilter
~vtkCollisionDetectionFilter() override
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:183
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:145
vtkCollisionDetectionFilter::New
static vtkCollisionDetectionFilter * New()
Standard methods for construction, type and printing.
vtkCollisionDetectionFilter::GetMTime
vtkMTimeType GetMTime() override
Return this object's modified time.
vtkCollisionDetectionFilter::GetInputData
vtkPolyData * GetInputData(int i)
Set and Get the input vtk polydata models.
vtkCollisionDetectionFilter::SetTransform
void SetTransform(int i, vtkLinearTransform *transform)
vtkAlgorithmOutput
Proxy object to connect input/output ports.
Definition: vtkAlgorithmOutput.h:66
vtkCollisionDetectionFilter::CollisionModes
CollisionModes
Definition: vtkCollisionDetectionFilter.h:143
vtkCollisionDetectionFilter::BoxTolerance
float BoxTolerance
Definition: vtkCollisionDetectionFilter.h:315
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:195
vtkCollisionDetectionFilter
performs collision determination between two polyhedral surfaces
Definition: vtkCollisionDetectionFilter.h:131
vtkCollisionDetectionFilter::NumberOfBoxTests
int NumberOfBoxTests
Definition: vtkCollisionDetectionFilter.h:309
vtkCollisionDetectionFilter::IntersectPolygonWithPolygon
int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], int npts2, double *pts2, double bounds2[6], double tol2, double x1[2], double x2[3], int CollisionMode)
Description: Intersect two polygons, return x1 and x2 as the two points of intersection.
vtkCollisionDetectionFilter::SetCollisionModeToAllContacts
void SetCollisionModeToAllContacts()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:158
vtkCollisionDetectionFilter::Opacity
float Opacity
Definition: vtkCollisionDetectionFilter.h:317
vtkCollisionDetectionFilter::SetInputData
void SetInputData(int i, vtkPolyData *model)
Set and Get the input vtk polydata models.
vtkCollisionDetectionFilter::GetCollisionModeAsString
const char * GetCollisionModeAsString(void)
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:161
vtkCollisionDetectionFilter::GetNumberOfContacts
int GetNumberOfContacts()
vtkCollisionDetectionFilter::GetContactsOutputPort
vtkAlgorithmOutput * GetContactsOutputPort()
Get the output with the points where the contacting cells intersect.
Definition: vtkCollisionDetectionFilter.h:212
vtkPolyDataAlgorithm::GetOutput
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
vtkCollisionDetectionFilter::SetCollisionModeToFirstContact
void SetCollisionModeToFirstContact()
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Definition: vtkCollisionDetectionFilter.h:159
vtkCollisionDetectionFilter::NumberOfCellsPerNode
int NumberOfCellsPerNode
Definition: vtkCollisionDetectionFilter.h:311
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:151