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