1 // Created on: 2015-12-15
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-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 #ifndef _SelectMgr_ViewClipRange_HeaderFile
17 #define _SelectMgr_ViewClipRange_HeaderFile
19 #include <Bnd_Range.hxx>
20 #include <Standard_TypeDef.hxx>
22 //! Class for handling depth clipping range.
23 //! It is used to perform checks in case if global (for the whole view)
24 //! clipping planes are defined inside of SelectMgr_RectangularFrustum class methods.
25 class SelectMgr_ViewClipRange
28 //! Creates an empty clip range.
29 SelectMgr_ViewClipRange()
34 //! Check if the given depth is not within clipping range(s),
35 //! e.g. TRUE means depth is clipped.
36 Standard_Boolean IsClipped (const Standard_Real theDepth) const
38 if (myUnclipRange.IsOut (theDepth))
42 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
44 if (!myClipRanges[aRangeIter].IsOut (theDepth))
49 return Standard_False;
52 //! Calculates the min not clipped value from the range.
53 //! Returns FALSE if the whole range is clipped.
54 Standard_Boolean GetNearestDepth (const Bnd_Range& theRange, Standard_Real& theDepth) const
56 if (!myUnclipRange.IsVoid() && myUnclipRange.IsOut (theRange))
61 Bnd_Range aCommonClipRange;
62 theRange.GetMin (theDepth);
64 if (!myUnclipRange.IsVoid() && myUnclipRange.IsOut (theDepth))
66 myUnclipRange.GetMin (theDepth);
69 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
71 if (!myClipRanges[aRangeIter].IsOut (theDepth))
73 aCommonClipRange = myClipRanges[aRangeIter];
78 if (aCommonClipRange.IsVoid())
83 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
85 if (!aCommonClipRange.IsOut (myClipRanges[aRangeIter]))
87 aCommonClipRange.Add (myClipRanges[aRangeIter]);
91 aCommonClipRange.GetMax (theDepth);
93 return !theRange.IsOut (theDepth);
96 //! Clears clipping range.
99 myClipRanges.resize (0);
100 myUnclipRange = Bnd_Range (RealFirst(), RealLast());
103 //! Returns the main unclipped range; [-inf, inf] by default.
104 Bnd_Range& ChangeUnclipRange() { return myUnclipRange; }
106 //! Adds a clipping sub-range (for clipping chains).
107 void AddClipSubRange (const Bnd_Range& theRange) { myClipRanges.push_back (theRange); }
111 std::vector<Bnd_Range> myClipRanges;
112 Bnd_Range myUnclipRange;
116 #endif // _SelectMgr_ViewClipRange_HeaderFile