Loading...
Searching...
No Matches
DataCoder.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#ifndef RACK_DataCoder
32#define RACK_DataCoder
33
34
35//
36//#include <drain/util/Rectangle.h>
37#include <drain/Type.h>
38#include <drain/image/AccumulationConverter.h>
39#include "hi5/Hi5.h"
40#include "data/ODIM.h"
41#include "Data.h"
42#include "DataSelector.h"
43#include "QuantityMap.h"
44//#include "Coordinates.h"
45
46
47namespace rack {
48
49using namespace drain::image;
50
51
52
53
55
62
63public:
64
65 DataCoder() : BeanLike(__FUNCTION__), defaultQuality(0.5),
66 dataODIM(defaultDataODIM), qualityODIM(defaultQualityODIM) {
67 init();
68 };
69
71 DataCoder(const ODIM & dataODIM) : BeanLike(__FUNCTION__), defaultQuality(0.5),
72 dataODIM(dataODIM), qualityODIM(defaultQualityODIM) {
73 init();
74 const QuantityMap & qm = getQuantityMap();
75 qm.setQuantityDefaults(defaultQualityODIM, "QIND", "C");
76 };
77
78 DataCoder(const ODIM & dataODIM, const ODIM & qualityODIM) : BeanLike(__FUNCTION__), defaultQuality(0.5),
79 dataODIM(dataODIM), qualityODIM(qualityODIM) {
80 init();
81 };
82
83 DataCoder(const DataCoder & converter) : BeanLike(__FUNCTION__), defaultQuality(converter.defaultQuality),
84 dataODIM(defaultDataODIM), qualityODIM(defaultQualityODIM) {
85 defaultDataODIM = converter.dataODIM;
86 defaultQualityODIM = converter.qualityODIM;
87 init();
88 };
89
90 virtual
91 ~DataCoder(){};
92
93 virtual
94 double getNoReadingMarker() const override {
95 return dataODIM.undetect;
96 }
97
99 virtual inline
100 double getNoDataMarker() const override {
101 return dataODIM.nodata;
102 }
103
105 virtual inline
106 double getWeightNoDataMarker() const override {
107 return qualityODIM.nodata;
108 }
109
110
111 virtual
112 bool decode(double & value) const override;
113
115 virtual
116 bool decode(double & value, double & weight) const override;
117
119
122 virtual
123 void encode(double & value, double & weight) const override;
124
125 virtual
126 void encodeWeight(double & weight) const override;
127
128 virtual
129 void encodeDiff(double & diff) const override;
130 /*
131 virtual inline
132 void encodeDiff(double & diff) const {
133 diff = qualityODIM.scaleInverse(diff);
134 };
135 */
136
138
144 void init();
145
146 /*
147 inline
148 double setLimits(){
149 dataODIM
150 }
151 double minValue;
152 double maxValue;
153 */
154
157
159
165
166 bool SKIP_UNDETECT;
167
169 static double undetectQualityCoeff;
170
171 const ODIM & dataODIM;
172 const ODIM & qualityODIM;
173
174 ODIM defaultDataODIM;
175 ODIM defaultQualityODIM;
176
177 /*
178 virtual inline
179 void toOStream(std::ostream & ostr) const {
180 ostr << getName() << ':' << parameters.toStr() << '\n';
181 //ostr << "DataConverter defaultQuality=" << defaultQuality << ", minDetectableValue=" << undetectValue << ", undetectQualityCoeff=" << undetectQualityCoeff << ", \n";
182 ostr << "\t data: " << EncodingODIM(dataODIM) << '\n';
183 ostr << "\t q: " << EncodingODIM(qualityODIM) << '\n';
184 //return ostr;
185 }
186 */
187
188
189protected:
190
193
194
196
200
201};
202
203
204inline
205std::ostream & operator<<(std::ostream & ostr, const DataCoder & coder) {
206 ostr << coder.getName() << ':' << coder.getParameters() << '\n';
207 //ostr << "DataConverter defaultQuality=" << defaultQuality << ", minDetectableValue=" << undetectValue << ", undetectQualityCoeff=" << undetectQualityCoeff << ", \n";
208 ostr << "\t data: " << EncodingODIM(coder.dataODIM) << '\n';
209 ostr << "\t q: " << EncodingODIM(coder.qualityODIM) << '\n';
210 return ostr;
211}
212
213
214} // rack::
215
216#endif
217
218// Rack
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:60
virtual const std::string & getName() const
Return the name of an instance.
Definition BeanLike.h:82
Converts ODIM encoded data (with markers) to natural values and backwards.
Definition DataCoder.h:61
void init()
Creates a naive quality field: data=1.0, undetect/nodata=0.0.
Definition DataCoder.cpp:49
static double undetectQualityCoeff
Quality, relative to data quality, applied in locations marked with undetect .
Definition DataCoder.h:169
DataCoder(const ODIM &dataODIM)
Without quality (with impicit quality)
Definition DataCoder.h:71
virtual bool decode(double &value) const override
Converts storage data containing marker codes etc to natural scale.
Definition DataCoder.cpp:94
virtual void encode(double &value, double &weight) const override
Converts natural-scale data to storage data containing marker codes etc.
Definition DataCoder.cpp:135
double undetectValue
Physical value applied in locations marked with undetect . This should be compatible with the quantit...
Definition DataCoder.h:164
virtual double getNoDataMarker() const override
NEW, untested...
Definition DataCoder.h:100
virtual void encodeWeight(double &weight) const override
Converts natural-scale data to storage data, applying marker codes if needed.
Definition DataCoder.cpp:152
double minCodeValue
In extraction (encoding), values lower than this value will be marked undetect .
Definition DataCoder.h:192
virtual void encodeDiff(double &diff) const override
When using unsigned types, encoding typically requires adding a positive bias and scaling the data.
Definition DataCoder.cpp:157
double detectionThreshold
A physical value greater than undetectValue. In \i encoding, lower values will be marked undetect ....
Definition DataCoder.h:199
virtual double getWeightNoDataMarker() const override
NEW, untested...
Definition DataCoder.h:106
virtual double getNoReadingMarker() const override
Returns a marker value which indicates that although data has been measured, it is not within require...
Definition DataCoder.h:94
double defaultQuality
If source data has no quality field, this value is applied for (detected) data.
Definition DataCoder.h:156
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:75
double nodata
data[n]/what (obligatory)
Definition EncodingODIM.h:157
ODIM metadata (quantity, gain, offset, undetect, nodata, date, time)
Definition ODIM.h:79
Definition QuantityMap.h:50
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
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition DataSelector.cpp:44
QuantityMap & getQuantityMap()
Definition QuantityMap.cpp:279
Converts raw data to values appropriate for accumulation.
Definition AccumulationConverter.h:50