Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:14:02

0001 // Created on: 2014-09-06
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BVH_DistanceField_Header
0017 #define _BVH_DistanceField_Header
0018 
0019 #include <BVH_Geometry.hxx>
0020 
0021 template <class T, int N>
0022 class BVH_ParallelDistanceFieldBuilder;
0023 
0024 //! Tool object for building 3D distance field from the set of BVH triangulations.
0025 //! Distance field is a scalar field that measures the distance from a given point
0026 //! to some object, including optional information about the inside and outside of
0027 //! the structure. Distance fields are used as alternative surface representations
0028 //! (like polygons or NURBS).
0029 template <class T, int N>
0030 class BVH_DistanceField
0031 {
0032   friend class BVH_ParallelDistanceFieldBuilder<T, N>;
0033 
0034 public:
0035   typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
0036 
0037 public:
0038   //! Creates empty 3D distance field.
0039   BVH_DistanceField(const int theMaximumSize, const bool theComputeSign);
0040 
0041   //! Releases resources of 3D distance field.
0042   virtual ~BVH_DistanceField();
0043 
0044   //! Builds 3D distance field from BVH geometry.
0045   bool Build(BVH_Geometry<T, N>& theGeometry);
0046 
0047   //! Returns parallel flag.
0048   inline bool IsParallel() const { return myIsParallel; }
0049 
0050   //! Set parallel flag controlling possibility of parallel execution.
0051   inline void SetParallel(const bool isParallel) { myIsParallel = isParallel; }
0052 
0053 public:
0054   //! Returns packed voxel data.
0055   const T* PackedData() const { return myVoxelData; }
0056 
0057   //! Returns distance value for the given voxel.
0058   T& Voxel(const int theX, const int theY, const int theZ)
0059   {
0060     return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
0061   }
0062 
0063   //! Returns distance value for the given voxel.
0064   T Voxel(const int theX, const int theY, const int theZ) const
0065   {
0066     return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
0067   }
0068 
0069   //! Returns size of voxel grid in X dimension.
0070   int DimensionX() const { return myDimensionX; }
0071 
0072   //! Returns size of voxel grid in Y dimension.
0073   int DimensionY() const { return myDimensionY; }
0074 
0075   //! Returns size of voxel grid in Z dimension.
0076   int DimensionZ() const { return myDimensionZ; }
0077 
0078   //! Returns size of single voxel.
0079   const BVH_VecNt& VoxelSize() const { return myVoxelSize; }
0080 
0081   //! Returns minimum corner of voxel grid.
0082   const BVH_VecNt& CornerMin() const { return myCornerMin; }
0083 
0084   //! Returns maximum corner of voxel grid.
0085   const BVH_VecNt& CornerMax() const { return myCornerMax; }
0086 
0087 protected:
0088   //! Performs building of distance field for the given Z slices.
0089   void BuildSlices(BVH_Geometry<T, N>& theGeometry, const int theStartZ, const int theFinalZ);
0090 
0091 protected:
0092   //! Array of voxels.
0093   T* myVoxelData;
0094 
0095   //! Size of single voxel.
0096   BVH_VecNt myVoxelSize;
0097 
0098   //! Minimum corner of voxel grid.
0099   BVH_VecNt myCornerMin;
0100 
0101   //! Maximum corner of voxel grid.
0102   BVH_VecNt myCornerMax;
0103 
0104   //! Size of voxel grid in X dimension.
0105   int myDimensionX;
0106 
0107   //! Size of voxel grid in Y dimension.
0108   int myDimensionY;
0109 
0110   //! Size of voxel grid in Z dimension.
0111   int myDimensionZ;
0112 
0113   //! Size of voxel grid in maximum dimension.
0114   int myMaximumSize;
0115 
0116   //! Enables/disables signing of distance field.
0117   bool myComputeSign;
0118 
0119   bool myIsParallel;
0120 };
0121 
0122 #include <BVH_DistanceField.lxx>
0123 
0124 #endif // _BVH_DistanceField_Header