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);
51 //! Returns packed voxel data.
52 const T* PackedData() const
57 //! Returns distance value for the given voxel.
58 T& Voxel (const Standard_Integer theX,
59 const Standard_Integer theY,
60 const Standard_Integer theZ)
62 return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
65 //! Returns distance value for the given voxel.
66 T Voxel (const Standard_Integer theX,
67 const Standard_Integer theY,
68 const Standard_Integer theZ) const
70 return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
73 //! Returns size of voxel grid in X dimension.
74 Standard_Integer DimensionX() const
79 //! Returns size of voxel grid in Y dimension.
80 Standard_Integer DimensionY() const
85 //! Returns size of voxel grid in Z dimension.
86 Standard_Integer DimensionZ() const
91 //! Returns size of single voxel.
92 const BVH_VecNt& VoxelSize() const
97 //! Returns minimum corner of voxel grid.
98 const BVH_VecNt& CornerMin() const
103 //! Returns maximum corner of voxel grid.
104 const BVH_VecNt& CornerMax() const
111 //! Performs building of distance field for the given Z slices.
112 void BuildSlices (BVH_Geometry<T, N>& theGeometry,
113 const Standard_Integer theStartZ, const Standard_Integer theFinalZ);
120 //! Size of single voxel.
121 BVH_VecNt myVoxelSize;
123 //! Minimum corner of voxel grid.
124 BVH_VecNt myCornerMin;
126 //! Maximum corner of voxel grid.
127 BVH_VecNt myCornerMax;
129 //! Size of voxel grid in X dimension.
130 Standard_Integer myDimensionX;
132 //! Size of voxel grid in Y dimension.
133 Standard_Integer myDimensionY;
135 //! Size of voxel grid in Z dimension.
136 Standard_Integer myDimensionZ;
138 //! Size of voxel grid in maximum dimension.
139 Standard_Integer myMaximumSize;
141 //! Enables/disables signing of distance field.
142 Standard_Boolean myComputeSign;
146 #include <BVH_DistanceField.lxx>
148 #endif // _BVH_DistanceField_Header