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
81
82 inline
83 Accumulator() : methodPtr(&undefinedMethod) {
84
86 /*
87 addMethod(overwriteMethod);
88 addMethod(maximumMethod);
89 addMethod(minimumMethod);
90 addMethod(averageMethod);
91 addMethod(weightedAverageMethod);
92 addMethod(maximumWeightMethod);
93 */
94 // setMethod(_overwriteMethod);
95
96 };
97
98 inline
99 Accumulator(const Accumulator & acc) : methodPtr(&undefinedMethod) {
100 setMethod(acc.getMethod()); // if unset, sets unset... ie. default method.
101 accArray.setGeometry(acc.accArray.getGeometry());
102 }
103
104
105 virtual inline
106 ~Accumulator(){};
107
109 void setMethod(const std::string & method);
110
112 void setMethod(const std::string & name, const std::string & params);
113
115
118 inline
119 void setMethod(const AccumulationMethod & method){
120 setMethod(method.getName(), method.getParameters().getValues());
121 }
122
123 inline
124 bool isMethodSet() const {
125 return (methodPtr != & undefinedMethod);
126 }
127
128 inline
129 const AccumulationMethod & getMethod() const {
130 return *methodPtr;
131 }
132
133 inline
134 AccumulationMethod & getMethod() {
135 return *methodPtr;
136 }
137
138 /*
139 void addMethod(AccumulationMethod & method){
140 // std::cerr << "addMethod:" << method.name << '\t' << method << '\n';
141 methods.insert(std::pair<std::string, AccumulationMethod &>(method.getName(), method));
142 }
143 */
144
146 inline
147 void add(const size_t i, double value, double weight) {
148 methodPtr->add(accArray, i, value, weight);
149 }
150
152 inline
153 void add(const size_t i, double value, double weight, unsigned int count) {
154 methodPtr->add(accArray, i, value, weight, count);
155 }
156
157
158
160
163 void addData(const Image & src, const AccumulationConverter & converter, double weight = 1.0, int iOffset=0, int jOffset=0);
164
166
170 void addData(const Image & src, const Image & srcQuality, const AccumulationConverter & converter, double weight = 1.0, int iOffset=0, int jOffset=0);
171
172
174
181 void addData(const Image & src, const Image & srcQuality, const Image & srcCount, const AccumulationConverter & converter);
182 // Could be easily added: ... double weight = 1.0, int iOffset=0, int jOffset=0
183
185
194 void extractField(char field, const AccumulationConverter & converter, Image & dst, const drain::Rectangle<int> & crop) const;
195
196
197 virtual
198 std::ostream & toStream(std::ostream & ostr) const;
199
200public:
201
203 // std::map<std::string, AccumulationMethod &> methods;
204
205protected:
206
208
209 /*
210 AccumulationMethod undefinedMethod;
211 OverwriteMethod overwriteMethod;
212 MaximumMethod maximumMethod;
213 MinimumMethod minimumMethod;
214 AverageMethod averageMethod;
215 WeightedAverageMethod weightedAverageMethod;
216 MaximumWeightMethod maximumWeightMethod;
217 */
218
219 AccumulationMethod * methodPtr;
220
221 // Initialize destination image to match the accumulation array - cropped if requested.
222 /*
223 * \param dst – destination image to be cropped if cropArea supplied
224 * \param cropArea – sub-area of the accumulation array; empty if no cropping requested.
225 *
226 * If cropArea geometry equals that of the accumulation array, it will be cleared and discarded in processing.
227 *
228 */
229 void initDst(const AccumulationConverter & coder, Image & dst, drain::Rectangle<int> & cropArea) const;
230
231
232};
233
234inline
235std::ostream & operator<<(std::ostream &ostr, const Accumulator & accumulator){
236 return accumulator.Accumulator::toStream(ostr);
237}
238
239
240} // image::
241
242} // drain::
243
244#endif /* Cumulator_H_ */
245
246// Drain
virtual const std::string & getName() const
Return the name of an instance.
Definition BeanLike.h:82
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:119
void add(const size_t i, double value, double weight, unsigned int count)
Adds decoded data that applies natural scaling.
Definition Accumulator.h:153
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.cpp:209
void setMethod(const std::string &method)
Set method to some of the predefined methods.
Definition Accumulator.cpp:104
Accumulator()
Definition Accumulator.h:83
void add(const size_t i, double value, double weight)
Adds decoded data that applies natural scaling.
Definition Accumulator.h:147
AccumulationArray accArray
Todo: export.
Definition Accumulator.h:80
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:122
AccumulationMethod undefinedMethod
A Some predefined methods, that can be set with setMethod(const std::string & key).
Definition Accumulator.h:207
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:184
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