resources-image.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 
32 // # pragma once
33 #ifndef RACK_RESOURCES_IMG_H
34 #define RACK_RESOURCES_IMG_H
35 
36 #include <string>
37 
38 #include <drain/RegExp.h>
39 #include <drain/image/Image.h>
40 #include <drain/image/TreeSVG.h>
41 #include <drain/image/TreeUtilsSVG.h>
42 #include <drain/imageops/PaletteOp.h>
43 #include <drain/imageops/ImageModifierPack.h>
44 #include <drain/imageops/PaletteOp.h>
45 #include <drain/prog/CommandBankUtils.h>
46 #include <drain/util/Rectangle.h>
47 // #include <drain/util/StatusFlags.h>
48 // #include <drain/util/TreeOrdered.h>
49 
50 //#include <drain/util/Variable.h>
51 
52 // #include "data/ProductConf.h"
53 #include "data/VariableFormatterODIM.h"
54 
55 //#include "resources-base.h"
56 
57 
58 namespace rack {
59 
60 
61 //using namespace drain::image;
62 
63 enum SvgInclude {
64  NONE = 0,
65  PNG = 1, // Main title in SVG image
66  SVG = 2,
67  TXT = 4,
68  SKIP = 16,
69  NEXT = 32,
70  ON = 64,
71  OFF = 128,
72  ALL = ON|(PNG|SVG|TXT),
73  UNKNOWN = 255,
74  // --- unused ? ---
75  // TITLE, // Default title
76 };
77 
78 /*
79 enum TitleClass {
80  NONE = 0,
81  MAIN = 1, // Main title in SVG image
82  GROUP = 2,
83  IMAGE = 4, // Small title in a corner of radar image (time, location)
84  TIME = 8, // Date and time attributes
85  LOCATION = 16, // Place (coordinates, municipality)
86  GENERAL = 32, // Default type
87 };
88 */
89 
90 
91 struct PanelConfSVG {
92 
94  IncludeFlagger svgIncludes;
95 
96  enum ElemClass {
97  NONE = 0,
98  MAIN = 1, // Main title in SVG image
99  GROUP = 2, // Group title
100  IMAGE = 4, // Image title: small text (time, location) in corners of radar images
101  TIME = 8, // Date and time attributes
102  LOCATION = 16, // Place (coordinates, municipality)
103  GENERAL = 32, // Default type
104  ALL = (63),
105  // MAIN,
106  IMAGE_PANEL,
107  IMAGE_BORDER, // RECT surrounding the image
108  SIDE_PANEL,
109  SHARED_METADATA, // Something that should not be repeated in panels.
110  // --- unused ? ---
111  // TITLE, // Default title
112  };
114  TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
115 
116  std::string imageTitle = "TIME,LOCATION,GENERAL";
117 
118 
119 
121  bool absolutePaths = true;
122 
123  std::string mainTitle = "AUTO";
124 
125  std::string groupTitleSyntax = "AUTO";
126  std::string groupTitleFormatted;
127 
128 
129  /*
130  typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
131  TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
132  */
133 
140  drain::UniTuple<double,3> fontSizes = {15.0, 12.0, 10.0};
141 
146  drain::UniTuple<double,3> boxHeights = {30.0, 25.0, 15.0};
147 
148  inline // maxPerGroup(10), layout(Alignment::HORZ, LayoutSVG::INCR), legend(LEFT, EMBED),
149  PanelConfSVG() : svgIncludes(SvgInclude::ALL), absolutePaths(true){
150  }
151 
152 
153 };
154 
155 }
156 
157 
158 namespace drain {
159 
160 template <>
162 
163 DRAIN_ENUM_OSTREAM(rack::SvgInclude);
164 
165 template <>
167 
168 DRAIN_ENUM_OSTREAM(rack::PanelConfSVG::ElemClass);
169 
170 
171 template <> // for T (Tree class)
172 template <> // for K (path elem arg)
173 bool image::TreeSVG::hasChild(const rack::PanelConfSVG::ElemClass & key) const ;
174 
175 
177 
180 template <> // for T (Tree class)
181 template <> // for K (path elem arg)
182 const image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & value) const;
183 
184 
185 template <> // for T (Tree class)
186 template <> // for K (path elem arg)
187 image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key);
188 
189 /*
190 template <> // for T (Tree class)
191 template <> // for K (path elem arg)
192 bool image::TreeSVG::hasChild(const rack::PanelConfSVG::ElemClass & key) const;
193 
194 
195 template <> // for T (Tree class)
196 template <> // for K (path elem arg)
197 image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key);
198 
199 template <> // for T (Tree class)
200 template <> // for K (path elem arg)
201 const image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key) const;
202 */
203 
204 
205 }
206 
207 using namespace drain::image;
208 
209 namespace rack {
210 
211 class GraphicsContext { // : public drain::BasicCommand {
212 
213 public:
214 
215 
217  GraphicsContext();
218 
220  GraphicsContext(const GraphicsContext & ctx);
221 
222  // SVG output configuration (layout)
223  TreeSVG svgTrack;
224  PanelConfSVG svgPanelConf; // under constr - consider embedding these to PanelConfSVG:
225  // std::string svgGroupNameSyntax = "group";
226  // std::string svgGroupNameFormatted;
227 
228  AlignBase::Axis mainOrientation = AlignBase::Axis::HORZ;
229  LayoutSVG::Direction mainDirection = LayoutSVG::Direction::INCR;
230  int svgDebug = 0;
231 
232  // Here AlignSVG::HorzAlign and AlignSVG::VertAlign not used, as they contain no Topol(ogy).
233  // CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::HORZ> alignHorz = {AlignSVG::Topol::INSIDE};
234  // CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::VERT> alignVert = {AlignSVG::Topol::INSIDE, AlignBase::Pos::MIN};
235  CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::HORZ> alignHorz = {AlignSVG::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
236  CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::VERT> alignVert = {AlignSVG::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
237 
238 
240 
243  // drain::image::TreeSVG & getStyle();
244 
246 
250  // drain::image::TreeSVG & getMainGroup();
251 
252  //drain::image::TreeSVG & getCurrentAlignedGroup();
253 
254  // virtual
255  // std::string getFormattedStatus(const std::string & format) const = 0;
256 
257  // drain::image::TreeSVG & getCurrentAlignedGroup();
258 
259  // drain::image::TreeSVG & getImagePanelGroup(const drain::FilePath & filepath);
260 
261  /*
262  typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
263  TitleFlagger svgTitles = ElemClass::NONE;
264  */
265  // std::string svgTitles = "";
266 
268  // static
269  // void applyAlignment(drain::image::TreeSVG & group);
270 
271 };
272 
273 
274 
275 
276 // Consider moving ImageKit here?
278 public:
279 
280 
282  ImageContext();
283 
285  ImageContext(const ImageContext & ctx);
286 
289 
291 
297 
298  // Accessed by CmdSampler
299  ImageSampler imageSampler;
300 
301 
302  inline
303  void setCurrentImageColor(const Image & src){
304  currentImage = &src;
305  }
306 
307  inline
308  void setCurrentImages(const Image & src){
309  currentImage = &src;
310  currentGrayImage = &src;
311  }
312 
313  inline
314  void unsetCurrentImages(){
315  currentImage = NULL;
316  currentGrayImage = NULL;
317  }
318 
319  void getImageStatus(drain::FlexVariableMap & statusMap) const;
320 
321 
323  const Image *currentImage; // = NULL;
324 
326  const Image *currentGrayImage; // = NULL; // data or grayImage
327 
328 
329  Image grayImage;
330  Image colorImage;
331 
332  std::string paletteKey;
333 
334 
335  // New
336  inline
337  Palette & getPalette(){
338  return PaletteOp::getPalette(paletteKey);
339  }
340 
341  // New
342  inline
343  Palette & getPalette(const std::string & key){
344  paletteKey = key;
345  return PaletteOp::getPalette(key);
346  }
347 
348  /*
349  struct {
350  drain::Point2D<unsigned short> tilesize = 256;
351  } geotiff;
352  */
354 
356  static
357  void getImageInfo(const Image *ptr, drain::Variable & entry);
358 
359 
360 
361  static std::string outputQuantitySyntax;
362 
363 //protected:
364 
365  void updateImageStatus(drain::VariableMap & statusMap) const ;
366 
367 
368 };
369 
370 
371 
372 
373 
374 
375 
376 
377 } /* namespace rack */
378 
379 #endif /* RACKLET_H_ */
380 
381 // Rack
Two-way mapping between strings and objects of template class T.
Definition: Dictionary.h:63
Flagger accepting values of enum type E.
Definition: EnumFlags.h:190
A map of FlexVariable:s.
Definition: VariableMap.h:138
A map of Variables.
Definition: VariableMap.h:61
Traverses image, returning samples.
Definition: ImageModifierPack.h:401
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
Definition: resources-image.h:211
Definition: resources-image.h:277
bool imagePhysical
Defines if the next image processing operation uses scaled intentsites instead of raw byte values.
Definition: resources-image.h:288
const Image * currentImage
Pointer to the last 2D data (image) processed.
Definition: resources-image.h:323
static std::string outputQuantitySyntax
Definition: resources-image.h:361
ODIMPathElem::group_t qualityGroups
Defines which quality data, if any, is used as input weight.
Definition: resources-image.h:296
const Image * currentGrayImage
Pointer to the last single-channel 2D data (image) processed.
Definition: resources-image.h:326
unsigned int group_t
In H5, "groups" correspond to directories or folders in file system.
Definition: ODIMPath.h:92
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:1277
DRAIN_VARIABLE Variable
Value container supporting dynamic type.
Definition: Variable.h:63
Definition: DataSelector.cpp:44
Wrapper for unique (static) dictionary of enum values.
Definition: EnumFlags.h:66
Definition: resources-image.h:91
drain::UniTuple< double, 3 > boxHeights
Definition: resources-image.h:146
bool absolutePaths
SVG file may contain several "modules", for example rows or columns of IMAGE:s. This is the name of t...
Definition: resources-image.h:121
drain::UniTuple< double, 3 > fontSizes
Definition: resources-image.h:140