Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0040   //! Empty constructor for use the default BVH_Builder
0041   BVH_IndexedBoxSet()
0042     : BVH_BoxSet <NumType, Dimension, DataType>()
0043   {
0044   }
0045   
0046   //! Constructor for usage the custom BVH builder
0047   BVH_IndexedBoxSet (const opencascade::handle <BVH_Builder <NumType, Dimension> >& theBuilder)
0048     : BVH_BoxSet <NumType, Dimension, DataType> (theBuilder)
0049   {
0050   }
0051 
0052 public: //! @name Setting expected size of the BVH
0053 
0054   //! Sets the expected size of BVH tree
0055   virtual void SetSize (const Standard_Size theSize) Standard_OVERRIDE
0056   {
0057     myIndices.reserve (theSize);
0058     BVH_BoxSet <NumType, Dimension, DataType>::SetSize (theSize);
0059   }
0060 
0061 public: //! @name Adding elements in BVH
0062 
0063   //! Adds the element into BVH
0064   virtual void Add (const DataType& theElement, const BVH_Box<NumType, Dimension>& theBox) Standard_OVERRIDE
0065   {
0066     myIndices.push_back (static_cast<Standard_Integer> (myIndices.size()));
0067     BVH_BoxSet <NumType, Dimension, DataType>::Add (theElement, theBox);
0068   }
0069 
0070 public: //! @name Clearing the elements and boxes
0071 
0072   //! Clears the vectors of elements and boxes
0073   virtual void Clear() Standard_OVERRIDE
0074   {
0075     myIndices.clear();
0076     BVH_BoxSet <NumType, Dimension, DataType>::Clear();
0077   }
0078 
0079 public: //! @name Necessary overrides for BVH construction
0080 
0081   //! Make inherited method Box() visible to avoid CLang warning
0082   using BVH_BoxSet <NumType, Dimension, DataType>::Box;
0083 
0084   //! Returns the bounding box with the given index.
0085   virtual BVH_Box <NumType, Dimension> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
0086   {
0087     return this->myBoxes[myIndices[theIndex]];
0088   }
0089 
0090   //! Swaps indices of two specified boxes.
0091   virtual void Swap (const Standard_Integer theIndex1,
0092                      const Standard_Integer theIndex2) Standard_OVERRIDE
0093   {
0094     std::swap (myIndices[theIndex1], myIndices[theIndex2]);
0095   }
0096 
0097   //! Returns the Element with the index theIndex.
0098   virtual DataType Element (const Standard_Integer theIndex) const Standard_OVERRIDE
0099   {
0100     return this->myElements[myIndices[theIndex]];
0101   }
0102 
0103 protected: //! @name Fields
0104 
0105   std::vector <Standard_Integer> myIndices;
0106 
0107 };
0108 
0109 #endif // _BVH_IndexedBoxSet_Header