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 <Standard_Macro.hxx>
20 #include <Standard_TypeDef.hxx>
21 #include <Standard_Transient.hxx>
22 #include <NCollection_Vec4.hxx>
23 #include <Graphic3d_MaterialAspect.hxx>
24 #include <Graphic3d_TextureMap.hxx>
25 #include <Aspect_HatchStyle.hxx>
28 class Graphic3d_AspectFillArea3d;
30 //! Container for properties describing graphic driver clipping planes.
31 //! It is up to application to create instances of this class and specify its
32 //! properties. The instances are passed into graphic driver or other facilities
33 //! that implement clipping features (e.g. selection).
34 //! Depending on usage context the class can be used to specify:
35 //! - Global clipping applied over the whole scene.
36 //! - Object-level clipping applied for each particular object.
37 //! The plane equation is specified in "world" coordinate system.
38 //! Please note that the set of planes can define convex clipping volume.
39 //! Be aware that number of clip planes supported by OpenGl is implementation
40 //! dependent: at least 6 planes are available. Thus, take into account
41 //! number of clipping planes passed for rendering: the object planes plus
42 //! the view defined ones.
43 class Graphic3d_ClipPlane : public Standard_Transient
47 typedef NCollection_Vec4<Standard_Real> Equation;
49 //! Default constructor.
50 //! Initializes clip plane container with the following properties:
51 //! - Equation (0.0, 0.0, 1.0, 0)
53 //! - IsCapping (False),
54 //! - Material (Graphic3d_NOM_DEFAULT),
56 //! - HatchStyle (Aspect_HS_HORIZONTAL),
57 //! - IsHatchOn (False)
58 Standard_EXPORT Graphic3d_ClipPlane();
61 //! @param theOther [in] the copied plane.
62 Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther);
64 //! Construct clip plane for the passed equation.
65 //! By default the plane is on, capping is turned off.
66 //! @param theEquation [in] the plane equation.
67 Standard_EXPORT Graphic3d_ClipPlane (const Equation& theEquation);
69 //! Construct clip plane from the passed geometrical definition.
70 //! By default the plane is on, capping is turned off.
71 //! @param thePlane [in] the plane.
72 Standard_EXPORT Graphic3d_ClipPlane (const gp_Pln& thePlane);
74 //! Set plane equation by its geometrical definition.
75 //! The equation is specified in "world" coordinate system.
76 //! @param thePlane [in] the plane.
77 Standard_EXPORT void SetEquation (const gp_Pln& thePlane);
79 //! Set 4-component equation vector for clipping plane.
80 //! The equation is specified in "world" coordinate system.
81 //! @param theEquation [in] the XYZW (or "ABCD") equation vector.
82 Standard_EXPORT void SetEquation (const Equation& theEquation);
84 //! Get 4-component equation vector for clipping plane.
85 //! @return clipping plane equation vector.
86 const Equation& GetEquation() const
91 //! Check that the clipping plane is turned on.
92 //! @return boolean flag indicating whether the plane is in on or off state.
93 Standard_Boolean IsOn() const
98 //! Change state of the clipping plane.
99 //! @param theIsOn [in] the flag specifying whether the graphic driver
100 //! clipping by this plane should be turned on or off.
101 Standard_EXPORT void SetOn(const Standard_Boolean theIsOn);
103 //! Change state of capping surface rendering.
104 //! @param theIsOn [in] the flag specifying whether the graphic driver should
105 //! perform rendering of capping surface produced by this plane. The graphic
106 //! driver produces this surface for convex graphics by means of stencil-test
107 //! and multi-pass rendering.
108 Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
110 //! Check state of capping surface rendering.
111 //! @return true (turned on) or false depending on the state.
112 Standard_Boolean IsCapping() const
117 //! Get geometrical definition. The plane is built up
118 //! from the equation clipping plane equation vector.
119 //! @return geometrical definition of clipping plane.
120 Standard_EXPORT gp_Pln ToPlane() const;
122 //! Clone plane. Virtual method to simplify copying procedure if plane
123 //! class is redefined at application level to add specific fields to it
124 //! e.g. id, name, etc.
125 //! @return new instance of clipping plane with same properties and attributes.
126 Standard_EXPORT virtual Handle(Graphic3d_ClipPlane) Clone() const;
128 public: // @name user-defined graphical attributes
130 //! Set material for rendering capping surface.
131 //! @param theMat [in] the material.
132 Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
134 //! @return capping material.
135 const Graphic3d_MaterialAspect& CappingMaterial() const
140 //! Set texture to be applied on capping surface.
141 //! @param theTexture [in] the texture.
142 Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
144 //! @return capping texture map.
145 const Handle(Graphic3d_TextureMap)& CappingTexture() const
150 //! Set hatch style (stipple) and turn hatching on.
151 //! @param theStyle [in] the hatch style.
152 Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
154 //! @return hatching style.
155 Aspect_HatchStyle CappingHatch() const
160 //! Turn on hatching.
161 Standard_EXPORT void SetCappingHatchOn();
163 //! Turn off hatching.
164 Standard_EXPORT void SetCappingHatchOff();
166 //! @return True if hatching mask is turned on.
167 Standard_Boolean IsHatchOn() const
172 //! This ID is used for managing associated resources in graphical driver.
173 //! The clip plane can be assigned within a range of IO which can be
174 //! displayed in separate OpenGl contexts. For each of the context an associated
175 //! OpenGl resource for graphical aspects should be created and kept.
176 //! The resources are stored in graphical driver for each of individual groups
177 //! of shared context under the clip plane identifier.
178 //! @return clip plane resource identifier string.
179 const TCollection_AsciiString& GetId() const
184 //! Compute and return capping aspect from the graphical attributes.
185 //! @return capping surface rendering aspect.
186 Standard_EXPORT Handle(Graphic3d_AspectFillArea3d) CappingAspect() const;
188 public: // @name modification counters
190 //! @return modification counter for equation.
191 unsigned int MCountEquation() const
193 return myEquationMod;
196 //! @return modification counter for aspect.
197 unsigned int MCountAspect() const
208 Equation myEquation; //!< Plane equation vector.
209 Standard_Boolean myIsOn; //!< State of the clipping plane.
210 Standard_Boolean myIsCapping; //!< State of graphic driver capping.
211 Graphic3d_MaterialAspect myMaterial; //!< Capping surface material.
212 Handle(Graphic3d_TextureMap) myTexture; //!< Capping surface texture.
213 Aspect_HatchStyle myHatch; //!< Capping surface hatch mask.
214 Standard_Boolean myHatchOn; //!< Capping surface hatching flag.
215 TCollection_AsciiString myId; //!< Resource id.
216 unsigned int myEquationMod; //!< Modification counter for equation.
217 unsigned int myAspectMod; //!< Modification counter of aspect.
221 DEFINE_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient);
224 DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)