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/RadarAccumulator.h"
56
57#include "resources-base.h"
58
59namespace rack {
60
61
62
64
67class RackContext : public ProductConf, public drain::SmartContext, public GraphicsContext, public ImageContext, public AndreContext, public Hdf5Context {
68
69public:
70
71
72
75
77 RackContext(const RackContext & ctx);
78
79 virtual
80 ~RackContext(){};
81
82
83 static
84 RackContext & getSharedContext(){
86 }
87
88 // Consider validVariableRE as general init parameter?
89 static
91
92 std::string getFormattedStatus(const std::string & s) const;
93
94 // DataSelector superSelector;
95
96 //static
97 //const drain::RegExp variableMapperSyntax;inputFilter
98 //drain::SingleFlagger<Reader::Mode>
99 // drain::SingleFlagger<hi5::Reader::Mode>
100 hi5::Reader::ModeFlagger inputFilter;
101
103 std::string inputPrefix;
104
106 std::string outputPrefix;
107
109 void resolveFilePath(const std::string & prefix, const std::string & filePath, std::string & finalFilePath);
110
112 /*
113 std::string targetEncoding; // consider encodingRequest !
114 ODIMPathElem appendResults;
116 int outputDataVerbosity;
117 */
118
119 // Accumulator for data in Cartesian coordinates
121
122 // Experimental
123 bool guessDatasetGroup(const Hi5Tree & src, ODIMPathElem & pathElem) const;
124
125 bool guessDatasetGroup(ODIMPathElem & pathElem){
126 Hi5Tree & src = getHi5(CURRENT);
127 return guessDatasetGroup(src, pathElem);
128 }
129
130
131
136 //inline
137 //Hi5Tree & getHi5(h5_role::value_t filter);
138 // return getHi5Full(filter);
139 // }
140
142
147 template <typename T, typename ...TT>
148 Hi5Tree & getHi5(const T &filter, const TT &... filters){
149
150 T f(filter);
151 //Hi5Tree & dst = getHi5Full(f);
152 if (f != 0){
153 // return dst;
154 //Hi5Tree & dst = getHi5Full(f);
155 return getHi5Full(f);
156 }
157 else
158 return getHi5(filters...);
159 }
160
161
162
163 //Hi5Tree & getHi5Full(h5_role::ivalue_t & filter);
164 Hi5Tree & getHi5Full(Hi5RoleFlagger::ivalue_t filter);
165
166 inline
167 Hi5Tree & getHi5(){
168 return empty; // or current?
169 }
170
177 Composite & getComposite(Hi5RoleFlagger::ivalue_t filter);
178
179
180 // Experimental
181 // ODIMPath currentPath;
182
184 //static
185 ODIMPath findImage(const DataSelector & imageSelector);
186
187 // static
188 ODIMPath findImage();
189
191 // sstatic
192 const drain::image::Image & getCurrentGrayImage(); //RackContext & ctx);
193
195 const drain::image::Image & getCurrentImage(); //RackContext & ctx);
196
197
199
203 const drain::image::Image & updateCurrentImage(); //RackContext & ctx);
204
206 drain::image::Image & getModifiableImage(); // (RackContext & ctx); // const DataSelector & selector
207
208 void convertGrayImage(const drain::image::Image & srcImage); // RackContext & ctx,
209
210 /*
211 virtual inline
212 drain::VariableMap & getStatusMap(bool update=true){
213 if (update){
214 Context::updateStatus(); // check if this should be moved under this->updateStatus() ? So this function could be removed.
215 updateStatus();
216 }
217 return statusMap;
218 };
219 */
220
221 static
222 const VariableFormatterODIM<drain::Variable> variableFormatter;
223
224 static
225 const VariableFormatterODIM<drain::FlexibleVariable> flexVariableFormatter;
226
227//private:
228protected:
229
230 virtual
231 void updateStatus() const final;
232 // Keep this class-specific.
233 //void updateStatus();
234
235 // typedef drain::Cloner<Context,RackContext> ctx_cloner_t;
236
237 // EXPERIMENTAL
238 static inline
239 RackContext & baseCtx() {
240 //return getContextCloner().getSourceOrig();
241 return drain::Static::get<RackContext>();
242 }
243
244 /*
245 static inline
246 ctx_cloner_t & getContextCloner(){
247 return getCloner<RackContext>();
248 }
249 */
250
251};
252
254
257class RackResources : public drain::SuperContextual<RackContext> {
258
259public:
260
261 RackResources(); // : inputOk(true), dataOk(true), currentHi5(&inputHi5), currentPolarHi5(&inputHi5), currentImage(NULL), currentGrayImage(NULL) {};
262
263 // Accumulator for data in polar coordinates
265
266
267};
268
271
272
273
274
275} /* namespace rack */
276
277#endif /* RACKLET_H_ */
278
279// Rack
Definition Context.h:205
A tool for expanding variables embedded in a std::string to literals.
Definition StringMapper.h:275
Adds class-specific convenience functions.
Definition Context.h:319
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:184
Definition resources-base.h:54
Cartesian composite (mosaic) of data from several radars.
Definition Composite.h:102
Definition resources-image.h:218
Definition resources-base.h:74
Definition resources-image.h:283
Definition ODIMPath.h:82
Shared properties for meteorological products and Cartesian products (composites and single-radar ima...
Definition ProductConf.h:64
Resources provided separately for each thread.
Definition resources.h:67
static const drain::StringMapper variableMapper
Definition resources.h:90
Composite & getComposite(Hi5RoleFlagger::ivalue_t filter)
Definition resources.cpp:196
drain::image::Image & getModifiableImage()
Return current image, if modifiable. Else, copy (convert).
Definition resources.cpp:469
const drain::image::Image & getCurrentGrayImage()
Light and lazy.
Definition resources.cpp:235
Composite composite
TODO: inherit from ProductBase.
Definition resources.h:120
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:253
Hi5Tree & getHi5(const T &filter, const TT &... filters)
Definition resources.h:148
Hi5RoleFlagger inputFlags
Definition resources.h:141
std::string inputPrefix
Path prefix for input files. Move to resources?
Definition resources.h:103
virtual void updateStatus() const final
Definition resources.cpp:551
void convertGrayImage(const drain::image::Image &srcImage)
Definition resources.cpp:433
const drain::image::Image & updateCurrentImage()
Ensures current image.
Definition resources.cpp:373
void resolveFilePath(const std::string &prefix, const std::string &filePath, std::string &finalFilePath)
Add prefix, unless filePath starts with a slash '/'.
Definition resources.cpp:63
std::string outputPrefix
Path prefix for output files. Move to resources?
Definition resources.h:106
A container for shared resources applied by RackLets.
Definition resources.h:257
Data array for creating composites and accumulated polar products (Surface rain fall or cluttermaps)
Definition RadarAccumulator.h:61
Definition DataSelector.cpp:44
RackResources & getResources()
Default instance.
Definition resources.cpp:604