0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / BVH / BVH_BoxSet.hxx
CommitLineData
7c1a8210 1// Created by: Eugeny MALTCHIKOV
2// Created on: 2019-04-17
3// Copyright (c) 2019 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_BoxSet_Header
17#define _BVH_BoxSet_Header
18
19#include <BVH_PrimitiveSet.hxx>
20
21//! Implements easy to use interfaces for adding the elements into
22//! BVH tree and its following construction.
23//! To make it more effective it is better to set the number of elements
24//! that are going to be added into BVH tree.
25//! For better efficiency on heavy data types it is recommended to use
26//! either BHV_IndexedBoxSet which uses indirect indexing for accessing
27//! the elements and their boxes or set the element to be an index
28//! of the real element in the application's internal data structures.
29//!
30//! \tparam NumType Numeric data type
31//! \tparam Dimension Vector dimension
32//! \tparam DataType Type of elements on which the boxes are built
33template <class NumType, int Dimension, class DataType = Standard_Integer>
34class BVH_BoxSet : public BVH_PrimitiveSet <NumType, Dimension>
35{
36public: //! @name Constructors
37
38 //! Empty constructor for use the default BVH_Builder
39 BVH_BoxSet()
40 : BVH_PrimitiveSet <NumType, Dimension>()
41 {
42 }
43
44 //! Constructor for usage the custom BVH builder
45 BVH_BoxSet (const opencascade::handle <BVH_Builder <NumType, Dimension> >& theBuilder)
46 : BVH_PrimitiveSet <NumType, Dimension> (theBuilder)
47 {
48 }
49
50public: //! @name Setting expected size of the BVH
51
52 //! Sets the expected size of BVH tree
53 virtual void SetSize (const Standard_Size theSize)
54 {
55 myElements.reserve (theSize);
56 myBoxes.reserve (theSize);
57 }
58
59public: //! @name Adding elements in BVH
60
61 //! Adds the element into BVH
62 virtual void Add (const DataType& theElement, const BVH_Box<NumType, Dimension>& theBox)
63 {
64 myElements.push_back (theElement);
65 myBoxes.push_back (theBox);
66 BVH_Object<NumType, Dimension>::myIsDirty = Standard_True;
67 }
68
69public: //! @name BVH construction
70
71 //! BVH construction
72 void Build()
73 {
74 BVH_PrimitiveSet <NumType, Dimension>::Update();
75 }
76
77public: //! @name Clearing the elements and boxes
78
79 //! Clears the vectors of elements and boxes
80 virtual void Clear()
81 {
82 myElements.clear();
83 myBoxes.clear();
84 BVH_Object<NumType, Dimension>::myIsDirty = Standard_True;
85 }
86
87public: //! @name Necessary overrides for BVH construction
88
89 //! Make inherited method Box() visible to avoid CLang warning
90 using BVH_PrimitiveSet <NumType, Dimension>::Box;
91
92 //! Returns the bounding box with the given index.
93 virtual BVH_Box <NumType, Dimension> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
94 {
95 return myBoxes[theIndex];
96 }
97
98 //! Returns centroid position along specified axis.
99 virtual Standard_Real Center (const Standard_Integer theIndex,
100 const Standard_Integer theAxis) const Standard_OVERRIDE
101 {
102 return Box (theIndex).Center (theAxis);
103 }
104
105 //! Returns the number of boxes.
106 virtual Standard_Integer Size() const Standard_OVERRIDE
107 {
108 return static_cast<Standard_Integer> (myBoxes.size());
109 }
110
111 //! Swaps indices of two specified boxes.
112 virtual void Swap (const Standard_Integer theIndex1,
113 const Standard_Integer theIndex2) Standard_OVERRIDE
114 {
115 std::swap (myElements[theIndex1], myElements[theIndex2]);
116 std::swap (myBoxes [theIndex1], myBoxes [theIndex2]);
117 }
118
119 //! Returns the Element with the index theIndex.
120 virtual DataType Element (const Standard_Integer theIndex) const
121 {
122 return myElements[theIndex];
123 }
124
125protected: //! @name Fields
126
127 std::vector <DataType> myElements; //!< Elements
128 std::vector <BVH_Box <NumType, Dimension> > myBoxes; //!< Boxes for the elements
129
130};
131
132#endif // _BVH_BoxSet_Header