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