PaletteEntry.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood 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/Dictionary.h" // temporary ?
43 #include "drain/util/JSON.h"
44 #include "Legend.h"
45 
46 
47 namespace drain
48 {
49 
50 
51 namespace image
52 {
53 
54 
56 
62 class PaletteEntry : public BeanLike {
63 
64 public:
65 
67  typedef double value_t;
68 
71 
73  PaletteEntry();
74 
76  PaletteEntry(const PaletteEntry & entry);
77 
79 
91  PaletteEntry(const char * code, const char * label, const color_t & color, value_t alpha=255.0, bool hidden=false);
92 
94 
105  PaletteEntry(const char * label, const color_t & color, value_t alpha=255.0, bool hidden=false);
106 
108 
120  PaletteEntry(const color_t & color, value_t alpha=255.0, bool hidden=false);
121 
123 
135  PaletteEntry(const std::initializer_list<Variable::init_pair_t > & args);
136 
138 
147  //PaletteEntry(const std::string & label);
148  PaletteEntry(const char * label);
149 
150  void checkAlpha();
151 
153  std::string code;
154 
156  std::string label;
157 
159  // double value;
160 
163 
166 
167 
169 
174  bool hidden;
175 
182  // std::ostream & toOStream(std::ostream &ostr, char separator='\t', char separator2=0) const;
183  std::ostream & toStream(std::ostream &ostr, char separator='\t') const;
184 
186  void getHexColor(std::ostream & ostr) const;
187 
188  inline
189  void getHexColor(std::string & str) const {
190  std::stringstream sstr;
191  getHexColor(sstr);
192  str = sstr.str();
193  }
194 
195  //template <class T>
196  /*
197  PaletteEntry & operator=(const drain::VariableMap & m){
198  setParameters(m);
199  return *this;
200  };
201  */
202 
203 protected:
204 
205  void init();
206 
207 };
208 
209 
210 
211 inline
212 std::ostream & operator<<(std::ostream &ostr, const PaletteEntry & entry){
213  return entry.toStream(ostr);
214 }
215 
216 
217 } // image::
218 
219 template <>
220 std::ostream & drain::Sprinter::toStream(std::ostream & ostr, const drain::image::PaletteEntry & entry, const drain::SprinterLayout & layout);
221 
222 
223 } // drain::
224 
225 /*
226 template <>
227 inline
228 std::ostream & drain::Sprinter::toStream(std::ostream & ostr, const drain::image::PaletteEntry::color_t & color, const drain::SprinterLayout & layout){
229 
230  ostr << layout.arrayChars.prefix; // << "xx";
231  ostr << std::fixed << std::setprecision(1); // ensure ".0"
232  drain::Sprinter::toStream(ostr, color[0], layout);
233  ostr << layout.arrayChars.separator;
234  drain::Sprinter::toStream(ostr, color[1], layout);
235  ostr << layout.arrayChars.separator;
236  drain::Sprinter::toStream(ostr, color[2], layout);
237  ostr << layout.arrayChars.suffix;
238  return ostr;
239 }
240 */
241 
242 
243 #endif
Something which has a name, a description and possibly some parameters of varying type.
Definition: BeanLike.h:60
static std::ostream & toStream(std::ostream &ostr, const std::initializer_list< T > &x, const SprinterLayout &layout=defaultLayout)
New (experimental)
Definition: Sprinter.h:420
Container for color, transparency (alpha) and textual id and description. Does not contain intensity ...
Definition: PaletteEntry.h:62
UniTuple< value_t, 3 > color_t
Color vector type.
Definition: PaletteEntry.h:70
std::string label
Short description for legends.
Definition: PaletteEntry.h:156
void getHexColor(std::ostream &ostr) const
Returns the color without leading marker (like "0x").
Definition: PaletteEntry.cpp:129
std::string code
Technical identifier (optional).
Definition: PaletteEntry.h:153
bool hidden
Suggests hiding the entry in legends. Does not affect colouring of images.
Definition: PaletteEntry.h:174
color_t color
Index or threshold value. Must be signed, as image data may generally have negative values.
Definition: PaletteEntry.h:162
PaletteEntry()
Default constructor.
Definition: PaletteEntry.cpp:55
double value_t
Intensity type.
Definition: PaletteEntry.h:67
std::ostream & toStream(std::ostream &ostr, char separator='\t') const
Definition: PaletteEntry.cpp:142
value_t alpha
Transparency.
Definition: PaletteEntry.h:165
Definition: DataSelector.cpp:1277
Definition: Sprinter.h:137