1 // Created on: 2014-09-06
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BVH_DistanceField_Header
17 #define _BVH_DistanceField_Header
19 #include <BVH_Geometry.hxx>
21 template<class T, int N> class BVH_ParallelDistanceFieldBuilder;
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
31 friend class BVH_ParallelDistanceFieldBuilder<T, N>;
35 typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
39 //! Creates empty 3D distance field.
40 BVH_DistanceField (const Standard_Integer theMaximumSize,
41 const Standard_Boolean theComputeSign);
43 //! Releases resources of 3D distance field.
44 virtual ~BVH_DistanceField();
46 //! Builds 3D distance field from BVH geometry.
47 Standard_Boolean Build (BVH_Geometry<T, N>& theGeometry);
49 //! Returns parallel flag.
50 inline Standard_Boolean IsParallel() const
55 //! Set parallel flag contolling possibility of parallel execution.
56 inline void SetParallel(const Standard_Boolean isParallel)
58 myIsParallel = isParallel;
63 //! Returns packed voxel data.
64 const T* PackedData() const
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)
74 return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
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
82 return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
85 //! Returns size of voxel grid in X dimension.
86 Standard_Integer DimensionX() const
91 //! Returns size of voxel grid in Y dimension.
92 Standard_Integer DimensionY() const
97 //! Returns size of voxel grid in Z dimension.
98 Standard_Integer DimensionZ() const
103 //! Returns size of single voxel.
104 const BVH_VecNt& VoxelSize() const
109 //! Returns minimum corner of voxel grid.
110 const BVH_VecNt& CornerMin() const
115 //! Returns maximum corner of voxel grid.
116 const BVH_VecNt& CornerMax() const
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);
132 //! Size of single voxel.
133 BVH_VecNt myVoxelSize;
135 //! Minimum corner of voxel grid.
136 BVH_VecNt myCornerMin;
138 //! Maximum corner of voxel grid.
139 BVH_VecNt myCornerMax;
141 //! Size of voxel grid in X dimension.
142 Standard_Integer myDimensionX;
144 //! Size of voxel grid in Y dimension.
145 Standard_Integer myDimensionY;
147 //! Size of voxel grid in Z dimension.
148 Standard_Integer myDimensionZ;
150 //! Size of voxel grid in maximum dimension.
151 Standard_Integer myMaximumSize;
153 //! Enables/disables signing of distance field.
154 Standard_Boolean myComputeSign;
156 Standard_Boolean myIsParallel;
159 #include <BVH_DistanceField.lxx>
161 #endif // _BVH_DistanceField_Header