DetectorOp.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 ANDRE_DETECTOR2_H_
33 #define ANDRE_DETECTOR2_H_
34 
35 
36 #include <main/palette-manager.h>
37 #include "AndreOp.h"
38 
39 
40 namespace rack {
41 
42 using namespace drain::image;
43 
44 
46 
49 class DetectorOp : public AndreOp {
50 
51 public:
52 
55  /*
56  DetectorOp(const std::string & name = __FUNCTION__, const std::string &description = "", unsigned short code = 0) : AndreOp(name,description), classCode(code ? code : 128+(++_count)) {
57  // dataSelector.path = ". * /da ta[0-9]+/?$";
58  // dataSelector.quantity = "DBZ.*";
59  dataSelector.setQuantity("^DBZH$");
60  // cumulateDetections = MAX;
61  REQUIRE_STANDARD_DATA = true;
62  UNIVERSAL = false;
63  }
64  */
65 
66  DetectorOp(const std::string & name = __FUNCTION__, const std::string & description = "", const std::string & echoClass = "") :
67  AndreOp(name,description), classEntry(PaletteManager::getPalette("CLASS").getEntryByCode(echoClass)) {
68  // classCode(PaletteManager::getPalette("CLASS").getValueByCode(echoClass)) {
69  // classCode(getClassCode(echoClass)) {
70 
71  // dataSelector.path = ". * /da ta[0-9]+/?$";
72  //dataSelector.quantity = "DBZ.*";
73  //dataSelector.setQuantityRegExp("^DBZH$");
74  dataSelector.setQuantities("DBZH:DBZ");
75  //cumulateDetections = MAX;
76  REQUIRE_STANDARD_DATA = true;
77  UNIVERSAL = false;
78 
79  //PaletteManager::getPalette("CLASS").getEntryByCode(code, lenient);
80  // std::cout << __FUNCTION__ << ':' << name << ':' << echoClass << '\n';
81  }
82 
83  // inline
84  // DetectorOp(const DetectorOp & op) : AndreOp(op), classCode(op.classCode), REQUIRE_STANDARD_DATA(op.REQUIRE_STANDARD_DATA), UNIVERSAL(op.UNIVERSAL) {}
85  inline
86 // DetectorOp(const DetectorOp & op) : AndreOp(op), classCode(op.classCode), UNIVERSAL(op.UNIVERSAL), REQUIRE_STANDARD_DATA(op.REQUIRE_STANDARD_DATA) {};
87  DetectorOp(const DetectorOp & op) : AndreOp(op), classEntry(op.classEntry), UNIVERSAL(op.UNIVERSAL), REQUIRE_STANDARD_DATA(op.REQUIRE_STANDARD_DATA) {};
88 
89  virtual
90  ~DetectorOp(){};
91 
93 
96  virtual
97  const std::string & getOutputQuantity(const std::string & inputQuantity = "") const;
98 
99  static bool SUPPORT_UNIVERSAL;
100 
102  //const unsigned short int classCode;
103 
105  const drain::image::Palette::value_type & classEntry;
106 
107 
108  // NEW
112  //virtual
113  //void processProduct(DataSetList<PolarDst> & srcVolume, DataSetList<PolarDst> & dstVolume) const;
114 
115 
116  virtual inline
117  void computeProducts(const DataSetMap<PolarSrc> & srcVolume, DataSetMap<PolarDst> & dstVolume) const {
118  drain::Logger mout(__FILE__, __FUNCTION__);
119  mout.unimplemented<LOG_INFO>("TODO... redirecting...");
120  runDetection(srcVolume, dstVolume);
121  }
122 
123 
124  // NEW
128  virtual
129  void runDetection(const DataSetMap<PolarSrc> & srcVolume, DataSetMap<PolarDst> & dstVolume) const;
130 
132  //virtual
133  //void processDataSets(const DataSetMap<PolarSrc> & srcVolume, DataSetMap<PolarDst> & dstVolume) const;
134 
136 
141  virtual
142  void runDetection(const DataSet<PolarSrc> & srcDataSet, PlainData<PolarDst> & dstProb, DataSet<PolarDst> & aux) const;
143 
145 
150  //virtual
151  //void processDataSet(const DataSet<PolarSrc> & srcDataSet, PlainData<PolarDst> & dstProb, DataSet<PolarDst> & aux) const;
152 
154 
158  virtual inline
159  void runDetector(const PlainData<PolarSrc> & srcData, PlainData<PolarDst> & dstProb) const {
160  drain::Logger mout(__FILE__, __FUNCTION__);
161  mout.unimplemented("function ", __FUNCTION__," not implemented for ", getName());
162  mout.error("stopping");
163  }
164  /*
165  {
166  drain::Logger mout(__FILE__, __FUNCTION__);
167  mout.unimplemented("function ", __FUNCTION__," not implemented for ", getName());
168  }*
169  */
170 
171  virtual
172  void processData(const Data<src_t > & srcData, Data<dst_t > & dstData) const {
173  drain::Logger mout(__FILE__, __FUNCTION__);
174  mout.special(__FUNCTION__, " now, here!");
175  //runDetector((const PlainData<PolarSrc> &) srcData, (PlainData<PolarDst> &)dstData);
176  // Default implementation is simple, creates no (2nd order) quality field of the detection
177  runDetector(srcData, dstData);
178  };
179 
180  //const unsigned short int CODE;
182  bool UNIVERSAL;
183 
184 protected:
185 
186  virtual
187  void initDataDst(const PlainData<PolarSrc> & srcData, PlainData<PolarDst> & dstData, const std::string & quantity = "") const;
188  //void initDataDst(PlainData<PolarDst> & dstData, const std::string & quantity, const ODIM & srcODIM);
189 
190 
191  // This is difficult...
192  //const Hi5Tree & getNormalizedData(const DataSet<> & srcDataSet, DataSet<> & dstDataSet, const std::string & quantity) const;
193 
194  // Consider raise to VolumeOp ?
195  void storeDebugData(int debugLevel, const ImageFrame & srcImage, const std::string & label) const;
196 
197  // Consider raise
198  void storeDebugData(const ImageFrame & srcImage, PlainData<PolarDst> & dstData, const std::string & quantityLabel) const;
199 
200 
202  virtual
203  void writeHow(PlainData<PolarDst> & dstData) const;
204 
205  // Detector classCode. Obsolete...
206  static
207  unsigned short int _count;
208 
209  mutable std::string upperCaseName;
210 
212 
220 
221 
223 
228  void _enhanceDirectionally(Image & data, float medianPos, int windowWidth) const;
229 
230  void _infect(Image & data, int windowWidth, int windowHeight, double enhancement) const;
231 
232 
233 };
234 
235 
236 } // rack::
237 
238 #endif /* ANDRE_OP_H_ */
239 
240 // Rack
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 & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition: Log.h:507
Image with static geometry.
Definition: ImageFrame.h:67
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
The base class for detector and removal operators.
Definition: AndreOp.h:55
Definition: Data.h:1368
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition: Data.h:1213
Data structure consisting of plain data and an optional quality data.
Definition: Data.h:1144
Base class for anomaly detectors.
Definition: DetectorOp.h:49
const drain::image::Palette::value_type & classEntry
Index applied in the legend of the classification results.
Definition: DetectorOp.h:105
virtual void computeProducts(const DataSetMap< PolarSrc > &srcVolume, DataSetMap< PolarDst > &dstVolume) const
Definition: DetectorOp.h:117
DetectorOp(const std::string &name=__FUNCTION__, const std::string &description="", const std::string &echoClass="")
Definition: DetectorOp.h:66
virtual void runDetector(const PlainData< PolarSrc > &srcData, PlainData< PolarDst > &dstProb) const
Process as sweep (data in one elevation angle)
Definition: DetectorOp.h:159
bool REQUIRE_STANDARD_DATA
Set to true if operator expects fixed background intensities instead of "nodata" defined by the Polar...
Definition: DetectorOp.h:219
bool UNIVERSAL
If true, applies also to quantities str than the one used in detection. The detection and the accumul...
Definition: DetectorOp.h:178
Essential class for storing radar data.
Definition: Data.h:302
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:44
Definition: palette-manager.h:41