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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Graphic3d_AspectFillArea3d_HeaderFile
18 #define _Graphic3d_AspectFillArea3d_HeaderFile
20 #include <Aspect_AspectFillAreaDefinitionError.hxx>
21 #include <Aspect_PolygonOffsetMode.hxx>
22 #include <Aspect_InteriorStyle.hxx>
23 #include <Aspect_TypeOfLine.hxx>
24 #include <Graphic3d_HatchStyle.hxx>
25 #include <Graphic3d_MaterialAspect.hxx>
26 #include <Graphic3d_PolygonOffset.hxx>
27 #include <Graphic3d_ShaderProgram.hxx>
28 #include <Graphic3d_TextureMap.hxx>
29 #include <Graphic3d_TextureSet.hxx>
30 #include <Graphic3d_TypeOfShadingModel.hxx>
31 #include <Standard.hxx>
32 #include <Standard_Boolean.hxx>
33 #include <Standard_Integer.hxx>
34 #include <Standard_ShortReal.hxx>
35 #include <Standard_Real.hxx>
36 #include <Standard_Type.hxx>
37 #include <Quantity_ColorRGBA.hxx>
39 //! This class defines graphic attributes for opaque 3d primitives (polygons, triangles, quadrilaterals).
40 class Graphic3d_AspectFillArea3d : public Standard_Transient
42 DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectFillArea3d, Standard_Transient)
45 //! Creates a context table for fill area primitives defined with the following default values:
47 //! InteriorStyle : Aspect_IS_EMPTY
48 //! InteriorColor : Quantity_NOC_CYAN1
49 //! EdgeColor : Quantity_NOC_WHITE
50 //! EdgeLineType : Aspect_TOL_SOLID
52 //! FrontMaterial : NOM_BRASS
53 //! BackMaterial : NOM_BRASS
54 //! HatchStyle : Aspect_HS_SOLID
56 //! Display of back-facing filled polygons.
57 //! No distinction between external and internal faces of FillAreas.
58 //! The edges are not drawn.
59 //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0.
60 Standard_EXPORT Graphic3d_AspectFillArea3d();
62 //! Creates a context table for fill area primitives defined with the specified values.
63 //! Display of back-facing filled polygons.
64 //! No distinction between external and internal faces of FillAreas.
65 //! The edges are not drawn.
66 //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0.
67 Standard_EXPORT Graphic3d_AspectFillArea3d (const Aspect_InteriorStyle theInterior,
68 const Quantity_Color& theInteriorColor,
69 const Quantity_Color& theEdgeColor,
70 const Aspect_TypeOfLine theEdgeLineType,
71 const Standard_Real theEdgeWidth,
72 const Graphic3d_MaterialAspect& theFrontMaterial,
73 const Graphic3d_MaterialAspect& theBackMaterial);
75 //! Return interior rendering style (Aspect_IS_EMPTY by default, which means nothing will be rendered!).
76 Aspect_InteriorStyle InteriorStyle() const { return myInteriorStyle; }
78 //! Modifies the interior type used for rendering
79 void SetInteriorStyle (const Aspect_InteriorStyle theStyle) { myInteriorStyle = theStyle; }
81 //! Returns shading model (Graphic3d_TOSM_DEFAULT by default, which means that Shading Model set as default for entire Viewer will be used)
82 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
84 //! Sets shading model
85 void SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel) { myShadingModel = theShadingModel; }
87 //! Return interior color.
88 const Quantity_Color& InteriorColor() const { return myInteriorColor.GetRGB(); }
90 //! Return interior color.
91 const Quantity_ColorRGBA& InteriorColorRGBA() const { return myInteriorColor; }
93 //! Modifies the color of the interior of the face
94 void SetInteriorColor (const Quantity_Color& theColor) { myInteriorColor.SetRGB (theColor); }
96 //! Modifies the color of the interior of the face
97 void SetInteriorColor (const Quantity_ColorRGBA& theColor) { myInteriorColor = theColor; }
99 //! Return back interior color.
100 const Quantity_Color& BackInteriorColor() const { return myBackInteriorColor.GetRGB(); }
102 //! Return back interior color.
103 const Quantity_ColorRGBA& BackInteriorColorRGBA() const { return myBackInteriorColor; }
105 //! Modifies the color of the interior of the back face
106 void SetBackInteriorColor (const Quantity_Color& theColor) { myBackInteriorColor.SetRGB (theColor); }
108 //! Modifies the color of the interior of the back face
109 void SetBackInteriorColor (const Quantity_ColorRGBA& theColor) { myBackInteriorColor = theColor; }
111 //! Returns the surface material of external faces
112 const Graphic3d_MaterialAspect& FrontMaterial() const { return myFrontMaterial; }
114 //! Returns the surface material of external faces
115 Graphic3d_MaterialAspect& ChangeFrontMaterial() { return myFrontMaterial; }
117 //! Modifies the surface material of external faces
118 void SetFrontMaterial (const Graphic3d_MaterialAspect& theMaterial) { myFrontMaterial = theMaterial; }
120 //! Returns the surface material of internal faces
121 const Graphic3d_MaterialAspect& BackMaterial() const { return myBackMaterial; }
123 //! Returns the surface material of internal faces
124 Graphic3d_MaterialAspect& ChangeBackMaterial() { return myBackMaterial; }
126 //! Modifies the surface material of internal faces
127 void SetBackMaterial (const Graphic3d_MaterialAspect& theMaterial) { myBackMaterial = theMaterial; }
129 //! Returns true if back faces should be suppressed (true by default).
130 bool ToSuppressBackFaces() const { return myToSuppressBackFaces; }
132 //! Assign back faces culling flag.
133 void SetSuppressBackFaces (bool theToSuppress) { myToSuppressBackFaces = theToSuppress; }
135 //! Returns true if back faces should be suppressed (true by default).
136 bool BackFace() const { return myToSuppressBackFaces; }
138 //! Allows the display of back-facing filled polygons.
139 void AllowBackFace() { myToSuppressBackFaces = false; }
141 //! Suppress the display of back-facing filled polygons.
142 //! A back-facing polygon is defined as a polygon whose
143 //! vertices are in a clockwise order with respect to screen coordinates.
144 void SuppressBackFace() { myToSuppressBackFaces = true; }
146 //! Returns true if material properties should be distinguished for back and front faces (false by default).
147 bool Distinguish() const { return myToDistinguishMaterials; }
149 //! Set material distinction between front and back faces.
150 void SetDistinguish (bool toDistinguish) { myToDistinguishMaterials = toDistinguish; }
152 //! Allows material distinction between front and back faces.
153 void SetDistinguishOn() { myToDistinguishMaterials = true; }
155 //! Forbids material distinction between front and back faces.
156 void SetDistinguishOff() { myToDistinguishMaterials = false; }
158 //! Return shader program.
159 const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; }
161 //! Sets up OpenGL/GLSL shader program.
162 void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; }
164 //! Return texture array to be mapped.
165 const Handle(Graphic3d_TextureSet)& TextureSet() const { return myTextureSet; }
167 //! Setup texture array to be mapped.
168 void SetTextureSet (const Handle(Graphic3d_TextureSet)& theTextures) { myTextureSet = theTextures; }
170 //! Return texture to be mapped.
171 //Standard_DEPRECATED("Deprecated method, TextureSet() should be used instead")
172 Handle(Graphic3d_TextureMap) TextureMap() const
174 return !myTextureSet.IsNull() && !myTextureSet->IsEmpty()
175 ? myTextureSet->First()
176 : Handle(Graphic3d_TextureMap)();
179 //! Assign texture to be mapped.
180 //! See also SetTextureMapOn() to actually activate texture mapping.
181 //Standard_DEPRECATED("Deprecated method, SetTextureSet() should be used instead")
182 Standard_EXPORT void SetTextureMap (const Handle(Graphic3d_TextureMap)& theTexture);
184 //! Return true if texture mapping is enabled (false by default).
185 bool ToMapTexture() const { return myToMapTexture; }
187 //! Return true if texture mapping is enabled (false by default).
188 bool TextureMapState() const { return myToMapTexture; }
190 //! Enable or disable texture mapping (has no effect if texture is not set).
191 void SetTextureMapOn (bool theToMap) { myToMapTexture = theToMap; }
193 //! Enable texture mapping (has no effect if texture is not set).
194 void SetTextureMapOn() { myToMapTexture = true; }
196 //! Disable texture mapping.
197 void SetTextureMapOff() { myToMapTexture = false; }
199 //! Returns current polygon offsets settings.
200 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
202 //! Returns current polygon offsets settings.
203 void PolygonOffsets (Standard_Integer& theMode,
204 Standard_ShortReal& theFactor,
205 Standard_ShortReal& theUnits) const
207 theMode = myPolygonOffset.Mode;
208 theFactor = myPolygonOffset.Factor;
209 theUnits = myPolygonOffset.Units;
212 //! Sets up OpenGL polygon offsets mechanism.
213 //! <aMode> parameter can contain various combinations of
214 //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means
215 //! that polygon offsets are not changed).
216 //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits>
217 //! arguments are used by graphic renderer to calculate a depth offset value:
219 //! offset = <aFactor> * m + <aUnits> * r, where
220 //! m - maximum depth slope for the polygon currently being displayed,
221 //! r - minimum window coordinates depth resolution (implementation-specific)
223 //! Default settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0.
225 //! Negative offset values move polygons closer to the viewport,
226 //! while positive values shift polygons away.
227 //! Consult OpenGL reference for details (glPolygonOffset function description).
228 void SetPolygonOffsets (const Standard_Integer theMode,
229 const Standard_ShortReal theFactor = 1.0f,
230 const Standard_ShortReal theUnits = 0.0f)
232 myPolygonOffset.Mode = (Aspect_PolygonOffsetMode )(theMode & Aspect_POM_Mask);
233 myPolygonOffset.Factor = theFactor;
234 myPolygonOffset.Units = theUnits;
239 //! Returns true if edges should be drawn (false by default).
240 bool ToDrawEdges() const { return myToDrawEdges; }
242 //! Set if edges should be drawn or not.
243 void SetDrawEdges (bool theToDraw) { myToDrawEdges = theToDraw; }
245 //! Returns true if edges should be drawn.
246 bool Edge() const { return myToDrawEdges; }
248 //! The edges of FillAreas are drawn.
249 void SetEdgeOn() { myToDrawEdges = true; }
251 //! The edges of FillAreas are not drawn.
252 void SetEdgeOff() { myToDrawEdges = false; }
254 //! Return color of edges.
255 const Quantity_Color& EdgeColor() const { return myEdgeColor.GetRGB(); }
257 //! Return color of edges.
258 const Quantity_ColorRGBA& EdgeColorRGBA() const { return myEdgeColor; }
260 //! Modifies the color of the edge of the face
261 void SetEdgeColor (const Quantity_Color& theColor) { myEdgeColor.SetRGB (theColor); }
263 //! Return edges line type.
264 Aspect_TypeOfLine EdgeLineType() const { return myEdgeType; }
266 //! Modifies the edge line type
267 void SetEdgeLineType (const Aspect_TypeOfLine theType) { myEdgeType = theType; }
269 //! Return width for edges in pixels.
270 Standard_ShortReal EdgeWidth() const { return myEdgeWidth; }
272 //! Modifies the edge thickness
273 //! Warning: Raises AspectFillAreaDefinitionError if the width is a negative value.
274 void SetEdgeWidth (const Standard_Real theWidth)
278 throw Aspect_AspectFillAreaDefinitionError("Bad value for EdgeLineWidth");
280 myEdgeWidth = (float )theWidth;
285 //! Returns the hatch type used when InteriorStyle is IS_HATCH
286 const Handle(Graphic3d_HatchStyle)& HatchStyle() const { return myHatchStyle; }
288 //! Modifies the hatch type used when InteriorStyle is IS_HATCH
289 void SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) { myHatchStyle = theStyle; }
291 //! Modifies the hatch type used when InteriorStyle is IS_HATCH
292 //! @warning This method always creates a new handle for a given hatch style
293 void SetHatchStyle (const Aspect_HatchStyle theStyle)
295 if (theStyle == Aspect_HS_SOLID)
297 myHatchStyle.Nullify();
301 myHatchStyle = new Graphic3d_HatchStyle (theStyle);
304 //! Returns the current values.
305 Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
306 void Values (Aspect_InteriorStyle& theStyle,
307 Quantity_Color& theIntColor,
308 Quantity_Color& theEdgeColor,
309 Aspect_TypeOfLine& theType,
310 Standard_Real& theWidth) const
312 theStyle = myInteriorStyle;
313 theIntColor = myInteriorColor.GetRGB();
314 theEdgeColor= myEdgeColor.GetRGB();
315 theType = myEdgeType;
316 theWidth = myEdgeWidth;
319 //! Returns the current values.
320 Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
321 void Values (Aspect_InteriorStyle& theStyle,
322 Quantity_Color& theIntColor,
323 Quantity_Color& theBackIntColor,
324 Quantity_Color& theEdgeColor,
325 Aspect_TypeOfLine& theType,
326 Standard_Real& theWidth) const
328 theStyle = myInteriorStyle;
329 theIntColor = myInteriorColor.GetRGB();
330 theBackIntColor= myBackInteriorColor.GetRGB();
331 theEdgeColor = myEdgeColor.GetRGB();
332 theType = myEdgeType;
333 theWidth = myEdgeWidth;
338 Handle(Graphic3d_ShaderProgram) myProgram;
339 Handle(Graphic3d_TextureSet) myTextureSet;
340 Graphic3d_MaterialAspect myFrontMaterial;
341 Graphic3d_MaterialAspect myBackMaterial;
343 Quantity_ColorRGBA myInteriorColor;
344 Quantity_ColorRGBA myBackInteriorColor;
345 Quantity_ColorRGBA myEdgeColor;
346 Aspect_InteriorStyle myInteriorStyle;
347 Graphic3d_TypeOfShadingModel myShadingModel;
348 Aspect_TypeOfLine myEdgeType;
349 Standard_ShortReal myEdgeWidth;
350 Handle(Graphic3d_HatchStyle) myHatchStyle;
352 Graphic3d_PolygonOffset myPolygonOffset;
353 bool myToDistinguishMaterials;
355 bool myToSuppressBackFaces;
360 DEFINE_STANDARD_HANDLE(Graphic3d_AspectFillArea3d, Standard_Transient)
362 #endif // _Graphic3d_AspectFillArea3d_HeaderFile