SlidingWindowOp.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood 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 
39 namespace drain
40 {
41 
42 namespace image
43 {
44 
45 
46 
48 
58 template <class W>
59 class SlidingWindowOp : public WindowOp<W> {
60 
61 public:
62 
63  typedef W window_t;
64 
65  SlidingWindowOp(typename W::conf_t & conf) : WindowOp<W>(conf, __FUNCTION__, ""){
66  };
67 
68  //SlidingWindowOp(const SlidingWindowOp & op) : WindowOp<W>(op){};
69 
70  virtual inline
71  ~SlidingWindowOp(){};
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  // Since templating was introduced, instantaneous classes can be created (instad of inheritance)
164  SlidingWindowOp(const std::string &name = __FUNCTION__, const std::string &description = "") : WindowOp<W>(name, description){
165  };
166 
167 protected:
168 
169  // virtual void processOLD(const ImageFrame & src, Image & dst) const;
170 
171 
172 };
173 
174 
175 
176 } // image::
177 
178 } // drain::
179 
180 #endif /*SLIDINGWINDOWOP_H_*/
181 
182 // Drain
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
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 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