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