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-base.h"
59
60namespace rack {
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
111 PolarSelector polarSelector;
112
113
114 // Accumulator for data in Cartesian coordinates
115 Composite composite;
116
117 // Experimental
118 bool guessDatasetGroup(const Hi5Tree & src, ODIMPathElem & pathElem) const;
119
120 bool guessDatasetGroup(ODIMPathElem & pathElem){
121 Hi5Tree & src = getHi5(CURRENT);
122 return guessDatasetGroup(src, pathElem);
123 }
124
125
126
131 //inline
132 //Hi5Tree & getHi5(h5_role::value_t filter);
133 // return getHi5Full(filter);
134 // }
135
137
142 // template <typename T, typename ...TT>
143 // Hi5Tree & getHi5(const T &filter, const TT &... filters){
144 template <typename ...TT>
145 Hi5Tree & getHi5(const Hi5RoleFlagger::ivalue_t &filter, const TT &... filters){
146
147 Hi5RoleFlagger::ivalue_t f(filter);
148 // Hi5Tree & dst = getHi5Full(f);
149 if (f != 0){
150 // return dst;
151 // Hi5Tree & dst = getHi5Full(f);
152 return getHi5Full(f);
153 }
154 else
155 return getHi5(filters...);
156 }
157
158
159
160 //Hi5Tree & getHi5Full(h5_role::ivalue_t & filter);
161 Hi5Tree & getHi5Full(Hi5RoleFlagger::ivalue_t filter);
162
163 inline
164 Hi5Tree & getHi5(){
165 return empty; // or current?
166 }
167
174 Composite & getComposite(Hi5RoleFlagger::ivalue_t filter);
175
176
177 // Experimental
178 // ODIMPath currentPath;
179
181 //static
182 ODIMPath findImage(const DataSelector & imageSelector);
183
184 // static
185 ODIMPath findImage();
186
188 // sstatic
189 const drain::image::Image & getCurrentGrayImage(); //RackContext & ctx);
190
192 const drain::image::Image & getCurrentImage(); //RackContext & ctx);
193
194
196
200 const drain::image::Image & updateCurrentImage(); //RackContext & ctx);
201
203 drain::image::Image & getModifiableImage(); // (RackContext & ctx); // const DataSelector & selector
204
205 void convertGrayImage(const drain::image::Image & srcImage); // RackContext & ctx,
206
207 /*
208 virtual inline
209 drain::VariableMap & getStatusMap(bool update=true){
210 if (update){
211 Context::updateStatus(); // check if this should be moved under this->updateStatus() ? So this function could be removed.
212 updateStatus();
213 }
214 return statusMap;
215 };
216 */
217
218 static
219 const VariableFormatterODIM<drain::Variable> variableFormatter;
220
221 static
222 const VariableFormatterODIM<drain::FlexibleVariable> flexVariableFormatter;
223
224//private:
225protected:
226
227 virtual
228 void updateStatus() const final;
229 // Keep this class-specific.
230 //void updateStatus();
231
232 // typedef drain::Cloner<Context,RackContext> ctx_cloner_t;
233
234 // EXPERIMENTAL
235 static inline
236 RackContext & baseCtx() {
237 //return getContextCloner().getSourceOrig();
238 return drain::Static::get<RackContext>();
239 }
240
241 /*
242 static inline
243 ctx_cloner_t & getContextCloner(){
244 return getCloner<RackContext>();
245 }
246 */
247
248};
249
251
254class RackResources : public drain::SuperContextual<RackContext> {
255
256public:
257
258 RackResources(); // : inputOk(true), dataOk(true), currentHi5(&inputHi5), currentPolarHi5(&inputHi5), currentImage(NULL), currentGrayImage(NULL) {};
259
260 // Accumulator for data in polar coordinates
262
263
264};
265
268
269
270
271
272} /* namespace rack */
273
274#endif /* RACKLET_H_ */
275
276// Rack
Definition Context.h:208
A tool for expanding variables embedded in a std::string to literals.
Definition StringMapper.h:275
Adds class-specific convenience functions.
Definition Context.h:322
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Definition resources-base.h:54
Cartesian composite (mosaic) of data from several radars.
Definition Composite.h:102
Definition resources-image.h:107
Definition resources-base.h:74
Definition resources-image.h:143
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
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
Hi5RoleFlagger inputFlags
Definition resources.h:136
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
Hi5Tree & getHi5(const Hi5RoleFlagger::ivalue_t &filter, const TT &... filters)
Definition resources.h:145
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:254
Data array for creating composites and accumulated polar products (Surface rain fall or cluttermaps)
Definition RadarAccumulator.h:122
Definition DataSelector.cpp:44
RackResources & getResources()
Default instance.
Definition resources.cpp:604
Definition PolarSector.h:110