31#ifndef DRAIN_WINDOW_H_
32#define DRAIN_WINDOW_H_
34#include "drain/util/Frame.h"
35#include "drain/util/Functor.h"
36#include "drain/util/FunctorBank.h"
37#include "drain/util/Static.h"
40#include "CoordinateHandler.h"
60 template <
class FT=IdentityFunctor>
62 WindowConfig(
int width=1,
int height=0,
const FT & functor = FT()) : frame(width,height ? height : width){
63 key = functor.getName();
85 int getWidth()
const {
91 int getHeight()
const {
96 typedef typename fmap_t::const_iterator ftor_entry_t;
111 const std::string k = functorBank.
resolve(ftorKey);
113 const fmap_t & m = functorBank.getMap();
114 ftor_entry_t it = m.find(k);
119 throw std::runtime_error(ftorKey +
'[' + k +
"]: no such entry, using IdentityFunctor");
126 const fmap_t::key_type & getFunctorName()
const {
135 return functorParameters;
146std::ostream & operator<<(std::ostream & ostr,
const WindowConfig & conf);
166 setSrcFrames(srcTray);
178 setDstFrames(dstTray);
204 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
206 if (srcTray.empty()){
207 mout.
error(
"src: no channels" );
211 if (srcTray.size() > 1){
212 mout.
warn(
"src: multiple channels" );
220 if (!srcTray.alpha.empty()){
221 setSrcFrameWeight(srcTray.
getAlpha(0));
231 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
233 if (dstTray.empty()){
234 mout.
error(
"dst: no channels" );
238 if (dstTray.size() > 1){
239 mout.
warn(
"dst: multiple channels" );
244 if (!dstTray.alpha.empty()){
245 setDstFrameWeight(dstTray.
getAlpha(0));
252 void setSrcFrameWeight(
const ImageFrame & srcW){
253 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
254 mout.
warn(
"Not implemented" );
259 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
260 mout.
warn(
"Not implemented" );
278 void setSrcFrameWeight(
const ImageFrame & srcW){
314 void setSrcFrame(
const Channel & srcChannel){
316 srcChannels.
set(srcChannel);
321 void setDstFrame(
Channel & dstChannel){
323 dstChannels.
set(dstChannel);
330 drain::Logger mout(getImgLog(),
"MultiChannelWindowCore", __FUNCTION__);
332 mout.
debug(
"setting srcTray" );
335 this->srcTray.
copy(srcTray);
336 if (!srcTray.empty()){
340 mout.
warn(
"setting empty srcTray" );
344 if (!srcTray.alpha.empty()){
345 this->srcWeight.
setView(srcTray.alpha.get());
348 mout.
debug(
"no srcTray.alpha" );
351 mout.
debug2(this->srcTray );
358 drain::Logger mout(getImgLog(),
"MultiChannelWindowCore", __FUNCTION__);
360 mout.
debug(
"setting dstTray" );
363 this->dstTray.
copy(dstTray);
364 if (!dstTray.empty()){
368 mout.
warn(
"setting empty dstTray" );
372 if (!dstTray.alpha.empty()){
373 this->dstWeight.
setView(this->dstTray.alpha.get());
376 mout.
debug(
"no srcTray.alpha" );
380 mout.
debug2(this->dstTray );
402template <
class C = WindowConfig,
class R = WindowCore>
417 Window(
size_t width=1,
size_t height=0) :
420 myFunctor(unicloner.getCloned(conf.getFunctorName())),
427 setSize(width, height==0 ? width : height);
436 myFunctor(unicloner.getCloned(conf.getFunctorName())),
443 setSize(conf.frame.width, conf.frame.height);
450 myFunctor(this->conf.
getFunctor(window.conf.getFunctorName())),
454 jRange(window.jRange)
456 setSize(conf.frame.width, conf.frame.height);
479 conf.frame.set(width, height);
486 return conf.frame.getArea();
519 bool isHorizontal()
const {
return (this->conf.frame.width > this->conf.frame.height); };
545 this->location.setLocation(0,0);
599 iRange.min = -(
static_cast<int>(width)-1)/2;
601 jRange.min = -(
static_cast<int>(height)-1)/2;
602 jRange.max = height/2;
617 bool debugDiag(
int bit = 4){
618 return (this->location.x == this->location.y) && ((this->location.x&((1<<bit)-1)) == 0);
624template <
class C,
class R>
626 ostr <<
"Window: " << conf.frame <<
' ';
627 ostr <<
'[' << iRange <<
'|' << jRange <<
']';
629 ostr <<
'@' << location <<
',' << coordinateHandler <<
' ';
630 ostr <<
"functor: " << this->myFunctor <<
'\n';
640template <
class P,
class R>
648 const Range<int> & horzRange = coordinateHandler.getXRange();
649 const Range<int> & vertRange = coordinateHandler.getYRange();
653 for (j = 0; j <= vertRange.max; ++j) {
654 for (i = 0; i <= horzRange.max; ++i) {
665 for (i = 0; i <= horzRange.max; ++i) {
666 for (j = 0; j <= vertRange.max; ++j) {
680template <
class P,
class R>
690template <
class P,
class R>
693 static const std::string & str(){
A Bank with additional support for brief, single char keys.
Definition Bank.h:317
virtual const std::string & resolve(const key_t &value) const
Given brief or long key, returns the long key .
Definition Bank.h:435
std::map< std::string, cloner_t * > map_t
Base class.
Definition Bank.h:79
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition BeanLike.h:144
Something that has width and height.
Definition Frame.h:55
Creates an entries offered by a bank and destroys them upon exit.
Definition Bank.h:484
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
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
void importCastableMap(const drain::SmartMap< T2 > &m)
Assign values from a map, possibly extending the map.
Definition SmartMap.h:274
A map of Variables.
Definition VariableMap.h:61
Image with static geometry.
Definition ImageChannel.h:60
Definition CoordinateHandler.h:77
Image with static geometry.
Definition ImageFrame.h:64
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:267
void setChannels(T2 &img)
Splits.
Definition ImageTray.h:402
void copy(const Tray< T2 > &t)
Add image sequence.
Definition ImageTray.h:346
const image_t & getAlpha(size_t i=0) const
Returns the i'th alpha image.
Definition ImageTray.h:329
ImageFrame that also has channels.
Definition ImageView.h:52
void setView(const ImageFrame &src)
Views the whole image.
Definition ImageView.h:65
void setDstFrames(ImageTray< Channel > &dstTray)
virtual inline
Definition Window.h:356
void setSrcFrames(const ImageTray< const Channel > &srcTray)
virtual inline
Definition Window.h:328
const image_t & get(size_t i=0) const
Returns the i'th image.
Definition ImageTray.h:81
void set(image_t &img, size_t i=0)
Replace image in position i.
Definition ImageTray.h:103
Base class for configurations applied in image processing windows, e.g. for operators of type WindowO...
Definition Window.h:56
void setFunctor(const std::string &ftorKey)
Get the cloner of the current functor type.
Definition Window.h:108
const VariableMap & getFunctorParams() const
Return the parameters to be set for proceeding getFunctor() calls.
Definition Window.h:134
Container for source and target images, and their setters.
Definition Window.h:155
Container for source and target images, and their setters.
Definition Window.h:193
Base class for windows applied by WindowOp's.
Definition Window.h:403
virtual void toStream(std::ostream &ostr) const
Definition Window.h:625
bool resetAtEdges
To avoid accumulated numerical errors esp. with floats, reset the statistics at row/cols ends....
Definition Window.h:528
virtual void run()
Main loop: traverses the source image and writes result to dst image.
Definition Window.h:641
Window(const C &conf)
Constructor adapting given configuration.
Definition Window.h:433
Point2D< int > location
Current location of this window.
Definition Window.h:522
int samplingArea
Number of pixels in the window (frame width*height?).
Definition Window.h:525
virtual void initialize()
Definition Window.h:541
size_t getSamplingArea()
Returns the area which has eventually been scaled (in a non-linear coordinate system)
Definition Window.h:491
virtual void setSize(size_t width, size_t height)
Sets the window size.
Definition Window.h:478
virtual void setLoopLimits(int width, int height)
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition Window.h:597
virtual void setImageLimits() const =0
Sets internal limits corresponding to image geometries. Typically using coordHandler.
virtual void write()=0
At each location, the result of computation to dst image(s).
virtual bool isHorizontal() const
Tells if the window should be moved (traversed of slided) row-by-row (horizontally) or column-by-colu...
Definition Window.h:519
void setLoopLimits()
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition Window.h:607
Window(size_t width=1, size_t height=0)
Constructor with geometry setting option.
Definition Window.h:417
virtual bool reset()
Function determining whether array should be cleared at the edge(s). Needed for 1) cleaning numerical...
Definition Window.h:569
virtual void update()
At each location, this is called to calculate and store something in members.
Definition Window.h:550
virtual ~Window()
Destructor.
Definition Window.h:470
Range< int > iRange
Studies source and destination images and decides whether scaling (SCALE=true) should be set.
Definition Window.h:583
bool SCALE
If set, scaling is applied, potentially slowering the computation.
Definition Window.h:531
size_t getArea()
Returns the nominal area in pixels.
Definition Window.h:485
Definition DataSelector.cpp:1277
UnaryFunctor & getFunctor(const std::string &nameAndParams, char separator)
Returns functor the parameters of which have been set.
Definition FunctorBank.cpp:81
FunctorBank & getFunctorBank()
Definition FunctorBank.cpp:51
Default implementation.
Definition TypeName.h:57