Loading...
Searching...
No Matches
image-ops.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
32
33#ifndef RACK_IMAGE_OPS
34#define RACK_IMAGE_OPS
35
36#include <list>
37#include <string>
38
39#include <drain/imageops/ImageOp.h>
40#include <drain/prog/CommandInstaller.h>
41//#include <drain/util/ReferenceMap.h>
42
43
44#include "resources.h"
45
46
47
48//drain::BeanRefAdapter<drain::image::ImageOp>
49
50//typedef drain::BeanRefCommand<drain::image::ImageOp> ImageOpCmd;
51
52
53namespace rack {
54
55
57
58
59public:
60
62 void execOp(const drain::image::ImageOp & imageOp, RackContext & ctx) const;
63
64 template <class OD>
65 void updateGeometryODIM(Hi5Tree & dstGroup, const std::string & quantity, drain::image::Geometry & geometry) const;
66
67 /*
68 template <class OD>
69 void updateGeometryODIM(Hi5Tree & dstGroup, const std::string & quantity, drain::image::Geometry & geometry) const {
70
71 drain::Logger mout(__FILE__, __FUNCTION__); // = resources.mout;
72
73 // OD odim;
74 typedef DstType<OD> dst_t;
75
76 DataSet<dst_t> dstDataSet(dstGroup, quantity);
77
78
79 for (typename DataSet<dst_t>::iterator dit = dstDataSet.begin(); dit != dstDataSet.end(); ++dit){
80
81 Data<dst_t> & d = dit->second;
82 if (geometry.getArea() == 0){
83 geometry.setArea(d.data.getWidth(), d.data.getHeight());
84 }
85 else if (geometry != d.data.getGeometry()) {
86 mout.warn("dataset group contains different geometries" , d.odim );
87 }
88
89 d.odim.setGeometry(d.data.getWidth(), d.data.getHeight());
90 //mout.note("modified odim geom " , d.odim );
91
92
93 }
94
95 //ODIM::copyToH5<ODIMPathElem::ROOT>(rootODIM, dstH5);
96
97 }
98 */
99
100
101
102};
103
104
105
106
107
108
110
114
115public:
116
118 "Flag. Handle intensities as physical quantities instead of storage typed values.", "physical", false){
119 //getParameters().link("value", ImageOpExec::physical);
120 };
121
122 virtual
123 void exec() const {
124 RackContext & ctx = getContext<RackContext>();
125 ctx.imagePhysical = value;
126 }
127
128
129};
130
131
132
134 inline ImageOpSection(): CommandSection("imageOps"){
135 drain::CommandBank::trimWords().insert("Functor"); // Functor
136 };
137};
138
139
140template <class OP>
141class RackImageOpCmd;
142
143
144class ImageOpModule : public drain::CommandModule<'i',ImageOpSection> {
145 //: public drain::CommandSection { // : public drain::CommandGroup {
146
147public:
148
150
152 // \tparam OP - Class derived from ImageOp
153 template <class OP>
154 void install(const std::string & name = OP().getName()){
155
156 try {
157
158 std::string key(name);
160
161 drain::Command & cmd = cmdBank.add<RackImageOpCmd<OP> >(key);
162 cmd.section = getSection().index;
163 }
164 catch (const std::exception &e) {
165 std::cerr << "error: ImageOpInstaller: " << name << '\n';
166 std::cerr << "error: " << e.what() << '\n';
167 }
168 }
169
170};
171
172
173} /* namespace rack */
174
175#endif
176
177// Rack
static std::set< std::string > & trimWords()
Words that are moved from class name prior to composing a command name.
Definition CommandBank.cpp:57
static void deriveCmdName(std::string &name, char prefix=0)
Given a command class name like MyFileReadCommand, derives a respective command line option ("myFileR...
Definition CommandBank.cpp:62
static char getPrefix()
Return the character used as prefix for the commands in this section.
Definition CommandInstaller.h:96
Combines command installation and sectioning.
Definition CommandInstaller.h:228
Definition CommandSections.h:54
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:55
A single-parameter command.
Definition Command.h:448
Definition Geometry.h:145
Base class for image processing functions.
Definition ImageOp.h:49
Switch for image operators to use physical scale instead of storage typed values.
Definition image-ops.h:113
virtual void exec() const
Run the command with current parameter values.
Definition image-ops.h:123
bool imagePhysical
Defines if the next image processing operation uses scaled intentsites instead of raw byte values.
Definition resources-image.h:294
Definition image-ops.h:56
void execOp(const drain::image::ImageOp &imageOp, RackContext &ctx) const
Shared function, to minimize copies in template classes.
Definition image-ops.cpp:154
Definition image-ops.h:144
void install(const std::string &name=OP().getName())
Add ImageOp command to registry (CommandBank).
Definition image-ops.h:154
ImageOpModule()
For separate commands.
Definition image-ops.cpp:910
Resources provided separately for each thread.
Definition resources.h:67
Designed for Rack.
Definition image-ops.cpp:112
Definition DataSelector.cpp:44
Definition image-ops.h:133