Analysis.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 #ifndef RACK_ANALYSIS_H
32 #define RACK_ANALYSIS_H
33 
34 #include <drain/Log.h>
35 #include <drain/TypeUtils.h>
36 #include <math.h>
37 
38 #include "drain/util/Fuzzy.h"
39 
40 //#include "drain/image/FuzzyOp.h"
41 
42 #include "drain/util/Functor.h"
43 #include "drain/util/FunctorBank.h"
44 //#include "drain/image/Window.h"
45 #include "drain/image/SegmentProber.h"
46 // #include "drain/image/SlidingWindow.h"
47 //#include "drain/image/GaussianWindow.h"
48 #include "drain/imageops/FunctorOp.h"
49 //#include "drain/imageops/GaussianAverageOp.h"
50 
51 //#include "drain/image/SequentialImageOp.h"
52 
53 #include "data/ODIM.h"
54 #include "data/PolarODIM.h"
55 #include "data/Quantity.h"
56 // #include "VolumeOp.h"
57 
58 
59 
60 // using namespace drain::image;
61 
62 // file RadarFunctorOp?
63 
64 namespace rack {
65 
67 
70 // NOTE may be bad, because UnaryFunctorOp pre-scales etc.
71 template <class F>
72 class RadarDataFunctor : public F {
73  public: //re
74  PolarODIM odimSrc;
75 
76  double nodataValue;
77  double undetectValue;
78 
79  RadarDataFunctor(double nodataValue = 0.0, double undetectValue = 0.0) : nodataValue(nodataValue),undetectValue(undetectValue) {
80  }
81 
82  virtual
83  inline
84  double operator()(double src) const {
85  if (src == odimSrc.nodata)
86  return nodataValue;
87  else if (src == odimSrc.undetect)
88  return undetectValue;
89  else
90  return F::operator()(odimSrc.scaleForward(src));
91  };
92 
93 };
94 
96 
99 /*
100 template <class F>
101 class NaturalRadarDataFunctor : public RadarDataFunctor<F> {
102  public: //re
103  const Quantity & q;
104  const PolarODIM & odimStd;
105 
106 
107  NaturalRadarDataFunctor(const std::string & quantity, char type='C') : q(getQuantityMap().get(quantity)), odimStd(q[type]){
108  }
109 
110 
111  virtual
112  inline
113  double operator()(double src) const {
114  if ((src != this->odimSrc.nodata) && (src != this->odimSrc.undetect))
115  return F::operator()(this->odimSrc.scaleForward(src));
116  else
117  return q.undetectValue;
118  };
119 
120 
121 
122 };
123 */
124 
125 
127 public:
128 
129  PolarODIM odimSrc;
130  //bool LIMIT;
131  double nodataValue;
132  double undetectValue;
133 
134  RadarFunctorBase() : nodataValue(0.0), undetectValue(0.0) {
135  //if (adaptParameters)
136  //LIMIT = limit;
137  };
138 
139 
140  void apply(const drain::image::Channel &src, drain::image::Channel & dst, const drain::UnaryFunctor & ftor, bool LIMIT = true) const;
141 
142 };
143 
145 template <class F>
147 public:
148 
149  /*
150  PolarODIM odimSrc;
151  bool LIMIT;
152  double nodataValue;
153  double undetectValue;
154 
155  RadarFunctorOp(bool limit = true) : LIMIT(limit), nodataValue(0.0), undetectValue(0.0) {
156  //if (adaptParameters)
157  this->getParameters().append(this->functor.getParameters());
158  };
159  */
160  inline
161  RadarFunctorOp(){
162  this->LIMIT = true;
163  };
164 
165 
166 
167  virtual inline
168  ~RadarFunctorOp(){};
169 
171 
173  virtual
175  apply(src, dst, this->functor, this->LIMIT);
176  }
177 
179 
188 
235 };
236 
237 
238 
239 // file RadWinOp?
240 
241 
242 
244 
271 class PolarSegmentProber : public drain::image::SizeProber { // SegmentProber<int,int>
272 public:
273 
274  // PolarSegmentProber(const Image & src, Image & dst) : SizeProber(src.getChannel(0), dst.getChannel(0)){};
275 
277 
279  virtual inline
280  void update(int i, int j){
281  size += i;
282  }
283 
284 };
285 
286 
287 
288 
289 
290 
291 } // rack::
292 
293 
294 
295 
296 #endif
297 
298 // Rack
Image with static geometry.
Definition: ImageChannel.h:60
Definition: SegmentProber.h:523
Class for using simple function objects (like std::functor) for sequential pixel iteration.
Definition: FunctorOp.h:135
double scaleForward(double x) const
Converts a quantity from storage scale: y = offset + gain*y .
Definition: EncodingODIM.h:225
double nodata
data[n]/what (obligatory)
Definition: EncodingODIM.h:151
Metadata structure for single-radar data (polar scans, volumes and products).
Definition: PolarODIM.h:45
Computes in polar coordinates.
Definition: Analysis.h:271
virtual void update(int i, int j)
Operation performed in each segment location (i,j). A function to be redefined in derived classes.
Definition: Analysis.h:280
Checks nodata and undetect before calling the functor.
Definition: Analysis.h:72
Definition: Analysis.h:126
Convenience (abbreviation)
Definition: Analysis.h:146
virtual void traverseChannel(const drain::image::Channel &src, drain::image::Channel &dst) const
Process the image.
Definition: Analysis.h:174
Definition: DataSelector.cpp:44
Definition: Functor.h:116