DataCoder.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 #ifndef DataCoder_H_
32 #define DataCoder_H_
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 
47 namespace rack {
48 
49 using namespace drain::image;
50 
51 
52 
53 
55 
62 
63 public:
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 
98  virtual
99  bool decode(double & value) const override;
100 
102  virtual
103  bool decode(double & value, double & weight) const override;
104 
106 
109  virtual
110  void encode(double & value, double & weight) const override;
111 
112  virtual
113  void encodeWeight(double & weight) const override;
114 
115  virtual
116  void encodeDiff(double & diff) const override;
117  /*
118  virtual inline
119  void encodeDiff(double & diff) const {
120  diff = qualityODIM.scaleInverse(diff);
121  };
122  */
123 
125 
131  void init();
132 
133  /*
134  inline
135  double setLimits(){
136  dataODIM
137  }
138  double minValue;
139  double maxValue;
140  */
141 
144 
146 
152 
153  bool SKIP_UNDETECT;
154 
156  static double undetectQualityCoeff;
157 
158  const ODIM & dataODIM;
159  const ODIM & qualityODIM;
160 
161  ODIM defaultDataODIM;
162  ODIM defaultQualityODIM;
163 
164  /*
165  virtual inline
166  void toOStream(std::ostream & ostr) const {
167  ostr << getName() << ':' << parameters.toStr() << '\n';
168  //ostr << "DataConverter defaultQuality=" << defaultQuality << ", minDetectableValue=" << undetectValue << ", undetectQualityCoeff=" << undetectQualityCoeff << ", \n";
169  ostr << "\t data: " << EncodingODIM(dataODIM) << '\n';
170  ostr << "\t q: " << EncodingODIM(qualityODIM) << '\n';
171  //return ostr;
172  }
173  */
174 
175 
176 protected:
177 
179  double minCodeValue;
180 
181 
183 
187 
188 };
189 
190 
191 inline
192 std::ostream & operator<<(std::ostream & ostr, const DataCoder & coder) {
193  ostr << coder.getName() << ':' << coder.getParameters() << '\n';
194  //ostr << "DataConverter defaultQuality=" << defaultQuality << ", minDetectableValue=" << undetectValue << ", undetectQualityCoeff=" << undetectQualityCoeff << ", \n";
195  ostr << "\t data: " << EncodingODIM(coder.dataODIM) << '\n';
196  ostr << "\t q: " << EncodingODIM(coder.qualityODIM) << '\n';
197  return ostr;
198 }
199 
200 
201 } // rack::
202 
203 #endif
204 
205 // 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:69
Converts ODIM encoded data (with markers) to natural values and backwards.
Definition: DataCoder.h:61
static double undetectQualityCoeff
Quality, relative to data quality, applied in locations marked with undetect .
Definition: DataCoder.h:156
DataCoder(const ODIM &dataODIM)
Without quality (with impicit quality)
Definition: DataCoder.h:71
double undetectValue
Physical value applied in locations marked with undetect . This should be compatible with the quantit...
Definition: DataCoder.h:151
double minCodeValue
In extraction (encoding), values lower than this value will be marked undetect .
Definition: DataCoder.h:179
double detectionThreshold
A physical value greater than undetectValue. In \i encoding, lower values will be marked undetect ....
Definition: DataCoder.h:186
double defaultQuality
If source data has no quality field, this value is applied for (detected) data.
Definition: DataCoder.h:143
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition: EncodingODIM.h:75
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 - but not the quantity itself. Optionally overrides with user v...
Definition: QuantityMap.cpp:398
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:44
Converts raw data to values appropriate for accumulation.
Definition: AccumulationConverter.h:50