GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Color.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _libCore_Color_hpp_
31 #define _libCore_Color_hpp_
32 
33 #include <iosfwd>
34 #include <boost/archive/text_oarchive.hpp>
35 #include <boost/archive/text_iarchive.hpp>
36 
37 
38 namespace GranOO3
39 {
40  namespace Core
41  {
42 
43  class Color
44  {
45  public:
46  Color();
47  Color(float r, float g, float b);
48  Color(float r, float g, float b, float a);
49 
50  ~Color();
51 
52  void set_color(float r, float g, float b, float a);
53  void set_color(float r, float g, float b);
54 
55  float get_red() const;
56  float get_blue() const;
57  float get_green() const;
58  float get_alpha() const;
59 
60  void set_red(float val);
61  void set_blue(float val);
62  void set_green(float val);
63  void set_alpha(float val);
64 
65  bool is_transparent() const;
66 
67  std::ostream& to_povray (std::ostream& out) const;
68 
69  private:
71  template<class Archive> void serialize(Archive& ar, const unsigned int );
72 
73  private:
74  float _red, _green, _blue, _alpha;
75  };
76 
77  std::ostream& operator<< (std::ostream& os, const Color& color);
78 
79  inline
81  : _red(0.), _green(0.), _blue(0.), _alpha(1.) {
82  }
83 
84  inline
85  Color::Color(float r, float g, float b)
86  : _red(r), _green(g), _blue(b), _alpha(1.) {
87  }
88 
89  inline
90  Color::Color(float r, float g, float b, float a)
91  : _red(r), _green(g), _blue(b), _alpha(a) {
92  }
93 
94  inline
96  }
97 
98  inline void
99  Color::set_color(float r, float g, float b, float a) {
100  _red = r;
101  _green = g;
102  _blue = b;
103  _alpha = a;
104  }
105 
106  inline void
107  Color::set_color(float r, float g, float b) {
108  _red = r;
109  _green = g;
110  _blue = b;
111  }
112 
113  inline bool
115  return (_alpha < 1.);
116  }
117 
118  inline float
119  Color::get_red() const {
120  return _red;
121  }
122 
123  inline float
124  Color::get_blue() const {
125  return _blue;
126  }
127 
128  inline float
130  return _green;
131  }
132 
133  inline float
135  return _alpha;
136  }
137 
138 
139  inline void
140  Color::set_blue(float val) {
141  _blue = val;
142  }
143 
144  inline void
145  Color::set_red(float val) {
146  _red = val;
147  }
148 
149  inline void
150  Color::set_green(float val) {
151  _green = val;
152  }
153 
154  inline void
155  Color::set_alpha(float val) {
156  _alpha = val;
157  }
158 
159 
160  template<class Archive> void
161  Color::serialize(Archive& ar, const unsigned int) {
162  ar & _red ;
163  ar & _green ;
164  ar & _blue ;
165  ar & _alpha ;
166  }
167 
168  }
169 }
170 
171 #endif
Definition: Color.hpp:44
float get_blue() const
Definition: Color.hpp:124
void serialize(Archive &ar, const unsigned int)
Definition: Color.hpp:161
void set_green(float val)
Definition: Color.hpp:150
void set_alpha(float val)
Definition: Color.hpp:155
float get_alpha() const
Definition: Color.hpp:134
void set_red(float val)
Definition: Color.hpp:145
Color()
Definition: Color.hpp:80
float get_red() const
Definition: Color.hpp:119
float _alpha
Definition: Color.hpp:74
void set_blue(float val)
Definition: Color.hpp:140
float _red
Definition: Color.hpp:74
void set_color(float r, float g, float b, float a)
Definition: Color.hpp:99
float get_green() const
Definition: Color.hpp:129
std::ostream & to_povray(std::ostream &out) const
Definition: Color.cpp:47
~Color()
Definition: Color.hpp:95
friend class boost::serialization::access
Definition: Color.hpp:70
float _blue
Definition: Color.hpp:74
bool is_transparent() const
Definition: Color.hpp:114
float _green
Definition: Color.hpp:74
std::ostream & operator<<(std::ostream &os, const Color &color)
Definition: Color.cpp:38
Definition: Common.hpp:198