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"
39#include "CoordinateHandler.h"
59 template <
class FT=IdentityFunctor>
61 WindowConfig(
int width=1,
int height=0,
const FT & functor = FT()) : frame(width,height ? height : width){
62 key = functor.getName();
84 int getWidth()
const {
90 int getHeight()
const {
95 typedef typename fmap_t::const_iterator ftor_entry_t;
110 const std::string k = functorBank.
resolve(ftorKey);
112 const fmap_t & m = functorBank.getMap();
113 ftor_entry_t it = m.find(k);
118 throw std::runtime_error(ftorKey +
'[' + k +
"]: no such entry, using IdentityFunctor");
125 const fmap_t::key_type & getFunctorName()
const {
134 return functorParameters;
145std::ostream & operator<<(std::ostream & ostr,
const WindowConfig & conf);
165 setSrcFrames(srcTray);
177 setDstFrames(dstTray);
203 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
205 if (srcTray.empty()){
206 mout.
error(
"src: no channels" );
210 if (srcTray.size() > 1){
211 mout.
warn(
"src: multiple channels" );
219 if (!srcTray.alpha.empty()){
220 setSrcFrameWeight(srcTray.
getAlpha(0));
230 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
232 if (dstTray.empty()){
233 mout.
error(
"dst: no channels" );
237 if (dstTray.size() > 1){
238 mout.
warn(
"dst: multiple channels" );
243 if (!dstTray.alpha.empty()){
244 setDstFrameWeight(dstTray.
getAlpha(0));
251 void setSrcFrameWeight(
const ImageFrame & srcW){
252 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
253 mout.
warn(
"Not implemented" );
258 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
259 mout.
warn(
"Not implemented" );
277 void setSrcFrameWeight(
const ImageFrame & srcW){
313 void setSrcFrame(
const Channel & srcChannel){
315 srcChannels.
set(srcChannel);
320 void setDstFrame(
Channel & dstChannel){
322 dstChannels.
set(dstChannel);
329 drain::Logger mout(getImgLog(),
"MultiChannelWindowCore", __FUNCTION__);
331 mout.
debug(
"setting srcTray" );
334 this->srcTray.
copy(srcTray);
335 if (!srcTray.empty()){
339 mout.
warn(
"setting empty srcTray" );
343 if (!srcTray.alpha.empty()){
344 this->srcWeight.
setView(srcTray.alpha.get());
347 mout.
debug(
"no srcTray.alpha" );
350 mout.
debug2(this->srcTray );
357 drain::Logger mout(getImgLog(),
"MultiChannelWindowCore", __FUNCTION__);
359 mout.
debug(
"setting dstTray" );
362 this->dstTray.
copy(dstTray);
363 if (!dstTray.empty()){
367 mout.
warn(
"setting empty dstTray" );
371 if (!dstTray.alpha.empty()){
372 this->dstWeight.
setView(this->dstTray.alpha.get());
375 mout.
debug(
"no srcTray.alpha" );
379 mout.
debug2(this->dstTray );
401template <
class C = WindowConfig,
class R = WindowCore>
416 Window(
size_t width=1,
size_t height=0) :
419 myFunctor(unicloner.getCloned(conf.getFunctorName())),
426 setSize(width, height==0 ? width : height);
435 myFunctor(unicloner.getCloned(conf.getFunctorName())),
442 setSize(conf.frame.width, conf.frame.height);
449 myFunctor(this->conf.
getFunctor(window.conf.getFunctorName())),
453 jRange(window.jRange)
455 setSize(conf.frame.width, conf.frame.height);
478 conf.frame.set(width, height);
485 return conf.frame.getArea();
518 bool isHorizontal()
const {
return (this->conf.frame.width > this->conf.frame.height); };
544 this->location.setLocation(0,0);
598 iRange.min = -(
static_cast<int>(width)-1)/2;
600 jRange.min = -(
static_cast<int>(height)-1)/2;
601 jRange.max = height/2;
616 bool debugDiag(
int bit = 4){
617 return (this->location.x == this->location.y) && ((this->location.x&((1<<bit)-1)) == 0);
623template <
class C,
class R>
625 ostr <<
"Window: " << conf.frame <<
' ';
626 ostr <<
'[' << iRange <<
'|' << jRange <<
']';
628 ostr <<
'@' << location <<
',' << coordinateHandler <<
' ';
629 ostr <<
"functor: " << this->myFunctor <<
'\n';
639template <
class P,
class R>
647 const Range<int> & horzRange = coordinateHandler.getXRange();
648 const Range<int> & vertRange = coordinateHandler.getYRange();
652 for (j = 0; j <= vertRange.max; ++j) {
653 for (i = 0; i <= horzRange.max; ++i) {
664 for (i = 0; i <= horzRange.max; ++i) {
665 for (j = 0; j <= vertRange.max; ++j) {
679template <
class P,
class R>
689template <
class P,
class R>
692 static const std::string & str(){
A Bank with additional support for brief, single char keys.
Definition Bank.h:315
virtual const std::string & resolve(const key_t &value) const
Given brief or long key, returns the long key .
Definition Bank.h:433
std::map< std::string, cloner_t * > map_t
Base class.
Definition Bank.h:77
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition BeanLike.h:142
Something that has width and height.
Definition Frame.h:53
Creates an entries offered by a bank and destroys them upon exit.
Definition Bank.h:482
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:270
A map of Variables.
Definition VariableMap.h:61
Image with static geometry.
Definition ImageChannel.h:58
Definition CoordinateHandler.h:74
Image with static geometry.
Definition ImageFrame.h:62
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
void setChannels(T2 &img)
Splits.
Definition ImageTray.h:401
void copy(const Tray< T2 > &t)
Add image sequence.
Definition ImageTray.h:345
const image_t & getAlpha(size_t i=0) const
Returns the i'th alpha image.
Definition ImageTray.h:328
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:355
void setSrcFrames(const ImageTray< const Channel > &srcTray)
virtual inline
Definition Window.h:327
const image_t & get(size_t i=0) const
Returns the i'th image.
Definition ImageTray.h:80
void set(image_t &img, size_t i=0)
Replace image in position i.
Definition ImageTray.h:102
Base class for configurations applied in image processing windows, e.g. for operators of type WindowO...
Definition Window.h:55
void setFunctor(const std::string &ftorKey)
Get the cloner of the current functor type.
Definition Window.h:107
const VariableMap & getFunctorParams() const
Return the parameters to be set for proceeding getFunctor() calls.
Definition Window.h:133
Container for source and target images, and their setters.
Definition Window.h:154
Container for source and target images, and their setters.
Definition Window.h:192
Base class for windows applied by WindowOp's.
Definition Window.h:402
virtual void toStream(std::ostream &ostr) const
Definition Window.h:624
bool resetAtEdges
To avoid accumulated numerical errors esp. with floats, reset the statistics at row/cols ends....
Definition Window.h:527
virtual void run()
Main loop: traverses the source image and writes result to dst image.
Definition Window.h:640
Window(const C &conf)
Constructor adapting given configuration.
Definition Window.h:432
Point2D< int > location
Current location of this window.
Definition Window.h:521
int samplingArea
Number of pixels in the window (frame width*height?).
Definition Window.h:524
virtual void initialize()
Definition Window.h:540
size_t getSamplingArea()
Returns the area which has eventually been scaled (in a non-linear coordinate system)
Definition Window.h:490
virtual void setSize(size_t width, size_t height)
Sets the window size.
Definition Window.h:477
virtual void setLoopLimits(int width, int height)
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition Window.h:596
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:518
void setLoopLimits()
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition Window.h:606
Window(size_t width=1, size_t height=0)
Constructor with geometry setting option.
Definition Window.h:416
virtual bool reset()
Function determining whether array should be cleared at the edge(s). Needed for 1) cleaning numerical...
Definition Window.h:568
virtual void update()
At each location, this is called to calculate and store something in members.
Definition Window.h:549
virtual ~Window()
Destructor.
Definition Window.h:469
Range< int > iRange
Studies source and destination images and decides whether scaling (SCALE=true) should be set.
Definition Window.h:582
bool SCALE
If set, scaling is applied, potentially slowering the computation.
Definition Window.h:530
size_t getArea()
Returns the nominal area in pixels.
Definition Window.h:484
Definition DataSelector.cpp:1277
UnaryFunctor & getFunctor(const std::string &nameAndParams, char separator)
Returns functor the parameters of which have been set.
Definition FunctorBank.cpp:77
FunctorBank & getFunctorBank()
Definition FunctorBank.cpp:47
Default implementation.
Definition TypeName.h:54