VTK  9.0.1
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 
67 /*
68  * @warning
69  * Currently only triangles are processed. Use vtkTriangleFilter to
70  * convert any strips or polygons to triangles.
71  */
73 
75 /*
76  * @cite
77  * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
78  * who wrote this class.
79  * Thanks to Peter C. Everett
80  * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
81  * particular, and all those who contributed to vtkOBBTree in general.
82  * The original code was contained here: https://github.com/glawlor/vtkbioeng
83  *
84  */
86 
88 /*
89  * @see
90  * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
91  */
93 
94 #ifndef vtkCollisionDetectionFilter_h
95 #define vtkCollisionDetectionFilter_h
96 
97 #include "vtkFieldData.h" // For GetContactCells
98 #include "vtkFiltersModelingModule.h" // For export macro
99 #include "vtkPolyDataAlgorithm.h"
100 
101 class vtkOBBTree;
102 class vtkPolyData;
103 class vtkPoints;
104 class vtkMatrix4x4;
105 class vtkLinearTransform;
106 class vtkIdTypeArray;
107 
108 class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm
109 {
110 public:
112 
117  void PrintSelf(ostream& os, vtkIndent indent) override;
119 
121  {
122  VTK_ALL_CONTACTS = 0,
123  VTK_FIRST_CONTACT = 1,
124  VTK_HALF_CONTACTS = 2
125  };
126 
128 
133  vtkSetClampMacro(CollisionMode, int, VTK_ALL_CONTACTS, VTK_HALF_CONTACTS);
134  vtkGetMacro(CollisionMode, int);
135 
136  void SetCollisionModeToAllContacts() { this->SetCollisionMode(VTK_ALL_CONTACTS); }
137  void SetCollisionModeToFirstContact() { this->SetCollisionMode(VTK_FIRST_CONTACT); }
138  void SetCollisionModeToHalfContacts() { this->SetCollisionMode(VTK_HALF_CONTACTS); }
139  const char* GetCollisionModeAsString(void)
140  {
141  if (this->CollisionMode == VTK_ALL_CONTACTS)
142  {
143  return "AllContacts";
144  }
145  else if (this->CollisionMode == VTK_FIRST_CONTACT)
146  {
147  return "FirstContact";
148  }
149  else
150  {
151  return "HalfContacts";
152  }
153  }
155 
157 
164  int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, double* pts2,
165  double bounds2[6], double tol2, double x1[2], double x2[3], int CollisionMode);
167 
169 
172  void SetInputData(int i, vtkPolyData* model);
173  vtkPolyData* GetInputData(int i);
175 
177 
183  vtkIdTypeArray* GetContactCells(int i);
185 
187 
191  vtkPolyData* GetContactsOutput() { return this->GetOutput(2); }
193 
195  /* Specify the transform object used to transform models. Alternatively, matrices
196  * can be set instead.
197 ` */
198  void SetTransform(int i, vtkLinearTransform* transform);
199  vtkLinearTransform* GetTransform(int i) { return this->Transform[i]; }
201 
203  /* Specify the matrix object used to transform models.
204  */
205  void SetMatrix(int i, vtkMatrix4x4* matrix);
206  vtkMatrix4x4* GetMatrix(int i);
208 
210  /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
211  */
212  vtkSetMacro(BoxTolerance, float);
213  vtkGetMacro(BoxTolerance, float);
215 
217  /* Set and Get the cell tolerance (squared value). Default is 0.0
218  */
219  vtkSetMacro(CellTolerance, double);
220  vtkGetMacro(CellTolerance, double);
222 
224  /*
225  * Set and Get the the flag to visualize the contact cells. If set the contacting cells
226  * will be coloured from red through to blue, with collisions first determined coloured red.
227  */
228  vtkSetMacro(GenerateScalars, int);
229  vtkGetMacro(GenerateScalars, int);
230  vtkBooleanMacro(GenerateScalars, int);
232 
234  /*
235  * Get the number of contacting cell pairs
236  */
238  {
239  return this->GetOutput(0)->GetFieldData()->GetArray("ContactCells")->GetNumberOfTuples();
240  }
242 
244  /*
245  * Get the number of box tests
246  */
247  vtkGetMacro(NumberOfBoxTests, int);
249 
251  /*
252  * Set and Get the number of cells in each OBB. Default is 2
253  */
254  vtkSetMacro(NumberOfCellsPerNode, int);
255  vtkGetMacro(NumberOfCellsPerNode, int);
257 
259  /*
260  * Set and Get the opacity of the polydata output when a collision takes place.
261  * Default is 1.0
262  */
263  vtkSetClampMacro(Opacity, float, 0.0, 1.0);
264  vtkGetMacro(Opacity, float);
266 
268  /*
269  * Return the MTime also considering the transform.
270  */
271  vtkMTimeType GetMTime() override;
273 
274 protected:
276  ~vtkCollisionDetectionFilter() override;
277 
278  // Usual data generation method
282 
284  vtkMatrix4x4* Matrix[2];
285 
287 
289 
291 
294  float Opacity;
295 
297 
298 private:
300  void operator=(const vtkCollisionDetectionFilter&) = delete;
301 };
302 
303 #endif
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:471
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
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:293
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:84
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.
static vtkPolyDataAlgorithm * New()
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:33
virtual vtkMTimeType GetMTime()
Return this object&#39;s modified time.
virtual vtkFieldData * GetFieldData()
Assign or retrieve a general field data to this data object.
void SetInputData(vtkDataObject *)
Assign a data object as input.
performs collision determination between two polyhedral surfaces
vtkLinearTransform * GetTransform(int i)
const char * GetCollisionModeAsString(void)
Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with two points per ...
Store zero or more vtkInformation instances.
vtkDataArray * GetArray(int i)
Not recommended for use.
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:33
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
abstract superclass for linear transformations