Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-05 08:36:24

0001 // Created by: Eugeny MALTCHIKOV
0002 // Created on: 2019-04-17
0003 // Copyright (c) 2019 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_BoxSet_Header
0017 #define _BVH_BoxSet_Header
0018 
0019 #include <BVH_PrimitiveSet.hxx>
0020 
0021 //! Implements easy to use interfaces for adding the elements into
0022 //! BVH tree and its following construction.
0023 //! To make it more effective it is better to set the number of elements
0024 //! that are going to be added into BVH tree.
0025 //! For better efficiency on heavy data types it is recommended to use
0026 //! either BHV_IndexedBoxSet which uses indirect indexing for accessing
0027 //! the elements and their boxes or set the element to be an index
0028 //! of the real element in the application's internal data structures.
0029 //!
0030 //! \tparam NumType Numeric data type
0031 //! \tparam Dimension Vector dimension
0032 //! \tparam DataType Type of elements on which the boxes are built
0033 template <class NumType, int Dimension, class DataType = Standard_Integer>
0034 class BVH_BoxSet : public BVH_PrimitiveSet<NumType, Dimension>
0035 {
0036 public: //! @name Constructors
0037   //! Empty constructor for use the default BVH_Builder
0038   BVH_BoxSet()
0039       : BVH_PrimitiveSet<NumType, Dimension>()
0040   {
0041   }
0042 
0043   //! Constructor for usage the custom BVH builder
0044   BVH_BoxSet(const opencascade::handle<BVH_Builder<NumType, Dimension>>& theBuilder)
0045       : BVH_PrimitiveSet<NumType, Dimension>(theBuilder)
0046   {
0047   }
0048 
0049 public: //! @name Setting expected size of the BVH
0050   //! Sets the expected size of BVH tree
0051   virtual void SetSize(const Standard_Size theSize)
0052   {
0053     myElements.reserve(theSize);
0054     myBoxes.reserve(theSize);
0055   }
0056 
0057 public: //! @name Adding elements in BVH
0058   //! Adds the element into BVH
0059   virtual void Add(const DataType& theElement, const BVH_Box<NumType, Dimension>& theBox)
0060   {
0061     myElements.push_back(theElement);
0062     myBoxes.push_back(theBox);
0063     BVH_Object<NumType, Dimension>::myIsDirty = Standard_True;
0064   }
0065 
0066 public: //! @name BVH construction
0067   //! BVH construction
0068   void Build() { BVH_PrimitiveSet<NumType, Dimension>::Update(); }
0069 
0070 public: //! @name Clearing the elements and boxes
0071   //! Clears the vectors of elements and boxes
0072   virtual void Clear()
0073   {
0074     myElements.clear();
0075     myBoxes.clear();
0076     BVH_Object<NumType, Dimension>::myIsDirty = Standard_True;
0077   }
0078 
0079 public: //! @name Necessary overrides for BVH construction
0080   //! Make inherited method Box() visible to avoid CLang warning
0081   using BVH_PrimitiveSet<NumType, Dimension>::Box;
0082 
0083   //! Returns the bounding box with the given index.
0084   virtual BVH_Box<NumType, Dimension> Box(const Standard_Integer theIndex) const Standard_OVERRIDE
0085   {
0086     return myBoxes[theIndex];
0087   }
0088 
0089   //! Returns centroid position along specified axis.
0090   virtual Standard_Real Center(const Standard_Integer theIndex,
0091                                const Standard_Integer theAxis) const Standard_OVERRIDE
0092   {
0093     return Box(theIndex).Center(theAxis);
0094   }
0095 
0096   //! Returns the number of boxes.
0097   virtual Standard_Integer Size() const Standard_OVERRIDE
0098   {
0099     return static_cast<Standard_Integer>(myBoxes.size());
0100   }
0101 
0102   //! Swaps indices of two specified boxes.
0103   virtual void Swap(const Standard_Integer theIndex1,
0104                     const Standard_Integer theIndex2) Standard_OVERRIDE
0105   {
0106     std::swap(myElements[theIndex1], myElements[theIndex2]);
0107     std::swap(myBoxes[theIndex1], myBoxes[theIndex2]);
0108   }
0109 
0110   //! Returns the Element with the index theIndex.
0111   virtual DataType Element(const Standard_Integer theIndex) const { return myElements[theIndex]; }
0112 
0113 protected:                                             //! @name Fields
0114   std::vector<DataType>                    myElements; //!< Elements
0115   std::vector<BVH_Box<NumType, Dimension>> myBoxes;    //!< Boxes for the elements
0116 };
0117 
0118 #endif // _BVH_BoxSet_Header