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_PrimitiveSet_HeaderFile
0017 #define BVH_PrimitiveSet_HeaderFile
0018 
0019 #include <BVH_Object.hxx>
0020 #include <BVH_Builder.hxx>
0021 #include <BVH_BinnedBuilder.hxx>
0022 
0023 //! Set of abstract geometric primitives organized with bounding
0024 //! volume hierarchy (BVH). Unlike an object set, this collection
0025 //! is designed for storing structural elements of a single object
0026 //! (such as triangles in the object triangulation). Because there
0027 //! may be a large number of such elements, the implementations of
0028 //! this interface should be sufficiently optimized.
0029 //! \tparam T Numeric data type
0030 //! \tparam N Vector dimension
0031 template<class T, int N>
0032 class BVH_PrimitiveSet : public BVH_Object<T, N>, public BVH_Set<T, N>
0033 {
0034 protected:
0035 
0036   using BVH_Set<T, N>::Box;
0037 
0038 public:
0039   static const Standard_Integer MaxTreeDepth = BVH_Constants_MaxTreeDepth;
0040 
0041   //! Creates set of abstract primitives.
0042   BVH_PrimitiveSet()
0043   : myBVH (new BVH_Tree<T, N>()),
0044     // set default builder - binned SAH split
0045     myBuilder (new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeDefault, BVH_Constants_MaxTreeDepth))
0046   {
0047     //
0048   }
0049 
0050   //! Creates set of abstract primitives.
0051   BVH_PrimitiveSet (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
0052   : myBVH (new BVH_Tree<T, N>()),
0053     myBuilder (theBuilder)
0054   {
0055     //
0056   }
0057 
0058   //! Releases resources of set of abstract primitives.
0059   virtual ~BVH_PrimitiveSet()
0060   {
0061     myBVH.Nullify();
0062     myBuilder.Nullify();
0063   }
0064 
0065 public:
0066 
0067   //! Returns AABB of primitive set.
0068   virtual BVH_Box<T, N> Box() const Standard_OVERRIDE
0069   {
0070     if (BVH_Object<T, N>::myIsDirty)
0071     {
0072       myBox = BVH_Set<T, N>::Box();
0073     }
0074     return myBox;
0075   }
0076 
0077   //! Returns BVH tree (and builds it if necessary).
0078   virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
0079   {
0080     if (BVH_Object<T, N>::myIsDirty)
0081     {
0082       Update();
0083     }
0084     return myBVH;
0085   }
0086 
0087   //! Returns the method (builder) used to construct BVH.
0088   virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
0089 
0090   //! Sets the method (builder) used to construct BVH.
0091   virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
0092 
0093 protected:
0094 
0095   //! Updates BVH of primitive set.
0096   virtual void Update()
0097   {
0098     if (BVH_Object<T, N>::myIsDirty)
0099     {
0100       myBuilder->Build (this, myBVH.operator->(), Box());
0101       BVH_Object<T, N>::myIsDirty = Standard_False;
0102     }
0103   }
0104 
0105 protected:
0106 
0107   opencascade::handle<BVH_Tree<T, N> >    myBVH;     //!< Constructed bottom-level BVH
0108   opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for bottom-level BVH
0109 
0110   mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric primitives
0111 
0112 };
0113 
0114 #endif // _BVH_PrimitiveSet_Header