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