summaryrefslogtreecommitdiff
path: root/inc/Voxel_CollisionDetection.hxx
blob: e67b9c7b540bbe9e3fc842bd0c44fd46b9ad12f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// This file is generated by WOK (CPPExt).
// Please do not edit this file; modify original file instead.
// The copyright and license terms as defined for the original file apply to 
// this header file considered to be the "object code" form of the original source.

#ifndef _Voxel_CollisionDetection_HeaderFile
#define _Voxel_CollisionDetection_HeaderFile

#ifndef _Standard_HeaderFile
#include <Standard.hxx>
#endif
#ifndef _Standard_Macro_HeaderFile
#include <Standard_Macro.hxx>
#endif

#ifndef _TopTools_ListOfShape_HeaderFile
#include <TopTools_ListOfShape.hxx>
#endif
#ifndef _Standard_Real_HeaderFile
#include <Standard_Real.hxx>
#endif
#ifndef _Standard_Integer_HeaderFile
#include <Standard_Integer.hxx>
#endif
#ifndef _Standard_Boolean_HeaderFile
#include <Standard_Boolean.hxx>
#endif
#ifndef _Standard_Address_HeaderFile
#include <Standard_Address.hxx>
#endif
#ifndef _Voxel_BoolDS_HeaderFile
#include <Voxel_BoolDS.hxx>
#endif
class TopoDS_Shape;
class Bnd_Box;
class Voxel_BoolDS;


//! Detects collisions between shapes. <br>
class Voxel_CollisionDetection  {
public:

  void* operator new(size_t,void* anAddress) 
  {
    return anAddress;
  }
  void* operator new(size_t size) 
  {
    return Standard::Allocate(size); 
  }
  void  operator delete(void *anAddress) 
  {
    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
  }

  //! An empty constructor. <br>
  Standard_EXPORT   Voxel_CollisionDetection();
  //! A constructor. <br>
//!          It defines deflection of triangulation for the shapes. <br>
//!          As lower the deflection is, as proper the triangulation is generated. <br>
//!          Also, it defines number of splits along X, Y and Z axes for generation of voxels. <br>
//!          As greater the numbers are, as greater number of voxels is used for detection of collision. <br>
  Standard_EXPORT   Voxel_CollisionDetection(const Standard_Real deflection,const Standard_Integer nbx,const Standard_Integer nby,const Standard_Integer nbz);
  //! Adds a shape. <br>
//!          Returns an index of the shape. <br>
  Standard_EXPORT     Standard_Integer AddShape(const TopoDS_Shape& shape) ;
  //! Replaces a shape by another one. <br>
//!          <ishape> is an index of the shape. <br>
//!          This method is useful for moving shape, for example. <br>
  Standard_EXPORT     Standard_Boolean ReplaceShape(const Standard_Integer ishape,const TopoDS_Shape& shape) ;
  //! Defines the deflection of triangulation of shapes. <br>
  Standard_EXPORT     void SetDeflection(const Standard_Real deflection) ;
  //! Defines the number of voxels along X, Y and Z axes. <br>
  Standard_EXPORT     void SetNbVoxels(const Standard_Integer nbx,const Standard_Integer nby,const Standard_Integer nbz) ;
  //! Defines a user-defined boundary box for generation of voxels. <br>
//!          If this method is not called, the algorithm calculates the boundary box itself. <br>
  Standard_EXPORT     void SetBoundaryBox(const Bnd_Box& box) ;
  //! Defines usage of volume of shapes in collision detection algorithm. <br>
//!          Beware, usage of volume a little bit decreases the speed of algorithm. <br>
  Standard_EXPORT     void SetUsageOfVolume(const Standard_Boolean usage) ;
  //! Doesn't clean the collision points on new call to the method Compute(). <br>
//!          It allows to see the collisions for a moving shape. <br>
  Standard_EXPORT     void KeepCollisions(const Standard_Boolean keep) ;
  //! Prepares data for computation of collisions. <br>
//!          It checks the inner parameters (number of voxels along X, Y and Z axes) and <br>
//!          voxelizes the shapes. <br>
//!          If the shape is not changed since the last call to this method, <br>
//!          this method may be not called for this shape. <br>
//!          <ishape> - is the index of the shape for processing by this method. <br>
//!          If it is equal to -1, all shapes will be processed. <br>
  Standard_EXPORT     Standard_Boolean Voxelize(const Standard_Integer ishape = -1) ;
  //! Computes the collisions. <br>
//!          This method may be called many times if, for example, the shapes are being moved. <br>
  Standard_EXPORT     Standard_Boolean Compute() ;
  //! Returns true if a collision is detected. <br>
  Standard_EXPORT     Standard_Boolean HasCollisions() const;
  //! Returns the collided voxels. <br>
  Standard_EXPORT    const Voxel_BoolDS& GetCollisions() const;
  //! A destructor. <br>
  Standard_EXPORT     void Destroy() ;
~Voxel_CollisionDetection()
{
  Destroy();
}





protected:





private:

  //! An internal method for cleaning the intermediate data. <br>
  Standard_EXPORT     void Clear() ;
  //! An internal method, which checks correspondance <br>
//!          of voxels to the parameters defined by user. <br>
  Standard_EXPORT     Standard_Boolean CheckVoxels(const Voxel_BoolDS& voxels) const;


TopTools_ListOfShape myShapes;
Standard_Real myDeflection;
Standard_Integer myNbX;
Standard_Integer myNbY;
Standard_Integer myNbZ;
Standard_Boolean myUsageOfVolume;
Standard_Boolean myKeepCollisions;
Standard_Real myX;
Standard_Real myY;
Standard_Real myZ;
Standard_Real myXLen;
Standard_Real myYLen;
Standard_Real myZLen;
Standard_Address myVoxels;
Voxel_BoolDS myCollisions;
Standard_Boolean myHasCollisions;


};





// other Inline functions and methods (like "C++: function call" methods)


#endif