DopplerInversionWindow.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 
32 #ifndef DOPPLER_Inversion_WINDOW_H_
33 #define DOPPLER_Inversion_WINDOW_H_
34 
35 
36 //#include "DopplerWindowOp.h"
37 
38 #include <cmath>
39 
40 #include "RadarWindows.h"
41 
42 namespace rack {
43 
44 
45 
47 public:
48 
49  inline
50  DopplerInversionConfig(int widthM=1500, double heightD=3.0) :
51  RadarWindowConfig(widthM, heightD){
52  };
53 
54 };
55 
57 public:
58 
59 };
60 
61 class DopplerInversionWindow : public SlidingRadarWindow<DopplerInversionConfig> {
62  //drain::image::SlidingWindowT<> { // TODO: move to Analysis.h, Templatize => SlidingWindowT
63 
64 
65 public:
66 
67  DopplerInversionWindow(const DopplerInversionConfig & conf, const PolarODIM & odimOut) :
68  SlidingRadarWindow<DopplerInversionConfig>(conf) , odimOut(odimOut), functor(NULL)
69  //, dSpan(3), dSpan2(2.0*dSpan)
70  { };
71 
72  inline
73  void setDstFrame2(drain::image::Image &d2){
74  dst2.setView(d2);
75  }
76 
77 
78  // Unneeded!? (Unchanged)
79  /*
80  inline
81  void setImageLimits() const {
82  src.adjustCoordinateHandler(coordinateHandler);
83  }
84  */
85 
86 
87  virtual
88  void initialize();
89 
91  inline
92  bool getDerivative(const drain::Point2D<int> &p, double & diff, bool debug=false) const {
93 
95 
96  pTmp.setLocation(p.x, p.y - 1);
97  if (!this->coordinateHandler.validate(pTmp))
98  return false;
99  const double d1 = src.get<double>(pTmp);
100 
101  pTmp.setLocation(p.x, p.y + 1);
102  if (!this->coordinateHandler.validate(pTmp))
103  return false;
104  const double d2 = src.get<double>(pTmp);
105 
106  if (odimSrc.deriveDifference(d1, d2, diff)){
107  diff *= 0.5; // due to above +1/-1
108  /*
109  if (debug && isDiag(2)){
110  std::cerr << " {" << d1 << ',' << d2 << "} \t => (" << odimSrc.scaleForward(d1) << ',' << odimSrc.scaleForward(d2) << "}\t => " << diff << '\n';
111  }
112  */
113  return true;
114  }
115  else
116  return false;
117 
118  }
119 
120 
121  const PolarODIM & odimOut;
122 
123  std::string functorSetup; // TODO: use that of Window::
124 
125 
126 protected:
127 
129  drain::UnaryFunctor *functor; // pointer :-( TODO: use that of Window::
130 
131  drain::FuzzyBell2<double> diffQuality;
132  drain::FuzzyBell2<double> matrixInformation;
133 
134  virtual inline
135  void addLeadingValue(double x){};
136 
137  virtual inline
138  void removeTrailingValue(double x){};
139 
140  //inline bool retrieveSpeedSample(d1, d2)
141 
143 
146  virtual
147  void addPixel(drain::Point2D<int> &p);
148 
150  virtual
152 
153  virtual
154  void write();
155 
156 protected:
157 
159 
160  virtual
161  void clear();
162 
163  inline
164  bool isDiag(int step) const {
165  return (location.x == location.y) && (location.x % step == 0);
166  }
167 
169 
170 private:
171 
172  double u = 0.0;
173  double v = 0.0;
174 
175  mutable double vMax;
176 
177  // Matrix determinant
178  double div;
179 
180  // Output quality
181  double quality;
182 
183  // Used for computing derivatives in addPixel/removePixel
184  drain::Point2D<int> locationTmp;
185 
187  //mutable double NI;
188 
190  // mutable double NI2;
191 
192 
194  //const int dSpan;
196  //const double dSpan2;
197 
198 
199  double diff;
200 
201 
202 
204 
205  // sum of differences
206  double sumDiff;
207  // sum differences Squared
208  double sumDiff2;
209 
210  // count/weight (quality weight)
211  double w;
212  // area, const (max weight)
213  double area;
214 
216  double sTd;
217 
219  double cTd;
220 
222  double sTs;
223 
225  double cTc;
226 
228  double cTs;
229 
230 
231  // Experimental
233  double sV;
235  double cV;
236 
237 
238 
240 
241  // Speed differences
242  double d1,d2;
243 
245  double s,c;
246 
247  //drain::FuzzyStepsoid<double> qualityFunctor;
248  drain::FuzzyBell<double> qualityFunctor;
249 
250 };
251 
252 
254 
255 
256 public:
257 
258  DopplerInversionWindowWeighted(const DopplerInversionConfig & conf, const PolarODIM & odimOut) :
259  DopplerInversionWindow(conf, odimOut) {
260  };
261 
262 };
263 
264 
265 } // ::rack
266 
267 
268 #endif /* DOPPLERInversionOP_H_ */
bool validate(Point2D< int > &p) const
Handles the coordinate, returning true if the position is reversible.
Definition: CoordinateHandler.h:223
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
ImageFrame that also has channels.
Definition: ImageView.h:52
void setView(const ImageFrame &src)
Views the whole image.
Definition: ImageView.h:65
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
Point2D< int > location
Current location of this window.
Definition: Window.h:520
Definition: DopplerInversionWindow.h:46
Definition: DopplerInversionWindow.h:56
Definition: DopplerInversionWindow.h:253
Definition: DopplerInversionWindow.h:61
drain::UnaryFunctor * functor
Handling altitude.
Definition: DopplerInversionWindow.h:129
virtual void removePixel(drain::Point2D< int > &p)
Removes the pixel located at (p.x,p.y) from the window statistic/quantity.
Definition: DopplerInversionWindow.cpp:164
virtual void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition: DopplerInversionWindow.cpp:54
virtual void addPixel(drain::Point2D< int > &p)
Add the pixel located at (p.x,p.y) to the window statistic/quantity.
Definition: DopplerInversionWindow.cpp:122
virtual void removeTrailingValue(double x)
Handles the converted (natural-scaled) value.
Definition: DopplerInversionWindow.h:138
bool getDerivative(const drain::Point2D< int > &p, double &diff, bool debug=false) const
Computes the derivative (m/s)/beam. Often rescaled with beam width.
Definition: DopplerInversionWindow.h:92
virtual void addLeadingValue(double x)
Handles the converted (natural-scaled) value.
Definition: DopplerInversionWindow.h:135
virtual void write()
Write the result in the target image.
Definition: DopplerInversionWindow.cpp:203
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: DopplerInversionWindow.cpp:279
Metadata structure for single-radar data (polar scans, volumes and products).
Definition: PolarODIM.h:45
Definition: RadarWindows.h:112
RadarWindowConfig(int widthM=1500, double heightD=3.0, double contributionThreshold=0.5, bool invertPolar=false, bool relativeScale=false)
Definition: RadarWindows.h:130
Definition: RadarWindows.h:311
Definition: DataSelector.cpp:44
Definition: Functor.h:116