Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SbColor4f.h
1 #ifndef COIN_SBCOLOR4F_H
2 #define COIN_SBCOLOR4F_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/system/inttypes.h>
37 #include <Inventor/SbVec4f.h>
38 #include <Inventor/SbColor.h>
39 
40 class SbVec4f;
41 
42 class COIN_DLL_API SbColor4f : public SbVec4f {
43 public:
44  SbColor4f(void);
45  SbColor4f(const SbColor &rgb, const float alpha = 1.0f);
46  SbColor4f(const SbVec4f& v);
47  SbColor4f(const float* const rgba);
48  SbColor4f(const float r, const float g, const float b, const float a = 1.0f);
49 
50  void setValue(const float r, const float g, const float b,
51  const float a = 1.0f);
52  void setValue(const float col[4]);
53  const float *getValue() const;
54  void getValue(float &r, float &g, float &b, float &a);
55 
56  SbColor4f& setRGB(const SbColor &col);
57  void getRGB(SbColor &color);
58  SbColor4f& setHSVValue(float h, float s, float v, float a = 1.0f);
59  SbColor4f& setHSVValue(const float hsv[3], float alpha = 1.0f);
60  void getHSVValue(float &h, float &s, float &v) const;
61  void getHSVValue(float hsv[3]) const;
62  SbColor4f& setPackedValue(const uint32_t rgba);
63  uint32_t getPackedValue() const;
64 
65  float operator[](const int idx) const;
66  float &operator[](const int idx);
67 
68  SbColor4f &operator*=(const float d);
69  SbColor4f &operator/=(const float d);
70  SbColor4f &operator+=(const SbColor4f &c);
71  SbColor4f &operator-=(const SbColor4f &c);
72 
73  friend COIN_DLL_API SbColor4f operator *(const SbColor4f &c, const float d);
74  friend COIN_DLL_API SbColor4f operator *(const float d, const SbColor4f &c);
75  friend COIN_DLL_API SbColor4f operator /(const SbColor4f &c, const float d);
76  friend COIN_DLL_API SbColor4f operator +(const SbColor4f &v1, const SbColor4f &v2);
77  friend COIN_DLL_API SbColor4f operator -(const SbColor4f &v1, const SbColor4f &v2);
78  friend COIN_DLL_API int operator ==(const SbColor4f &v1, const SbColor4f &v2);
79  friend COIN_DLL_API int operator !=(const SbColor4f &v1, const SbColor4f &v2);
80 
81 private:
82  float red() const { return this->vec[0]; }
83  float green() const { return this->vec[1]; }
84  float blue() const { return this->vec[2]; }
85  float alpha() const { return this->vec[3]; }
86 };
87 
88 COIN_DLL_API SbColor4f operator *(const SbColor4f &c, const float d);
89 COIN_DLL_API SbColor4f operator *(const float d, const SbColor4f &c);
90 COIN_DLL_API SbColor4f operator /(const SbColor4f &c, const float d);
91 COIN_DLL_API SbColor4f operator +(const SbColor4f &v1, const SbColor4f &v2);
92 COIN_DLL_API SbColor4f operator -(const SbColor4f &v1, const SbColor4f &v2);
93 COIN_DLL_API int operator ==(const SbColor4f &v1, const SbColor4f &v2);
94 COIN_DLL_API int operator !=(const SbColor4f &v1, const SbColor4f &v2);
95 
96 typedef class SbColor4f SbColorRGBA; // TGS compatibility
97 
98 #endif // !COIN_SBCOLOR4F_H
The SbColor class contains the red, green and blue components which make up a color value...
Definition: SbColor.h:39
The SbVec4f class is a 4 dimensional vector with floating point coordinates.
Definition: SbVec4f.h:49
The SbColor4f class contains the red, green, blue and alpha components which make up a color value...
Definition: SbColor4f.h:42
SbVec4f & setValue(const float v[4])
Definition: SbVec4f.h:59
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:102
SbVec4f & operator-=(const SbVec4f &v)
Definition: SbVec4f.h:83
SbVec4f operator*(const SbVec4f &v, float d)
Definition: SbVec4f.h:93
SbVec4f & operator*=(float d)
Definition: SbVec4f.h:80
SbVec2s operator-(const SbVec2s &v1, const SbVec2s &v2)
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:106
SbVec4f operator+(const SbVec4f &v1, const SbVec4f &v2)
Definition: SbVec4f.h:106
SbVec4f & operator/=(float d)
Definition: SbVec4f.h:81
const float * getValue(void) const
Definition: SbVec4f.h:66
float & operator[](int i)
Definition: SbVec4f.h:69
SbVec4f & operator+=(const SbVec4f &v)
Definition: SbVec4f.h:82
int operator==(const SbVec4f &v1, const SbVec4f &v2)
Definition: SbVec4f.h:114
SbVec2s operator/(const SbVec2s &v, int d)
int operator!=(const SbVec4f &v1, const SbVec4f &v2)
Definition: SbVec4f.h:118
SbVec2s operator*(const SbVec2s &v, int d)
SbVec4f operator-(void) const
Definition: SbVec4f.h:84
SbVec2s operator+(const SbVec2s &v1, const SbVec2s &v2)
SbVec4f operator/(const SbVec4f &v, float d)
Definition: SbVec4f.h:101