Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:19

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> class BVH_ParallelDistanceFieldBuilder;
0022 
0023 //! Tool object for building 3D distance field from the set of BVH triangulations.
0024 //! Distance field is a scalar field that measures the distance from a given point
0025 //! to some object, including optional information about the inside and outside of
0026 //! the structure. Distance fields are used as alternative surface representations
0027 //! (like polygons or NURBS).
0028 template<class T, int N>
0029 class BVH_DistanceField
0030 {
0031   friend class BVH_ParallelDistanceFieldBuilder<T, N>;
0032 
0033 public:
0034 
0035   typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
0036 
0037 public:
0038 
0039   //! Creates empty 3D distance field.
0040   BVH_DistanceField (const Standard_Integer theMaximumSize,
0041                      const Standard_Boolean theComputeSign);
0042 
0043   //! Releases resources of 3D distance field.
0044   virtual ~BVH_DistanceField();
0045 
0046   //! Builds 3D distance field from BVH geometry.
0047   Standard_Boolean Build (BVH_Geometry<T, N>& theGeometry);
0048 
0049   //! Returns parallel flag.
0050   inline Standard_Boolean IsParallel() const
0051   {
0052     return myIsParallel;
0053   }
0054 
0055   //! Set parallel flag contolling possibility of parallel execution.
0056   inline void SetParallel(const Standard_Boolean isParallel)
0057   {
0058     myIsParallel = isParallel;
0059   }
0060 
0061 public:
0062 
0063   //! Returns packed voxel data.
0064   const T* PackedData() const
0065   {
0066     return myVoxelData;
0067   }
0068 
0069   //! Returns distance value for the given voxel.
0070   T& Voxel (const Standard_Integer theX,
0071             const Standard_Integer theY,
0072             const Standard_Integer theZ)
0073   {
0074     return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
0075   }
0076 
0077   //! Returns distance value for the given voxel.
0078   T Voxel (const Standard_Integer theX,
0079            const Standard_Integer theY,
0080            const Standard_Integer theZ) const
0081   {
0082     return myVoxelData[theX + (theY + theZ * myDimensionY) * myDimensionX];
0083   }
0084 
0085   //! Returns size of voxel grid in X dimension.
0086   Standard_Integer DimensionX() const
0087   {
0088     return myDimensionX;
0089   }
0090 
0091   //! Returns size of voxel grid in Y dimension.
0092   Standard_Integer DimensionY() const
0093   {
0094     return myDimensionY;
0095   }
0096 
0097   //! Returns size of voxel grid in Z dimension.
0098   Standard_Integer DimensionZ() const
0099   {
0100     return myDimensionZ;
0101   }
0102 
0103   //! Returns size of single voxel.
0104   const BVH_VecNt& VoxelSize() const
0105   {
0106     return myVoxelSize;
0107   }
0108 
0109   //! Returns minimum corner of voxel grid.
0110   const BVH_VecNt& CornerMin() const
0111   {
0112     return myCornerMin;
0113   }
0114 
0115   //! Returns maximum corner of voxel grid.
0116   const BVH_VecNt& CornerMax() const
0117   {
0118     return myCornerMax;
0119   }
0120 
0121 protected:
0122 
0123   //! Performs building of distance field for the given Z slices.
0124   void BuildSlices (BVH_Geometry<T, N>& theGeometry,
0125     const Standard_Integer theStartZ, const Standard_Integer theFinalZ);
0126 
0127 protected:
0128 
0129   //! Array of voxels.
0130   T* myVoxelData;
0131 
0132   //! Size of single voxel.
0133   BVH_VecNt myVoxelSize;
0134 
0135   //! Minimum corner of voxel grid.
0136   BVH_VecNt myCornerMin;
0137 
0138   //! Maximum corner of voxel grid.
0139   BVH_VecNt myCornerMax;
0140 
0141   //! Size of voxel grid in X dimension.
0142   Standard_Integer myDimensionX;
0143 
0144   //! Size of voxel grid in Y dimension.
0145   Standard_Integer myDimensionY;
0146 
0147   //! Size of voxel grid in Z dimension.
0148   Standard_Integer myDimensionZ;
0149 
0150   //! Size of voxel grid in maximum dimension.
0151   Standard_Integer myMaximumSize;
0152 
0153   //! Enables/disables signing of distance field.
0154   Standard_Boolean myComputeSign;
0155 
0156   Standard_Boolean myIsParallel;
0157 };
0158 
0159 #include <BVH_DistanceField.lxx>
0160 
0161 #endif // _BVH_DistanceField_Header