FEDEM Model Database  R8.0
Source code of the FEDEM model database
FmColor.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
8 #ifndef FM_COLOR_H
9 #define FM_COLOR_H
10 
11 #include <array>
12 #include <iostream>
13 
14 #define I3 std::array<int,3>
15 #define F3 std::array<float,3>
16 #define FF 255.0f
17 
18 
23 class FmColor : public F3
24 {
25 public:
27  FmColor(float r = 0.0f, float g = 0.0f, float b = 0.0f) : F3({r,g,b}) {}
29  FmColor(const F3& c) : F3(c) {}
31  FmColor(const I3& c) : F3({c[0]/FF,c[1]/FF,c[2]/FF}) {}
32 };
33 
34 
35 inline std::ostream& operator<<(std::ostream& os, const FmColor& color)
36 {
37  std::streamsize oldPrec = os.precision(7);
38  os << color[0] << ' ' << color[1] << ' ' << color[2];
39  os.precision(oldPrec);
40  return os;
41 }
42 
43 inline std::istream& operator>>(std::istream& is, FmColor& color)
44 {
45  FmColor tmp;
46  is >> tmp[0] >> tmp[1] >> tmp[2];
47  if (is) color = tmp;
48  return is;
49 }
50 
51 #undef I3
52 #undef F3
53 #undef FF
54 #endif
#define FF
Definition: FmColor.H:16
std::ostream & operator<<(std::ostream &os, const FmColor &color)
Definition: FmColor.H:35
#define F3
Definition: FmColor.H:15
#define I3
Definition: FmColor.H:14
std::istream & operator>>(std::istream &is, FmColor &color)
Definition: FmColor.H:43
Representation of a RGB color by floats in range [0.0,1.0].
Definition: FmColor.H:24
FmColor(float r=0.0f, float g=0.0f, float b=0.0f)
Default constructor.
Definition: FmColor.H:27
FmColor(const F3 &c)
Copy constructor.
Definition: FmColor.H:29
FmColor(const I3 &c)
Conversion from integer representation in range [0,255].
Definition: FmColor.H:31