Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2013-12-20
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_Geometry_HeaderFile
0017 #define BVH_Geometry_HeaderFile
0018 
0019 #include <BVH_ObjectSet.hxx>
0020 #include <BVH_Builder.hxx>
0021 #include <BVH_BinnedBuilder.hxx>
0022 
0023 //! BVH geometry as a set of abstract geometric objects
0024 //! organized with bounding volume hierarchy (BVH).
0025 //! \tparam T Numeric data type
0026 //! \tparam N Vector dimension
0027 template<class T, int N>
0028 class BVH_Geometry : public BVH_ObjectSet<T, N>
0029 {
0030 public:
0031 
0032   //! Creates uninitialized BVH geometry.
0033   BVH_Geometry()
0034   : myIsDirty (Standard_False),
0035     myBVH (new BVH_Tree<T, N>()),
0036     // set default builder - binned SAH split
0037     myBuilder (new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsOptimal> (BVH_Constants_LeafNodeSizeSingle))
0038   {
0039     //
0040   }
0041 
0042   //! Creates uninitialized BVH geometry.
0043   BVH_Geometry (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
0044   : myIsDirty (Standard_False),
0045     myBVH (new BVH_Tree<T, N>()),
0046     myBuilder (theBuilder)
0047   {
0048     //
0049   }
0050 
0051   //! Releases resources of BVH geometry.
0052   virtual ~BVH_Geometry()
0053   {
0054     myBVH.Nullify();
0055     myBuilder.Nullify();
0056   }
0057 
0058 public:
0059 
0060   //! Returns TRUE if geometry state should be updated.
0061   virtual Standard_Boolean IsDirty() const { return myIsDirty; }
0062 
0063   //! Marks geometry as outdated.
0064   virtual void MarkDirty() { myIsDirty = Standard_True; }
0065 
0066   //! Returns AABB of the given object.
0067   using BVH_ObjectSet<T, N>::Box;
0068 
0069   //! Returns AABB of the whole geometry.
0070   virtual BVH_Box<T, N> Box() const Standard_OVERRIDE
0071   {
0072     if (myIsDirty)
0073     {
0074       myBox = BVH_Set<T, N>::Box();
0075     }
0076     return myBox;
0077   }
0078 
0079   //! Returns BVH tree (and builds it if necessary).
0080   virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
0081   {
0082     if (myIsDirty)
0083     {
0084       Update();
0085     }
0086     return myBVH;
0087   }
0088 
0089   //! Returns the method (builder) used to construct BVH.
0090   virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
0091 
0092   //! Sets the method (builder) used to construct BVH.
0093   virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
0094 
0095 protected:
0096 
0097   //! Updates internal geometry state.
0098   virtual void Update()
0099   {
0100     if (myIsDirty)
0101     {
0102       myBuilder->Build (this, myBVH.operator->(), Box());
0103       myIsDirty = Standard_False;
0104     }
0105   }
0106 
0107 protected:
0108 
0109   Standard_Boolean                        myIsDirty; //!< Is geometry state outdated?
0110   opencascade::handle<BVH_Tree<T, N> >    myBVH;     //!< Constructed hight-level BVH
0111   opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for hight-level BVH
0112 
0113   mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric objects
0114 
0115 };
0116 
0117 #endif // _BVH_Geometry_Header