0027317: Some visualisation tests failed because of exceptions generated by FP signals.
[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
41e08b4d 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;
61
62 if (aCenter <= Standard_Real (-ShortRealLast()))
63 return -ShortRealLast();
64 if (aCenter >= Standard_Real (ShortRealLast()))
65 return ShortRealLast();
66
67 return Standard_ShortReal (aCenter);
b7cd4ba7 68}
69
70// =======================================================================
71// function : Swap
72// purpose :
73// =======================================================================
74void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
75 const Standard_Integer theIdx2)
76{
385c43e7 77 myStructs.Swap (theIdx1 + 1, theIdx2 + 1);
b7cd4ba7 78}
79
80// =======================================================================
b7cd4ba7 81// function : Add
82// purpose :
83// =======================================================================
825aa485 84Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct)
b7cd4ba7 85{
385c43e7 86 const Standard_Integer aSize = myStructs.Size();
87
88 if (myStructs.Add (theStruct) > aSize) // new structure?
89 {
90 MarkDirty();
825aa485 91
92 return Standard_True;
385c43e7 93 }
825aa485 94
95 return Standard_False;
b7cd4ba7 96}
97
98// =======================================================================
99// function : Remove
100// purpose :
101// =======================================================================
825aa485 102Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct)
b7cd4ba7 103{
385c43e7 104 const Standard_Integer anIndex = myStructs.FindIndex (theStruct);
105
106 if (anIndex != 0)
b7cd4ba7 107 {
385c43e7 108 myStructs.Swap (Size(), anIndex);
109 myStructs.RemoveLast();
110 MarkDirty();
825aa485 111
112 return Standard_True;
b7cd4ba7 113 }
825aa485 114
115 return Standard_False;
b7cd4ba7 116}
117
118// =======================================================================
119// function : Clear
120// purpose :
121// =======================================================================
122void OpenGl_BVHClipPrimitiveSet::Clear()
123{
124 myStructs.Clear();
125 MarkDirty();
126}
127
128// =======================================================================
129// function : GetStructureById
130// purpose :
131// =======================================================================
132const OpenGl_Structure* OpenGl_BVHClipPrimitiveSet::GetStructureById (Standard_Integer theId)
133{
385c43e7 134 return myStructs.FindKey (theId + 1);
b7cd4ba7 135}