Loading...
Searching...
No Matches
ImageModifierPack.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 IMAGE_MODIFIER_PACK_H
32#define IMAGE_MODIFIER_PACK_H
33
34#include "drain/util/Histogram.h"
35#include "drain/image/Sampler.h"
36
37#include "ImageMod.h"
38
39namespace drain {
40
41namespace image {
42
43
44
45
46
47class ImageChannels : public ImageMod {
48
49public:
50
51 ImageChannels() : ImageMod(__FUNCTION__, "Redefine channel geometry. See also --geometry") {
52 parameters.link("imageChannels", imageChannelCount = 1UL);
53 parameters.link("alphaChannels", alphaChannelCount = 0UL);
54 };
55
56 ImageChannels(const ImageChannels & op) : ImageMod(op), imageChannelCount(op.imageChannelCount), alphaChannelCount(op.alphaChannelCount) {
57 parameters.copyStruct(op.getParameters(), op, *this);
58 }
59
60
61 virtual
62 void initialize(Image & dst) const;
63
64 virtual
65 void traverseChannel(Channel & dst) const {};
66
67
68protected:
69
70 mutable
71 size_t imageChannelCount;
72
73 mutable
74 size_t alphaChannelCount;
75
76};
77
78
79
80class ImageCoordPolicy : public ImageMod {
81
82public:
83
84 ImageCoordPolicy() : ImageMod(__FUNCTION__, "Coordinate under/overflow policy: 0=UNDEFINED, 1=LIMIT, 2=WRAP, 3=MIRROR, 4=POLAR"){
85 parameters.link("policy", value, "<xUF>[,<yUF>[,<xOF>,<yOF>]]");
86 parameters.separator = 0;
87 };
88
90 parameters.copyStruct(op.getParameters(), op, *this);
91 }
92
94 void initialize(Image & dst) const;
95
96 virtual
97 void traverseChannel(Channel & dst) const;
98
99 std::string value;
100
101protected:
102
103 mutable CoordinatePolicy policy;
104
105};
106
107
108
110
119class ImageEncoding : public ImageMod {
120
121public:
122
123
124 ImageEncoding() : ImageMod(__FUNCTION__, "Set desired target properties") { // TODO
125
126 refMap.link("type", encoding.type);
127 //refMap.link("scale", encoding.ValueScaling::tuple());
128 refMap.link("scale", encoding.getScaling().tuple()).fillArray = false;
129 refMap.link("range", encoding.getPhysicalRange().tuple()).fillArray = false; //physRange);
130 //refMap.link("min", this->scaling.physRange.min, "physical_value");
131 //refMap.link("max", this->scaling.physRange.max, "physical_value");
132
133 parameters.link("request", request, refMap.getKeys());
134 parameters.separator = 0;
135
136 };
137
138 ImageEncoding(const ImageEncoding & op) : ImageMod(op) {
139 parameters.copyStruct(op.getParameters(), op, *this);
140 refMap.copyStruct(op.refMap, op, *this); // should work? UniTuple instances use local (inside-object) memory
141 }
142
143 virtual
144 void initialize(Image & dst) const;
145
146 virtual
147 void traverseChannel(Channel & dst) const {
148 //drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__);
149 //mout.fail("Feelu" );
150 };
151 //virtual
152 //void process(Image & dst) const;
153
154protected:
155
156 std::string request;
157
158
159 mutable drain::ReferenceMap refMap;
160
161 //mutable std::string type;
162 // mutable drain::ValueScaling scaling;
163 mutable drain::image::Encoding encoding;
164 //mutable double scale;
165 //mutable double minValue;
166 //mutable double maxValue;
167 // mutable std::string view;
168};
169
170
172
183class ImageFill : public ImageMod {
184
185public:
186
187 ImageFill() : ImageMod(__FUNCTION__, "Fill the image with intensity <value>[,<green>,<blue>[,alpha]]. See also 'plotfile'.") {
188 // "value", "0", "<value>[,<green>,<blue>[,alpha]]") {
189 parameters.separator = 0;
190 parameters.link("value", value);
191 };
192
193 ImageFill(const ImageFill & op) : ImageMod(op) {
194 parameters.copyStruct(op.getParameters(), op, *this);
195 }
196
197
198 virtual
199 void traverseChannel(Channel & dst) const;
200
201 virtual
202 void traverseChannels(ImageTray<Channel> & dst) const;
203
204protected:
205
206 std::string value;
207
208};
209
213class ImageHistogram : public ImageMod {
214
215public:
216
217 ImageHistogram() : ImageMod(__FUNCTION__, "Compute the image Histogram .") {
218 //parameters.separator = 0;
219 parameters.link("bins", bins = 256);
220 //parameters.link("store", store = true, "save as attribute");
221 parameters.link("store", store = "histogram", "attribute name (empty = don't save)");
222 parameters.link("filename", filename = "", "<filename>.txt");
223 // Todo prefix/comment
224 };
225
226 ImageHistogram(const ImageHistogram & op) : ImageMod(op), bins(op.bins) {
227 parameters.copyStruct(op.getParameters(), op, *this);
228 }
229
230 virtual
231 void traverseChannel(Channel & dst) const;
232
233 //virtual void computeHistogram(const Channel & dst, drain::Histogram & histogram) const;
234 //mutable drain::Histogram histogram;
235 //protected:
236
237 size_t bins;
238
239 // bool
240 std::string store;
241
242 std::string filename;
243
244};
245
246
256class ImageGeometry : public ImageMod {
257
258public:
259
260 inline
261 ImageGeometry() : ImageMod(__FUNCTION__, "Create image with given geometry. See also --channels") {
262
263 parameters.link("width", width = 0UL, "pix");
264 parameters.link("heigh", height = 0UL, "pix");
265 parameters.link("imageChannels", imageChannelCount = 1UL);
266 parameters.link("alphaChannels", alphaChannelCount = 0UL);
267
268 };
269
270 ImageGeometry(const ImageGeometry & op) : ImageMod(op) {
271 parameters.copyStruct(op.getParameters(), op, *this);
272 }
273
274 virtual
275 void initialize(Image & dst) const;
276
277 virtual
278 void traverseChannel(Channel & dst) const {};
279
280protected:
281
282 size_t width = 0;
283 mutable size_t height = 0;
284 mutable size_t imageChannelCount = 1;
285 mutable size_t alphaChannelCount = 0;
286
287
288};
289
290
291
292
294
303class ImagePlot: public ImageMod {
304
305public:
306
307 ImagePlot() : ImageMod(__FUNCTION__, "Set intensity at (i,j) to (f1,f2,f3,...)."){
308 // See 'plotFile' and 'fill'.", "value", "0,0,0", "<i>,<j>,<f1>[,f2,f3,alpha]" ) {
309 parameters.separator = 0;
310 parameters.link("value", value="0,0,0", "<i>,<j>,<f1>[,f2,f3,alpha]");
311
312 };
313
314 ImagePlot(const ImagePlot & op) : ImageMod(op) {
315 parameters.copyStruct(op.getParameters(), op, *this);
316 }
317
318
319 virtual
320 void traverseChannels(ImageTray<Channel> & dst) const;
321
322protected:
323
324
325
326 std::string value;
327};
328
329
330class ImagePlotFile: public ImageMod {
331
332public:
333
334 ImagePlotFile() : ImageMod(__FUNCTION__, "Plots a given file. See 'plot'."){
335 parameters.link("filename", filename = "", "string");
336 };
337
338 ImagePlotFile(const ImagePlotFile & op) : ImageMod(op) {
339 parameters.copyStruct(op.getParameters(), op, *this);
340 }
341
342 virtual
343 void traverseFrame(ImageFrame & dst) const;
344 //void traverseChannel(Channel & dst) const {};
345
346protected:
347
348 std::string filename;
349
350};
351
353
362class ImageBox: public ImageMod {
363
364public:
365
366 ImageBox() : ImageMod(__FUNCTION__, "Set intensity at (i:i2,j:j2) to (f1,f2,f3,...)."){
367 // See 'BoxFile' and 'fill'.", "value", "0,0,0", "<i>,<j>,<f1>[,f2,f3,alpha]" ) {
368 //parameters.separator = 0;
369 parameters.link("i", iRange.tuple(),"i:i2").fillArray = true;
370 parameters.link("j", jRange.tuple(),"j:j2").fillArray = true;
371 parameters.link("value", value="0", "<f1>[:f2:f3:alpha]").fillArray = true;
372
373 };
374
375 inline
376 ImageBox(const ImageBox & op) : ImageMod(op) {
377 parameters.copyStruct(op.getParameters(), op, *this);
378 }
379
380 virtual
381 void traverseChannels(ImageTray<Channel> & dst) const;
382
383//protected:
384
385 Range<int> iRange;
386 Range<int> jRange;
387 std::string value;
388
389};
390
391
393
400class ImageSampler : public ImageMod {
401
402public:
403
405 ImageSampler() : ImageMod(__FUNCTION__, "Extract samples. See --format.") {
406 parameters.append(sampler.getParameters());
407 }
408 // parameters.link("file", filename = "", "string");
409
410 ImageSampler(const ImageSampler & op) : ImageMod(op), sampler(op.sampler) {
411 //parameters.append(sampler.getParameters());
412 parameters.copyStruct(op.sampler.getParameters(), op.sampler, this->sampler);
413 };
414
416
419 virtual
420 void process(Image & dst) const;
421
422 inline
423 const Sampler & getSampler(){
424 return sampler;
425 };
426
427 virtual inline
428 const std::string & getFormat() const {
429 return format;
430 };
431
432 /*
433 virtual inline
434 std::string & getFormat(){
435 return format;
436 };
437 */
438
440 std::string filename;
441
442protected:
443
444 ImageSampler(const std::string & name, const std::string & description) : ImageMod(name, description){
445 parameters.append(sampler.getParameters());
446 }
447
448
449 mutable Sampler sampler;
450
451
453 std::string format;
454
455};
456
457
458
459} // namespace image
460
461} // namespace drain
462
463
464#endif /* IMAGE_OP_H_ */
465
466// Drain
Definition Range.h:52
Definition ReferenceMap.h:215
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition ReferenceMap.h:336
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:415
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:81
const Range< double > & getPhysicalRange() const
Returns a typical or supported range for physical values.
Definition ValueScaling.h:220
virtual const ValueScaling & getScaling() const
Get linear scaling.
Definition ValueScaling.h:146
Image with static geometry.
Definition ImageChannel.h:58
Policies for coordinate underflows and overflows.
Definition CoordinatePolicy.h:100
Definition ImageConf.h:51
std::string type
Information of the current type.
Definition ImageConf.h:103
Plots a single value in an image. The value will be scaled; notice that alpha channel is scaled by de...
Definition ImageModifierPack.h:362
virtual void traverseChannels(ImageTray< Channel > &dst) const
Run this modifier for a set of channels.
Definition ImageModifierPack.cpp:367
Definition ImageModifierPack.h:47
virtual void initialize(Image &dst) const
Modifies the geometry and the type of dst such that traverseChannel(Channel &) can be called.
Definition ImageModifierPack.cpp:51
virtual void traverseChannel(Channel &dst) const
Run this modifier for an image frame.
Definition ImageModifierPack.h:65
Definition ImageModifierPack.h:80
virtual void traverseChannel(Channel &dst) const
Run this modifier for an image frame.
Definition ImageModifierPack.cpp:289
void initialize(Image &dst) const
Sets the policy.
Definition ImageModifierPack.cpp:244
Changes the type of a target image.
Definition ImageModifierPack.h:119
virtual void initialize(Image &dst) const
Modifies the geometry and the type of dst such that traverseChannel(Channel &) can be called.
Definition ImageModifierPack.cpp:62
virtual void traverseChannel(Channel &dst) const
Run this modifier for an image frame.
Definition ImageModifierPack.h:147
Definition ImageModifierPack.h:183
virtual void traverseChannel(Channel &dst) const
Run this modifier for an image frame.
Definition ImageModifierPack.cpp:217
virtual void traverseChannels(ImageTray< Channel > &dst) const
Run this modifier for a set of channels.
Definition ImageModifierPack.cpp:199
Image with static geometry.
Definition ImageFrame.h:62
Definition ImageModifierPack.h:256
virtual void initialize(Image &dst) const
Modifies the geometry and the type of dst such that traverseChannel(Channel &) can be called.
Definition ImageModifierPack.cpp:225
virtual void traverseChannel(Channel &dst) const
Run this modifier for an image frame.
Definition ImageModifierPack.h:278
Definition ImageModifierPack.h:213
virtual void traverseChannel(Channel &dst) const
Run this modifier for an image frame.
Definition ImageModifierPack.cpp:104
Class for operations that modify an existing image instead of producing a new image.
Definition ImageMod.h:52
Definition ImageModifierPack.h:330
Plots a single value in an image. The value will be scaled; notice that alpha channel is scaled by de...
Definition ImageModifierPack.h:303
virtual void traverseChannels(ImageTray< Channel > &dst) const
Run this modifier for a set of channels.
Definition ImageModifierPack.cpp:298
Traverses image, returning samples.
Definition ImageModifierPack.h:400
ImageSampler()
Default constructor.
Definition ImageModifierPack.h:405
std::string format
Output format, e.g. '{LON} {LAT} {AMVU} {AMVV} {QIND}'.
Definition ImageModifierPack.h:453
virtual void process(Image &dst) const
Runs Sampler on the given image.
Definition ImageModifierPack.cpp:484
std::string filename
If defined, sampler will directly write to this file. The default constructor does not reference this...
Definition ImageModifierPack.h:440
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
Utility for sampling images (2D data), outputting formatted text data.
Definition Sampler.h:162
Definition DataSelector.cpp:1277