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 <drain/UniTuple.h>
35#include <iomanip>
36
37#include "ImageFile.h"
38#include "Geometry.h"
39#include "TreeSVG.h"
40
41//#include "drain/util/BeanLike.h"
42#include "drain/util/VariableMap.h"
43
44#include "drain/util/Dictionary.h" // temporary ?
45#include "drain/util/JSON.h"
46#include "Legend.h"
47
48
49namespace drain
50{
51
53class FavaBean {
54public:
55
56 inline
57 FavaBean(){};
58
59 inline
60 FavaBean(const FavaBean & b){};
61
62 typedef FlexVariableMap map_t;
63
64 inline
65 const map_t & getParameters() const { return parameters; };
66
67 inline
68 map_t & getParameters() { return parameters; };
69
70
71 const std::string name; // todo separate (Beanlet)
72
73 const std::string description; // todo separate (Beanlet)
74
75 //ReferenceMap parameters; // todo separate (Beanlet)
76 map_t parameters; // todo separate (Beanlet)?
77
78};
79
80namespace image
81{
82
83
84
85
86class PalEntry { // : public ABC { //: public drain::BeanLike {
87
88
89public:
90
91
93 typedef double value_t;
94
96 //typedef drain::UniTuple<value_t,3> color_t;
97 typedef std::vector<value_t> color_vect_t;
99
100 PalEntry(const color_vect_t & color={}, value_t alpha=1.0, const std::string & label = "");
101
102 PalEntry(const std::initializer_list<drain::Variable::init_pair_t > & args);
103
104//protected:
105
106 //ReferenceMap parameters; // todo separate (Beanlet)
107 map_t parameters; // todo separate (Beanlet)?
108
109 //color_t color;
110 drain::FlexibleVariable & color; // "Inverse" linkage to parameters.
111 value_t alpha = 1.0;
112
113 std::string label;
114
115 inline
116 PalEntry & operator=(const PalEntry & b);
117
118
119 inline
120 const map_t & getParameters() const { return parameters; };
121
122 inline
123 map_t & getParameters() { return parameters; };
124
125
126 const std::string name; // todo separate (Beanlet)
127
128 const std::string description; // todo separate (Beanlet)
129
130protected:
131
132 //ReferenceMap parameters; // todo separate (Beanlet)
133
134 void init();
135
136};
137
138
139
140
142
148class PaletteEntry { // : public BeanLike { // public FavaBean { //
149
150public:
151
153 typedef double value_t;
154
155 // UUSI
156 typedef std::vector<value_t> color_vect_t;
158
160 typedef FlexibleVariable color_t; // NEW
161 // typedef UniTuple<value_t,3> color_t; // UNITUPLE
162 // typedef std::vector<value_t> color_t; // VECT
163
165 PaletteEntry();
166
168 PaletteEntry(const PaletteEntry & entry);
169
171
183 PaletteEntry(const char * code, const char * label, const color_vect_t & color, value_t alpha=255.0, bool hidden=false);
184
186
197 PaletteEntry(const char * label, const color_vect_t & color, value_t alpha=255.0, bool hidden=false);
198
200
212 PaletteEntry(const color_vect_t & color, value_t alpha=255.0, bool hidden=false);
213
215
227 PaletteEntry(const std::initializer_list<Variable::init_pair_t > & args);
228
230
239 //PaletteEntry(const std::string & label);
240 PaletteEntry(const char * label);
241
242 // UUSI
243 map_t parameters;
244
246 std::string code;
247
249 std::string label;
250
252 // double value;
253 // Experimental
255
257 // color_t color;
258
261
262
264
269 bool hidden;
270
271 // inline
272 PaletteEntry & operator=(const PaletteEntry & b);
273
274
275 inline
276 const map_t & getParameters() const { return parameters; };
277
278 inline
279 map_t & getParameters() { return parameters; };
280
287 // std::ostream & toOStream(std::ostream &ostr, char separator='\t', char separator2=0) const;
288 std::ostream & toStream(std::ostream &ostr, char separator='\t') const;
289
290 void checkAlpha();
291
292
294 void getHexColor(std::ostream & ostr) const;
295
297 inline
298 void getHexColor(std::string & str, const std::string & prefix = "") const {
299 std::stringstream sstr;
300 sstr << prefix;
301 getHexColor(sstr);
302 str = sstr.str();
303 }
304
305 //template <class T>
306 /*
307 PaletteEntry & operator=(const drain::VariableMap & m){
308 setParameters(m);
309 return *this;
310 };
311 */
312
313protected:
314
315 void init();
316
317};
318
319
320
321inline
322std::ostream & operator<<(std::ostream &ostr, const PaletteEntry & entry){
323 return entry.toStream(ostr);
324}
325
326
327} // image::
328
329template <>
330std::ostream & drain::Sprinter::toStream(std::ostream & ostr, const drain::image::PaletteEntry & entry, const drain::SprinterLayout & layout);
331
332
333} // drain::
334
335/*
336template <>
337inline
338std::ostream & drain::Sprinter::toStream(std::ostream & ostr, const drain::image::PaletteEntry::color_t & color, const drain::SprinterLayout & layout){
339
340 ostr << layout.arrayChars.prefix; // << "xx";
341 ostr << std::fixed << std::setprecision(1); // ensure ".0"
342 drain::Sprinter::toStream(ostr, color[0], layout);
343 ostr << layout.arrayChars.separator;
344 drain::Sprinter::toStream(ostr, color[1], layout);
345 ostr << layout.arrayChars.separator;
346 drain::Sprinter::toStream(ostr, color[2], layout);
347 ostr << layout.arrayChars.suffix;
348 return ostr;
349}
350*/
351
352
353#endif
BeanLike-like, based on FlexMap.
Definition PaletteEntry.h:53
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:420
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
Definition PaletteEntry.h:86
std::vector< value_t > color_vect_t
Color vector type.
Definition PaletteEntry.h:97
double value_t
Threshold value (lowest value to be associated with entry (color and alpha)
Definition PaletteEntry.h:93
Container for color, transparency (alpha) and textual id and description. Does not contain intensity ...
Definition PaletteEntry.h:148
std::string label
Short description for legends.
Definition PaletteEntry.h:249
void getHexColor(std::ostream &ostr) const
Returns the color without leading marker (like "0x").
Definition PaletteEntry.cpp:222
std::string code
Technical identifier (optional).
Definition PaletteEntry.h:246
bool hidden
Suggests hiding the entry in legends. Does not affect colouring of images.
Definition PaletteEntry.h:269
FlexibleVariable color_t
Color vector type.
Definition PaletteEntry.h:160
void getHexColor(std::string &str, const std::string &prefix="") const
Write colour in hexadecimal notation, with an optional prefix (often "#").
Definition PaletteEntry.h:298
FlexibleVariable & color
Index or threshold value. Must be signed, as image data may generally have negative values.
Definition PaletteEntry.h:254
PaletteEntry()
Default constructor.
Definition PaletteEntry.cpp:106
double value_t
Intensity type.
Definition PaletteEntry.h:153
std::ostream & toStream(std::ostream &ostr, char separator='\t') const
Definition PaletteEntry.cpp:235
value_t alpha
Colors, or more generally, channel values.
Definition PaletteEntry.h:260
Definition DataSelector.cpp:1277
Definition Sprinter.h:137