0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BVH / BVH_ObjectSet.hxx
1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BVH_ObjectSet_Header
17 #define _BVH_ObjectSet_Header
18
19 #include <BVH_Set.hxx>
20 #include <BVH_Object.hxx>
21
22 //! Array of abstract entities (bounded by BVH boxes) to built BVH.
23 //! \tparam T Numeric data type
24 //! \tparam N Vector dimension
25 template<class T, int N>
26 class BVH_ObjectSet : public BVH_Set<T, N>
27 {
28 public:
29
30   //! Type of array of geometric objects.
31   typedef NCollection_Vector<opencascade::handle<BVH_Object<T, N> > > BVH_ObjectList;
32
33 public:
34
35   //! Creates new set of geometric objects.
36   BVH_ObjectSet() {}
37
38   //! Releases resources of set of geometric objects.
39   virtual ~BVH_ObjectSet() {}
40
41 public:
42
43   //! Removes all geometric objects.
44   virtual void Clear()
45   {
46     for (typename BVH_ObjectList::Iterator anObjectIter (myObjects); anObjectIter.More(); anObjectIter.Next())
47     {
48       anObjectIter.ChangeValue().Nullify();
49     }
50     myObjects.Clear();
51   }
52
53   //! Returns reference to the array of geometric objects.
54   BVH_ObjectList& Objects() { return myObjects; }
55
56   //! Returns reference to the  array of geometric objects.
57   const BVH_ObjectList& Objects() const { return myObjects; }
58
59 public:
60
61   //! Return total number of objects.
62   virtual Standard_Integer Size() const Standard_OVERRIDE { return myObjects.Size(); }
63
64   //! Returns AABB of entire set of objects.
65   using BVH_Set<T, N>::Box;
66
67   //! Returns AABB of the given object.
68   virtual BVH_Box<T, N> Box (const Standard_Integer theIndex) const Standard_OVERRIDE { return myObjects.Value (theIndex)->Box(); }
69
70   //! Returns centroid position along the given axis.
71   virtual T Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE
72   {
73     // Note: general implementation, not optimal
74     return BVH::CenterAxis<T, N>::Center (myObjects.Value (theIndex)->Box(), theAxis);
75   }
76
77   //! Performs transposing the two given objects in the set.
78   virtual void Swap (const Standard_Integer theIndex1, const Standard_Integer theIndex2) Standard_OVERRIDE
79   {
80     std::swap (myObjects.ChangeValue (theIndex1),
81                myObjects.ChangeValue (theIndex2));
82   }
83
84 protected:
85
86   BVH_ObjectList myObjects; //!< Array of geometric objects
87
88 };
89
90 #endif // _BVH_ObjectSet_Header