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 // to prevent float overflow
58 const Standard_Real aMin = Standard_Real (aBndBox.CornerMin()[theAxis]);
59 const Standard_Real aMax = Standard_Real (aBndBox.CornerMax()[theAxis]);
60 const Standard_Real aCenter = (aMin + aMax) * 0.5;
62 if (aCenter <= Standard_Real (-ShortRealLast()))
63 return -ShortRealLast();
64 if (aCenter >= Standard_Real (ShortRealLast()))
65 return ShortRealLast();
67 return Standard_ShortReal (aCenter);
70 // =======================================================================
73 // =======================================================================
74 void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
75 const Standard_Integer theIdx2)
77 myStructs.Swap (theIdx1 + 1, theIdx2 + 1);
80 // =======================================================================
83 // =======================================================================
84 Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct)
86 const Standard_Integer aSize = myStructs.Size();
88 if (myStructs.Add (theStruct) > aSize) // new structure?
95 return Standard_False;
98 // =======================================================================
101 // =======================================================================
102 Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct)
104 const Standard_Integer anIndex = myStructs.FindIndex (theStruct);
108 myStructs.Swap (Size(), anIndex);
109 myStructs.RemoveLast();
112 return Standard_True;
115 return Standard_False;
118 // =======================================================================
121 // =======================================================================
122 void OpenGl_BVHClipPrimitiveSet::Clear()
128 // =======================================================================
129 // function : GetStructureById
131 // =======================================================================
132 const OpenGl_Structure* OpenGl_BVHClipPrimitiveSet::GetStructureById (Standard_Integer theId)
134 return myStructs.FindKey (theId + 1);