Loading...
Searching...
No Matches
SlidingWindowOp.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 SLIDINGWINDOWOP13_H_
32#define SLIDINGWINDOWOP13_H_
33
34#include "drain/image/SlidingWindow.h"
35
36#include "CopyOp.h"
37#include "WindowOp.h"
38
39namespace drain
40{
41
42namespace image
43{
44
45
46
48
58template <class W>
59class SlidingWindowOp : public WindowOp<W> {
60
61public:
62
63 typedef W window_t;
64
65 SlidingWindowOp(const typename W::conf_t & conf) : WindowOp<W>(conf, __FUNCTION__, ""){
66 };
67
68 //SlidingWindowOp(const SlidingWindowOp & op) : WindowOp<W>(op){};
69
70 virtual inline
72
73 virtual inline
74 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const {
75 // drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__); //REPL this->name+"[const ImageTray &, ImageTray &]", __FUNCTION__);
76 this->traverseChannelsSeparately(src, dst);
77 }
78
79
80
81 virtual
82 void traverseChannel(const Channel &src, Channel &dst) const {
83
84 //Logger mout(getImgLog(), __FILE__, __FUNCTION__); //REPL getImgLog(), this->name+"(SlidingWindowOp/2) (unweighted)", __FUNCTION__);
85 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
86
87 mout.debug("unweighted version");
88
89 typename W::unweighted window(this->conf); // copies parameters (hopefully)
90 //ImageTray<const Channel> & src
91 window.setSrcFrame(src);
92 window.setDstFrame(dst);
93
94 mout.debug2(window );
95 //mout.warn(window.myFunctor.getName() , '#' , window.myFunctor.getParameters() );
96
97 /*
98 for (int i=0; i<50; ++i){
99 std::cerr << __FUNCTION__ << i << '\t' << window.myFunctor(i) << '\n';
100 }
101 */
102
103 //mout.debug3(window.getSrc() );
104 //mout.debug3("slide:" );
105
106 window.run();
107 //mout.debug3("end" );
108
109 };
110
111 virtual
112 void traverseChannel(const Channel &src, const Channel &srcWeight, Channel &dst, Channel &dstWeight) const {
113
114 //Logger mout(getImgLog(), __FILE__, __FUNCTION__); //REPL getImgLog(), this->name+"(SlidingWindowOp/4)", __FUNCTION__);
115
116 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
117
118 mout.debug("weighted version" );
119 if (srcWeight.isEmpty()){
120 mout.error("weight image empty" );
121 }
122
123 W window(this->conf); // W::conf_t & must be compatible & sufficient
124 window.setSrcFrame(src);
125 window.setSrcFrameWeight(srcWeight);
126 window.setDstFrame(dst);
127 window.setDstFrameWeight(dstWeight);
128
129 mout.debug3(window );
130
131 window.run();
132
133 };
134
135 void traverseMultiChannel(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const {
136
137 // Logger mout(getImgLog(), __FILE__, __FUNCTION__); //REPL getImgLog(), this->name+"(SlidingWindowOp/4)", __FUNCTION__);
138 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
139
140 mout.debug("start" );
141
142 if (!src.hasAlpha() || !dst.hasAlpha()){
143 mout.info("unweighted window" );
144 typename W::unweighted window(this->conf);
145 window.setSrcFrames(src);
146 window.setDstFrames(dst);
147 mout.debug3(window );
148 window.run();
149 }
150 else {
151 mout.info("weighted window" );
152 W window(this->conf);
153 window.setSrcFrames(src);
154 window.setDstFrames(dst);
155 mout.debug3(window );
156 window.run();
157 }
158
159
160 };
161
162
163 // With templates, instantaneous classes can be created (instead of inheritance)
164 SlidingWindowOp(const std::string &name = __FUNCTION__, const std::string &description = "") : WindowOp<W>(name, description){
165 };
166
167 virtual inline
168 const std::string & getName() const override {
170 }
171
172
173};
174
175} // image::
176
177template <class W>
178struct TypeName<image::SlidingWindowOp<W> > {
179
180 static const std::string & str(){
181 static const std::string name = drain::StringBuilder<>("SlidingWindowOp<", drain::TypeName<W>::str(), ">");
182 return name;
183 }
184
185};
186
187} // drain::
188
189#endif // DRAIN_SLIDINGWINDOWOP_H_
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:666
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:676
Definition StringBuilder.h:58
Image with static geometry.
Definition ImageChannel.h:60
void traverseChannelsSeparately(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Process each (src,dst) channel pair independently. Raise error if their counts differ.
Definition ImageOp.cpp:340
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:267
Template for operators applying pipeline-like sliding window.
Definition SlidingWindowOp.h:59
virtual const std::string & getName() const override
Return the name of an instance.
Definition SlidingWindowOp.h:168
virtual void traverseChannel(const Channel &src, const Channel &srcWeight, Channel &dst, Channel &dstWeight) const
Apply to single channel with alpha.
Definition SlidingWindowOp.h:112
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition SlidingWindowOp.h:82
Definition WindowOp.h:50
Definition DataSelector.cpp:1277
Definition Type.h:542
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:558