42cf5bc1 |
1 | // Created on: 1991-11-04 |
2 | // Created by: NW,JPB,CAL |
3 | // Copyright (c) 1991-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _Graphic3d_AspectFillArea3d_HeaderFile |
18 | #define _Graphic3d_AspectFillArea3d_HeaderFile |
19 | |
b6472664 |
20 | #include <Aspect_AspectFillAreaDefinitionError.hxx> |
21 | #include <Aspect_PolygonOffsetMode.hxx> |
22 | #include <Aspect_InteriorStyle.hxx> |
23 | #include <Aspect_TypeOfLine.hxx> |
c40eb6b9 |
24 | #include <Graphic3d_AlphaMode.hxx> |
640d5fe2 |
25 | #include <Graphic3d_HatchStyle.hxx> |
b6472664 |
26 | #include <Graphic3d_MaterialAspect.hxx> |
27 | #include <Graphic3d_PolygonOffset.hxx> |
28 | #include <Graphic3d_ShaderProgram.hxx> |
29 | #include <Graphic3d_TextureMap.hxx> |
cc8cbabe |
30 | #include <Graphic3d_TextureSet.hxx> |
dc89236f |
31 | #include <Graphic3d_TypeOfShadingModel.hxx> |
42cf5bc1 |
32 | #include <Standard.hxx> |
42cf5bc1 |
33 | #include <Standard_Boolean.hxx> |
42cf5bc1 |
34 | #include <Standard_Integer.hxx> |
35 | #include <Standard_ShortReal.hxx> |
42cf5bc1 |
36 | #include <Standard_Real.hxx> |
b6472664 |
37 | #include <Standard_Type.hxx> |
38 | #include <Quantity_ColorRGBA.hxx> |
42cf5bc1 |
39 | |
b6472664 |
40 | //! This class defines graphic attributes for opaque 3d primitives (polygons, triangles, quadrilaterals). |
41 | class Graphic3d_AspectFillArea3d : public Standard_Transient |
42 | { |
43 | DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectFillArea3d, Standard_Transient) |
42cf5bc1 |
44 | public: |
45 | |
b6472664 |
46 | //! Creates a context table for fill area primitives defined with the following default values: |
42cf5bc1 |
47 | //! |
b6472664 |
48 | //! InteriorStyle : Aspect_IS_EMPTY |
49 | //! InteriorColor : Quantity_NOC_CYAN1 |
50 | //! EdgeColor : Quantity_NOC_WHITE |
51 | //! EdgeLineType : Aspect_TOL_SOLID |
52 | //! EdgeWidth : 1.0 |
53 | //! FrontMaterial : NOM_BRASS |
54 | //! BackMaterial : NOM_BRASS |
ec7c343f |
55 | //! HatchStyle : Aspect_HS_SOLID |
42cf5bc1 |
56 | //! |
57 | //! Display of back-facing filled polygons. |
b6472664 |
58 | //! No distinction between external and internal faces of FillAreas. |
42cf5bc1 |
59 | //! The edges are not drawn. |
60 | //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0. |
61 | Standard_EXPORT Graphic3d_AspectFillArea3d(); |
62 | |
b6472664 |
63 | //! Creates a context table for fill area primitives defined with the specified values. |
42cf5bc1 |
64 | //! Display of back-facing filled polygons. |
b6472664 |
65 | //! No distinction between external and internal faces of FillAreas. |
42cf5bc1 |
66 | //! The edges are not drawn. |
67 | //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0. |
b6472664 |
68 | Standard_EXPORT Graphic3d_AspectFillArea3d (const Aspect_InteriorStyle theInterior, |
69 | const Quantity_Color& theInteriorColor, |
70 | const Quantity_Color& theEdgeColor, |
71 | const Aspect_TypeOfLine theEdgeLineType, |
72 | const Standard_Real theEdgeWidth, |
73 | const Graphic3d_MaterialAspect& theFrontMaterial, |
74 | const Graphic3d_MaterialAspect& theBackMaterial); |
75 | |
76 | //! Return interior rendering style (Aspect_IS_EMPTY by default, which means nothing will be rendered!). |
77 | Aspect_InteriorStyle InteriorStyle() const { return myInteriorStyle; } |
78 | |
79 | //! Modifies the interior type used for rendering |
80 | void SetInteriorStyle (const Aspect_InteriorStyle theStyle) { myInteriorStyle = theStyle; } |
81 | |
dc89236f |
82 | //! Returns shading model (Graphic3d_TOSM_DEFAULT by default, which means that Shading Model set as default for entire Viewer will be used) |
83 | Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; } |
84 | |
85 | //! Sets shading model |
86 | void SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel) { myShadingModel = theShadingModel; } |
87 | |
c40eb6b9 |
88 | //! Returns the way how alpha value should be treated (Graphic3d_AlphaMode_BlendAuto by default, for backward compatibility). |
89 | Graphic3d_AlphaMode AlphaMode() const { return myAlphaMode; } |
90 | |
91 | //! Returns alpha cutoff threshold, for discarding fragments within Graphic3d_AlphaMode_Mask mode (0.5 by default). |
92 | //! If the alpha value is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent. |
93 | Standard_ShortReal AlphaCutoff() const { return myAlphaCutoff; } |
94 | |
95 | //! Defines the way how alpha value should be treated. |
96 | void SetAlphaMode (Graphic3d_AlphaMode theMode, Standard_ShortReal theAlphaCutoff = 0.5f) |
97 | { |
98 | myAlphaMode = theMode; |
99 | myAlphaCutoff = theAlphaCutoff; |
100 | } |
101 | |
b6472664 |
102 | //! Return interior color. |
103 | const Quantity_Color& InteriorColor() const { return myInteriorColor.GetRGB(); } |
104 | |
105 | //! Return interior color. |
106 | const Quantity_ColorRGBA& InteriorColorRGBA() const { return myInteriorColor; } |
107 | |
108 | //! Modifies the color of the interior of the face |
109 | void SetInteriorColor (const Quantity_Color& theColor) { myInteriorColor.SetRGB (theColor); } |
110 | |
a71a71de |
111 | //! Modifies the color of the interior of the face |
112 | void SetInteriorColor (const Quantity_ColorRGBA& theColor) { myInteriorColor = theColor; } |
113 | |
b6472664 |
114 | //! Return back interior color. |
115 | const Quantity_Color& BackInteriorColor() const { return myBackInteriorColor.GetRGB(); } |
116 | |
117 | //! Return back interior color. |
118 | const Quantity_ColorRGBA& BackInteriorColorRGBA() const { return myBackInteriorColor; } |
119 | |
120 | //! Modifies the color of the interior of the back face |
121 | void SetBackInteriorColor (const Quantity_Color& theColor) { myBackInteriorColor.SetRGB (theColor); } |
122 | |
a71a71de |
123 | //! Modifies the color of the interior of the back face |
124 | void SetBackInteriorColor (const Quantity_ColorRGBA& theColor) { myBackInteriorColor = theColor; } |
125 | |
b6472664 |
126 | //! Returns the surface material of external faces |
127 | const Graphic3d_MaterialAspect& FrontMaterial() const { return myFrontMaterial; } |
128 | |
4e1bc39a |
129 | //! Returns the surface material of external faces |
130 | Graphic3d_MaterialAspect& ChangeFrontMaterial() { return myFrontMaterial; } |
131 | |
42cf5bc1 |
132 | //! Modifies the surface material of external faces |
b6472664 |
133 | void SetFrontMaterial (const Graphic3d_MaterialAspect& theMaterial) { myFrontMaterial = theMaterial; } |
134 | |
135 | //! Returns the surface material of internal faces |
136 | const Graphic3d_MaterialAspect& BackMaterial() const { return myBackMaterial; } |
137 | |
4e1bc39a |
138 | //! Returns the surface material of internal faces |
139 | Graphic3d_MaterialAspect& ChangeBackMaterial() { return myBackMaterial; } |
140 | |
b6472664 |
141 | //! Modifies the surface material of internal faces |
142 | void SetBackMaterial (const Graphic3d_MaterialAspect& theMaterial) { myBackMaterial = theMaterial; } |
143 | |
144 | //! Returns true if back faces should be suppressed (true by default). |
145 | bool ToSuppressBackFaces() const { return myToSuppressBackFaces; } |
146 | |
147 | //! Assign back faces culling flag. |
148 | void SetSuppressBackFaces (bool theToSuppress) { myToSuppressBackFaces = theToSuppress; } |
149 | |
150 | //! Returns true if back faces should be suppressed (true by default). |
151 | bool BackFace() const { return myToSuppressBackFaces; } |
152 | |
153 | //! Allows the display of back-facing filled polygons. |
154 | void AllowBackFace() { myToSuppressBackFaces = false; } |
155 | |
156 | //! Suppress the display of back-facing filled polygons. |
42cf5bc1 |
157 | //! A back-facing polygon is defined as a polygon whose |
b6472664 |
158 | //! vertices are in a clockwise order with respect to screen coordinates. |
159 | void SuppressBackFace() { myToSuppressBackFaces = true; } |
160 | |
161 | //! Returns true if material properties should be distinguished for back and front faces (false by default). |
162 | bool Distinguish() const { return myToDistinguishMaterials; } |
163 | |
164 | //! Set material distinction between front and back faces. |
165 | void SetDistinguish (bool toDistinguish) { myToDistinguishMaterials = toDistinguish; } |
166 | |
167 | //! Allows material distinction between front and back faces. |
168 | void SetDistinguishOn() { myToDistinguishMaterials = true; } |
169 | |
170 | //! Forbids material distinction between front and back faces. |
171 | void SetDistinguishOff() { myToDistinguishMaterials = false; } |
172 | |
173 | //! Return shader program. |
174 | const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; } |
175 | |
176 | //! Sets up OpenGL/GLSL shader program. |
177 | void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; } |
178 | |
cc8cbabe |
179 | //! Return texture array to be mapped. |
180 | const Handle(Graphic3d_TextureSet)& TextureSet() const { return myTextureSet; } |
181 | |
182 | //! Setup texture array to be mapped. |
183 | void SetTextureSet (const Handle(Graphic3d_TextureSet)& theTextures) { myTextureSet = theTextures; } |
184 | |
b6472664 |
185 | //! Return texture to be mapped. |
cc8cbabe |
186 | //Standard_DEPRECATED("Deprecated method, TextureSet() should be used instead") |
187 | Handle(Graphic3d_TextureMap) TextureMap() const |
188 | { |
189 | return !myTextureSet.IsNull() && !myTextureSet->IsEmpty() |
190 | ? myTextureSet->First() |
191 | : Handle(Graphic3d_TextureMap)(); |
192 | } |
b6472664 |
193 | |
194 | //! Assign texture to be mapped. |
cc8cbabe |
195 | //! See also SetTextureMapOn() to actually activate texture mapping. |
196 | //Standard_DEPRECATED("Deprecated method, SetTextureSet() should be used instead") |
197 | Standard_EXPORT void SetTextureMap (const Handle(Graphic3d_TextureMap)& theTexture); |
b6472664 |
198 | |
199 | //! Return true if texture mapping is enabled (false by default). |
200 | bool ToMapTexture() const { return myToMapTexture; } |
201 | |
202 | //! Return true if texture mapping is enabled (false by default). |
203 | bool TextureMapState() const { return myToMapTexture; } |
204 | |
cc8cbabe |
205 | //! Enable or disable texture mapping (has no effect if texture is not set). |
206 | void SetTextureMapOn (bool theToMap) { myToMapTexture = theToMap; } |
207 | |
b6472664 |
208 | //! Enable texture mapping (has no effect if texture is not set). |
209 | void SetTextureMapOn() { myToMapTexture = true; } |
210 | |
211 | //! Disable texture mapping. |
212 | void SetTextureMapOff() { myToMapTexture = false; } |
213 | |
214 | //! Returns current polygon offsets settings. |
215 | const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; } |
216 | |
a6df1715 |
217 | //! Sets polygon offsets settings. |
218 | void SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset) { myPolygonOffset = theOffset; } |
219 | |
b6472664 |
220 | //! Returns current polygon offsets settings. |
221 | void PolygonOffsets (Standard_Integer& theMode, |
222 | Standard_ShortReal& theFactor, |
223 | Standard_ShortReal& theUnits) const |
224 | { |
225 | theMode = myPolygonOffset.Mode; |
226 | theFactor = myPolygonOffset.Factor; |
227 | theUnits = myPolygonOffset.Units; |
228 | } |
229 | |
42cf5bc1 |
230 | //! Sets up OpenGL polygon offsets mechanism. |
231 | //! <aMode> parameter can contain various combinations of |
232 | //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means |
233 | //! that polygon offsets are not changed). |
234 | //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits> |
235 | //! arguments are used by graphic renderer to calculate a depth offset value: |
236 | //! |
237 | //! offset = <aFactor> * m + <aUnits> * r, where |
238 | //! m - maximum depth slope for the polygon currently being displayed, |
239 | //! r - minimum window coordinates depth resolution (implementation-specific) |
240 | //! |
b6472664 |
241 | //! Default settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0. |
42cf5bc1 |
242 | //! |
243 | //! Negative offset values move polygons closer to the viewport, |
244 | //! while positive values shift polygons away. |
245 | //! Consult OpenGL reference for details (glPolygonOffset function description). |
b6472664 |
246 | void SetPolygonOffsets (const Standard_Integer theMode, |
247 | const Standard_ShortReal theFactor = 1.0f, |
248 | const Standard_ShortReal theUnits = 0.0f) |
249 | { |
250 | myPolygonOffset.Mode = (Aspect_PolygonOffsetMode )(theMode & Aspect_POM_Mask); |
251 | myPolygonOffset.Factor = theFactor; |
252 | myPolygonOffset.Units = theUnits; |
253 | } |
254 | |
255 | public: |
42cf5bc1 |
256 | |
b6472664 |
257 | //! Returns true if edges should be drawn (false by default). |
2a332745 |
258 | bool ToDrawEdges() const { return myToDrawEdges && myEdgeType != Aspect_TOL_EMPTY; } |
42cf5bc1 |
259 | |
b6472664 |
260 | //! Set if edges should be drawn or not. |
2a332745 |
261 | void SetDrawEdges (bool theToDraw) |
262 | { |
263 | myToDrawEdges = theToDraw; |
264 | if (myEdgeType == Aspect_TOL_EMPTY) |
265 | { |
266 | myEdgeType = Aspect_TOL_SOLID; |
267 | } |
268 | } |
42cf5bc1 |
269 | |
b6472664 |
270 | //! Returns true if edges should be drawn. |
2a332745 |
271 | bool Edge() const { return ToDrawEdges(); } |
42cf5bc1 |
272 | |
b6472664 |
273 | //! The edges of FillAreas are drawn. |
2a332745 |
274 | void SetEdgeOn() { SetDrawEdges (true); } |
42cf5bc1 |
275 | |
b6472664 |
276 | //! The edges of FillAreas are not drawn. |
2a332745 |
277 | void SetEdgeOff() { SetDrawEdges (false); } |
42cf5bc1 |
278 | |
b6472664 |
279 | //! Return color of edges. |
280 | const Quantity_Color& EdgeColor() const { return myEdgeColor.GetRGB(); } |
42cf5bc1 |
281 | |
b6472664 |
282 | //! Return color of edges. |
283 | const Quantity_ColorRGBA& EdgeColorRGBA() const { return myEdgeColor; } |
42cf5bc1 |
284 | |
b6472664 |
285 | //! Modifies the color of the edge of the face |
286 | void SetEdgeColor (const Quantity_Color& theColor) { myEdgeColor.SetRGB (theColor); } |
42cf5bc1 |
287 | |
2a332745 |
288 | //! Modifies the color of the edge of the face |
289 | void SetEdgeColor (const Quantity_ColorRGBA& theColor) { myEdgeColor = theColor; } |
290 | |
b6472664 |
291 | //! Return edges line type. |
292 | Aspect_TypeOfLine EdgeLineType() const { return myEdgeType; } |
42cf5bc1 |
293 | |
b6472664 |
294 | //! Modifies the edge line type |
295 | void SetEdgeLineType (const Aspect_TypeOfLine theType) { myEdgeType = theType; } |
42cf5bc1 |
296 | |
b6472664 |
297 | //! Return width for edges in pixels. |
298 | Standard_ShortReal EdgeWidth() const { return myEdgeWidth; } |
42cf5bc1 |
299 | |
b6472664 |
300 | //! Modifies the edge thickness |
301 | //! Warning: Raises AspectFillAreaDefinitionError if the width is a negative value. |
302 | void SetEdgeWidth (const Standard_Real theWidth) |
303 | { |
304 | if (theWidth <= 0.0) |
305 | { |
9775fa61 |
306 | throw Aspect_AspectFillAreaDefinitionError("Bad value for EdgeLineWidth"); |
b6472664 |
307 | } |
308 | myEdgeWidth = (float )theWidth; |
309 | } |
42cf5bc1 |
310 | |
2a332745 |
311 | //! Returns TRUE if drawing element edges should discard first edge in triangle; FALSE by default. |
312 | //! Graphics hardware works mostly with triangles, so that wireframe presentation will draw triangle edges by default. |
313 | //! This flag allows rendering wireframe presentation of quad-only array split into triangles. |
314 | //! For this, quads should be split in specific order, so that the quad diagonal (to be NOT rendered) goes first: |
315 | //! 1------2 |
316 | //! / / Triangle #1: 2-0-1; Triangle #2: 0-2-3 |
317 | //! 0------3 |
318 | bool ToSkipFirstEdge() const { return myToSkipFirstEdge; } |
319 | |
320 | //! Set skip first triangle edge flag for drawing wireframe presentation of quads array split into triangles. |
321 | void SetSkipFirstEdge (bool theToSkipFirstEdge) { myToSkipFirstEdge = theToSkipFirstEdge; } |
322 | |
6ef0d6f1 |
323 | //! Returns TRUE if silhouette (outline) should be drawn (with edge color and width); FALSE by default. |
324 | bool ToDrawSilhouette() const { return myToDrawSilhouette; } |
325 | |
326 | //! Enables/disables drawing silhouette (outline). |
327 | void SetDrawSilhouette (bool theToDraw) { myToDrawSilhouette = theToDraw; } |
328 | |
b6472664 |
329 | public: |
42cf5bc1 |
330 | |
b6472664 |
331 | //! Returns the hatch type used when InteriorStyle is IS_HATCH |
640d5fe2 |
332 | const Handle(Graphic3d_HatchStyle)& HatchStyle() const { return myHatchStyle; } |
42cf5bc1 |
333 | |
b6472664 |
334 | //! Modifies the hatch type used when InteriorStyle is IS_HATCH |
640d5fe2 |
335 | void SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) { myHatchStyle = theStyle; } |
336 | |
337 | //! Modifies the hatch type used when InteriorStyle is IS_HATCH |
338 | //! @warning This method always creates a new handle for a given hatch style |
339 | void SetHatchStyle (const Aspect_HatchStyle theStyle) |
340 | { |
341 | if (theStyle == Aspect_HS_SOLID) |
342 | { |
343 | myHatchStyle.Nullify(); |
344 | return; |
345 | } |
346 | |
347 | myHatchStyle = new Graphic3d_HatchStyle (theStyle); |
348 | } |
42cf5bc1 |
349 | |
b6472664 |
350 | //! Returns the current values. |
351 | Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters") |
352 | void Values (Aspect_InteriorStyle& theStyle, |
353 | Quantity_Color& theIntColor, |
354 | Quantity_Color& theEdgeColor, |
355 | Aspect_TypeOfLine& theType, |
356 | Standard_Real& theWidth) const |
357 | { |
358 | theStyle = myInteriorStyle; |
359 | theIntColor = myInteriorColor.GetRGB(); |
360 | theEdgeColor= myEdgeColor.GetRGB(); |
361 | theType = myEdgeType; |
362 | theWidth = myEdgeWidth; |
363 | } |
42cf5bc1 |
364 | |
b6472664 |
365 | //! Returns the current values. |
366 | Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters") |
367 | void Values (Aspect_InteriorStyle& theStyle, |
368 | Quantity_Color& theIntColor, |
369 | Quantity_Color& theBackIntColor, |
370 | Quantity_Color& theEdgeColor, |
371 | Aspect_TypeOfLine& theType, |
372 | Standard_Real& theWidth) const |
373 | { |
374 | theStyle = myInteriorStyle; |
375 | theIntColor = myInteriorColor.GetRGB(); |
376 | theBackIntColor= myBackInteriorColor.GetRGB(); |
377 | theEdgeColor = myEdgeColor.GetRGB(); |
378 | theType = myEdgeType; |
379 | theWidth = myEdgeWidth; |
380 | } |
42cf5bc1 |
381 | |
b6472664 |
382 | protected: |
383 | |
384 | Handle(Graphic3d_ShaderProgram) myProgram; |
cc8cbabe |
385 | Handle(Graphic3d_TextureSet) myTextureSet; |
b6472664 |
386 | Graphic3d_MaterialAspect myFrontMaterial; |
387 | Graphic3d_MaterialAspect myBackMaterial; |
388 | |
640d5fe2 |
389 | Quantity_ColorRGBA myInteriorColor; |
390 | Quantity_ColorRGBA myBackInteriorColor; |
391 | Quantity_ColorRGBA myEdgeColor; |
392 | Aspect_InteriorStyle myInteriorStyle; |
dc89236f |
393 | Graphic3d_TypeOfShadingModel myShadingModel; |
c40eb6b9 |
394 | Graphic3d_AlphaMode myAlphaMode; |
395 | Standard_ShortReal myAlphaCutoff; |
640d5fe2 |
396 | Aspect_TypeOfLine myEdgeType; |
397 | Standard_ShortReal myEdgeWidth; |
398 | Handle(Graphic3d_HatchStyle) myHatchStyle; |
b6472664 |
399 | |
400 | Graphic3d_PolygonOffset myPolygonOffset; |
2a332745 |
401 | bool myToSkipFirstEdge; |
b6472664 |
402 | bool myToDistinguishMaterials; |
403 | bool myToDrawEdges; |
6ef0d6f1 |
404 | bool myToDrawSilhouette; |
b6472664 |
405 | bool myToSuppressBackFaces; |
406 | bool myToMapTexture; |
407 | |
408 | }; |
42cf5bc1 |
409 | |
b6472664 |
410 | DEFINE_STANDARD_HANDLE(Graphic3d_AspectFillArea3d, Standard_Transient) |
42cf5bc1 |
411 | |
412 | #endif // _Graphic3d_AspectFillArea3d_HeaderFile |