0030537: Visualization - wrapping text in font text formatter
[occt.git] / src / Graphic3d / Graphic3d_CLight.hxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#ifndef _Graphic3d_CLight_HeaderFile
15#define _Graphic3d_CLight_HeaderFile
16
992ed6b3 17#include <gp_Dir.hxx>
c357e426 18#include <Graphic3d_TypeOfLightSource.hxx>
12381341 19#include <Graphic3d_Vec.hxx>
c357e426 20#include <NCollection_List.hxx>
992ed6b3 21#include <TCollection_AsciiString.hxx>
22#include <Quantity_ColorRGBA.hxx>
23
24//! Generic light source definition.
25//! This class defines arbitrary light source - see Graphic3d_TypeOfLightSource enumeration.
26//! Some parameters are applicable only to particular light type;
27//! calling methods unrelated to current type will throw an exception.
28class Graphic3d_CLight : public Standard_Transient
12381341 29{
992ed6b3 30 DEFINE_STANDARD_RTTIEXT(Graphic3d_CLight, Standard_Transient)
12381341 31public:
32
992ed6b3 33 //! Empty constructor, which should be followed by light source properties configuration.
34 Standard_EXPORT Graphic3d_CLight (Graphic3d_TypeOfLightSource theType);
35
36 //! Returns the Type of the Light, cannot be changed after object construction.
37 Graphic3d_TypeOfLightSource Type() const { return myType; }
38
39 //! Returns light source name; empty string by default.
40 const TCollection_AsciiString& Name() const { return myName; }
41
42 //! Sets light source name.
43 void SetName (const TCollection_AsciiString& theName) { myName = theName; }
44
45 //! Returns the color of the light source; WHITE by default.
46 const Quantity_Color& Color() const { return myColor.GetRGB(); }
47
48 //! Defines the color of a light source by giving the basic color.
49 Standard_EXPORT void SetColor (const Quantity_Color& theColor);
12381341 50
992ed6b3 51 //! Check that the light source is turned on; TRUE by default.
52 //! This flag affects all occurrences of light sources, where it was registered and activated;
53 //! so that it is possible defining an active light in View which is actually in disabled state.
54 Standard_Boolean IsEnabled() const { return myIsEnabled; }
55
56 //! Change enabled state of the light state.
57 //! This call does not remove or deactivate light source in Views/Viewers;
58 //! instead it turns it OFF so that it just have no effect.
59 Standard_EXPORT void SetEnabled (Standard_Boolean theIsOn);
60
61 //! Returns true if the light is a headlight; FALSE by default.
62 //! Headlight flag means that light position/direction are defined not in a World coordinate system, but relative to the camera orientation.
63 Standard_Boolean IsHeadlight() const { return myIsHeadlight; }
64
65 //! Alias for IsHeadlight().
66 Standard_Boolean Headlight() const { return myIsHeadlight; }
67
68 //! Setup headlight flag.
69 Standard_EXPORT void SetHeadlight (Standard_Boolean theValue);
70
71//! @name positional/spot light properties
72public:
12381341 73
992ed6b3 74 //! Returns location of positional/spot light; (0, 0, 0) by default.
75 const gp_Pnt& Position() const { return myPosition; }
12381341 76
992ed6b3 77 //! Setup location of positional/spot light.
78 Standard_EXPORT void SetPosition (const gp_Pnt& thePosition);
12381341 79
992ed6b3 80 //! Returns location of positional/spot light.
81 void Position (Standard_Real& theX,
82 Standard_Real& theY,
83 Standard_Real& theZ) const
84 {
85 theX = myPosition.X();
86 theY = myPosition.Y();
87 theZ = myPosition.Z();
88 }
12381341 89
992ed6b3 90 //! Setup location of positional/spot light.
91 void SetPosition (Standard_Real theX, Standard_Real theY, Standard_Real theZ) { SetPosition (gp_Pnt (theX, theY, theZ)); }
92
93 //! Returns constant attenuation factor of positional/spot light source; 1.0f by default.
94 //! Distance attenuation factors of reducing positional/spot light intensity depending on the distance from its position:
95 //! @code
96 //! float anAttenuation = 1.0 / (ConstAttenuation() + LinearAttenuation() * theDistance + QuadraticAttenuation() * theDistance * theDistance);
97 //! @endcode
98 Standard_ShortReal ConstAttenuation() const { return myParams.x(); }
99
100 //! Returns linear attenuation factor of positional/spot light source; 0.0 by default.
101 //! Distance attenuation factors of reducing positional/spot light intensity depending on the distance from its position:
102 //! @code
103 //! float anAttenuation = 1.0 / (ConstAttenuation() + LinearAttenuation() * theDistance + QuadraticAttenuation() * theDistance * theDistance);
104 //! @endcode
105 Standard_ShortReal LinearAttenuation() const { return myParams.y(); }
106
107 //! Returns the attenuation factors.
108 void Attenuation (Standard_Real& theConstAttenuation,
109 Standard_Real& theLinearAttenuation) const
110 {
111 theConstAttenuation = ConstAttenuation();
112 theLinearAttenuation = LinearAttenuation();
113 }
12381341 114
992ed6b3 115 //! Defines the coefficients of attenuation; values should be >= 0.0 and their summ should not be equal to 0.
116 Standard_EXPORT void SetAttenuation (Standard_ShortReal theConstAttenuation,
117 Standard_ShortReal theLinearAttenuation);
12381341 118
992ed6b3 119//! @name directional/spot light additional properties
12381341 120public:
121
992ed6b3 122 //! Returns direction of directional/spot light.
123 gp_Dir Direction() const { return gp_Dir (myDirection.x(), myDirection.y(), myDirection.z()); }
124
125 //! Sets direction of directional/spot light.
126 Standard_EXPORT void SetDirection (const gp_Dir& theDir);
127
128 //! Returns the theVx, theVy, theVz direction of the light source.
129 void Direction (Standard_Real& theVx,
130 Standard_Real& theVy,
131 Standard_Real& theVz) const
12381341 132 {
992ed6b3 133 theVx = myDirection.x();
134 theVy = myDirection.y();
135 theVz = myDirection.z();
12381341 136 }
137
992ed6b3 138 //! Sets direction of directional/spot light.
139 void SetDirection (Standard_Real theVx, Standard_Real theVy, Standard_Real theVz) { SetDirection (gp_Dir (theVx, theVy, theVz)); }
140
141//! @name spotlight additional definition parameters
142public:
143
144 //! Returns an angle in radians of the cone created by the spot; 30 degrees by default.
145 Standard_ShortReal Angle() const { return myParams.z(); }
146
147 //! Angle in radians of the cone created by the spot, should be within range (0.0, M_PI).
148 Standard_EXPORT void SetAngle (Standard_ShortReal theAngle);
149
150 //! Returns intensity distribution of the spot light, within [0.0, 1.0] range; 1.0 by default.
151 //! This coefficient should be converted into spotlight exponent within [0.0, 128.0] range:
152 //! @code
153 //! float aSpotExponent = Concentration() * 128.0;
154 //! anAttenuation *= pow (aCosA, aSpotExponent);"
155 //! @endcode
156 //! The concentration factor determines the dispersion of the light on the surface, the default value (1.0) corresponds to a minimum of dispersion.
157 Standard_ShortReal Concentration() const { return myParams.w(); }
158
159 //! Defines the coefficient of concentration; value should be within range [0.0, 1.0].
160 Standard_EXPORT void SetConcentration (Standard_ShortReal theConcentration);
161
162//! @name Ray-Tracing / Path-Tracing light properties
12381341 163public:
164
992ed6b3 165 //! Returns the intensity of light source; 1.0 by default.
166 Standard_ShortReal Intensity() const { return myIntensity; }
167
168 //! Modifies the intensity of light source, which should be > 0.0.
169 Standard_EXPORT void SetIntensity (Standard_ShortReal theValue);
170
171 //! Returns the smoothness of light source (either smoothing angle for directional light or smoothing radius in case of positional light); 0.0 by default.
172 Standard_ShortReal Smoothness() const { return mySmoothness; }
173
174 //! Modifies the smoothing radius of positional/spot light; should be >= 0.0.
175 Standard_EXPORT void SetSmoothRadius (Standard_ShortReal theValue);
176
177 //! Modifies the smoothing angle (in radians) of directional light source; should be within range [0.0, M_PI/2].
178 Standard_EXPORT void SetSmoothAngle (Standard_ShortReal theValue);
179
88b312d3 180 //! Returns maximum distance on which point light source affects to objects and is considered during illumination calculations.
181 //! 0.0 means disabling range considering at all without any distance limits.
182 //! Has sense only for point light sources (positional and spot).
183 Standard_ShortReal Range() const { return myDirection.w(); }
184
185 //! Modifies maximum distance on which point light source affects to objects and is considered during illumination calculations.
186 //! Positional and spot lights are only point light sources.
187 //! 0.0 means disabling range considering at all without any distance limits.
188 Standard_EXPORT void SetRange (Standard_ShortReal theValue);
189
992ed6b3 190//! @name low-level access methods
191public:
192
193 //! @return light resource identifier string
194 const TCollection_AsciiString& GetId() const { return myId; }
195
196 //! Packed light parameters.
197 const Graphic3d_Vec4& PackedParams() const { return myParams; }
198
199 //! Returns the color of the light source with dummy Alpha component, which should be ignored.
200 const Graphic3d_Vec4& PackedColor() const { return myColor; }
201
88b312d3 202 //! Returns direction of directional/spot light and range for positional/spot light in alpha channel.
203 const Graphic3d_Vec4& PackedDirectionRange() const { return myDirection; }
992ed6b3 204
205 //! @return modification counter
206 Standard_Size Revision() const { return myRevision; }
a5162275 207
208 //! Dumps the content of me into the stream
209 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
992ed6b3 210
211private:
212
213 //! Access positional/spot light constant attenuation coefficient from packed vector.
214 Standard_ShortReal& changeConstAttenuation() { return myParams.x(); }
215
216 //! Access positional/spot light linear attenuation coefficient from packed vector.
217 Standard_ShortReal& changeLinearAttenuation() { return myParams.y(); }
218
219 //! Access spotlight angle parameter from packed vector.
88b312d3 220 Standard_ShortReal& changeAngle() { return myParams.z(); }
992ed6b3 221
222 //! Access spotlight concentration parameter from packed vector.
88b312d3 223 Standard_ShortReal& changeConcentration() { return myParams.w(); }
992ed6b3 224
225private:
226
227 //! Generate unique object id.
228 void makeId();
229
230 //! Update modification counter.
231 void updateRevisionIf (bool theIsModified)
232 {
233 if (theIsModified)
234 {
235 ++myRevision;
236 }
237 }
238
239private:
240
241 Graphic3d_CLight (const Graphic3d_CLight& );
242 Graphic3d_CLight& operator= (const Graphic3d_CLight& );
243
244protected:
245
246 TCollection_AsciiString myId; //!< resource id
247 TCollection_AsciiString myName; //!< user given name
248 gp_Pnt myPosition; //!< light position
249 Quantity_ColorRGBA myColor; //!< light color
250 Graphic3d_Vec4 myDirection; //!< direction of directional/spot light
251 Graphic3d_Vec4 myParams; //!< packed light parameters
252 Standard_ShortReal mySmoothness; //!< radius for point light or cone angle for directional light
253 Standard_ShortReal myIntensity; //!< intensity multiplier for light
254 const Graphic3d_TypeOfLightSource myType; //!< Graphic3d_TypeOfLightSource enumeration
255 Standard_Size myRevision; //!< modification counter
256 Standard_Boolean myIsHeadlight; //!< flag to mark head light
257 Standard_Boolean myIsEnabled; //!< enabled state
12381341 258
259};
7fd59977 260
992ed6b3 261DEFINE_STANDARD_HANDLE(Graphic3d_CLight, Standard_Transient)
c357e426 262
12381341 263#endif // Graphic3d_CLight_HeaderFile