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>
21 #include <Standard_OStream.hxx>
22 #include <Standard_Dump.hxx>
27 class Graphic3d_SequenceOfHClipPlane;
29 //! Class for handling depth clipping range.
30 //! It is used to perform checks in case if global (for the whole view)
31 //! clipping planes are defined inside of SelectMgr_RectangularFrustum class methods.
32 class SelectMgr_ViewClipRange
35 //! Creates an empty clip range.
36 SelectMgr_ViewClipRange()
41 //! Check if the given depth is not within clipping range(s),
42 //! e.g. TRUE means depth is clipped.
43 Standard_Boolean IsClipped (const Standard_Real theDepth) const
45 if (myUnclipRange.IsOut (theDepth))
49 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
51 if (!myClipRanges[aRangeIter].IsOut (theDepth))
56 return Standard_False;
59 //! Calculates the min not clipped value from the range.
60 //! Returns FALSE if the whole range is clipped.
61 Standard_Boolean GetNearestDepth (const Bnd_Range& theRange, Standard_Real& theDepth) const
63 if (!myUnclipRange.IsVoid() && myUnclipRange.IsOut (theRange))
68 Bnd_Range aCommonClipRange;
69 theRange.GetMin (theDepth);
71 if (!myUnclipRange.IsVoid() && myUnclipRange.IsOut (theDepth))
73 myUnclipRange.GetMin (theDepth);
76 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
78 if (!myClipRanges[aRangeIter].IsOut (theDepth))
80 aCommonClipRange = myClipRanges[aRangeIter];
85 if (aCommonClipRange.IsVoid())
90 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
92 if (!aCommonClipRange.IsOut (myClipRanges[aRangeIter]))
94 aCommonClipRange.Add (myClipRanges[aRangeIter]);
98 aCommonClipRange.GetMax (theDepth);
100 return !theRange.IsOut (theDepth);
105 //! Clears clipping range.
108 myClipRanges.resize (0);
109 myUnclipRange = Bnd_Range (RealFirst(), RealLast());
112 //! Add clipping planes. Planes and picking ray should be defined in the same coordinate system.
113 Standard_EXPORT void AddClippingPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes,
114 const gp_Ax1& thePickRay);
116 //! Returns the main unclipped range; [-inf, inf] by default.
117 Bnd_Range& ChangeUnclipRange() { return myUnclipRange; }
119 //! Adds a clipping sub-range (for clipping chains).
120 void AddClipSubRange (const Bnd_Range& theRange) { myClipRanges.push_back (theRange); }
122 //! Dumps the content of me into the stream
123 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const;
127 std::vector<Bnd_Range> myClipRanges;
128 Bnd_Range myUnclipRange;
132 #endif // _SelectMgr_ViewClipRange_HeaderFile