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 <Graphic3d_BvhCStructureSet.hxx>
18 #include <BVH_BinnedBuilder.hxx>
19 #include <Graphic3d_CStructure.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_BvhCStructureSet, BVH_PrimitiveSet3d)
23 // =======================================================================
24 // function : Graphic3d_BvhCStructureSet
26 // =======================================================================
27 Graphic3d_BvhCStructureSet::Graphic3d_BvhCStructureSet()
29 myBuilder = new BVH_BinnedBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth);
32 // =======================================================================
35 // =======================================================================
36 Standard_Integer Graphic3d_BvhCStructureSet::Size() const
38 return myStructs.Size();
41 // =======================================================================
44 // =======================================================================
45 Graphic3d_BndBox3d Graphic3d_BvhCStructureSet::Box (const Standard_Integer theIdx) const
47 return myStructs.FindKey (theIdx + 1)->BoundingBox();
50 // =======================================================================
53 // =======================================================================
54 Standard_Real Graphic3d_BvhCStructureSet::Center (const Standard_Integer theIdx,
55 const Standard_Integer theAxis) const
57 Graphic3d_BndBox3d aBndBox = myStructs.FindKey (theIdx + 1)->BoundingBox();
59 const Standard_Real aMin = aBndBox.CornerMin()[theAxis];
60 const Standard_Real aMax = aBndBox.CornerMax()[theAxis];
61 const Standard_Real aCenter = (aMin + aMax) * 0.5;
65 // =======================================================================
68 // =======================================================================
69 void Graphic3d_BvhCStructureSet::Swap (const Standard_Integer theIdx1,
70 const Standard_Integer theIdx2)
72 myStructs.Swap (theIdx1 + 1, theIdx2 + 1);
75 // =======================================================================
78 // =======================================================================
79 Standard_Boolean Graphic3d_BvhCStructureSet::Add (const Graphic3d_CStructure* theStruct)
81 const Standard_Integer aSize = myStructs.Size();
83 if (myStructs.Add (theStruct) > aSize) // new structure?
90 return Standard_False;
93 // =======================================================================
96 // =======================================================================
97 Standard_Boolean Graphic3d_BvhCStructureSet::Remove (const Graphic3d_CStructure* theStruct)
99 const Standard_Integer anIndex = myStructs.FindIndex (theStruct);
103 myStructs.Swap (Size(), anIndex);
104 myStructs.RemoveLast();
107 return Standard_True;
110 return Standard_False;
113 // =======================================================================
116 // =======================================================================
117 void Graphic3d_BvhCStructureSet::Clear()
123 // =======================================================================
124 // function : GetStructureById
126 // =======================================================================
127 const Graphic3d_CStructure* Graphic3d_BvhCStructureSet::GetStructureById (Standard_Integer theId)
129 return myStructs.FindKey (theId + 1);