31 #ifndef RACK_RADAR_WINDOWS_H
32 #define RACK_RADAR_WINDOWS_H
36 #include <drain/Log.h>
37 #include <drain/TypeUtils.h>
38 #include <drain/util/Fuzzy.h>
39 #include <drain/util/Functor.h>
40 #include <drain/util/FunctorBank.h>
41 #include <drain/image/Window.h>
42 #include <drain/image/SegmentProber.h>
43 #include <drain/image/SlidingWindow.h>
44 #include <drain/image/GaussianWindow.h>
45 #include <drain/imageops/FunctorOp.h>
46 #include <drain/imageops/GaussianAverageOp.h>
49 #include "data/ODIM.h"
50 #include "data/PolarODIM.h"
51 #include "data/Quantity.h"
101 assignSequence(geom.tuple());
117 double contributionThreshold = 0.5;
120 bool invertPolar =
false;
123 bool relativeScale =
false;
130 RadarWindowConfig(
int widthM=1500,
double heightD=3.0,
double contributionThreshold = 0.5,
bool invertPolar=
false,
bool relativeScale=
false) :
133 contributionThreshold(contributionThreshold), invertPolar(invertPolar), relativeScale(relativeScale) {
134 this->widthM = widthM;
135 this->heightD = heightD;
143 contributionThreshold(conf.contributionThreshold),
144 invertPolar(conf.invertPolar),
145 relativeScale(conf.relativeScale){
160 double contributionThreshold = 0.5,
bool invertPolar=
false,
bool relativeScale=
false) :
163 contributionThreshold(contributionThreshold), invertPolar(invertPolar), relativeScale(relativeScale) {
165 this->widthM = widthM;
166 this->heightD = heightD;
178 void updatePixelSize(
const PolarODIM & inputODIM);
191 template <
class C,
class R=RadarWindowCore>
196 this->resetAtEdges =
true;
200 this->resetAtEdges = conf.invertPolar;
216 mout.
debug2(
"src props for odim: " , src.getProperties() );
218 this->odimSrc.updateFromMap(src.getProperties());
219 mout.info(
"NI=" , this->odimSrc.getNyquist(LOG_WARNING) );
220 mout.info(
"copied odim: " ,
EncodingODIM(this->odimSrc) );
225 mout.
debug2(
"src Scaling: " , src.getScaling() );
244 if (drain::Type::call<drain::typeIsSmallInt>(this->dst.getType())){
247 mout.info(
"(not implemented: functor scaling for small int dst)" );
256 this->coordinateHandler.set(this->src.getGeometry(), this->src.getCoordinatePolicy());
265 if (this->odimSrc.area.height == 0)
266 mout.
error(
"src odim.area.height==0" );
269 const double r =
static_cast<double>(this->odimSrc.area.height) / (2.0*M_PI);
270 const int max =
static_cast<int>(this->odimSrc.area.width);
272 rangeNorm =
static_cast<int>(r);
274 rangeNormEnd =
static_cast<int>(r *
static_cast<double>(this->conf.frame.height));
275 if ((rangeNorm <= 0) || (rangeNormEnd >= max)){
276 mout.
note(rangeNorm ,
'-' , rangeNormEnd );
290 if (this->location.x <= rangeNorm){
291 this->setLoopLimits(this->conf.frame.width, this->conf.frame.height);
293 else if (this->location.x < rangeNormEnd){
294 this->setLoopLimits(this->conf.frame.width, (rangeNorm * this->conf.frame.height)/(this->location.x+1) );
298 this->setLoopLimits(this->conf.frame.width, 1);
302 countMin = this->conf.contributionThreshold * this->getSamplingArea();
310 template <
class C,
class R=RadarWindowCore>
325 if (this->coordinateHandler.validate(p)){
326 double x = this->src.template get<double>(p);
327 if ((x != this->odimSrc.nodata) && (x != this->odimSrc.undetect))
328 removeTrailingValue(this->odimSrc.scaleForward(x));
334 if (this->coordinateHandler.validate(p)){
335 double x = this->src.template get<double>(p);
336 if ((x != this->odimSrc.nodata) && (x != this->odimSrc.undetect))
337 addLeadingValue(this->odimSrc.scaleForward(x));
422 this->dst.putScaled(this->location.x, this->location.y, this->myFunctor(sum/
static_cast<double>(count)));
425 this->dst.put(this->location, this->odimSrc.undetect);
473 if (this->coordinateHandler.validate(p)){
474 double x = this->src.template get<double>(p);
475 if (this->odimSrc.isValue(x)){
476 this->w = this->srcWeight.template get<sum_t>(p);
477 this->sum += w*this->odimSrc.scaling.fwd(x);
486 if (this->coordinateHandler.validate(p)){
487 double x = this->src.template get<double>(p);
488 if (this->odimSrc.isValue(x)){
489 this->w = this->srcWeight.template get<sum_t>(p);
490 this->sum -= w*this->odimSrc.scaling.fwd(x);
500 this->dst.put(this->location, this->odimSrc.scaling.inv(this->sum/sumW));
502 this->dstWeight.put(this->location, sumW/
static_cast<sum_t
>(this->count));
505 this->dst.put(this->location, this->odimSrc.undetect);
506 this->dstWeight.put(this->location, 0);
553 void setCoeff(
double c){
555 throw std::runtime_error(
"RadarWindowSoftMax: zero coeff");
576 sum -= ::exp(coeff * x);
582 sum += ::exp(coeff * x);
591 this->dst.put(this->location, this->fuzzifier(coeffInv*::log(sum/
static_cast<double>(count))));
650 double countD =
static_cast<double>(count);
651 this->dst.put(this->location, this->fuzzifier( ::sqrt(sum2/countD - sum*sum/(countD*countD)) ));
659 this->dst.put(this->location, 0);
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & note(const TT &... args)
For top-level information.
Definition: Log.h:485
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
Tuple of N elements of type T.
Definition: UniTuple.h:65
Image with static geometry.
Definition: ImageFrame.h:67
Window implementation that uses incremental update of state.
Definition: SlidingWindow.h:50
virtual bool reset()
Returns false, if traversal should be ended.
Definition: SlidingWindow.h:212
Base class for configurations applied in image processing windows, e.g. for operators of type WindowO...
Definition: Window.h:56
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition: EncodingODIM.h:75
Metadata structure for single-radar data (polar scans, volumes and products).
Definition: PolarODIM.h:45
Definition: RadarWindows.h:358
virtual void write()
Write the result in the target image.
Definition: RadarWindows.h:418
virtual void removeTrailingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:406
virtual void addLeadingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:412
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: RadarWindows.h:400
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
RadarWindowConfig(const FT &ftor, int widthM=1500, double heightD=3.0, double contributionThreshold=0.5, bool invertPolar=false, bool relativeScale=false)
Definition: RadarWindows.h:159
Definition: RadarWindows.h:60
PolarODIM odimSrc
Definition: RadarWindows.h:79
double NI
Definition: RadarWindows.h:84
RadarWindowCore()
Will act as base class: Window<RadarWindowCore> : public RadarWindowCore {...}, init currently not su...
Definition: RadarWindows.h:68
Like pixel window, but width is metres and height is degrees.
Definition: RadarWindows.h:93
Definition: RadarWindows.h:544
virtual void write()
Write the result in the target image.
Definition: RadarWindows.h:589
virtual void removeTrailingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:575
virtual void addLeadingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:581
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: RadarWindows.h:569
Sliding window for computing standard deviation of scalar quantities.
Definition: RadarWindows.h:605
virtual void write()
Write the result in the target image.
Definition: RadarWindows.h:647
virtual void removeTrailingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:629
virtual void addLeadingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:637
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: RadarWindows.h:621
Definition: RadarWindows.h:436
virtual void addPixel(drain::Point2D< int > &p) final
Adds a pixel to window statistics. Unvalidated location.
Definition: RadarWindows.h:472
virtual void removePixel(drain::Point2D< int > &p) final
Removes a pixel from window statistics. Unvalidated location.
Definition: RadarWindows.h:485
virtual void write() final
Write the result in the target image.
Definition: RadarWindows.h:498
virtual void clear() final
Clears the applied statistics. Redefined in derived classes.
Definition: RadarWindows.h:464
A two-dimensional image processing window that handles the special ODIM codes and scales the result....
Definition: RadarWindows.h:192
void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition: RadarWindows.h:255
void setSrcFrame(const drain::image::ImageFrame &src)
Sets input image and retrieves ODIM metadata from image Properties.
Definition: RadarWindows.h:212
virtual void initialize() override
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition: RadarWindows.h:240
virtual bool reset()
Returns false, if traversal should be ended.
Definition: RadarWindows.h:288
void setRangeNorm()
To compensate polar geometry, set applicable range for pixel area scaling.
Definition: RadarWindows.h:261
Definition: RadarWindows.h:311
virtual void addPixel(drain::Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition: RadarWindows.h:333
virtual void removePixel(drain::Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition: RadarWindows.h:324
virtual void removeTrailingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:343
virtual void addLeadingValue(double x)
Handles the converted (natural-scaled) value.
Definition: RadarWindows.h:347
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:1277
Definition: DataSelector.cpp:44