0025222: Visualization - provide distance field builder in the Math/BVH package
[occt.git] / src / BVH / BVH_DistanceField.hxx
CommitLineData
df932fdf 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
21template<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).
28template<class T, int N>
29class BVH_DistanceField
30{
31 friend class BVH_ParallelDistanceFieldBuilder<T, N>;
32
33public:
34
35 typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
36
37public:
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
49public:
50
51 //! Returns packed voxel data.
52 const T* PackedData() const
53 {
54 return myVoxelData;
55 }
56
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)
61 {
62 return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
63 }
64
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
69 {
70 return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
71 }
72
73 //! Returns size of voxel grid in X dimension.
74 Standard_Integer DimensionX() const
75 {
76 return myDimensionX;
77 }
78
79 //! Returns size of voxel grid in Y dimension.
80 Standard_Integer DimensionY() const
81 {
82 return myDimensionY;
83 }
84
85 //! Returns size of voxel grid in Z dimension.
86 Standard_Integer DimensionZ() const
87 {
88 return myDimensionZ;
89 }
90
91 //! Returns size of single voxel.
92 const BVH_VecNt& VoxelSize() const
93 {
94 return myVoxelSize;
95 }
96
97 //! Returns minimum corner of voxel grid.
98 const BVH_VecNt& CornerMin() const
99 {
100 return myCornerMin;
101 }
102
103 //! Returns maximum corner of voxel grid.
104 const BVH_VecNt& CornerMax() const
105 {
106 return myCornerMax;
107 }
108
109protected:
110
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);
114
115protected:
116
117 //! Array of voxels.
118 T* myVoxelData;
119
120 //! Size of single voxel.
121 BVH_VecNt myVoxelSize;
122
123 //! Minimum corner of voxel grid.
124 BVH_VecNt myCornerMin;
125
126 //! Maximum corner of voxel grid.
127 BVH_VecNt myCornerMax;
128
129 //! Size of voxel grid in X dimension.
130 Standard_Integer myDimensionX;
131
132 //! Size of voxel grid in Y dimension.
133 Standard_Integer myDimensionY;
134
135 //! Size of voxel grid in Z dimension.
136 Standard_Integer myDimensionZ;
137
138 //! Size of voxel grid in maximum dimension.
139 Standard_Integer myMaximumSize;
140
141 //! Enables/disables signing of distance field.
142 Standard_Boolean myComputeSign;
143
144};
145
146#include <BVH_DistanceField.lxx>
147
148#endif // _BVH_DistanceField_Header