VTK
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 
64  /*
65  * @warning
66  * Currently only triangles are processed. Use vtkTriangleFilter to
67  * convert any strips or polygons to triangles.
68  */
70 
72 /*
73  * @cite
74  * Goodwin Lawlor <goodwin.lawlor@ucd.ie>, University College Dublin,
75  * who wrote this class.
76  * Thanks to Peter C. Everett
77  * <pce@world.std.com> for vtkOBBTree::IntersectWithOBBTree() in
78  * particular, and all those who contributed to vtkOBBTree in general.
79  * The original code was contained here: https://github.com/glawlor/vtkbioeng
80  *
81  */
83 
85 /*
86  * @see
87  * vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree
88  */
90 
91 #ifndef vtkCollisionDetectionFilter_h
92 #define vtkCollisionDetectionFilter_h
93 
94 #include "vtkFiltersModelingModule.h" // For export macro
95 #include "vtkPolyDataAlgorithm.h"
96 #include "vtkFieldData.h" // For GetContactCells
97 
98 class vtkOBBTree;
99 class vtkPolyData;
100 class vtkPoints;
101 class vtkMatrix4x4;
102 class vtkLinearTransform;
103 class vtkIdTypeArray;
104 
105 class VTKFILTERSMODELING_EXPORT vtkCollisionDetectionFilter
106 : public vtkPolyDataAlgorithm
107 {
108  public:
110 
115  void PrintSelf(ostream& os, vtkIndent indent) override;
117 
119  {
120  VTK_ALL_CONTACTS = 0,
121  VTK_FIRST_CONTACT = 1,
122  VTK_HALF_CONTACTS = 2
123  };
124 
126 
131  vtkSetClampMacro(CollisionMode,int,VTK_ALL_CONTACTS,VTK_HALF_CONTACTS);
132  vtkGetMacro(CollisionMode,int);
133 
134  void SetCollisionModeToAllContacts() {this->SetCollisionMode(VTK_ALL_CONTACTS);};
135  void SetCollisionModeToFirstContact() {this->SetCollisionMode(VTK_FIRST_CONTACT);};
136  void SetCollisionModeToHalfContacts() {this->SetCollisionMode(VTK_HALF_CONTACTS);};
137  const char *GetCollisionModeAsString(void)
138  {
139  if ( this->CollisionMode == VTK_ALL_CONTACTS )
140  {
141  return "AllContacts";
142  }
143  else if (this->CollisionMode == VTK_FIRST_CONTACT)
144  {
145  return "FirstContact";
146  }
147  else
148  {
149  return "HalfContacts";
150  }
151  }
153 
155 
162  int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6],
163  int npts2, double *pts2,
164  double bounds2[6], double tol2,
165  double x1[2], double x2[3],
166  int CollisionMode);
168 
170 
173  void SetInputData(int i, vtkPolyData *model);
174  vtkPolyData *GetInputData(int i);
176 
178 
184  vtkIdTypeArray *GetContactCells(int i);
186 
188 
194 
196  /* Specify the transform object used to transform models. Alternatively, matrices
197  * can be set instead.
198 ` */
199  void SetTransform(int i, vtkLinearTransform *transform);
200  vtkLinearTransform *GetTransform(int i) {return this->Transform[i];}
202 
204  /* Specify the matrix object used to transform models.
205  */
206  void SetMatrix(int i, vtkMatrix4x4 *matrix);
207  vtkMatrix4x4 *GetMatrix(int i);
209 
211  /* Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001
212  */
213  vtkSetMacro(BoxTolerance, float);
214  vtkGetMacro(BoxTolerance, float);
216 
218  /* Set and Get the cell tolerance (squared value). Default is 0.0
219  */
220  vtkSetMacro(CellTolerance, double);
221  vtkGetMacro(CellTolerance, double);
223 
225  /*
226  * Set and Get the the flag to visualize the contact cells. If set the contacting cells
227  * will be coloured from red through to blue, with collisions first determined coloured red.
228  */
229  vtkSetMacro(GenerateScalars, int);
230  vtkGetMacro(GenerateScalars, int);
231  vtkBooleanMacro(GenerateScalars,int);
233 
235  /*
236  * Get the number of contacting cell pairs
237  */
239  { return this->GetOutput(0)->GetFieldData()->GetArray("ContactCells")->GetNumberOfTuples(); }
241 
243  /*
244  * Get the number of box tests
245  */
246  vtkGetMacro(NumberOfBoxTests, int);
248 
250  /*
251  * Set and Get the number of cells in each OBB. Default is 2
252  */
253  vtkSetMacro(NumberOfCellsPerNode, int);
254  vtkGetMacro(NumberOfCellsPerNode, int);
256 
258  /*
259  * Set and Get the opacity of the polydata output when a collision takes place.
260  * Default is 1.0
261  */
262  vtkSetClampMacro(Opacity, float, 0.0, 1.0);
263  vtkGetMacro(Opacity, float);
265 
267  /*
268  * Return the MTime also considering the transform.
269  */
270  vtkMTimeType GetMTime() override;
272 
273 protected:
275  ~vtkCollisionDetectionFilter() override;
276 
277  // Usual data generation method
281 
283  vtkMatrix4x4 *Matrix[2];
284 
286 
288 
290 
293  float Opacity;
294 
296 
297 private:
298 
300  void operator=(const vtkCollisionDetectionFilter&) = delete;
301 };
302 
303 
304 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:39
vtkCollisionDetectionFilter::CollisionMode
int CollisionMode
Definition: vtkCollisionDetectionFilter.h:295
vtkCollisionDetectionFilter::SetCollisionModeToHalfContacts
void SetCollisionModeToHalfContacts()
Definition: vtkCollisionDetectionFilter.h:136
vtkCollisionDetectionFilter::GetTransform
vtkLinearTransform * GetTransform(int i)
Definition: vtkCollisionDetectionFilter.h:200
vtkAlgorithm::GetOutputPort
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:489
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkCollisionDetectionFilter::CellTolerance
float CellTolerance
Definition: vtkCollisionDetectionFilter.h:292
vtkCollisionDetectionFilter::GenerateScalars
int GenerateScalars
Definition: vtkCollisionDetectionFilter.h:289
vtkOBBTree
generate oriented bounding box (OBB) tree
Definition: vtkOBBTree.h:88
vtkCollisionDetectionFilter::GetContactsOutput
vtkPolyData * GetContactsOutput()
Definition: vtkCollisionDetectionFilter.h:192
vtkPolyDataAlgorithm::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDataObject::GetFieldData
virtual vtkFieldData * GetFieldData()
vtkX3D::Transform
Definition: vtkX3D.h:41
vtkLinearTransform
abstract superclass for linear transformations
Definition: vtkLinearTransform.h:34
vtkFieldData::GetArray
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkFieldData.h
vtkPolyDataAlgorithm.h
vtkAbstractArray::GetNumberOfTuples
vtkIdType GetNumberOfTuples()
Get the number of complete tuples (a component group) in the array.
Definition: vtkAbstractArray.h:174
vtkPolyDataAlgorithm::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
vtkObject::GetMTime
virtual vtkMTimeType GetMTime()
Return this object's modified time.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
vtkCollisionDetectionFilter::Tree1
vtkOBBTree * Tree1
Definition: vtkCollisionDetectionFilter.h:280
vtkPolyDataAlgorithm::SetInputData
void SetInputData(vtkDataObject *)
Assign a data object as input.
vtkCollisionDetectionFilter::Tree0
vtkOBBTree * Tree0
Definition: vtkCollisionDetectionFilter.h:279
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:70
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:41
vtkAlgorithmOutput
Proxy object to connect input/output ports.
Definition: vtkAlgorithmOutput.h:42
vtkCollisionDetectionFilter::CollisionModes
CollisionModes
Definition: vtkCollisionDetectionFilter.h:118
vtkCollisionDetectionFilter::BoxTolerance
float BoxTolerance
Definition: vtkCollisionDetectionFilter.h:291
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
vtkCollisionDetectionFilter
performs collision determination between two polyhedral surfaces
Definition: vtkCollisionDetectionFilter.h:105
vtkCollisionDetectionFilter::NumberOfBoxTests
int NumberOfBoxTests
Definition: vtkCollisionDetectionFilter.h:285
vtkCollisionDetectionFilter::SetCollisionModeToAllContacts
void SetCollisionModeToAllContacts()
Definition: vtkCollisionDetectionFilter.h:134
vtkCollisionDetectionFilter::Opacity
float Opacity
Definition: vtkCollisionDetectionFilter.h:293
vtkCollisionDetectionFilter::GetCollisionModeAsString
const char * GetCollisionModeAsString(void)
Definition: vtkCollisionDetectionFilter.h:137
vtkCollisionDetectionFilter::GetNumberOfContacts
int GetNumberOfContacts()
Definition: vtkCollisionDetectionFilter.h:238
vtkCollisionDetectionFilter::GetContactsOutputPort
vtkAlgorithmOutput * GetContactsOutputPort()
Get the output with the points where the contacting cells intersect.
Definition: vtkCollisionDetectionFilter.h:191
vtkPolyDataAlgorithm::GetOutput
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
vtkPolyDataAlgorithm::New
static vtkPolyDataAlgorithm * New()
vtkCollisionDetectionFilter::SetCollisionModeToFirstContact
void SetCollisionModeToFirstContact()
Definition: vtkCollisionDetectionFilter.h:135
vtkCollisionDetectionFilter::NumberOfCellsPerNode
int NumberOfCellsPerNode
Definition: vtkCollisionDetectionFilter.h:287
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:304
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:44