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 BORDER, // Overall image border
105 // SHARED_METADATA, // Something that should not be repeated in panels.
106 // --- unused ? ---
107 // TITLE, // Default title
108 };
110 TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
111
112 std::string imageTitle = "TIME,LOCATION,GENERAL";
113
114 enum PathPolicy {
115 ABSOLUTE = 1, // Else is relative, stripped away using inputPrefix?
116 PREFIXED = 2, // file:// is appended
117 };
118
121
122 PathPolicyFlagger pathPolicyFlagger = ABSOLUTE;
123 std::string pathPolicy = "ABSOLUTE";
124 // bool absolutePaths = true;
125
126 std::string mainTitle = "AUTO"; // redesign?
127 // std::string groupIdentifier = "AUTO"; // redesign?
128 std::string groupIdentifier = ""; // NEW
129 std::string groupTitle = "AUTO"; // NEW
130 // std::string groupTitleFormatted; dynamic, so better store in data-title attribute
131
132
133 /*
134 typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
135 TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
136 */
137
145
151
152 inline // maxPerGroup(10), layout(Alignment::HORZ, LayoutSVG::INCR), legend(LEFT, EMBED),
153 PanelConfSVG() : svgIncludes(SvgInclude::ALL), pathPolicyFlagger(PathPolicy::ABSOLUTE), pathPolicy("ABSOLUTE") { // absolutePaths(true){
154 }
155
156
157};
158
159}
160
161
162namespace drain {
163
164template <>
166DRAIN_ENUM_OSTREAM(rack::SvgInclude);
167
168template <>
170DRAIN_ENUM_OSTREAM(rack::PanelConfSVG::ElemClass);
171
172
173template <>
175DRAIN_ENUM_OSTREAM(rack::PanelConfSVG::PathPolicy);
176
177
178template <> // for T (Tree class)
179template <> // for K (path elem arg)
180bool image::TreeSVG::hasChild(const rack::PanelConfSVG::ElemClass & key) const ;
181
182
184
187template <> // for T (Tree class)
188template <> // for K (path elem arg)
189const image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & value) const;
190
191
192template <> // for T (Tree class)
193template <> // for K (path elem arg)
194image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key);
195
196/*
197template <> // for T (Tree class)
198template <> // for K (path elem arg)
199bool image::TreeSVG::hasChild(const rack::PanelConfSVG::ElemClass & key) const;
200
201
202template <> // for T (Tree class)
203template <> // for K (path elem arg)
204image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key);
205
206template <> // for T (Tree class)
207template <> // for K (path elem arg)
208const image::TreeSVG & image::TreeSVG::operator[](const rack::PanelConfSVG::ElemClass & key) const;
209*/
210
211
212}
213
214// using namespace drain::image;
215
216
217namespace rack {
218
219using namespace drain::image;
220
221class GraphicsContext { // : public drain::BasicCommand {
222
223
224public:
225
226
227
230
232 GraphicsContext(const GraphicsContext & ctx);
233
234 TreeSVG svgTrack;
235
236 // SVG output configuration (layout)
237 PanelConfSVG svgPanelConf; // under constr
238
239 AlignBase::Axis mainOrientation = AlignBase::Axis::HORZ;
240 LayoutSVG::Direction mainDirection = LayoutSVG::Direction::INCR;
241
242 // Here AlignSVG::HorzAlign and AlignSVG::VertAlign unused, as they contain no Topol(ogy).
243 CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::HORZ> alignHorz = {AlignSVG::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
244 CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::VERT> alignVert = {AlignSVG::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
245
246 AlignAnchorSVG::anchor_t anchorHorz;
247 AlignAnchorSVG::anchor_t anchorVert;
248
249 int svgDebug = 0;
250
252
255 // drain::image::TreeSVG & getStyle();
256
258
262 // drain::image::TreeSVG & getMainGroup();
263
264 //drain::image::TreeSVG & getCurrentAlignedGroup();
265
266 // virtual
267 // std::string getFormattedStatus(const std::string & format) const = 0;
268
269 // drain::image::TreeSVG & getCurrentAlignedGroup();
270
271 // drain::image::TreeSVG & getImagePanelGroup(const drain::FilePath & filepath);
272
273 /*
274 typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
275 TitleFlagger svgTitles = ElemClass::NONE;
276 */
277 // std::string svgTitles = "";
278
280 // static
281 // void applyAlignment(drain::image::TreeSVG & group);
282
283};
284
285
286
287
288// Consider moving ImageKit here?
290public:
291
292
294 ImageContext();
295
297 ImageContext(const ImageContext & ctx);
298
301
303
309
310 // Accessed by CmdSampler
311 ImageSampler imageSampler;
312
313
314 inline
315 void setCurrentImageColor(const Image & src){
316 currentImage = &src;
317 }
318
319 inline
320 void setCurrentImages(const Image & src){
321 currentImage = &src;
322 currentGrayImage = &src;
323 }
324
325 inline
326 void unsetCurrentImages(){
327 currentImage = nullptr;
328 currentGrayImage = nullptr;
329 }
330
331 void getImageStatus(drain::FlexVariableMap & statusMap) const;
332
333
335 const Image *currentImage = nullptr; // = NULL;
336
338 const Image *currentGrayImage = nullptr; // = NULL; // data or grayImage
339
340
341 Image grayImage;
342 Image colorImage;
343
344 std::string paletteKey;
345
346
347 inline
348 Palette & getPalette(){
349 return PaletteOp::getPalette(paletteKey);
350 }
351
352 Palette & getPalette(const std::string & key);
353
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
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:221
GraphicsContext()
Default constructor.
Definition resources-image.cpp:163
Definition resources-image.h:289
bool imagePhysical
Defines if the next image processing operation uses scaled intentsites instead of raw byte values.
Definition resources-image.h:300
const Image * currentImage
Pointer to the last 2D data (image) processed.
Definition resources-image.h:335
static void getImageInfo(const Image *ptr, drain::Variable &entry)
Given image pointer (null ok), get properties.
Definition resources-image.cpp:294
static std::string outputQuantitySyntax
Definition resources-image.h:361
ImageContext()
Default constr.
Definition resources-image.cpp:179
ODIMPathElem::group_t qualityGroups
Defines which quality data, if any, is used as input weight.
Definition resources-image.h:308
const Image * currentGrayImage
Pointer to the last single-channel 2D data (image) processed.
Definition resources-image.h:338
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:550
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:120
drain::UniTuple< double, 3 > boxHeights
Definition resources-image.h:150
drain::UniTuple< double, 3 > fontSizes
Definition resources-image.h:144