1 // Created on: 2013-07-12
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 65 (the "License") You may not use the content of this file
7 // except in compliance with the License Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file
10 // The Initial Developer of the Original Code is Open CASCADE SAS, having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License
20 #ifndef _Graphic3d_ClipPlane_HeaderFile
21 #define _Graphic3d_ClipPlane_HeaderFile
23 #include <Standard_Macro.hxx>
24 #include <Standard_TypeDef.hxx>
25 #include <Standard_Transient.hxx>
26 #include <NCollection_Vec4.hxx>
27 #include <Graphic3d_MaterialAspect.hxx>
28 #include <Graphic3d_TextureMap.hxx>
29 #include <Aspect_HatchStyle.hxx>
31 DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)
34 class Graphic3d_AspectFillArea3d;
35 class Handle(Graphic3d_AspectFillArea3d);
37 //! Container for properties describing graphic driver clipping planes.
38 //! It is up to application to create instances of this class and specify its
39 //! properties. The instances are passed into graphic driver or other facilities
40 //! that implement clipping features (e.g. selection).
41 //! Depending on usage context the class can be used to specify:
42 //! - Global clipping applied over the whole scene.
43 //! - Object-level clipping applied for each particular object.
44 //! The plane equation is specified in "world" coordinate system.
45 //! Please note that the set of planes can define convex clipping volume.
46 //! Be aware that number of clip planes supported by OpenGl is implementation
47 //! dependent: at least 6 planes are available. Thus, take into account
48 //! number of clipping planes passed for rendering: the object planes plus
49 //! the view defined ones.
50 class Graphic3d_ClipPlane : public Standard_Transient
54 typedef NCollection_Vec4<Standard_Real> Equation;
56 //! Default constructor.
57 //! Initializes clip plane container with the following properties:
58 //! - Equation (0.0, 0.0, 1.0, 0)
60 //! - IsCapping (False),
61 //! - Material (Graphic3d_NOM_DEFAULT),
63 //! - HatchStyle (Aspect_HS_HORIZONTAL),
64 //! - IsHatchOn (False)
65 Standard_EXPORT Graphic3d_ClipPlane();
68 //! @param theOther [in] the copied plane.
69 Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther);
71 //! Construct clip plane for the passed equation.
72 //! By default the plane is on, capping is turned off.
73 //! @param theEquation [in] the plane equation.
74 Standard_EXPORT Graphic3d_ClipPlane (const Equation& theEquation);
76 //! Construct clip plane from the passed geometrical definition.
77 //! By default the plane is on, capping is turned off.
78 //! @param thePlane [in] the plane.
79 Standard_EXPORT Graphic3d_ClipPlane (const gp_Pln& thePlane);
81 //! Set plane equation by its geometrical definition.
82 //! The equation is specified in "world" coordinate system.
83 //! @param thePlane [in] the plane.
84 Standard_EXPORT void SetEquation (const gp_Pln& thePlane);
86 //! Set 4-component equation vector for clipping plane.
87 //! The equation is specified in "world" coordinate system.
88 //! @param theEquation [in] the XYZW (or "ABCD") equation vector.
89 Standard_EXPORT void SetEquation (const Equation& theEquation);
91 //! Get 4-component equation vector for clipping plane.
92 //! @return clipping plane equation vector.
93 const Equation& GetEquation() const
98 //! Check that the clipping plane is turned on.
99 //! @return boolean flag indicating whether the plane is in on or off state.
100 Standard_Boolean IsOn() const
105 //! Change state of the clipping plane.
106 //! @param theIsOn [in] the flag specifying whether the graphic driver
107 //! clipping by this plane should be turned on or off.
108 Standard_EXPORT void SetOn(const Standard_Boolean theIsOn);
110 //! Change state of capping surface rendering.
111 //! @param theIsOn [in] the flag specifying whether the graphic driver should
112 //! perform rendering of capping surface produced by this plane. The graphic
113 //! driver produces this surface for convex graphics by means of stencil-test
114 //! and multi-pass rendering.
115 Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
117 //! Check state of capping surface rendering.
118 //! @return true (turned on) or false depending on the state.
119 Standard_Boolean IsCapping() const
124 //! Get geometrical definition. The plane is built up
125 //! from the equation clipping plane equation vector.
126 //! @return geometrical definition of clipping plane.
127 Standard_EXPORT gp_Pln ToPlane() const;
129 //! Clone plane. Virtual method to simplify copying procedure if plane
130 //! class is redefined at application level to add specific fields to it
131 //! e.g. id, name, etc.
132 //! @return new instance of clipping plane with same properties and attributes.
133 Standard_EXPORT virtual Handle(Graphic3d_ClipPlane) Clone() const;
135 public: // @name user-defined graphical attributes
137 //! Set material for rendering capping surface.
138 //! @param theMat [in] the material.
139 Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
141 //! @return capping material.
142 const Graphic3d_MaterialAspect& CappingMaterial() const
147 //! Set texture to be applied on capping surface.
148 //! @param theTexture [in] the texture.
149 Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
151 //! @return capping texture map.
152 const Handle(Graphic3d_TextureMap)& CappingTexture() const
157 //! Set hatch style (stipple) and turn hatching on.
158 //! @param theStyle [in] the hatch style.
159 Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
161 //! @return hatching style.
162 Aspect_HatchStyle CappingHatch() const
167 //! Turn on hatching.
168 Standard_EXPORT void SetCappingHatchOn();
170 //! Turn off hatching.
171 Standard_EXPORT void SetCappingHatchOff();
173 //! @return True if hatching mask is turned on.
174 Standard_Boolean IsHatchOn() const
179 //! This ID is used for managing associated resources in graphical driver.
180 //! The clip plane can be assigned within a range of IO which can be
181 //! displayed in separate OpenGl contexts. For each of the context an associated
182 //! OpenGl resource for graphical aspects should be created and kept.
183 //! The resources are stored in graphical driver for each of individual groups
184 //! of shared context under the clip plane identifier.
185 //! @return clip plane resource identifier string.
186 const TCollection_AsciiString& GetId() const
191 //! Compute and return capping aspect from the graphical attributes.
192 //! @return capping surface rendering aspect.
193 Standard_EXPORT Handle(Graphic3d_AspectFillArea3d) CappingAspect() const;
195 public: // @name modification counters
197 //! @return modification counter for equation.
198 unsigned int MCountEquation() const
200 return myEquationMod;
203 //! @return modification counter for aspect.
204 unsigned int MCountAspect() const
215 Equation myEquation; //!< Plane equation vector.
216 Standard_Boolean myIsOn; //!< State of the clipping plane.
217 Standard_Boolean myIsCapping; //!< State of graphic driver capping.
218 Graphic3d_MaterialAspect myMaterial; //!< Capping surface material.
219 Handle(Graphic3d_TextureMap) myTexture; //!< Capping surface texture.
220 Aspect_HatchStyle myHatch; //!< Capping surface hatch mask.
221 Standard_Boolean myHatchOn; //!< Capping surface hatching flag.
222 TCollection_AsciiString myId; //!< Resource id.
223 unsigned int myEquationMod; //!< Modification counter for equation.
224 unsigned int myAspectMod; //!< Modification counter of aspect.
228 DEFINE_STANDARD_RTTI(Graphic3d_ClipPlane);