0030655: Modeling Data - Provide interfaces for selection of the elements from BVH...
[occt.git] / src / BVH / BVH_DistanceField.hxx
1 // Created on: 2014-09-06
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-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 _BVH_DistanceField_Header
17 #define _BVH_DistanceField_Header
18
19 #include <BVH_Geometry.hxx>
20
21 template<class T, int N> class BVH_ParallelDistanceFieldBuilder;
22
23 //! Tool object for building 3D distance field from the set of BVH triangulations.
24 //! Distance field is a scalar field that measures the distance from a given point
25 //! to some object, including optional information about the inside and outside of
26 //! the structure. Distance fields are used as alternative surface representations
27 //! (like polygons or NURBS).
28 template<class T, int N>
29 class BVH_DistanceField
30 {
31   friend class BVH_ParallelDistanceFieldBuilder<T, N>;
32
33 public:
34
35   typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
36
37 public:
38
39   //! Creates empty 3D distance field.
40   BVH_DistanceField (const Standard_Integer theMaximumSize,
41                      const Standard_Boolean theComputeSign);
42
43   //! Releases resources of 3D distance field.
44   virtual ~BVH_DistanceField();
45
46   //! Builds 3D distance field from BVH geometry.
47   Standard_Boolean Build (BVH_Geometry<T, N>& theGeometry);
48
49   //! Returns parallel flag.
50   inline Standard_Boolean IsParallel() const
51   {
52     return myIsParallel;
53   }
54
55   //! Set parallel flag contolling possibility of parallel execution.
56   inline void SetParallel(const Standard_Boolean isParallel)
57   {
58     myIsParallel = isParallel;
59   }
60
61 public:
62
63   //! Returns packed voxel data.
64   const T* PackedData() const
65   {
66     return myVoxelData;
67   }
68
69   //! Returns distance value for the given voxel.
70   T& Voxel (const Standard_Integer theX,
71             const Standard_Integer theY,
72             const Standard_Integer theZ)
73   {
74     return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
75   }
76
77   //! Returns distance value for the given voxel.
78   T Voxel (const Standard_Integer theX,
79            const Standard_Integer theY,
80            const Standard_Integer theZ) const
81   {
82     return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
83   }
84
85   //! Returns size of voxel grid in X dimension.
86   Standard_Integer DimensionX() const
87   {
88     return myDimensionX;
89   }
90
91   //! Returns size of voxel grid in Y dimension.
92   Standard_Integer DimensionY() const
93   {
94     return myDimensionY;
95   }
96
97   //! Returns size of voxel grid in Z dimension.
98   Standard_Integer DimensionZ() const
99   {
100     return myDimensionZ;
101   }
102
103   //! Returns size of single voxel.
104   const BVH_VecNt& VoxelSize() const
105   {
106     return myVoxelSize;
107   }
108
109   //! Returns minimum corner of voxel grid.
110   const BVH_VecNt& CornerMin() const
111   {
112     return myCornerMin;
113   }
114
115   //! Returns maximum corner of voxel grid.
116   const BVH_VecNt& CornerMax() const
117   {
118     return myCornerMax;
119   }
120
121 protected:
122
123   //! Performs building of distance field for the given Z slices.
124   void BuildSlices (BVH_Geometry<T, N>& theGeometry,
125     const Standard_Integer theStartZ, const Standard_Integer theFinalZ);
126
127 protected:
128
129   //! Array of voxels.
130   T* myVoxelData;
131
132   //! Size of single voxel.
133   BVH_VecNt myVoxelSize;
134
135   //! Minimum corner of voxel grid.
136   BVH_VecNt myCornerMin;
137
138   //! Maximum corner of voxel grid.
139   BVH_VecNt myCornerMax;
140
141   //! Size of voxel grid in X dimension.
142   Standard_Integer myDimensionX;
143
144   //! Size of voxel grid in Y dimension.
145   Standard_Integer myDimensionY;
146
147   //! Size of voxel grid in Z dimension.
148   Standard_Integer myDimensionZ;
149
150   //! Size of voxel grid in maximum dimension.
151   Standard_Integer myMaximumSize;
152
153   //! Enables/disables signing of distance field.
154   Standard_Boolean myComputeSign;
155
156   Standard_Boolean myIsParallel;
157 };
158
159 #include <BVH_DistanceField.lxx>
160
161 #endif // _BVH_DistanceField_Header