b7cd4ba7 |
1 | // Created on: 2013-12-25 |
2 | // Created by: Varvara POSKONINA |
3 | // Copyright (c) 1999-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 | #include <OpenGl_BVHClipPrimitiveSet.hxx> |
17 | |
18 | #include <BVH_BinnedBuilder.hxx> |
c04c30b3 |
19 | #include <Graphic3d_GraphicDriver.hxx> |
b7cd4ba7 |
20 | |
f5b72419 |
21 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_BVHClipPrimitiveSet, BVH_PrimitiveSet3d) |
22 | |
b7cd4ba7 |
23 | // ======================================================================= |
24 | // function : OpenGl_BVHClipPrimitiveSet |
25 | // purpose : |
26 | // ======================================================================= |
27 | OpenGl_BVHClipPrimitiveSet::OpenGl_BVHClipPrimitiveSet() |
28 | { |
f5b72419 |
29 | myBuilder = new BVH_BinnedBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth); |
b7cd4ba7 |
30 | } |
31 | |
32 | // ======================================================================= |
33 | // function : Size |
34 | // purpose : |
35 | // ======================================================================= |
36 | Standard_Integer OpenGl_BVHClipPrimitiveSet::Size() const |
37 | { |
38 | return myStructs.Size(); |
39 | } |
40 | |
41 | // ======================================================================= |
42 | // function : Box |
43 | // purpose : |
44 | // ======================================================================= |
7c3ef2f7 |
45 | Graphic3d_BndBox3d OpenGl_BVHClipPrimitiveSet::Box (const Standard_Integer theIdx) const |
b7cd4ba7 |
46 | { |
385c43e7 |
47 | return myStructs.FindKey (theIdx + 1)->BoundingBox(); |
b7cd4ba7 |
48 | } |
49 | |
50 | // ======================================================================= |
51 | // function : Center |
52 | // purpose : |
53 | // ======================================================================= |
7c3ef2f7 |
54 | Standard_Real OpenGl_BVHClipPrimitiveSet::Center (const Standard_Integer theIdx, |
55 | const Standard_Integer theAxis) const |
b7cd4ba7 |
56 | { |
7c3ef2f7 |
57 | Graphic3d_BndBox3d aBndBox = myStructs.FindKey (theIdx + 1)->BoundingBox(); |
385c43e7 |
58 | |
7c3ef2f7 |
59 | const Standard_Real aMin = aBndBox.CornerMin()[theAxis]; |
60 | const Standard_Real aMax = aBndBox.CornerMax()[theAxis]; |
41e08b4d |
61 | const Standard_Real aCenter = (aMin + aMax) * 0.5; |
7c3ef2f7 |
62 | return aCenter; |
b7cd4ba7 |
63 | } |
64 | |
65 | // ======================================================================= |
66 | // function : Swap |
67 | // purpose : |
68 | // ======================================================================= |
69 | void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1, |
70 | const Standard_Integer theIdx2) |
71 | { |
385c43e7 |
72 | myStructs.Swap (theIdx1 + 1, theIdx2 + 1); |
b7cd4ba7 |
73 | } |
74 | |
b7cd4ba7 |
75 | // ======================================================================= |
76 | // function : Add |
77 | // purpose : |
78 | // ======================================================================= |
825aa485 |
79 | Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct) |
b7cd4ba7 |
80 | { |
385c43e7 |
81 | const Standard_Integer aSize = myStructs.Size(); |
82 | |
83 | if (myStructs.Add (theStruct) > aSize) // new structure? |
84 | { |
85 | MarkDirty(); |
825aa485 |
86 | |
87 | return Standard_True; |
385c43e7 |
88 | } |
825aa485 |
89 | |
90 | return Standard_False; |
b7cd4ba7 |
91 | } |
92 | |
93 | // ======================================================================= |
94 | // function : Remove |
95 | // purpose : |
96 | // ======================================================================= |
825aa485 |
97 | Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct) |
b7cd4ba7 |
98 | { |
385c43e7 |
99 | const Standard_Integer anIndex = myStructs.FindIndex (theStruct); |
100 | |
101 | if (anIndex != 0) |
b7cd4ba7 |
102 | { |
385c43e7 |
103 | myStructs.Swap (Size(), anIndex); |
104 | myStructs.RemoveLast(); |
105 | MarkDirty(); |
825aa485 |
106 | |
107 | return Standard_True; |
b7cd4ba7 |
108 | } |
825aa485 |
109 | |
110 | return Standard_False; |
b7cd4ba7 |
111 | } |
112 | |
113 | // ======================================================================= |
114 | // function : Clear |
115 | // purpose : |
116 | // ======================================================================= |
117 | void OpenGl_BVHClipPrimitiveSet::Clear() |
118 | { |
119 | myStructs.Clear(); |
120 | MarkDirty(); |
121 | } |
122 | |
123 | // ======================================================================= |
124 | // function : GetStructureById |
125 | // purpose : |
126 | // ======================================================================= |
127 | const OpenGl_Structure* OpenGl_BVHClipPrimitiveSet::GetStructureById (Standard_Integer theId) |
128 | { |
385c43e7 |
129 | return myStructs.FindKey (theId + 1); |
b7cd4ba7 |
130 | } |