Loading...
Searching...
No Matches
FlowAverageWindowOp.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 FLOW_AVG_W_H_
32#define FLOW_AVG_W_H_
33
34#include <drain/TypeUtils.h>
35#include <algorithm>
36
37// #include "CopyOp.h"
38// #include "Window.h"
39//
40#include "SlidingWindowOp.h"
41
42namespace drain
43{
44
45namespace image
46{
47
49
52// TODO: redesign RadarWindowConfig<Polar> ? and
53class FlowAverageWindow : public SlidingWindow<WindowConfig, MultiChannelWindowCore> {
54
55public:
56
58
59 FlowAverageWindow(int width=5, int height=0) : SlidingWindow<WindowConfig, MultiChannelWindowCore>(width, height){ //qualitySensitive(false)
60 clear();
61 };
62
63 FlowAverageWindow(const WindowConfig & conf) : SlidingWindow<WindowConfig, MultiChannelWindowCore>(conf) { //qualitySensitive(false) {
64 clear();
65 };
66
67 // ODIM odimSrc; future option.
68
69 //bool qualitySensitive;
70
71protected:
72
73 double sumMagnitude;
74 std::vector<double> sum;
75 /*
76 double sumU;
77 double sumV;
78 double sumU2;
79 double sumV2;
80 */
81 double sumW;
82 unsigned int count;
84 // drain::ValueScaling dstScaling
85
86 void initialize(){
87
88 drain::Logger mout(getImgLog(), "FlowAverageWindow", __FUNCTION__);
89
90 mout.debug2("srcTray:\n" , srcTray );
91 mout.debug2("dstTray:\n" , dstTray );
92
93 if (srcWeight.isEmpty())
94 mout.debug("no src alpha" );
95
96 if (dstWeight.isEmpty())
97 mout.debug("no dst alpha" );
98
99 if (!srcTray.checkGeometry()){
100 mout.special("scrTray geom: " , srcTray.getGeometry() );
101 mout.special("content geom: " , srcTray );
102 mout.error("srcTray geometry inconsistent" );
103 };
104
105 if (!dstTray.checkGeometry()){
106 mout.special("dstTray geom: " , dstTray.getGeometry() );
107 mout.special("content geom: " , dstTray );
108 mout.error("dstTray geometry inconsistent" );
109 };
110
113 this->location.setLocation(0,0);
114
115 limiter = this->dst.getConf().getLimiter<double>();
116
117 sum.resize(dstTray.size(), 0.0);
118 fillBoth();
119 }
120
122 void clear(){
123 std::fill(sum.begin(), sum.end(), 0);
124 sumMagnitude = 0.0;
125 sumW = 0.0;
126 count = 0;
127 };
128
129 void setImageLimits() const {
130 this->coordinateHandler.set(this->src.getGeometry(), this->src.getCoordinatePolicy());
131 //src.adjustCoordinateHandler(this->coordinateHandler);
132 }
133
134 virtual
135 void removePixel(Point2D<int> & p);
136
137 virtual
138 void addPixel(Point2D<int> & p);
139
140 virtual
141 void write();
142
143
144};
145
147
148public:
149
150 FlowAverageWindowWeighted(int width=5, int height=0) : FlowAverageWindow(width, height) {
151 };
152
154 };
155
156
157 virtual
158 void removePixel(Point2D<int> & p);
159
160 virtual
161 void addPixel(Point2D<int> & p);
162
163 virtual
164 void write();
165
166};
167
169
172class FlowAverageOp : public SlidingWindowOp<FlowAverageWindowWeighted> {
173
174public:
175
176 FlowAverageOp() : SlidingWindowOp<FlowAverageWindowWeighted>(__FUNCTION__, "Window average that preserves the magnitude"){
177 };
178
179 virtual inline
180 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const {
181 // drain::Logger mout(getImgLog(), __FUNCTION__,__FILE__); //REP (this->name+"[const ImageTray &, ImageTray &]", __FUNCTION__);
182 this->traverseMultiChannel(src, dst);
183 }
184
185 virtual inline
186 const std::string & getName() const override {
187 return name;
188 };
189
190
191};
192
193
194
195
196
197}
198
199}
200
201#endif // FLOW_AVG_W_H_
202
203// Drain
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:666
Logger & special(const TT &... args)
Other useful information.
Definition Log.h:531
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:676
Window average that preserves the magnitude.
Definition FlowAverageWindowOp.h:172
virtual const std::string & getName() const override
Return the name of an instance.
Definition FlowAverageWindowOp.h:186
Definition FlowAverageWindowOp.h:146
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition FlowAverageWindowOp.cpp:147
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition FlowAverageWindowOp.cpp:121
virtual void write()
Write the result in the target image.
Definition FlowAverageWindowOp.cpp:174
Window average that preserves the magnitude.
Definition FlowAverageWindowOp.h:53
void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition FlowAverageWindowOp.h:86
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition FlowAverageWindowOp.cpp:70
void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition FlowAverageWindowOp.h:129
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition FlowAverageWindowOp.cpp:49
virtual void write()
Write the result in the target image.
Definition FlowAverageWindowOp.cpp:89
void clear()
Clears statistics.
Definition FlowAverageWindowOp.h:122
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:267
Template for operators applying pipeline-like sliding window.
Definition SlidingWindowOp.h:59
Window implementation that uses incremental update of state.
Definition SlidingWindow.h:50
virtual void fillBoth()
Clears and computes the statistics for the current location.
Definition SlidingWindow.h:396
Base class for configurations applied in image processing windows, e.g. for operators of type WindowO...
Definition Window.h:56
Point2D< int > location
Current location of this window.
Definition Window.h:523
void setLoopLimits()
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition Window.h:608
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:96
Definition DataSelector.cpp:1277
Definition Point.h:48