Loading...
Searching...
No Matches
resources.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_H_
34#define RACK_RESOURCES_H_
35
36#include <string>
37
38#include <drain/RegExp.h>
39#include <drain/image/Image.h>
40#include <drain/imageops/ImageModifierPack.h>
41// #include <drain/imageops/PaletteOp.h>
42#include <drain/prog/CommandBankUtils.h>
43#include <drain/util/Rectangle.h>
44#include <drain/util/StatusFlags.h>
45#include <drain/util/TreeOrdered.h>
46//#include <drain/util/Variable.h>
47
48#include "hi5/Hi5.h"
49#include "hi5/Hi5Read.h"
50#include "data/DataSelector.h"
51#include "data/PolarODIM.h"
52#include "data/ProductConf.h"
53#include "data/VariableFormatterODIM.h"
54#include "radar/Composite.h"
55#include "radar/PolarSector.h"
56#include "radar/RadarAccumulator.h"
57
58#include "resources-image.h"
59#include "resources-base.h"
60
61#include "resources-svg.h"
62
63namespace rack {
64
65
67
70class RackContext : public ProductConf, public drain::SmartContext, public GraphicsContext, public ImageContext, public AndreContext, public Hdf5Context {
71
72public:
73
74
75
78
81
82 virtual
83 ~RackContext(){};
84
85
86 virtual
87 drain::image::TreeSVG & getStackedGroup() final override;
88
89 static
90 RackContext & getSharedContext(){
92 }
93
94 // Consider validVariableRE as general init parameter?
95 static
97
98 std::string getFormattedStatus(const std::string & s) const;
99
100 // DataSelector superSelector;
101
102 //static
103 //const drain::RegExp variableMapperSyntax;inputFilter
104 //drain::SingleFlagger<Reader::Mode>
105 // drain::SingleFlagger<hi5::Reader::Mode>
106 hi5::Reader::ModeFlagger inputFilter;
107
109 std::string inputPrefix;
110
112 std::string outputPrefix;
113
115 void resolveFilePath(const std::string & prefix, const std::string & filePath, std::string & finalFilePath);
116
117 PolarSelector polarSelector;
118
119
120 // Accumulator for data in Cartesian coordinates
121 Composite composite;
122
123 // Experimental
124 bool guessDatasetGroup(const Hi5Tree & src, ODIMPathElem & pathElem) const;
125
126 bool guessDatasetGroup(ODIMPathElem & pathElem){
127 Hi5Tree & src = getHi5(CURRENT);
128 return guessDatasetGroup(src, pathElem);
129 }
130
131
132
137 //inline
138 //Hi5Tree & getHi5(h5_role::value_t filter);
139 // return getHi5Full(filter);
140 // }
141
143
148 // template <typename T, typename ...TT>
149 // Hi5Tree & getHi5(const T &filter, const TT &... filters){
150 template <typename ...TT>
151 Hi5Tree & getHi5(const Hi5RoleFlagger::ivalue_t &filter, const TT &... filters){
152
153 Hi5RoleFlagger::ivalue_t f(filter);
154 // Hi5Tree & dst = getHi5Full(f);
155 if (f != 0){
156 // return dst;
157 // Hi5Tree & dst = getHi5Full(f);
158 // return getHi5Full(f);
159 Hi5Tree & dst = getHi5Full(f);
160 if (!dst.empty()){
161 return dst;
162 }
163 }
164 //else {
165 return getHi5(filters...);
166 //}
167 }
168
169
170
171 //Hi5Tree & getHi5Full(h5_role::ivalue_t & filter);
172 Hi5Tree & getHi5Full(Hi5RoleFlagger::ivalue_t filter);
173
174 inline
175 Hi5Tree & getHi5(){
176 return empty; // or current?
177 }
178
185 Composite & getComposite(Hi5RoleFlagger::ivalue_t filter);
186
187
188 // Experimental
189 // ODIMPath currentPath;
190
192 //static
193 ODIMPath findImage(const DataSelector & imageSelector);
194
195 // static
196 ODIMPath findImage();
197
199 // sstatic
200 const drain::image::Image & getCurrentGrayImage(); //RackContext & ctx);
201
203 const drain::image::Image & getCurrentImage(); //RackContext & ctx);
204
205
207
211 const drain::image::Image & updateCurrentImage(); //RackContext & ctx);
212
214 drain::image::Image & getModifiableImage(); // (RackContext & ctx); // const DataSelector & selector
215
216 void convertGrayImage(const drain::image::Image & srcImage); // RackContext & ctx,
217
218 /*
219 virtual inline
220 drain::VariableMap & getStatusMap(bool update=true){
221 if (update){
222 Context::updateStatus(); // check if this should be moved under this->updateStatus() ? So this function could be removed.
223 updateStatus();
224 }
225 return statusMap;
226 };
227 */
228
229 static
230 const VariableFormatterODIM<drain::Variable> variableFormatter;
231
232 static
233 const VariableFormatterODIM<drain::FlexibleVariable> flexVariableFormatter;
234
235//private:
236protected:
237
238 virtual
239 void updateStatus() const final;
240 // Keep this class-specific.
241 //void updateStatus();
242
243 // typedef drain::Cloner<Context,RackContext> ctx_cloner_t;
244
245 // EXPERIMENTAL
246 static inline
247 RackContext & baseCtx() {
248 //return getContextCloner().getSourceOrig();
249 return drain::Static::get<RackContext>();
250 }
251
252 /*
253 static inline
254 ctx_cloner_t & getContextCloner(){
255 return getCloner<RackContext>();
256 }
257 */
258
259};
260
262
265class RackResources : public drain::SuperContextual<RackContext> {
266
267public:
268
269 RackResources(); // : inputOk(true), dataOk(true), currentHi5(&inputHi5), currentPolarHi5(&inputHi5), currentImage(NULL), currentGrayImage(NULL) {};
270
271 // Accumulator for data in polar coordinates
273
274
275};
276
279
280
281
282
283} /* namespace rack */
284
285#endif /* RACKLET_H_ */
286
287// Rack
Definition Context.h:220
Definition StringMapper.h:114
Adds class-specific convenience functions.
Definition Context.h:335
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
Definition resources-base.h:54
Cartesian composite (mosaic) of data from several radars.
Definition Composite.h:102
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Definition resources-svg.h:105
Definition resources-base.h:74
Definition resources-image.h:63
DOC: Add class description.
Definition ODIMPath.h:82
Shared properties for meteorological products and Cartesian products (composites and single-radar ima...
Definition ProductConf.h:63
Resources provided separately for each thread.
Definition resources.h:70
static const drain::StringMapper variableMapper
Definition resources.h:96
Composite & getComposite(Hi5RoleFlagger::ivalue_t filter)
Definition resources.cpp:239
drain::image::Image & getModifiableImage()
Return current image, if modifiable. Else, copy (convert).
Definition resources.cpp:512
const drain::image::Image & getCurrentGrayImage()
Light and lazy.
Definition resources.cpp:278
RackContext()
Initializes data and image pointers to default targets or NULL.
Definition resources.cpp:42
const drain::image::Image & getCurrentImage()
Light and lazy.
Definition resources.cpp:296
Hi5RoleFlagger inputFlags
Definition resources.h:142
std::string inputPrefix
Path prefix for input files. Move to resources?
Definition resources.h:109
virtual void updateStatus() const final
Definition resources.cpp:594
void convertGrayImage(const drain::image::Image &srcImage)
Definition resources.cpp:476
Hi5Tree & getHi5(const Hi5RoleFlagger::ivalue_t &filter, const TT &... filters)
Definition resources.h:151
const drain::image::Image & updateCurrentImage()
Ensures current image.
Definition resources.cpp:416
void resolveFilePath(const std::string &prefix, const std::string &filePath, std::string &finalFilePath)
Add prefix, unless filePath starts with a slash '/'.
Definition resources.cpp:106
std::string outputPrefix
Path prefix for output files. Move to resources?
Definition resources.h:112
A container for shared resources applied by RackLets.
Definition resources.h:265
Definition AltitudeOp.cpp:42
RackResources & getResources()
Default instance.
Definition resources.cpp:647
Definition PolarSector.h:109