42cf5bc1 |
1 | // Created on: 2008-07-14 |
2 | // Created by: Vladislav ROMASHKO |
3 | // Copyright (c) 2008-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _Voxel_CollisionDetection_HeaderFile |
17 | #define _Voxel_CollisionDetection_HeaderFile |
18 | |
19 | #include <Standard.hxx> |
20 | #include <Standard_DefineAlloc.hxx> |
21 | #include <Standard_Handle.hxx> |
22 | |
23 | #include <TopTools_ListOfShape.hxx> |
24 | #include <Standard_Real.hxx> |
25 | #include <Standard_Integer.hxx> |
26 | #include <Standard_Boolean.hxx> |
27 | #include <Standard_Address.hxx> |
28 | #include <Voxel_BoolDS.hxx> |
29 | class TopoDS_Shape; |
30 | class Bnd_Box; |
31 | class Voxel_BoolDS; |
32 | |
33 | |
34 | //! Detects collisions between shapes. |
35 | class Voxel_CollisionDetection |
36 | { |
37 | public: |
38 | |
39 | DEFINE_STANDARD_ALLOC |
40 | |
41 | |
42 | //! An empty constructor. |
43 | Standard_EXPORT Voxel_CollisionDetection(); |
44 | |
45 | //! A constructor. |
46 | //! It defines deflection of triangulation for the shapes. |
47 | //! As lower the deflection is, as proper the triangulation is generated. |
48 | //! Also, it defines number of splits along X, Y and Z axes for generation of voxels. |
49 | //! As greater the numbers are, as greater number of voxels is used for detection of collision. |
50 | Standard_EXPORT Voxel_CollisionDetection(const Standard_Real deflection, const Standard_Integer nbx, const Standard_Integer nby, const Standard_Integer nbz); |
51 | |
52 | //! Adds a shape. |
53 | //! Returns an index of the shape. |
54 | Standard_EXPORT Standard_Integer AddShape (const TopoDS_Shape& shape); |
55 | |
56 | //! Replaces a shape by another one. |
57 | //! <ishape> is an index of the shape. |
58 | //! This method is useful for moving shape, for example. |
59 | Standard_EXPORT Standard_Boolean ReplaceShape (const Standard_Integer ishape, const TopoDS_Shape& shape); |
60 | |
61 | //! Defines the deflection of triangulation of shapes. |
62 | Standard_EXPORT void SetDeflection (const Standard_Real deflection); |
63 | |
64 | //! Defines the number of voxels along X, Y and Z axes. |
65 | Standard_EXPORT void SetNbVoxels (const Standard_Integer nbx, const Standard_Integer nby, const Standard_Integer nbz); |
66 | |
67 | //! Defines a user-defined boundary box for generation of voxels. |
68 | //! If this method is not called, the algorithm calculates the boundary box itself. |
69 | Standard_EXPORT void SetBoundaryBox (const Bnd_Box& box); |
70 | |
71 | //! Defines usage of volume of shapes in collision detection algorithm. |
72 | //! Beware, usage of volume a little bit decreases the speed of algorithm. |
73 | Standard_EXPORT void SetUsageOfVolume (const Standard_Boolean usage); |
74 | |
75 | //! Doesn't clean the collision points on new call to the method Compute(). |
76 | //! It allows to see the collisions for a moving shape. |
77 | Standard_EXPORT void KeepCollisions (const Standard_Boolean keep); |
78 | |
79 | //! Prepares data for computation of collisions. |
80 | //! It checks the inner parameters (number of voxels along X, Y and Z axes) and |
81 | //! voxelizes the shapes. |
82 | //! If the shape is not changed since the last call to this method, |
83 | //! this method may be not called for this shape. |
84 | //! <ishape> - is the index of the shape for processing by this method. |
85 | //! If it is equal to -1, all shapes will be processed. |
86 | Standard_EXPORT Standard_Boolean Voxelize (const Standard_Integer ishape = -1); |
87 | |
88 | //! Computes the collisions. |
89 | //! This method may be called many times if, for example, the shapes are being moved. |
90 | Standard_EXPORT Standard_Boolean Compute(); |
91 | |
92 | //! Returns true if a collision is detected. |
93 | Standard_EXPORT Standard_Boolean HasCollisions() const; |
94 | |
95 | //! Returns the collided voxels. |
96 | Standard_EXPORT const Voxel_BoolDS& GetCollisions() const; |
97 | |
98 | //! A destructor. |
99 | Standard_EXPORT void Destroy(); |
100 | ~Voxel_CollisionDetection() |
101 | { |
102 | Destroy(); |
103 | } |
104 | |
105 | |
106 | |
107 | |
108 | protected: |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | private: |
115 | |
116 | |
117 | //! An internal method for cleaning the intermediate data. |
118 | Standard_EXPORT void Clear(); |
119 | |
120 | //! An internal method, which checks correspondance |
121 | //! of voxels to the parameters defined by user. |
122 | Standard_EXPORT Standard_Boolean CheckVoxels (const Voxel_BoolDS& voxels) const; |
123 | |
124 | |
125 | TopTools_ListOfShape myShapes; |
126 | Standard_Real myDeflection; |
127 | Standard_Integer myNbX; |
128 | Standard_Integer myNbY; |
129 | Standard_Integer myNbZ; |
130 | Standard_Boolean myUsageOfVolume; |
131 | Standard_Boolean myKeepCollisions; |
132 | Standard_Real myX; |
133 | Standard_Real myY; |
134 | Standard_Real myZ; |
135 | Standard_Real myXLen; |
136 | Standard_Real myYLen; |
137 | Standard_Real myZLen; |
138 | Standard_Address myVoxels; |
139 | Voxel_BoolDS myCollisions; |
140 | Standard_Boolean myHasCollisions; |
141 | |
142 | |
143 | }; |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | #endif // _Voxel_CollisionDetection_HeaderFile |