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
83/*
84 * @warning
85 * Currently only triangles are processed. Use vtkTriangleFilter to
86 * convert any strips or polygons to triangles.
87 */
89
91/*
92 * @cite
93 * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
94 * who wrote this class.
95 * Thanks to Peter C. Everett
96 * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
97 * particular, and all those who contributed to vtkOBBTree in general.
98 * The original code was contained here: https://github.com/glawlor/vtkbioeng
99 *
100 */
102
104/*
105 * @see
106 * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
107 */
109
110#ifndef vtkCollisionDetectionFilter_h
111#define vtkCollisionDetectionFilter_h
112
113#include "vtkFieldData.h" // For GetContactCells
114#include "vtkFiltersModelingModule.h" // For export macro
115#include "vtkPolyDataAlgorithm.h"
116
117class vtkOBBTree;
118class vtkPolyData;
119class vtkPoints;
120class vtkMatrix4x4;
122class vtkIdTypeArray;
123
124class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
125{
126public:
128
133 void PrintSelf(ostream& os, vtkIndent indent) override;
135
137 {
138 VTK_ALL_CONTACTS = 0,
139 VTK_FIRST_CONTACT = 1,
140 VTK_HALF_CONTACTS = 2
141 };
142
144
149 vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
150 vtkGetMacro(CollisionMode, int);
151
152 void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
153 void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
154 void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
155 const char* GetCollisionModeAsString(void)
156 {
157 if (this->CollisionMode == VTK_ALL_CONTACTS)
158 {
159 return "AllContacts";
160 }
161 else if (this->CollisionMode == VTK_FIRST_CONTACT)
162 {
163 return "FirstContact";
164 }
165 else
166 {
167 return "HalfContacts";
168 }
169 }
171
173
180 int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
181 double bounds2[6], double tol2, double x1[2], double x2[3], int CollisionMode);
183
185
188 void SetInputData(int i, vtkPolyData* model);
191
193
201
203
209
211 /* Specify the transform object used to transform models. Alternatively, matrices
212 * can be set instead.
213` */
214 void SetTransform(int i, vtkLinearTransform* transform);
215 vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
217
219 /* Specify the matrix object used to transform models.
220 */
221 void SetMatrix(int i, vtkMatrix4x4* matrix);
224
226 /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
227 */
228 vtkSetMacro(BoxTolerance, float);
229 vtkGetMacro(BoxTolerance, float);
231
233 /* Set and Get the cell tolerance (squared value). Default is 0.0
234 */
235 vtkSetMacro(CellTolerance, double);
236 vtkGetMacro(CellTolerance, double);
238
240 /*
241 * Set and Get the the flag to visualize the contact cells. If set the contacting cells
242 * will be coloured from red through to blue, with collisions first determined coloured red.
243 */
244 vtkSetMacro(GenerateScalars, int);
245 vtkGetMacro(GenerateScalars, int);
246 vtkBooleanMacro(GenerateScalars, int);
248
250 /*
251 * Get the number of contacting cell pairs.
252 *
253 * @note If FirstContact mode is set, it will return either 0 or 1.
254 * @warning It is mandatory to call Update() before, otherwise -1 is returned
255 * @return -1 if internal nullptr is found, otherwise the number of contacts found
256 */
259
261 /*
262 * Get the number of box tests
263 */
264 vtkGetMacro(NumberOfBoxTests, int);
266
268 /*
269 * Set and Get the number of cells in each OBB. Default is 2
270 */
271 vtkSetMacro(NumberOfCellsPerNode, int);
272 vtkGetMacro(NumberOfCellsPerNode, int);
274
276 /*
277 * Set and Get the opacity of the polydata output when a collision takes place.
278 * Default is 1.0
279 */
280 vtkSetClampMacro(Opacity, float, 0.0, 1.0);
281 vtkGetMacro(Opacity, float);
283
285 /*
286 * Return the MTime also considering the transform.
287 */
290
291protected:
294
295 // Usual data generation method
299
301 vtkMatrix4x4* Matrix[2];
302
304
306
308
311 float Opacity;
312
314
315private:
317 void operator=(const vtkCollisionDetectionFilter&) = delete;
318};
319
320#endif
Proxy object to connect input/output ports.
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:529
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.
const char * GetCollisionModeAsString(void)
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)
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.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:113
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:145
generate oriented bounding box (OBB) tree
Definition: vtkOBBTree.h:165
represent and manipulate 3D points
Definition: vtkPoints.h:143
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:195
@ Transform
Definition: vtkX3D.h:47
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287