Loading...
Searching...
No Matches
Accumulator.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 ACCUMULATOR_H_
32#define ACCUMULATOR_H_
33
34#include <drain/image/CoordinatePolicy.h>
35#include <limits>
36#include <math.h>
37
38#include <stdexcept>
39
40#include "drain/util/Point.h"
41#include "drain/util/Rectangle.h"
42
43#include "ImageT.h"
44#include "AccumulationArray.h"
45#include "AccumulationMethods.h"
46#include "AccumulationConverter.h"
47
48
49
50// TODO: image/
54namespace drain
55{
56
57namespace image
58{
59
60
61
62
63// New
75//class Accumulator : public AccumulationArray {
77public:
78
84 enum FieldType {
85 DATA_SPECIFIC = 32, // Ascii bit for lower-case chars, see below
86 QUALITY = 256, // Marker for non-data
87 DATA = 'd', // Main data, of named quantity
88 WEIGHT = 'w'|QUALITY, // Quality
89 COUNT = 'c'|QUALITY, // Number of samples
90 DEVIATION = 's'|QUALITY, // Separation: std.dev or difference
91 WEIGHT_DS = 'W'|QUALITY, // Quality
92 COUNT_DS = 'C'|QUALITY, // Number of samples
93 DEVIATION_DS = 'S'|QUALITY // Separation
94 };
95
96 typedef std::list<FieldType> FieldList;
97
98 // Deprecating?
99 inline static
100 char getFieldChar(FieldType field){
101 return static_cast<char>(field & 127);
102 }
103
104 static
105 FieldType getField(char field);
106
107 inline static
108 bool isQuality(FieldType field){
109 return (field & QUALITY) != 0;
110 }
111
113 inline static
115 return (field & DATA_SPECIFIC) != 0;
116 }
117
118 static
119 void getFields(const std::string & fieldStr, FieldList & fieldList);
120
121 static
122 void createFieldList(const std::string & fieldChars, FieldList & fieldList);
123
124
126 static
127 const dict_t dict;
128
131
132 inline
133 Accumulator() : methodPtr(&undefinedMethod) {
134
136 /*
137 addMethod(overwriteMethod);
138 addMethod(maximumMethod);
139 addMethod(minimumMethod);
140 addMethod(averageMethod);
141 addMethod(weightedAverageMethod);
142 addMethod(maximumWeightMethod);
143 */
144 // setMethod(_overwriteMethod);
145
146 };
147
148 inline
149 Accumulator(const Accumulator & acc) : methodPtr(&undefinedMethod) {
150 setMethod(acc.getMethod()); // if unset, sets unset... ie. default method.
151 accArray.setGeometry(acc.accArray.getGeometry());
152 }
153
154
155 virtual inline
156 ~Accumulator(){};
157
159 void setMethod(const std::string & method);
160
162 void setMethod(const std::string & name, const std::string & params);
163
165
168 inline
169 void setMethod(const AccumulationMethod & method){
170 setMethod(method.getName(), method.getParameters().getValues());
171 }
172
173 inline
174 bool isMethodSet() const {
175 return (methodPtr != & undefinedMethod);
176 }
177
178 inline
179 const AccumulationMethod & getMethod() const {
180 return *methodPtr;
181 }
182
183 inline
184 AccumulationMethod & getMethod() {
185 return *methodPtr;
186 }
187
188 /*
189 void addMethod(AccumulationMethod & method){
190 // std::cerr << "addMethod:" << method.name << '\t' << method << '\n';
191 methods.insert(std::pair<std::string, AccumulationMethod &>(method.getName(), method));
192 }
193 */
194
196 inline
197 void add(const size_t i, double value, double weight) {
198 methodPtr->add(accArray, i, value, weight);
199 }
200
202 inline
203 void add(const size_t i, double value, double weight, unsigned int count) {
204 methodPtr->add(accArray, i, value, weight, count);
205 }
206
207
208
210
213 void addData(const Image & src, const AccumulationConverter & converter, double weight = 1.0, int iOffset=0, int jOffset=0);
214
216
220 void addData(const Image & src, const Image & srcQuality, const AccumulationConverter & converter, double weight = 1.0, int iOffset=0, int jOffset=0);
221
222
224
231 void addData(const Image & src, const Image & srcQuality, const Image & srcCount, const AccumulationConverter & converter);
232 // Could be easily added: ... double weight = 1.0, int iOffset=0, int jOffset=0
233
235
244 inline
245 void extractField(char field, const AccumulationConverter & converter, Image & dst, const drain::Rectangle<int> & crop) const {
246 extractField(getField(field), converter, dst, crop);
247 }
248
249 void extractField(FieldType field, const AccumulationConverter & converter, Image & dst, const drain::Rectangle<int> & crop) const;
250 /*
251 {
252 extractField(getFieldChar(field), converter, dst, crop);
253 }
254 */
255
256
257 virtual
258 std::ostream & toStream(std::ostream & ostr) const;
259
260public:
261
263 // std::map<std::string, AccumulationMethod &> methods;
264
265protected:
266
268
269 /*
270 AccumulationMethod undefinedMethod;
271 OverwriteMethod overwriteMethod;
272 MaximumMethod maximumMethod;
273 MinimumMethod minimumMethod;
274 AverageMethod averageMethod;
275 WeightedAverageMethod weightedAverageMethod;
276 MaximumWeightMethod maximumWeightMethod;
277 */
278
279 AccumulationMethod * methodPtr;
280
281 // Initialize destination image to match the accumulation array - cropped if requested.
282 /*
283 * \param dst – destination image to be cropped if cropArea supplied
284 * \param cropArea – sub-area of the accumulation array; empty if no cropping requested.
285 *
286 * If cropArea geometry equals that of the accumulation array, it will be cleared and discarded in processing.
287 *
288 */
289 void initDst(const AccumulationConverter & coder, Image & dst, drain::Rectangle<int> & cropArea) const;
290
291
292};
293
294inline
295std::ostream & operator<<(std::ostream &ostr, const Accumulator & accumulator){
296 return accumulator.Accumulator::toStream(ostr);
297}
298
299
300} // image::
301
302} // drain::
303
304#endif /* Cumulator_H_ */
305
306// Drain
virtual const std::string & getName() const
Return the name of an instance.
Definition BeanLike.h:82
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
void getValues(std::ostream &ostr) const
Dumps the values.
Definition SmartMap.h:353
General-purpose image compositing.
Definition AccumulationArray.h:112
virtual void setGeometry(size_t width, size_t height)
Changes the geometry of all the layers.
Definition AccumulationArray.cpp:47
Function for accumulating data: maximum, average, weighted average etc.
Definition AccumulationMethods.h:65
virtual void add(AccumulationArray &accArray, const size_t i, double value, double weight) const
Adds a weighted value to the accumulation array.
Definition AccumulationMethods.h:92
Definition Accumulator.h:76
void setMethod(const AccumulationMethod &method)
Copies the method and its parameters.
Definition Accumulator.h:169
static bool isSpecific(FieldType field)
Future option to mark scaled/normalized etc.
Definition Accumulator.h:114
static void createFieldList(const std::string &fieldChars, FieldList &fieldList)
Definition Accumulator.cpp:78
void add(const size_t i, double value, double weight, unsigned int count)
Adds decoded data that applies natural scaling.
Definition Accumulator.h:203
void extractField(char field, const AccumulationConverter &converter, Image &dst, const drain::Rectangle< int > &crop) const
Extracts the accumulated quantity or secondary quantities like weight and standard deviation.
Definition Accumulator.h:245
FieldType
Definition Accumulator.h:84
void setMethod(const std::string &method)
Set method to some of the predefined methods.
Definition Accumulator.cpp:193
Accumulator()
Definition Accumulator.h:133
void add(const size_t i, double value, double weight)
Adds decoded data that applies natural scaling.
Definition Accumulator.h:197
AccumulationArray accArray
Todo: export.
Definition Accumulator.h:130
void addData(const Image &src, const AccumulationConverter &converter, double weight=1.0, int iOffset=0, int jOffset=0)
Add (accumulate) data with given prior weight.
Definition Accumulator.cpp:211
AccumulationMethod undefinedMethod
A Some predefined methods, that can be set with setMethod(const std::string & key).
Definition Accumulator.h:267
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Definition DataSelector.cpp:1277
Rectange defined through lower left and upper right coordinates.
Definition Rectangle.h:65
Converts raw data to values appropriate for accumulation.
Definition AccumulationConverter.h:50