#ifndef _OpenGl_Clipping_H__
#define _OpenGl_Clipping_H__
-#include <Aspect_GenId.hxx>
-#include <Graphic3d_ClipPlane.hxx>
#include <Graphic3d_SequenceOfHClipPlane.hxx>
-#include <NCollection_DataMap.hxx>
-#include <NCollection_Handle.hxx>
+#include <NCollection_Vector.hxx>
#include <Standard_TypeDef.hxx>
-#include <OpenGl_Matrix.hxx>
-class OpenGl_Workspace;
+class OpenGl_ClippingIterator;
//! This class contains logics related to tracking and modification of clipping plane
//! state for particular OpenGl context. It contains information about enabled
//! class.
class OpenGl_Clipping
{
-public:
-
- //! Enumerates supported equation coordinate spaces.
- enum EquationCoords
- {
- EquationCoords_View,
- EquationCoords_World
- };
-
+ friend class OpenGl_ClippingIterator;
public: //! @name general methods
//! Default constructor.
Standard_EXPORT OpenGl_Clipping();
//! Initialize.
- //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
- Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
+ Standard_EXPORT void Init();
-public: //! @name non-modifying getters
+ //! Setup list of global (for entire view) clipping planes
+ //! and clears local plane list if it was not released before.
+ Standard_EXPORT void Reset (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
- //! Check whether the clipping plane has been added to the current context state.
- //! @param thePlane [in] the plane to check.
- //! @return True if plane is set.
- inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
- {
- return myPlaneStates.IsBound (thePlane);
- }
+ //! Setup list of local (for current object) clipping planes.
+ Standard_EXPORT void SetLocalPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
- //! Get clip planes defined for context.
- //! @return sequence of set clipping planes.
- inline const Graphic3d_SequenceOfHClipPlane& Planes() const
- {
- return myPlanes;
- }
+ //! @return true if there are enabled capping planes
+ Standard_Boolean IsCappingOn() const { return myNbCapping > 0; }
- //! @return kind of equation coordinate space used for the clip plane.
- inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
- {
- return myPlaneStates.Find (thePlane).CoordSpace;
- }
+ //! @return true if there are enabled clipping or capping planes
+ Standard_Boolean IsClippingOrCappingOn() const { return NbClippingOrCappingOn() > 0; }
- //! Check whether the clipping plane has been set and enabled for the current context state.
- //! @param thePlane [in] the plane to check.
- //! @return True if plane is enabled.
- inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
+ //! @return number of enabled clipping + capping planes
+ Standard_Integer NbClippingOrCappingOn() const
{
- return myPlaneStates.Find (thePlane).IsEnabled;
+ if (IsCappingDisableAllExcept())
+ {
+ return 1; // all Chains are disabled - only single (sub) plane is active
+ }
+ return myNbClipping + myNbCapping
+ + (IsCappingEnableAllExcept() ? -1 : 0); // exclude 1 plane with Capping filter turned ON
}
- //! @return true if there are enabled clipping planes (NOT capping)
- inline Standard_Boolean IsClippingOn() const
+ //! Return TRUE if there are clipping chains in the list (defining more than 1 sub-plane)
+ Standard_Boolean HasClippingChains() const
{
- return myNbClipping > 0;
+ if (IsCappingDisableAllExcept() // all chains are disabled - only single (sub) plane is active;
+ || myNbChains == (myNbClipping + myNbCapping)) // no sub-planes
+ {
+ return Standard_False;
+ }
+ return !IsCappingEnableAllExcept()
+ || myCappedChain->NbChainNextPlanes() == 1
+ || myNbChains > 1; // if capping filter ON - chains counter should be decremented
}
- //! @return true if there are enabled capping planes
- inline Standard_Boolean IsCappingOn() const
- {
- return myNbCapping > 0;
- }
+public: //! @name advanced method for disabling defined planes
- //! @return true if there are enabled clipping or capping planes
- inline Standard_Boolean IsClippingOrCappingOn() const
- {
- return (myNbClipping + myNbCapping) > 0;
- }
+ //! Return true if some clipping planes have been temporarily disabled.
+ Standard_Boolean HasDisabled() const { return myNbDisabled > 0; }
-public: //! @name clipping state modification commands
+ //! Disable plane temporarily.
+ Standard_EXPORT Standard_Boolean SetEnabled (const OpenGl_ClippingIterator& thePlane,
+ const Standard_Boolean theIsEnabled);
- //! Add planes to the context clipping at the specified system of coordinates.
- //! This methods loads appropriate transformation matrix from workspace to
- //! to transform equation coordinates. The planes become enabled in the context.
- //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
- //! are simply ignored.
- //! @param thePlanes [in/out] the list of planes to be added.
- //! The list then provides information on which planes were really added to clipping state.
- //! This list then can be used to fall back to previous state.
- //! @param theCoordSpace [in] the equation definition space.
- //! @param theWS [in] the workspace to access the matrices.
- Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
- const EquationCoords& theCoordSpace,
- const Handle(OpenGl_Workspace)& theWS);
+ //! Temporarily disable all planes from the global (view) list, keep only local (object) list.
+ Standard_EXPORT void DisableGlobal();
- //! Add planes to the context clipping at the specified system of coordinates.
- //! This method assumes that appropriate matrix is already set in context state.
- //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
- //! are simply ignored.
- //! @param thePlanes [in/out] the list of planes to be added.
- //! The list then provides information on which planes were really added to clipping state.
- //! This list then can be used to fall back to previous state.
- //! @param theCoordSpace [in] the equation definition space.
- Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
- const EquationCoords& theCoordSpace);
+ //! Restore all temporarily disabled planes.
+ //! Does NOT affect constantly disabled planes Graphic3d_ClipPlane::IsOn().
+ Standard_EXPORT void RestoreDisabled();
- //! Remove the passed set of clipping planes from the context state.
- //! @param thePlanes [in] the planes to remove from list.
- Standard_EXPORT void Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes);
+//! @name capping algorithm filter
+public:
- //! Enable or disable clipping plane in the OpenGl context.
- //! @param thePlane [in] the plane to affect.
- //! @param theIsEnabled [in] the state of the plane.
- Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
- const Standard_Boolean theIsEnabled);
+ //! Chain which is either temporary disabled or the only one enabled for Capping algorithm.
+ const Handle(Graphic3d_ClipPlane)& CappedChain() const { return myCappedChain; }
-public: //! @name Short-cuts
+ //! Sub-plane index within filtered Chain; positive number for DisableAllExcept and negative for EnableAllExcept.
+ Standard_Integer CappedSubPlane() const { return myCappedSubPlane; }
- //! Add planes to the context clipping at the view system of coordinates.
- //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
- //! are simply ignored.
- //! @param thePlanes [in/out] the list of planes to be added.
- //! The list then provides information on which planes were really added to clipping state.
- //! This list then can be used to fall back to previous state.
- //! @param theWS [in] the workspace to access the matrices.
- inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
- {
- Add (thePlanes, EquationCoords_View, theWS);
- }
+ //! Return TRUE if capping algorithm is in state, when all clipping planes are temporarily disabled except currently processed one.
+ bool IsCappingFilterOn() const { return !myCappedChain.IsNull(); }
- //! Add planes to the context clipping at the view system of coordinates.
- //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
- //! are simply ignored.
- //! @param thePlanes [in/out] the list of planes to be added.
- //! The list then provides information on which planes were really added to clipping state.
- //! This list then can be used to fall back to previous state.
- inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes)
- {
- Add (thePlanes, EquationCoords_View);
- }
+ //! Return TRUE if capping algorithm is in state, when all clipping planes are temporarily disabled except currently processed one.
+ bool IsCappingDisableAllExcept() const { return myCappedSubPlane > 0; }
- //! Add planes to the context clipping at the world system of coordinates.
- //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
- //! are simply ignored.
- //! @param thePlanes [in/out] the list of planes to be added.
- //! The list then provides information on which planes were really added to clipping state.
- //! This list then can be used to fall back to previous state.
- //! @param theWS [in] the workspace to access the matrices.
- inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
- {
- Add (thePlanes, EquationCoords_World, theWS);
- }
+ //! Return TRUE if capping algorithm is in state, when all clipping planes are enabled except currently rendered one.
+ bool IsCappingEnableAllExcept() const { return myCappedSubPlane < 0; }
+
+ //! Temporarily disable all planes except specified one for Capping algorithm.
+ //! Does not affect already disabled planes.
+ Standard_EXPORT void DisableAllExcept (const Handle(Graphic3d_ClipPlane)& theChain,
+ const Standard_Integer theSubPlaneIndex);
+
+ //! Enable back planes disabled by ::DisableAllExcept() for Capping algorithm.
+ //! Keeps only specified plane enabled.
+ Standard_EXPORT void EnableAllExcept (const Handle(Graphic3d_ClipPlane)& theChain,
+ const Standard_Integer theSubPlaneIndex);
- //! Add planes to the context clipping at the world system of coordinates.
+ //! Resets chain filter for Capping algorithm.
+ Standard_EXPORT void ResetCappingFilter();
+
+protected: //! @name clipping state modification commands
+
+ //! Add planes to the context clipping at the specified system of coordinates.
+ //! This methods loads appropriate transformation matrix from workspace to
+ //! to transform equation coordinates. The planes become enabled in the context.
//! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
//! are simply ignored.
- //! @param thePlanes [in/out] the list of planes to be added.
+ //!
+ //! Within FFP, method also temporarily resets ModelView matrix before calling glClipPlane().
+ //! Otherwise the method just redirects to addLazy().
+ //!
+ //! @param thePlanes [in/out] the list of planes to be added
//! The list then provides information on which planes were really added to clipping state.
//! This list then can be used to fall back to previous state.
- inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes)
- {
- Add (thePlanes, EquationCoords_World);
- }
+ Standard_EXPORT void add (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
+ const Standard_Integer theStartIndex);
- //! Remove all of the planes from context state.
- inline void RemoveAll()
- {
- Remove (Planes());
- }
+ //! Remove the passed set of clipping planes from the context state.
+ //! @param thePlanes [in] the planes to remove from list.
+ Standard_EXPORT void remove (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
+ const Standard_Integer theStartIndex);
private:
- struct PlaneProps
- {
- // declare default constructor
- // to allow compilation of template collections
- PlaneProps() {}
- PlaneProps (const EquationCoords theCoords,
- const Standard_Integer theID,
- const Standard_Boolean theIsEnabled)
- {
- CoordSpace = theCoords;
- ContextID = theID;
- IsEnabled = theIsEnabled;
- }
+ Handle(Graphic3d_SequenceOfHClipPlane) myPlanesGlobal; //!< global clipping planes
+ Handle(Graphic3d_SequenceOfHClipPlane) myPlanesLocal; //!< object clipping planes
+ NCollection_Vector<Standard_Boolean> myDisabledPlanes; //!< ids of disabled planes
- EquationCoords CoordSpace;
- Standard_Integer ContextID;
- Standard_Boolean IsEnabled;
- };
+ Handle(Graphic3d_ClipPlane) myCappedChain; //!< chain which is either temporary disabled or the only one enabled for Capping algorithm
+ Standard_Integer myCappedSubPlane; //!< sub-plane index within filtered chain; positive number for DisableAllExcept and negative for EnableAllExcept
-private:
-
- typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
- typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
-
- Graphic3d_SequenceOfHClipPlane myPlanes; //!< defined clipping planes
- OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props
- OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids
- Standard_Boolean myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
- Standard_Boolean myNbCapping; //!< number of enabled capping planes
+ Standard_Integer myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
+ Standard_Integer myNbCapping; //!< number of enabled capping planes
+ Standard_Integer myNbChains; //!< number of enabled chains
+ Standard_Integer myNbDisabled; //!< number of defined but disabled planes
private:
-
//! Copying allowed only within Handles
OpenGl_Clipping (const OpenGl_Clipping& );
OpenGl_Clipping& operator= (const OpenGl_Clipping& );