1 // Created on: 2013-12-25
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_BVHClipPrimitiveSet.hxx>
18 #include <BVH_BinnedBuilder.hxx>
19 #include <Graphic3d_GraphicDriver.hxx>
21 // =======================================================================
22 // function : OpenGl_BVHClipPrimitiveSet
24 // =======================================================================
25 OpenGl_BVHClipPrimitiveSet::OpenGl_BVHClipPrimitiveSet()
27 myBuilder = new BVH_BinnedBuilder<Standard_ShortReal, 4> (1, 32);
30 // =======================================================================
33 // =======================================================================
34 Standard_Integer OpenGl_BVHClipPrimitiveSet::Size() const
36 return myStructs.Size();
39 // =======================================================================
42 // =======================================================================
43 Graphic3d_BndBox4f OpenGl_BVHClipPrimitiveSet::Box (const Standard_Integer theIdx) const
45 return myStructs.FindKey (theIdx + 1)->BoundingBox();
48 // =======================================================================
51 // =======================================================================
52 Standard_ShortReal OpenGl_BVHClipPrimitiveSet::Center (const Standard_Integer theIdx,
53 const Standard_Integer theAxis) const
55 Graphic3d_BndBox4f aBndBox = myStructs.FindKey (theIdx + 1)->BoundingBox();
57 return (aBndBox.CornerMin()[theAxis] +
58 aBndBox.CornerMax()[theAxis]) * 0.5f;
61 // =======================================================================
64 // =======================================================================
65 void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
66 const Standard_Integer theIdx2)
68 myStructs.Swap (theIdx1 + 1, theIdx2 + 1);
71 // =======================================================================
74 // =======================================================================
75 void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfIndexedMapOfStructure& theStructs)
79 for (Standard_Integer aPriorityIdx = 0, aNbPriorities = theStructs.Length(); aPriorityIdx < aNbPriorities; ++aPriorityIdx)
81 for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next())
83 const OpenGl_Structure* aStruct = aStructIter.Value();
85 if (!aStruct->IsAlwaysRendered())
87 myStructs.Add (aStruct);
95 // =======================================================================
98 // =======================================================================
99 void OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct)
101 const Standard_Integer aSize = myStructs.Size();
103 if (myStructs.Add (theStruct) > aSize) // new structure?
109 // =======================================================================
112 // =======================================================================
113 void OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct)
115 const Standard_Integer anIndex = myStructs.FindIndex (theStruct);
119 myStructs.Swap (Size(), anIndex);
120 myStructs.RemoveLast();
125 // =======================================================================
128 // =======================================================================
129 void OpenGl_BVHClipPrimitiveSet::Clear()
135 // =======================================================================
136 // function : GetStructureById
138 // =======================================================================
139 const OpenGl_Structure* OpenGl_BVHClipPrimitiveSet::GetStructureById (Standard_Integer theId)
141 return myStructs.FindKey (theId + 1);