4269bd1b |
1 | // Created on: 2013-07-12 |
2 | // Created by: Anton POLETAEV |
3 | // Copyright (c) 2013 OPEN CASCADE SAS |
4 | // |
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 |
9 | // |
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 |
12 | // |
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 |
19 | |
20 | #ifndef _Graphic3d_ClipPlane_HeaderFile |
21 | #define _Graphic3d_ClipPlane_HeaderFile |
22 | |
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> |
30 | |
31 | DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient) |
32 | |
33 | class gp_Pln; |
34 | class Graphic3d_AspectFillArea3d; |
35 | class Handle(Graphic3d_AspectFillArea3d); |
36 | |
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. |
b859a34d |
44 | //! The plane equation is specified in "world" coordinate system. |
4269bd1b |
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 |
b859a34d |
47 | //! dependent: at least 6 planes are available. Thus, take into account |
4269bd1b |
48 | //! number of clipping planes passed for rendering: the object planes plus |
49 | //! the view defined ones. |
50 | class Graphic3d_ClipPlane : public Standard_Transient |
51 | { |
52 | public: |
53 | |
54 | typedef NCollection_Vec4<Standard_Real> Equation; |
55 | |
56 | //! Default constructor. |
57 | //! Initializes clip plane container with the following properties: |
58 | //! - Equation (0.0, 0.0, 1.0, 0) |
59 | //! - IsOn (True), |
60 | //! - IsCapping (False), |
61 | //! - Material (Graphic3d_NOM_DEFAULT), |
62 | //! - Texture (NULL), |
63 | //! - HatchStyle (Aspect_HS_HORIZONTAL), |
64 | //! - IsHatchOn (False) |
65 | Standard_EXPORT Graphic3d_ClipPlane(); |
66 | |
67 | //! Copy constructor. |
68 | //! @param theOther [in] the copied plane. |
69 | Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther); |
70 | |
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); |
75 | |
b859a34d |
76 | //! Construct clip plane from the passed geometrical definition. |
4269bd1b |
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); |
80 | |
81 | //! Set plane equation by its geometrical definition. |
b859a34d |
82 | //! The equation is specified in "world" coordinate system. |
4269bd1b |
83 | //! @param thePlane [in] the plane. |
84 | Standard_EXPORT void SetEquation (const gp_Pln& thePlane); |
85 | |
86 | //! Set 4-component equation vector for clipping plane. |
b859a34d |
87 | //! The equation is specified in "world" coordinate system. |
4269bd1b |
88 | //! @param theEquation [in] the XYZW (or "ABCD") equation vector. |
89 | Standard_EXPORT void SetEquation (const Equation& theEquation); |
90 | |
91 | //! Get 4-component equation vector for clipping plane. |
92 | //! @return clipping plane equation vector. |
93 | const Equation& GetEquation() const |
94 | { |
95 | return myEquation; |
96 | } |
97 | |
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 |
101 | { |
102 | return myIsOn; |
103 | } |
104 | |
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); |
109 | |
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 |
b859a34d |
114 | //! and multi-pass rendering. |
4269bd1b |
115 | Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn); |
116 | |
117 | //! Check state of capping surface rendering. |
118 | //! @return true (turned on) or false depending on the state. |
119 | Standard_Boolean IsCapping() const |
120 | { |
121 | return myIsCapping; |
122 | } |
123 | |
b859a34d |
124 | //! Get geometrical definition. The plane is built up |
4269bd1b |
125 | //! from the equation clipping plane equation vector. |
126 | //! @return geometrical definition of clipping plane. |
127 | Standard_EXPORT gp_Pln ToPlane() const; |
128 | |
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; |
134 | |
135 | public: // @name user-defined graphical attributes |
136 | |
137 | //! Set material for rendering capping surface. |
138 | //! @param theMat [in] the material. |
139 | Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat); |
140 | |
141 | //! @return capping material. |
142 | const Graphic3d_MaterialAspect& CappingMaterial() const |
143 | { |
144 | return myMaterial; |
145 | } |
146 | |
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); |
150 | |
151 | //! @return capping texture map. |
152 | const Handle(Graphic3d_TextureMap)& CappingTexture() const |
153 | { |
154 | return myTexture; |
155 | } |
156 | |
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); |
160 | |
161 | //! @return hatching style. |
162 | Aspect_HatchStyle CappingHatch() const |
163 | { |
164 | return myHatch; |
165 | } |
166 | |
167 | //! Turn on hatching. |
168 | Standard_EXPORT void SetCappingHatchOn(); |
169 | |
170 | //! Turn off hatching. |
171 | Standard_EXPORT void SetCappingHatchOff(); |
172 | |
173 | //! @return True if hatching mask is turned on. |
174 | Standard_Boolean IsHatchOn() const |
175 | { |
176 | return myHatchOn; |
177 | } |
178 | |
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 |
187 | { |
188 | return myId; |
189 | } |
190 | |
b859a34d |
191 | //! Compute and return capping aspect from the graphical attributes. |
4269bd1b |
192 | //! @return capping surface rendering aspect. |
193 | Standard_EXPORT Handle(Graphic3d_AspectFillArea3d) CappingAspect() const; |
194 | |
b859a34d |
195 | public: // @name modification counters |
4269bd1b |
196 | |
197 | //! @return modification counter for equation. |
198 | unsigned int MCountEquation() const |
199 | { |
200 | return myEquationMod; |
201 | } |
202 | |
203 | //! @return modification counter for aspect. |
204 | unsigned int MCountAspect() const |
205 | { |
206 | return myAspectMod; |
207 | } |
208 | |
209 | private: |
210 | |
211 | void MakeId(); |
212 | |
213 | private: |
214 | |
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. |
225 | |
226 | public: |
227 | |
228 | DEFINE_STANDARD_RTTI(Graphic3d_ClipPlane); |
229 | }; |
230 | |
231 | #endif |