Loading...
Searching...
No Matches
fileio-read.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#ifndef RACK_FILE_IO_READ
33#define RACK_FILE_IO_READ
34
35//#include <drain/prog/CommandRegistry.h>
36#include <drain/prog/CommandInstaller.h>
37#include <hi5/Hi5Read.h>
38
39//#include "data/Quantity.h"
40
41#include "resources.h"
42
43namespace rack {
44
45
47/*
48class CmdInputSelect : public drain::BasicCommand {
49
50public:
51
52 CmdInputSelect() : drain::BasicCommand(__FUNCTION__, "Read ATTRIBUTES (1), DATA(2) or both (3)."){
53 //, "value", hi5::Reader::ATTRIBUTES|hi5::Reader::DATASETS, "flag"){};
54 getParameters().link("value", getResources().inputSelect = hi5::Reader::ATTRIBUTES|hi5::Reader::DATASETS, "flag");
55 }
56
57};
58*/
59
61
65class CmdInputPrefix : public drain::SimpleCommand<std::string> {
66
67public:
68
69 inline
70 CmdInputPrefix() : drain::SimpleCommand<std::string>(__FUNCTION__, "Path prefix for input files."){
71 //RackContext & ctx = getContext<RackContext>(); // DO NOT LINK, dynamic context!
72 //getParameters().link("path", getResources().inputPrefix = "");
73 };
74
75 inline
76 void exec() const {
77 getContext<RackContext>().inputPrefix = value;
78 }
79};
80
81
82
84
90class CmdInputFile : public drain::SimpleCommand<std::string> {
91
92public:
93
94 inline
95 CmdInputFile() : drain::SimpleCommand<std::string>(__FUNCTION__, "Read HDF5, text or image file",
96 "filename", "", "<filename>.[h5|hdf5|png|pgm|ppm|txt]"){ //, inputComplete(true) {
97 //execRoutine = true;
98 //this->section = drain::Static::get<drain::GeneralSection>().index | drain::Static::get<drain::TriggerSection>().index
99 };
100
101
102 //mutable bool inputComplete;
103
104 // Essentially calls readFile
105 void exec() const;
106
107 // Called by exec, allowing recursion (esp. by readListFile)
108 void readFile(const std::string & fileName) const;
109
110protected:
111
112 void readFileH5(const std::string & fullFilename) const;
113 void readListFile(const std::string & fullFilename) const;
114 void readTextFile(const std::string & fullFilename) const;
115 void readImageFile(const std::string & fullFilename) const;
116
117 //void readFileAndAppendH5(const std::string & fullFilename) const;
118
119 void appendCartesianH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
120 void attachCartesianH5(Hi5Tree & srcRoot, Hi5Tree & dstRoot) const;
121
122 void appendPolarH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
123 //void appendPolarH5OLD(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
124
125 typedef std::map<std::string, ODIMPathElem> quantity_map;
126
127 void updateData(Hi5Tree & srcData, const std::string & srcKey, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
128 // void updateDataNEW(Hi5Tree & srcData, const ODIMPathElem & srcElem, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
129
130
131 void updateQuality(Hi5Tree & srcData, Hi5Tree & dstData) const;
132
133
134 template <class OD> // const drain::VariableMap & rootProperties,
135 void deriveImageODIM( const drain::image::Image &srcImage,
136 OD & odim) const {
137 // See also EncodingODIM copyFro
138 const drain::image::Geometry & g = srcImage.getGeometry();
139 odim.setGeometry(g.getWidth(), g.getHeight());
140 odim.type = drain::Type::getTypeChar(srcImage.getType());
141 //odim.updateFromMap(rootProperties);
142 odim.updateFromMap(srcImage.properties);
143 if (odim.scaling.scale == 0){
144 if (!odim.quantity.empty())
145 getQuantityMap().setQuantityDefaults(odim, odim.quantity);
146 }
147
148 //odim.copyToData(dst);
149
150 }
151
152};
153
154
155
157
161class CmdInputSelect : public drain::SimpleCommand<std::string> {
162
163public:
164
165 inline
166 CmdInputSelect() : drain::SimpleCommand<std::string>(__FUNCTION__, "Selector for input data."){
167 };
168
169 inline
170 void exec() const {
171 getContext<RackContext>().inputSelect = value;
172 }
173};
174
175
176} // rack
177
178
179
180/*
181template <class OD>
182void CmdInputFile::deriveImageODIM(){
183}
184*/
185
186#endif
187
188// Rack
A single-parameter command.
Definition Command.h:448
Definition Geometry.h:145
FlexVariableMap properties
Container for user-defined KEY=VALUE metadata.
Definition ImageFrame.h:369
const std::type_info & getType() const
Get the storage type.
Definition ImageLike.h:100
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:184
Input HDF5, PNG or text file.
Definition fileio-read.h:90
void appendPolarH5(Hi5Tree &tmpSrc, Hi5Tree &dst) const
Add DATASET groups of srcRoot to dstRoot.
Definition fileio-read.cpp:459
void attachCartesianH5(Hi5Tree &srcRoot, Hi5Tree &dstRoot) const
Definition fileio-read.cpp:418
void exec() const
Run the command with current parameter values.
Definition fileio-read.cpp:57
void readFileH5(const std::string &fullFilename) const
Reads hdf5 file and appends it to H5 structure. Works only with sweeps (SCAN), volume (PVOL) or Carte...
Definition fileio-read.cpp:172
void readImageFile(const std::string &fullFilename) const
Definition fileio-read.cpp:980
A debugging facility. Obsolete?
Definition fileio-read.h:65
void exec() const
Run the command with current parameter values.
Definition fileio-read.h:76
Data selector for subsequent input files.
Definition fileio-read.h:161
void exec() const
Run the command with current parameter values.
Definition fileio-read.h:170
bool setQuantityDefaults(EncodingODIM &dst, const std::string &quantity, const std::string &values="") const
Sets default values of given quantity without assigning the quantity. Optionally overrides with user ...
Definition QuantityMap.cpp:207
Definition DataSelector.cpp:44
QuantityMap & getQuantityMap()
Definition QuantityMap.cpp:279