Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-23 09:17:18

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_IndexedBoxSet_Header
0017 #define _BVH_IndexedBoxSet_Header
0018 
0019 #include <BVH_BoxSet.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 //! It uses the indirect indexing for accessing the elements and their boxes
0026 //! which allows using heavy data types as elements with better efficiency
0027 //! during BVH construction and just a bit slower selection time.
0028 //! Due to better BVH tree construction time the class will be more efficient
0029 //! than BVH_BoxSet on the operations where just a few selections from
0030 //! the tree required.
0031 //!
0032 //! \tparam NumType Numeric data type
0033 //! \tparam Dimension Vector dimension
0034 //! \tparam DataType Type of elements on which the boxes are built
0035 template <class NumType, int Dimension, class DataType = Standard_Integer>
0036 class BVH_IndexedBoxSet : public BVH_BoxSet<NumType, Dimension, DataType>
0037 {
0038 public: //! @name Constructors
0039   //! Empty constructor for use the default BVH_Builder
0040   BVH_IndexedBoxSet()
0041       : BVH_BoxSet<NumType, Dimension, DataType>()
0042   {
0043   }
0044 
0045   //! Constructor for usage the custom BVH builder
0046   BVH_IndexedBoxSet(const opencascade::handle<BVH_Builder<NumType, Dimension>>& theBuilder)
0047       : BVH_BoxSet<NumType, Dimension, DataType>(theBuilder)
0048   {
0049   }
0050 
0051 public: //! @name Setting expected size of the BVH
0052   //! Sets the expected size of BVH tree
0053   virtual void SetSize(const Standard_Size theSize) Standard_OVERRIDE
0054   {
0055     myIndices.reserve(theSize);
0056     BVH_BoxSet<NumType, Dimension, DataType>::SetSize(theSize);
0057   }
0058 
0059 public: //! @name Adding elements in BVH
0060   //! Adds the element into BVH
0061   virtual void Add(const DataType&                    theElement,
0062                    const BVH_Box<NumType, Dimension>& theBox) Standard_OVERRIDE
0063   {
0064     myIndices.push_back(static_cast<Standard_Integer>(myIndices.size()));
0065     BVH_BoxSet<NumType, Dimension, DataType>::Add(theElement, theBox);
0066   }
0067 
0068 public: //! @name Clearing the elements and boxes
0069   //! Clears the vectors of elements and boxes
0070   virtual void Clear() Standard_OVERRIDE
0071   {
0072     myIndices.clear();
0073     BVH_BoxSet<NumType, Dimension, DataType>::Clear();
0074   }
0075 
0076 public: //! @name Necessary overrides for BVH construction
0077   //! Make inherited method Box() visible to avoid CLang warning
0078   using BVH_BoxSet<NumType, Dimension, DataType>::Box;
0079 
0080   //! Returns the bounding box with the given index.
0081   virtual BVH_Box<NumType, Dimension> Box(const Standard_Integer theIndex) const Standard_OVERRIDE
0082   {
0083     return this->myBoxes[myIndices[theIndex]];
0084   }
0085 
0086   //! Swaps indices of two specified boxes.
0087   virtual void Swap(const Standard_Integer theIndex1,
0088                     const Standard_Integer theIndex2) Standard_OVERRIDE
0089   {
0090     std::swap(myIndices[theIndex1], myIndices[theIndex2]);
0091   }
0092 
0093   //! Returns the Element with the index theIndex.
0094   virtual DataType Element(const Standard_Integer theIndex) const Standard_OVERRIDE
0095   {
0096     return this->myElements[myIndices[theIndex]];
0097   }
0098 
0099 protected: //! @name Fields
0100   std::vector<Standard_Integer> myIndices;
0101 };
0102 
0103 #endif // _BVH_IndexedBoxSet_Header