Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:17:14

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   //! Creates uninitialized BVH geometry.
0032   BVH_Geometry()
0033       : myIsDirty(false),
0034         myBVH(new BVH_Tree<T, N>()),
0035         // set default builder - binned SAH split
0036         myBuilder(new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsOptimal>(
0037           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(false),
0045         myBVH(new BVH_Tree<T, N>()),
0046         myBuilder(theBuilder)
0047   {
0048     //
0049   }
0050 
0051   //! Releases resources of BVH geometry.
0052   ~BVH_Geometry() override
0053   {
0054     myBVH.Nullify();
0055     myBuilder.Nullify();
0056   }
0057 
0058 public:
0059   //! Returns TRUE if geometry state should be updated.
0060   virtual bool IsDirty() const { return myIsDirty; }
0061 
0062   //! Marks geometry as outdated.
0063   virtual void MarkDirty() { myIsDirty = true; }
0064 
0065   //! Returns AABB of the given object.
0066   using BVH_ObjectSet<T, N>::Box;
0067 
0068   //! Returns AABB of the whole geometry.
0069   BVH_Box<T, N> Box() const override
0070   {
0071     if (myIsDirty)
0072     {
0073       myBox = BVH_Set<T, N>::Box();
0074     }
0075     return myBox;
0076   }
0077 
0078   //! Returns BVH tree (and builds it if necessary).
0079   virtual const opencascade::handle<BVH_Tree<T, N>>& BVH()
0080   {
0081     if (myIsDirty)
0082     {
0083       Update();
0084     }
0085     return myBVH;
0086   }
0087 
0088   //! Returns the method (builder) used to construct BVH.
0089   virtual const opencascade::handle<BVH_Builder<T, N>>& Builder() const { return myBuilder; }
0090 
0091   //! Sets the method (builder) used to construct BVH.
0092   virtual void SetBuilder(const opencascade::handle<BVH_Builder<T, N>>& theBuilder)
0093   {
0094     myBuilder = theBuilder;
0095   }
0096 
0097 protected:
0098   //! Updates internal geometry state.
0099   virtual void Update()
0100   {
0101     if (myIsDirty)
0102     {
0103       myBuilder->Build(this, myBVH.operator->(), Box());
0104       myIsDirty = false;
0105     }
0106   }
0107 
0108 protected:
0109   bool                                   myIsDirty; //!< Is geometry state outdated?
0110   opencascade::handle<BVH_Tree<T, N>>    myBVH;     //!< Constructed high-level BVH
0111   opencascade::handle<BVH_Builder<T, N>> myBuilder; //!< Builder for high-level BVH
0112 
0113   mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric objects
0114 };
0115 
0116 #endif // _BVH_Geometry_Header