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> |
19 | |
20 | // ======================================================================= |
21 | // function : OpenGl_BVHClipPrimitiveSet |
22 | // purpose : |
23 | // ======================================================================= |
24 | OpenGl_BVHClipPrimitiveSet::OpenGl_BVHClipPrimitiveSet() |
25 | { |
26 | myBuilder = new BVH_BinnedBuilder<Standard_ShortReal, 4> (1, 32); |
27 | } |
28 | |
29 | // ======================================================================= |
30 | // function : Size |
31 | // purpose : |
32 | // ======================================================================= |
33 | Standard_Integer OpenGl_BVHClipPrimitiveSet::Size() const |
34 | { |
35 | return myStructs.Size(); |
36 | } |
37 | |
38 | // ======================================================================= |
39 | // function : Box |
40 | // purpose : |
41 | // ======================================================================= |
42 | Graphic3d_BndBox4f OpenGl_BVHClipPrimitiveSet::Box (const Standard_Integer theIdx) const |
43 | { |
44 | return myStructs (theIdx + 1)->BoundingBox(); |
45 | } |
46 | |
47 | // ======================================================================= |
48 | // function : Center |
49 | // purpose : |
50 | // ======================================================================= |
51 | Standard_ShortReal OpenGl_BVHClipPrimitiveSet::Center (const Standard_Integer theIdx, |
52 | const Standard_Integer theAxis) const |
53 | { |
54 | Graphic3d_BndBox4f aBndBox = myStructs (theIdx + 1)->BoundingBox(); |
55 | Standard_ShortReal aCenter = theAxis == 0 ? (aBndBox.CornerMin().x() + aBndBox.CornerMax().x()) * 0.5f |
56 | : (theAxis == 1 ? (aBndBox.CornerMin().y() + aBndBox.CornerMax().y()) * 0.5f |
57 | : (theAxis == 2 ? (aBndBox.CornerMin().z() + aBndBox.CornerMax().z()) * 0.5f |
58 | : (aBndBox.CornerMin().w() + aBndBox.CornerMax().w()) * 0.5f)); |
59 | return aCenter; |
60 | } |
61 | |
62 | // ======================================================================= |
63 | // function : Swap |
64 | // purpose : |
65 | // ======================================================================= |
66 | void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1, |
67 | const Standard_Integer theIdx2) |
68 | { |
69 | const OpenGl_Structure* aStruct1 = myStructs (theIdx1 + 1); |
70 | const OpenGl_Structure* aStruct2 = myStructs (theIdx2 + 1); |
71 | myStructs.ChangeValue (theIdx1 + 1) = aStruct2; |
72 | myStructs.ChangeValue (theIdx2 + 1) = aStruct1; |
73 | } |
74 | |
75 | // ======================================================================= |
76 | // function : Assign |
77 | // purpose : |
78 | // ======================================================================= |
79 | void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfStructure& theStructs) |
80 | { |
81 | myStructs.Clear(); |
82 | |
83 | const Standard_Integer aNbPriorities = theStructs.Length(); |
b7cd4ba7 |
84 | for (Standard_Integer aPriorityIdx = 0; aPriorityIdx < aNbPriorities; ++aPriorityIdx) |
85 | { |
a1954302 |
86 | for (OpenGl_SequenceOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next()) |
b7cd4ba7 |
87 | { |
88 | const OpenGl_Structure* aStruct = aStructIter.Value(); |
89 | if (!aStruct->IsAlwaysRendered()) |
90 | myStructs.Append (aStruct); |
91 | } |
92 | } |
93 | |
94 | MarkDirty(); |
95 | } |
96 | |
97 | // ======================================================================= |
98 | // function : Add |
99 | // purpose : |
100 | // ======================================================================= |
101 | void OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct) |
102 | { |
103 | myStructs.Append (theStruct); |
104 | MarkDirty(); |
105 | } |
106 | |
107 | // ======================================================================= |
108 | // function : Remove |
109 | // purpose : |
110 | // ======================================================================= |
111 | void OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct) |
112 | { |
113 | for (Standard_Integer anIdx = 1; anIdx <= myStructs.Size(); ++anIdx) |
114 | { |
115 | if (myStructs (anIdx) == theStruct) |
116 | { |
117 | myStructs.Remove (anIdx); |
118 | MarkDirty(); |
119 | break; |
120 | } |
121 | } |
122 | } |
123 | |
124 | // ======================================================================= |
125 | // function : Clear |
126 | // purpose : |
127 | // ======================================================================= |
128 | void OpenGl_BVHClipPrimitiveSet::Clear() |
129 | { |
130 | myStructs.Clear(); |
131 | MarkDirty(); |
132 | } |
133 | |
134 | // ======================================================================= |
135 | // function : GetStructureById |
136 | // purpose : |
137 | // ======================================================================= |
138 | const OpenGl_Structure* OpenGl_BVHClipPrimitiveSet::GetStructureById (Standard_Integer theId) |
139 | { |
140 | return myStructs (theId + 1); |
141 | } |