Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 09:17: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_ObjectSet_HeaderFile
0017 #define BVH_ObjectSet_HeaderFile
0018 
0019 #include <BVH_Set.hxx>
0020 #include <BVH_Object.hxx>
0021 #include <NCollection_DynamicArray.hxx>
0022 
0023 //! Array of abstract entities (bounded by BVH boxes) to built BVH.
0024 //! \tparam T Numeric data type
0025 //! \tparam N Vector dimension
0026 template <class T, int N>
0027 class BVH_ObjectSet : public BVH_Set<T, N>
0028 {
0029 public:
0030   //! Type of array of geometric objects.
0031   typedef NCollection_DynamicArray<opencascade::handle<BVH_Object<T, N>>> BVH_ObjectList;
0032 
0033 public:
0034   //! Creates new set of geometric objects.
0035   BVH_ObjectSet() = default;
0036 
0037   //! Releases resources of set of geometric objects.
0038   ~BVH_ObjectSet() override = default;
0039 
0040 public:
0041   //! Removes all geometric objects.
0042   virtual void Clear()
0043   {
0044     for (typename BVH_ObjectList::Iterator anObjectIter(myObjects); anObjectIter.More();
0045          anObjectIter.Next())
0046     {
0047       anObjectIter.ChangeValue().Nullify();
0048     }
0049     myObjects.Clear();
0050   }
0051 
0052   //! Returns reference to the array of geometric objects.
0053   BVH_ObjectList& Objects() { return myObjects; }
0054 
0055   //! Returns reference to the array of geometric objects.
0056   const BVH_ObjectList& Objects() const { return myObjects; }
0057 
0058 public:
0059   //! Return total number of objects.
0060   int Size() const override { return myObjects.Length(); }
0061 
0062   //! Returns AABB of entire set of objects.
0063   using BVH_Set<T, N>::Box;
0064 
0065   //! Returns AABB of the given object.
0066   BVH_Box<T, N> Box(const int theIndex) const override { return myObjects.Value(theIndex)->Box(); }
0067 
0068   //! Returns centroid position along the given axis.
0069   T Center(const int theIndex, const int theAxis) const override
0070   {
0071     // Note: general implementation, not optimal
0072     return BVH::CenterAxis<T, N>::Center(myObjects.Value(theIndex)->Box(), theAxis);
0073   }
0074 
0075   //! Performs transposing the two given objects in the set.
0076   void Swap(const int theIndex1, const int theIndex2) override
0077   {
0078     std::swap(myObjects.ChangeValue(theIndex1), myObjects.ChangeValue(theIndex2));
0079   }
0080 
0081 protected:
0082   BVH_ObjectList myObjects; //!< Array of geometric objects
0083 };
0084 
0085 #endif // _BVH_ObjectSet_Header