0028306: Visualization - viewer crashes if style for shaded display is set to HATCH
[occt.git] / src / Graphic3d / Graphic3d_AspectFillArea3d.hxx
CommitLineData
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>
640d5fe2 24#include <Graphic3d_HatchStyle.hxx>
b6472664 25#include <Graphic3d_MaterialAspect.hxx>
26#include <Graphic3d_PolygonOffset.hxx>
27#include <Graphic3d_ShaderProgram.hxx>
28#include <Graphic3d_TextureMap.hxx>
42cf5bc1 29#include <Standard.hxx>
42cf5bc1 30#include <Standard_Boolean.hxx>
42cf5bc1 31#include <Standard_Integer.hxx>
32#include <Standard_ShortReal.hxx>
42cf5bc1 33#include <Standard_Real.hxx>
b6472664 34#include <Standard_Type.hxx>
35#include <Quantity_ColorRGBA.hxx>
42cf5bc1 36
b6472664 37//! This class defines graphic attributes for opaque 3d primitives (polygons, triangles, quadrilaterals).
38class Graphic3d_AspectFillArea3d : public Standard_Transient
39{
40 DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectFillArea3d, Standard_Transient)
42cf5bc1 41public:
42
b6472664 43 //! Creates a context table for fill area primitives defined with the following default values:
42cf5bc1 44 //!
b6472664 45 //! InteriorStyle : Aspect_IS_EMPTY
46 //! InteriorColor : Quantity_NOC_CYAN1
47 //! EdgeColor : Quantity_NOC_WHITE
48 //! EdgeLineType : Aspect_TOL_SOLID
49 //! EdgeWidth : 1.0
50 //! FrontMaterial : NOM_BRASS
51 //! BackMaterial : NOM_BRASS
ec7c343f 52 //! HatchStyle : Aspect_HS_SOLID
42cf5bc1 53 //!
54 //! Display of back-facing filled polygons.
b6472664 55 //! No distinction between external and internal faces of FillAreas.
42cf5bc1 56 //! The edges are not drawn.
57 //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0.
58 Standard_EXPORT Graphic3d_AspectFillArea3d();
59
b6472664 60 //! Creates a context table for fill area primitives defined with the specified values.
42cf5bc1 61 //! Display of back-facing filled polygons.
b6472664 62 //! No distinction between external and internal faces of FillAreas.
42cf5bc1 63 //! The edges are not drawn.
64 //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0.
b6472664 65 Standard_EXPORT Graphic3d_AspectFillArea3d (const Aspect_InteriorStyle theInterior,
66 const Quantity_Color& theInteriorColor,
67 const Quantity_Color& theEdgeColor,
68 const Aspect_TypeOfLine theEdgeLineType,
69 const Standard_Real theEdgeWidth,
70 const Graphic3d_MaterialAspect& theFrontMaterial,
71 const Graphic3d_MaterialAspect& theBackMaterial);
72
73 //! Return interior rendering style (Aspect_IS_EMPTY by default, which means nothing will be rendered!).
74 Aspect_InteriorStyle InteriorStyle() const { return myInteriorStyle; }
75
76 //! Modifies the interior type used for rendering
77 void SetInteriorStyle (const Aspect_InteriorStyle theStyle) { myInteriorStyle = theStyle; }
78
79 //! Return interior color.
80 const Quantity_Color& InteriorColor() const { return myInteriorColor.GetRGB(); }
81
82 //! Return interior color.
83 const Quantity_ColorRGBA& InteriorColorRGBA() const { return myInteriorColor; }
84
85 //! Modifies the color of the interior of the face
86 void SetInteriorColor (const Quantity_Color& theColor) { myInteriorColor.SetRGB (theColor); }
87
88 //! Return back interior color.
89 const Quantity_Color& BackInteriorColor() const { return myBackInteriorColor.GetRGB(); }
90
91 //! Return back interior color.
92 const Quantity_ColorRGBA& BackInteriorColorRGBA() const { return myBackInteriorColor; }
93
94 //! Modifies the color of the interior of the back face
95 void SetBackInteriorColor (const Quantity_Color& theColor) { myBackInteriorColor.SetRGB (theColor); }
96
97 //! Returns the surface material of external faces
98 const Graphic3d_MaterialAspect& FrontMaterial() const { return myFrontMaterial; }
99
42cf5bc1 100 //! Modifies the surface material of external faces
b6472664 101 void SetFrontMaterial (const Graphic3d_MaterialAspect& theMaterial) { myFrontMaterial = theMaterial; }
102
103 //! Returns the surface material of internal faces
104 const Graphic3d_MaterialAspect& BackMaterial() const { return myBackMaterial; }
105
106 //! Modifies the surface material of internal faces
107 void SetBackMaterial (const Graphic3d_MaterialAspect& theMaterial) { myBackMaterial = theMaterial; }
108
109 //! Returns true if back faces should be suppressed (true by default).
110 bool ToSuppressBackFaces() const { return myToSuppressBackFaces; }
111
112 //! Assign back faces culling flag.
113 void SetSuppressBackFaces (bool theToSuppress) { myToSuppressBackFaces = theToSuppress; }
114
115 //! Returns true if back faces should be suppressed (true by default).
116 bool BackFace() const { return myToSuppressBackFaces; }
117
118 //! Allows the display of back-facing filled polygons.
119 void AllowBackFace() { myToSuppressBackFaces = false; }
120
121 //! Suppress the display of back-facing filled polygons.
42cf5bc1 122 //! A back-facing polygon is defined as a polygon whose
b6472664 123 //! vertices are in a clockwise order with respect to screen coordinates.
124 void SuppressBackFace() { myToSuppressBackFaces = true; }
125
126 //! Returns true if material properties should be distinguished for back and front faces (false by default).
127 bool Distinguish() const { return myToDistinguishMaterials; }
128
129 //! Set material distinction between front and back faces.
130 void SetDistinguish (bool toDistinguish) { myToDistinguishMaterials = toDistinguish; }
131
132 //! Allows material distinction between front and back faces.
133 void SetDistinguishOn() { myToDistinguishMaterials = true; }
134
135 //! Forbids material distinction between front and back faces.
136 void SetDistinguishOff() { myToDistinguishMaterials = false; }
137
138 //! Return shader program.
139 const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; }
140
141 //! Sets up OpenGL/GLSL shader program.
142 void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; }
143
144 //! Return texture to be mapped.
145 const Handle(Graphic3d_TextureMap)& TextureMap() const { return myTextureMap; }
146
147 //! Assign texture to be mapped.
148 //! See also SetTextureMap() to actually activate texture mapping.
149 void SetTextureMap (const Handle(Graphic3d_TextureMap)& theTexture) { myTextureMap = theTexture; }
150
151 //! Return true if texture mapping is enabled (false by default).
152 bool ToMapTexture() const { return myToMapTexture; }
153
154 //! Return true if texture mapping is enabled (false by default).
155 bool TextureMapState() const { return myToMapTexture; }
156
b6472664 157 //! Enable texture mapping (has no effect if texture is not set).
158 void SetTextureMapOn() { myToMapTexture = true; }
159
160 //! Disable texture mapping.
161 void SetTextureMapOff() { myToMapTexture = false; }
162
163 //! Returns current polygon offsets settings.
164 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
165
166 //! Returns current polygon offsets settings.
167 void PolygonOffsets (Standard_Integer& theMode,
168 Standard_ShortReal& theFactor,
169 Standard_ShortReal& theUnits) const
170 {
171 theMode = myPolygonOffset.Mode;
172 theFactor = myPolygonOffset.Factor;
173 theUnits = myPolygonOffset.Units;
174 }
175
42cf5bc1 176 //! Sets up OpenGL polygon offsets mechanism.
177 //! <aMode> parameter can contain various combinations of
178 //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means
179 //! that polygon offsets are not changed).
180 //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits>
181 //! arguments are used by graphic renderer to calculate a depth offset value:
182 //!
183 //! offset = <aFactor> * m + <aUnits> * r, where
184 //! m - maximum depth slope for the polygon currently being displayed,
185 //! r - minimum window coordinates depth resolution (implementation-specific)
186 //!
b6472664 187 //! Default settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0.
42cf5bc1 188 //!
189 //! Negative offset values move polygons closer to the viewport,
190 //! while positive values shift polygons away.
191 //! Consult OpenGL reference for details (glPolygonOffset function description).
b6472664 192 void SetPolygonOffsets (const Standard_Integer theMode,
193 const Standard_ShortReal theFactor = 1.0f,
194 const Standard_ShortReal theUnits = 0.0f)
195 {
196 myPolygonOffset.Mode = (Aspect_PolygonOffsetMode )(theMode & Aspect_POM_Mask);
197 myPolygonOffset.Factor = theFactor;
198 myPolygonOffset.Units = theUnits;
199 }
200
201public:
42cf5bc1 202
b6472664 203 //! Returns true if edges should be drawn (false by default).
204 bool ToDrawEdges() const { return myToDrawEdges; }
42cf5bc1 205
b6472664 206 //! Set if edges should be drawn or not.
207 void SetDrawEdges (bool theToDraw) { myToDrawEdges = theToDraw; }
42cf5bc1 208
b6472664 209 //! Returns true if edges should be drawn.
210 bool Edge() const { return myToDrawEdges; }
42cf5bc1 211
b6472664 212 //! The edges of FillAreas are drawn.
213 void SetEdgeOn() { myToDrawEdges = true; }
42cf5bc1 214
b6472664 215 //! The edges of FillAreas are not drawn.
216 void SetEdgeOff() { myToDrawEdges = false; }
42cf5bc1 217
b6472664 218 //! Return color of edges.
219 const Quantity_Color& EdgeColor() const { return myEdgeColor.GetRGB(); }
42cf5bc1 220
b6472664 221 //! Return color of edges.
222 const Quantity_ColorRGBA& EdgeColorRGBA() const { return myEdgeColor; }
42cf5bc1 223
b6472664 224 //! Modifies the color of the edge of the face
225 void SetEdgeColor (const Quantity_Color& theColor) { myEdgeColor.SetRGB (theColor); }
42cf5bc1 226
b6472664 227 //! Return edges line type.
228 Aspect_TypeOfLine EdgeLineType() const { return myEdgeType; }
42cf5bc1 229
b6472664 230 //! Modifies the edge line type
231 void SetEdgeLineType (const Aspect_TypeOfLine theType) { myEdgeType = theType; }
42cf5bc1 232
b6472664 233 //! Return width for edges in pixels.
234 Standard_ShortReal EdgeWidth() const { return myEdgeWidth; }
42cf5bc1 235
b6472664 236 //! Modifies the edge thickness
237 //! Warning: Raises AspectFillAreaDefinitionError if the width is a negative value.
238 void SetEdgeWidth (const Standard_Real theWidth)
239 {
240 if (theWidth <= 0.0)
241 {
242 Aspect_AspectFillAreaDefinitionError::Raise ("Bad value for EdgeLineWidth");
243 }
244 myEdgeWidth = (float )theWidth;
245 }
42cf5bc1 246
b6472664 247public:
42cf5bc1 248
b6472664 249 //! Returns the hatch type used when InteriorStyle is IS_HATCH
640d5fe2 250 const Handle(Graphic3d_HatchStyle)& HatchStyle() const { return myHatchStyle; }
42cf5bc1 251
b6472664 252 //! Modifies the hatch type used when InteriorStyle is IS_HATCH
640d5fe2 253 void SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) { myHatchStyle = theStyle; }
254
255 //! Modifies the hatch type used when InteriorStyle is IS_HATCH
256 //! @warning This method always creates a new handle for a given hatch style
257 void SetHatchStyle (const Aspect_HatchStyle theStyle)
258 {
259 if (theStyle == Aspect_HS_SOLID)
260 {
261 myHatchStyle.Nullify();
262 return;
263 }
264
265 myHatchStyle = new Graphic3d_HatchStyle (theStyle);
266 }
42cf5bc1 267
b6472664 268 //! Returns the current values.
269 Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
270 void Values (Aspect_InteriorStyle& theStyle,
271 Quantity_Color& theIntColor,
272 Quantity_Color& theEdgeColor,
273 Aspect_TypeOfLine& theType,
274 Standard_Real& theWidth) const
275 {
276 theStyle = myInteriorStyle;
277 theIntColor = myInteriorColor.GetRGB();
278 theEdgeColor= myEdgeColor.GetRGB();
279 theType = myEdgeType;
280 theWidth = myEdgeWidth;
281 }
42cf5bc1 282
b6472664 283 //! Returns the current values.
284 Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
285 void Values (Aspect_InteriorStyle& theStyle,
286 Quantity_Color& theIntColor,
287 Quantity_Color& theBackIntColor,
288 Quantity_Color& theEdgeColor,
289 Aspect_TypeOfLine& theType,
290 Standard_Real& theWidth) const
291 {
292 theStyle = myInteriorStyle;
293 theIntColor = myInteriorColor.GetRGB();
294 theBackIntColor= myBackInteriorColor.GetRGB();
295 theEdgeColor = myEdgeColor.GetRGB();
296 theType = myEdgeType;
297 theWidth = myEdgeWidth;
298 }
42cf5bc1 299
b6472664 300protected:
301
302 Handle(Graphic3d_ShaderProgram) myProgram;
303 Handle(Graphic3d_TextureMap) myTextureMap;
304 Graphic3d_MaterialAspect myFrontMaterial;
305 Graphic3d_MaterialAspect myBackMaterial;
306
640d5fe2 307 Quantity_ColorRGBA myInteriorColor;
308 Quantity_ColorRGBA myBackInteriorColor;
309 Quantity_ColorRGBA myEdgeColor;
310 Aspect_InteriorStyle myInteriorStyle;
311 Aspect_TypeOfLine myEdgeType;
312 Standard_ShortReal myEdgeWidth;
313 Handle(Graphic3d_HatchStyle) myHatchStyle;
b6472664 314
315 Graphic3d_PolygonOffset myPolygonOffset;
316 bool myToDistinguishMaterials;
317 bool myToDrawEdges;
318 bool myToSuppressBackFaces;
319 bool myToMapTexture;
320
321};
42cf5bc1 322
b6472664 323DEFINE_STANDARD_HANDLE(Graphic3d_AspectFillArea3d, Standard_Transient)
42cf5bc1 324
325#endif // _Graphic3d_AspectFillArea3d_HeaderFile