Loading...
Searching...
No Matches
PaletteEntry.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef DRAIN_PALETTE_ENTRY
32#define DRAIN_PALETTE_ENTRY
33
34#include <iomanip>
35
36
37//#include "drain/util/BeanLike.h"
38#include "drain/util/VariableMap.h"
39
40#include "Legend.h"
41
42
43namespace drain
44{
45
47class FavaBean {
48public:
49
50 inline
51 FavaBean(){};
52
53 inline
54 FavaBean(const FavaBean & b){};
55
56 typedef FlexVariableMap map_t;
57
58 inline
59 const map_t & getParameters() const { return parameters; };
60
61 inline
62 map_t & getParameters() { return parameters; };
63
64
65 const std::string name; // todo separate (Beanlet)
66
67 const std::string description; // todo separate (Beanlet)
68
69 //ReferenceMap parameters; // todo separate (Beanlet)
70 map_t parameters; // todo separate (Beanlet)?
71
72};
73
74namespace image
75{
76
77
78
79
80class PalEntry { // : public ABC { //: public drain::BeanLike {
81
82
83public:
84
85
87 typedef double value_t;
88
90 //typedef drain::UniTuple<value_t,3> color_t;
91 typedef std::vector<value_t> color_vect_t;
93
94 PalEntry(const color_vect_t & color={}, value_t alpha=1.0, const std::string & label = "");
95
96 PalEntry(const std::initializer_list<drain::Variable::init_pair_t > & args);
97
98//protected:
99
100 //ReferenceMap parameters; // todo separate (Beanlet)
101 map_t parameters; // todo separate (Beanlet)?
102
103 //color_t color;
104 drain::FlexibleVariable & color; // "Inverse" linkage to parameters.
105 value_t alpha = 1.0;
106
107 std::string label;
108
109 inline
110 PalEntry & operator=(const PalEntry & b);
111
112
113 inline
114 const map_t & getParameters() const { return parameters; };
115
116 inline
117 map_t & getParameters() { return parameters; };
118
119
120 const std::string name; // todo separate (Beanlet)
121
122 const std::string description; // todo separate (Beanlet)
123
124protected:
125
126 //ReferenceMap parameters; // todo separate (Beanlet)
127
128 void init();
129
130};
131
132
133
134
136
142class PaletteEntry { // : public BeanLike { // public FavaBean { //
143
144public:
145
147 typedef double value_t;
148
149 // UUSI
150 typedef std::vector<value_t> color_vect_t;
152
154 typedef FlexibleVariable color_t; // NEW
155 // typedef UniTuple<value_t,3> color_t; // UNITUPLE
156 // typedef std::vector<value_t> color_t; // VECT
157
159 PaletteEntry();
160
162 PaletteEntry(const PaletteEntry & entry);
163
165
177 PaletteEntry(const char * code, const char * label, const color_vect_t & color, value_t alpha=255.0, bool hidden=false);
178
180
191 PaletteEntry(const char * label, const color_vect_t & color, value_t alpha=255.0, bool hidden=false);
192
194
206 PaletteEntry(const color_vect_t & color, value_t alpha=255.0, bool hidden=false);
207
209
221 PaletteEntry(const std::initializer_list<Variable::init_pair_t > & args);
222
224
233 //PaletteEntry(const std::string & label);
234 PaletteEntry(const char * label);
235
236 // UUSI
237 map_t parameters;
238
240 std::string code;
241
243 std::string label;
244
246 // double value;
247 // Experimental
249
251 // color_t color;
252
255
256
258
263 bool hidden;
264
265 // inline
266 PaletteEntry & operator=(const PaletteEntry & b);
267
268
269 inline
270 const map_t & getParameters() const { return parameters; };
271
272 inline
273 map_t & getParameters() { return parameters; };
274
281 // std::ostream & toOStream(std::ostream &ostr, char separator='\t', char separator2=0) const;
282 std::ostream & toStream(std::ostream &ostr, char separator='\t') const;
283
284 void checkAlpha();
285
286
288 void getHexColor(std::ostream & ostr) const;
289
291 inline
292 void getHexColor(std::string & str, const std::string & prefix = "") const {
293 std::stringstream sstr;
294 sstr << prefix;
295 getHexColor(sstr);
296 str = sstr.str();
297 }
298
299 //template <class T>
300 /*
301 PaletteEntry & operator=(const drain::VariableMap & m){
302 setParameters(m);
303 return *this;
304 };
305 */
306
307protected:
308
309 void init();
310
311};
312
313
314
315inline
316std::ostream & operator<<(std::ostream &ostr, const PaletteEntry & entry){
317 return entry.toStream(ostr);
318}
319
320
321} // image::
322
323template <>
324std::ostream & drain::Sprinter::toStream(std::ostream & ostr, const drain::image::PaletteEntry & entry, const drain::SprinterLayout & layout);
325
326
327} // drain::
328
329/*
330template <>
331inline
332std::ostream & drain::Sprinter::toStream(std::ostream & ostr, const drain::image::PaletteEntry::color_t & color, const drain::SprinterLayout & layout){
333
334 ostr << layout.arrayChars.prefix; // << "xx";
335 ostr << std::fixed << std::setprecision(1); // ensure ".0"
336 drain::Sprinter::toStream(ostr, color[0], layout);
337 ostr << layout.arrayChars.separator;
338 drain::Sprinter::toStream(ostr, color[1], layout);
339 ostr << layout.arrayChars.separator;
340 drain::Sprinter::toStream(ostr, color[2], layout);
341 ostr << layout.arrayChars.suffix;
342 return ostr;
343}
344*/
345
346
347#endif
BeanLike-like, based on FlexMap.
Definition PaletteEntry.h:47
A map of FlexVariable:s.
Definition VariableMap.h:138
static std::ostream & toStream(std::ostream &ostr, const std::initializer_list< T > &x, const SprinterLayout &layout=defaultLayout)
New (experimental)
Definition Sprinter.h:423
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
Definition PaletteEntry.h:80
std::vector< value_t > color_vect_t
Color vector type.
Definition PaletteEntry.h:91
double value_t
Threshold value (lowest value to be associated with entry (color and alpha)
Definition PaletteEntry.h:87
Container for color, transparency (alpha) and textual id and description. Does not contain intensity ...
Definition PaletteEntry.h:142
std::string label
Short description for legends.
Definition PaletteEntry.h:243
void getHexColor(std::ostream &ostr) const
Returns the color without leading marker (like "0x").
Definition PaletteEntry.cpp:219
std::string code
Technical identifier (optional).
Definition PaletteEntry.h:240
bool hidden
Suggests hiding the entry in legends. Does not affect colouring of images.
Definition PaletteEntry.h:263
FlexibleVariable color_t
Color vector type.
Definition PaletteEntry.h:154
void getHexColor(std::string &str, const std::string &prefix="") const
Write colour in hexadecimal notation, with an optional prefix (often "#").
Definition PaletteEntry.h:292
FlexibleVariable & color
Index or threshold value. Must be signed, as image data may generally have negative values.
Definition PaletteEntry.h:248
PaletteEntry()
Default constructor.
Definition PaletteEntry.cpp:103
double value_t
Intensity type.
Definition PaletteEntry.h:147
std::ostream & toStream(std::ostream &ostr, char separator='\t') const
Definition PaletteEntry.cpp:232
value_t alpha
Colors, or more generally, channel values.
Definition PaletteEntry.h:254
Definition DataSelector.cpp:1277
Definition Sprinter.h:136