Loading...
Searching...
No Matches
resources-image.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
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
48#include "data/QuantityMap.h"
49#include "data/VariableFormatterODIM.h"
50
51
52namespace rack {
53
54
55//using namespace drain::image;
56
57enum SvgInclude {
58 NONE = 0,
59 PNG = 1, // Main title in SVG image
60 SVG = 2,
61 TXT = 4,
62 SKIP = 16,
63 NEXT = 32,
64 ON = 64,
65 OFF = 128,
66 ALL = ON|(PNG|SVG|TXT),
67 UNKNOWN = 255,
68 // --- unused ? ---
69 // TITLE, // Default title
70};
71
72
73/*
74enum TitleClass {
75 NONE = 0,
76 MAIN = 1, // Main title in SVG image
77 GROUP = 2,
78 IMAGE = 4, // Small title in a corner of radar image (time, location)
79 TIME = 8, // Date and time attributes
80 LOCATION = 16, // Place (coordinates, municipality)
81 GENERAL = 32, // Default type
82};
83*/
84
85
87
89 IncludeFlagger svgIncludes;
90
91 enum ElemClass {
92 NONE = 0,
93 MAIN_TITLE = 1, // Main title in SVG image
94 GROUP_TITLE = 2, // Group title
95 IMAGE = 4, // Image title: small text (time, location) in corners of radar images
96 TIME = 8, // Date and time attributes
97 LOCATION = 16, // Place (coordinates, municipality)
98 GENERAL = 32, // Default type
99 ALL = (63),
100 // MAIN,
101 IMAGE_PANEL,
102 IMAGE_BORDER, // RECT surrounding the image
103 SIDE_PANEL,
104 // SHARED_METADATA, // Something that should not be repeated in panels.
105 // --- unused ? ---
106 // TITLE, // Default title
107 };
109 TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
110
111 std::string imageTitle = "TIME,LOCATION,GENERAL";
112
113 enum PathPolicy {
114 ABSOLUTE = 1, // Else is relative, stripped away using inputPrefix?
115 PREFIXED = 2, // file:// is appended
116 };
117
120
121 PathPolicyFlagger pathPolicyFlagger = ABSOLUTE;
122 std::string pathPolicy = "ABSOLUTE";
123 // bool absolutePaths = true;
124
125 std::string mainTitle = "AUTO"; // redesign?
126 // std::string groupIdentifier = "AUTO"; // redesign?
127 std::string groupIdentifier = ""; // NEW
128 std::string groupTitle = "AUTO"; // NEW
129 // std::string groupTitleFormatted; dynamic, so better store in data-title attribute
130
131
132 /*
133 typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
134 TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
135 */
136
144
150
151 inline // maxPerGroup(10), layout(Alignment::HORZ, LayoutSVG::INCR), legend(LEFT, EMBED),
152 PanelConfSVG() : svgIncludes(SvgInclude::ALL), pathPolicyFlagger(PathPolicy::ABSOLUTE), pathPolicy("ABSOLUTE") { // absolutePaths(true){
153 }
154
155
156};
157
158}
159
160
161namespace drain {
162
163template <>
165DRAIN_ENUM_OSTREAM(rack::SvgInclude);
166
167template <>
169DRAIN_ENUM_OSTREAM(rack::PanelConfSVG::ElemClass);
170
171
172template <>
174DRAIN_ENUM_OSTREAM(rack::PanelConfSVG::PathPolicy);
175
176
177template <> // for T (Tree class)
178template <> // for K (path elem arg)
179bool image::TreeSVG::hasChild(const rack::PanelConfSVG::ElemClass & key) const ;
180
181
183
186template <> // for T (Tree class)
187template <> // for K (path elem arg)
188const image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & value) const;
189
190
191template <> // for T (Tree class)
192template <> // for K (path elem arg)
193image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key);
194
195/*
196template <> // for T (Tree class)
197template <> // for K (path elem arg)
198bool image::TreeSVG::hasChild(const rack::PanelConfSVG::ElemClass & key) const;
199
200
201template <> // for T (Tree class)
202template <> // for K (path elem arg)
203image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key);
204
205template <> // for T (Tree class)
206template <> // for K (path elem arg)
207const image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key) const;
208*/
209
210
211}
212
213// using namespace drain::image;
214
215
216namespace rack {
217
218using namespace drain::image;
219
220class GraphicsContext { // : public drain::BasicCommand {
221
222
223public:
224
225
226
229
231 GraphicsContext(const GraphicsContext & ctx);
232
233 TreeSVG svgTrack;
234
235 // SVG output configuration (layout)
236 PanelConfSVG svgPanelConf; // under constr
237
238 AlignBase::Axis mainOrientation = AlignBase::Axis::HORZ;
239 LayoutSVG::Direction mainDirection = LayoutSVG::Direction::INCR;
240
241 // Here AlignSVG::HorzAlign and AlignSVG::VertAlign unused, as they contain no Topol(ogy).
242 CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::HORZ> alignHorz = {AlignSVG::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
243 CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::VERT> alignVert = {AlignSVG::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
244
245 AlignAnchorSVG::anchor_t anchorHorz;
246 AlignAnchorSVG::anchor_t anchorVert;
247
248 int svgDebug = 0;
249
251
254 // drain::image::TreeSVG & getStyle();
255
257
261 // drain::image::TreeSVG & getMainGroup();
262
263 //drain::image::TreeSVG & getCurrentAlignedGroup();
264
265 // virtual
266 // std::string getFormattedStatus(const std::string & format) const = 0;
267
268 // drain::image::TreeSVG & getCurrentAlignedGroup();
269
270 // drain::image::TreeSVG & getImagePanelGroup(const drain::FilePath & filepath);
271
272 /*
273 typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
274 TitleFlagger svgTitles = ElemClass::NONE;
275 */
276 // std::string svgTitles = "";
277
279 // static
280 // void applyAlignment(drain::image::TreeSVG & group);
281
282};
283
284
285
286
287// Consider moving ImageKit here?
289public:
290
291
293 ImageContext();
294
296 ImageContext(const ImageContext & ctx);
297
300
302
308
309 // Accessed by CmdSampler
310 ImageSampler imageSampler;
311
312
313 inline
314 void setCurrentImageColor(const Image & src){
315 currentImage = &src;
316 }
317
318 inline
319 void setCurrentImages(const Image & src){
320 currentImage = &src;
321 currentGrayImage = &src;
322 }
323
324 inline
325 void unsetCurrentImages(){
326 currentImage = nullptr;
327 currentGrayImage = nullptr;
328 }
329
330 void getImageStatus(drain::FlexVariableMap & statusMap) const;
331
332
334 const Image *currentImage = nullptr; // = NULL;
335
337 const Image *currentGrayImage = nullptr; // = NULL; // data or grayImage
338
339
340 Image grayImage;
341 Image colorImage;
342
343 std::string paletteKey;
344
345
346 inline
347 Palette & getPalette(){
348 return PaletteOp::getPalette(paletteKey);
349 }
350
351 Palette & getPalette(const std::string & key);
352
353
355 static
356 void getImageInfo(const Image *ptr, drain::Variable & entry);
357
358
359
360 static std::string outputQuantitySyntax;
361
362//protected:
363
364 void updateImageStatus(drain::VariableMap & statusMap) const ;
365
366
367};
368
369
370
371
372
373
374
375
376} /* namespace rack */
377
378#endif /* RACKLET_H_ */
379
380// Rack
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
Default default value...
Definition EnumFlags.h:247
A map of FlexVariable:s.
Definition VariableMap.h:138
Tuple of N elements of type T.
Definition UniTuple.h:65
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:193
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:64
Definition resources-image.h:220
GraphicsContext()
Default constructor.
Definition resources-image.cpp:162
Definition resources-image.h:288
bool imagePhysical
Defines if the next image processing operation uses scaled intentsites instead of raw byte values.
Definition resources-image.h:299
const Image * currentImage
Pointer to the last 2D data (image) processed.
Definition resources-image.h:334
static void getImageInfo(const Image *ptr, drain::Variable &entry)
Given image pointer (null ok), get properties.
Definition resources-image.cpp:293
static std::string outputQuantitySyntax
Definition resources-image.h:360
ImageContext()
Default constr.
Definition resources-image.cpp:178
ODIMPathElem::group_t qualityGroups
Defines which quality data, if any, is used as input weight.
Definition resources-image.h:307
const Image * currentGrayImage
Pointer to the last single-channel 2D data (image) processed.
Definition resources-image.h:337
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
A container for a static dictionary of enumeration values.
Definition EnumFlags.h:69
Definition AlignAnchorSVG.h:76
"Alternative" partial alignment configuration for single object. Partial means that either OBJECT its...
Definition AlignSVG.h:553
Definition resources-image.h:86
drain::EnumFlagger< drain::MultiFlagger< PathPolicy > > PathPolicyFlagger
SVG file may contain several "modules", for example rows or columns of IMAGE:s. This is the name of t...
Definition resources-image.h:119
drain::UniTuple< double, 3 > boxHeights
Definition resources-image.h:149
drain::UniTuple< double, 3 > fontSizes
Definition resources-image.h:143