1 // Created on: 2013-07-12
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013-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 _Graphic3d_ClipPlane_HeaderFile
17 #define _Graphic3d_ClipPlane_HeaderFile
19 #include <Aspect_HatchStyle.hxx>
21 #include <Graphic3d_AspectFillArea3d.hxx>
22 #include <Graphic3d_CappingFlags.hxx>
23 #include <Graphic3d_TextureMap.hxx>
24 #include <NCollection_Vec4.hxx>
25 #include <Standard_Macro.hxx>
26 #include <Standard_TypeDef.hxx>
27 #include <Standard_Transient.hxx>
29 //! Container for properties describing graphic driver clipping planes.
30 //! It is up to application to create instances of this class and specify its
31 //! properties. The instances are passed into graphic driver or other facilities
32 //! that implement clipping features (e.g. selection).
33 //! Depending on usage context the class can be used to specify:
34 //! - Global clipping applied over the whole scene.
35 //! - Object-level clipping applied for each particular object.
36 //! The plane equation is specified in "world" coordinate system.
37 //! Please note that the set of planes can define convex clipping volume.
38 //! Be aware that number of clip planes supported by OpenGl is implementation
39 //! dependent: at least 6 planes are available. Thus, take into account
40 //! number of clipping planes passed for rendering: the object planes plus
41 //! the view defined ones.
42 class Graphic3d_ClipPlane : public Standard_Transient
46 typedef NCollection_Vec4<Standard_Real> Equation;
48 //! Default constructor.
49 //! Initializes clip plane container with the following properties:
50 //! - Equation (0.0, 0.0, 1.0, 0)
52 //! - IsCapping (False),
53 //! - Material (Graphic3d_NOM_DEFAULT),
55 //! - HatchStyle (Aspect_HS_HORIZONTAL),
56 //! - IsHatchOn (False)
57 Standard_EXPORT Graphic3d_ClipPlane();
60 //! @param theOther [in] the copied plane.
61 Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther);
63 //! Construct clip plane for the passed equation.
64 //! By default the plane is on, capping is turned off.
65 //! @param theEquation [in] the plane equation.
66 Standard_EXPORT Graphic3d_ClipPlane (const Equation& theEquation);
68 //! Construct clip plane from the passed geometrical definition.
69 //! By default the plane is on, capping is turned off.
70 //! @param thePlane [in] the plane.
71 Standard_EXPORT Graphic3d_ClipPlane (const gp_Pln& thePlane);
73 //! Set plane equation by its geometrical definition.
74 //! The equation is specified in "world" coordinate system.
75 //! @param thePlane [in] the plane.
76 Standard_EXPORT void SetEquation (const gp_Pln& thePlane);
78 //! Set 4-component equation vector for clipping plane.
79 //! The equation is specified in "world" coordinate system.
80 //! @param theEquation [in] the XYZW (or "ABCD") equation vector.
81 Standard_EXPORT void SetEquation (const Equation& theEquation);
83 //! Get 4-component equation vector for clipping plane.
84 //! @return clipping plane equation vector.
85 const Equation& GetEquation() const
90 //! Check that the clipping plane is turned on.
91 //! @return boolean flag indicating whether the plane is in on or off state.
92 Standard_Boolean IsOn() const
97 //! Change state of the clipping plane.
98 //! @param theIsOn [in] the flag specifying whether the graphic driver
99 //! clipping by this plane should be turned on or off.
100 Standard_EXPORT void SetOn(const Standard_Boolean theIsOn);
102 //! Change state of capping surface rendering.
103 //! @param theIsOn [in] the flag specifying whether the graphic driver should
104 //! perform rendering of capping surface produced by this plane. The graphic
105 //! driver produces this surface for convex graphics by means of stencil-test
106 //! and multi-pass rendering.
107 Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
109 //! Check state of capping surface rendering.
110 //! @return true (turned on) or false depending on the state.
111 Standard_Boolean IsCapping() const
116 //! Get geometrical definition.
117 //! @return geometrical definition of clipping plane
118 const gp_Pln& ToPlane() const { return myPlane; }
120 //! Clone plane. Virtual method to simplify copying procedure if plane
121 //! class is redefined at application level to add specific fields to it
122 //! e.g. id, name, etc.
123 //! @return new instance of clipping plane with same properties and attributes.
124 Standard_EXPORT virtual Handle(Graphic3d_ClipPlane) Clone() const;
126 public: // @name user-defined graphical attributes
128 //! Set material for rendering capping surface.
129 //! @param theMat [in] the material.
130 Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
132 //! @return capping material.
133 const Graphic3d_MaterialAspect& CappingMaterial() const { return myAspect->FrontMaterial(); }
135 //! Set texture to be applied on capping surface.
136 //! @param theTexture [in] the texture.
137 Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
139 //! @return capping texture map.
140 Handle(Graphic3d_TextureMap) CappingTexture() const { return !myAspect->TextureSet().IsNull() && !myAspect->TextureSet()->IsEmpty()
141 ? myAspect->TextureSet()->First()
142 : Handle(Graphic3d_TextureMap)(); }
144 //! Set hatch style (stipple) and turn hatching on.
145 //! @param theStyle [in] the hatch style.
146 Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
148 //! @return hatching style.
149 Aspect_HatchStyle CappingHatch() const { return (Aspect_HatchStyle)myAspect->HatchStyle()->HatchType(); }
151 //! Set custom hatch style (stipple) and turn hatching on.
152 //! @param theStyle [in] the hatch pattern.
153 Standard_EXPORT void SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle);
155 //! @return hatching style.
156 const Handle(Graphic3d_HatchStyle)& CappingCustomHatch() const { return myAspect->HatchStyle(); }
158 //! Turn on hatching.
159 Standard_EXPORT void SetCappingHatchOn();
161 //! Turn off hatching.
162 Standard_EXPORT void SetCappingHatchOff();
164 //! @return True if hatching mask is turned on.
165 Standard_Boolean IsHatchOn() const { return myAspect->InteriorStyle() == Aspect_IS_HATCH; }
167 //! This ID is used for managing associated resources in graphical driver.
168 //! The clip plane can be assigned within a range of IO which can be
169 //! displayed in separate OpenGl contexts. For each of the context an associated
170 //! OpenGl resource for graphical aspects should be created and kept.
171 //! The resources are stored in graphical driver for each of individual groups
172 //! of shared context under the clip plane identifier.
173 //! @return clip plane resource identifier string.
174 const TCollection_AsciiString& GetId() const
181 //! Return capping aspect.
182 //! @return capping surface rendering aspect.
183 const Handle(Graphic3d_AspectFillArea3d)& CappingAspect() const { return myAspect; }
185 //! Assign capping aspect.
186 Standard_EXPORT void SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
188 //! Flag indicating whether material for capping plane should be taken from object.
189 //! Default value: FALSE (use dedicated capping plane material).
190 bool ToUseObjectMaterial() const { return (myFlags & Graphic3d_CappingFlags_ObjectMaterial) != 0; }
192 //! Set flag for controlling the source of capping plane material.
193 void SetUseObjectMaterial (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectMaterial); }
195 //! Flag indicating whether texture for capping plane should be taken from object.
196 //! Default value: FALSE.
197 bool ToUseObjectTexture() const { return (myFlags & Graphic3d_CappingFlags_ObjectTexture) != 0; }
199 //! Set flag for controlling the source of capping plane texture.
200 void SetUseObjectTexture (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectTexture); }
202 //! Flag indicating whether shader program for capping plane should be taken from object.
203 //! Default value: FALSE.
204 bool ToUseObjectShader() const { return (myFlags & Graphic3d_CappingFlags_ObjectShader) != 0; }
206 //! Set flag for controlling the source of capping plane shader program.
207 void SetUseObjectShader(bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectShader); }
209 //! Return true if some fill area aspect properties should be taken from object.
210 bool ToUseObjectProperties() const { return myFlags != Graphic3d_CappingFlags_None; }
212 public: // @name modification counters
214 //! @return modification counter for equation.
215 unsigned int MCountEquation() const
217 return myEquationMod;
220 //! @return modification counter for aspect.
221 unsigned int MCountAspect() const
228 //! Generate unique object id for OpenGL graphic resource manager.
231 //! Set capping flag.
232 Standard_EXPORT void setCappingFlag (bool theToUse, int theFlag);
236 Handle(Graphic3d_AspectFillArea3d) myAspect; //!< fill area aspect
237 TCollection_AsciiString myId; //!< resource id
238 gp_Pln myPlane; //!< plane definition
239 Equation myEquation; //!< plane equation vector
240 unsigned int myFlags; //!< capping flags
241 unsigned int myEquationMod; //!< modification counter for equation
242 unsigned int myAspectMod; //!< modification counter of aspect
243 Standard_Boolean myIsOn; //!< state of the clipping plane
244 Standard_Boolean myIsCapping; //!< state of graphic driver capping
248 DEFINE_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
251 DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)