Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03: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_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 
0038   //! Empty constructor for use the default BVH_Builder
0039   BVH_BoxSet()
0040     : BVH_PrimitiveSet <NumType, Dimension>()
0041   {
0042   }
0043   
0044   //! Constructor for usage the custom BVH builder
0045   BVH_BoxSet (const opencascade::handle <BVH_Builder <NumType, Dimension> >& theBuilder)
0046     : BVH_PrimitiveSet <NumType, Dimension> (theBuilder)
0047   {
0048   }
0049 
0050 public: //! @name Setting expected size of the BVH
0051 
0052   //! Sets the expected size of BVH tree
0053   virtual void SetSize (const Standard_Size theSize)
0054   {
0055     myElements.reserve (theSize);
0056     myBoxes.reserve (theSize);
0057   }
0058 
0059 public: //! @name Adding elements in BVH
0060 
0061   //! Adds the element into BVH
0062   virtual void Add (const DataType& theElement, const BVH_Box<NumType, Dimension>& theBox)
0063   {
0064     myElements.push_back (theElement);
0065     myBoxes.push_back (theBox);
0066     BVH_Object<NumType, Dimension>::myIsDirty = Standard_True;
0067   }
0068 
0069 public: //! @name BVH construction
0070 
0071   //! BVH construction
0072   void Build()
0073   {
0074     BVH_PrimitiveSet <NumType, Dimension>::Update();
0075   }
0076 
0077 public: //! @name Clearing the elements and boxes
0078 
0079   //! Clears the vectors of elements and boxes
0080   virtual void Clear()
0081   {
0082     myElements.clear();
0083     myBoxes.clear();
0084     BVH_Object<NumType, Dimension>::myIsDirty = Standard_True;
0085   }
0086 
0087 public: //! @name Necessary overrides for BVH construction
0088 
0089   //! Make inherited method Box() visible to avoid CLang warning
0090   using BVH_PrimitiveSet <NumType, Dimension>::Box;
0091 
0092   //! Returns the bounding box with the given index.
0093   virtual BVH_Box <NumType, Dimension> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
0094   {
0095     return myBoxes[theIndex];
0096   }
0097 
0098   //! Returns centroid position along specified axis.
0099   virtual Standard_Real Center (const Standard_Integer theIndex,
0100                                 const Standard_Integer theAxis) const Standard_OVERRIDE
0101   {
0102     return Box (theIndex).Center (theAxis);
0103   }
0104 
0105   //! Returns the number of boxes.
0106   virtual Standard_Integer Size() const Standard_OVERRIDE
0107   {
0108     return static_cast<Standard_Integer> (myBoxes.size());
0109   }
0110 
0111   //! Swaps indices of two specified boxes.
0112   virtual void Swap (const Standard_Integer theIndex1,
0113                      const Standard_Integer theIndex2) Standard_OVERRIDE
0114   {
0115     std::swap (myElements[theIndex1], myElements[theIndex2]);
0116     std::swap (myBoxes   [theIndex1], myBoxes   [theIndex2]);
0117   }
0118 
0119   //! Returns the Element with the index theIndex.
0120   virtual DataType Element (const Standard_Integer theIndex) const
0121   {
0122     return myElements[theIndex];
0123   }
0124 
0125 protected: //! @name Fields
0126 
0127   std::vector <DataType> myElements;                   //!< Elements
0128   std::vector <BVH_Box <NumType, Dimension> > myBoxes; //!< Boxes for the elements
0129 
0130 };
0131 
0132 #endif // _BVH_BoxSet_Header