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"
38 #include "ImageView.h"
39 #include "ImageTray.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;
146 std::ostream & operator<<(std::ostream & ostr,
const WindowConfig & conf);
167 setSrcFrames(srcTray);
179 setDstFrames(dstTray);
205 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
207 if (srcTray.empty()){
208 mout.
error(
"src: no channels" );
212 if (srcTray.size() > 1){
213 mout.
warn(
"src: multiple channels" );
221 if (!srcTray.alpha.empty()){
222 setSrcFrameWeight(srcTray.
getAlpha(0));
232 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
234 if (dstTray.empty()){
235 mout.
error(
"dst: no channels" );
239 if (dstTray.size() > 1){
240 mout.
warn(
"dst: multiple channels" );
245 if (!dstTray.alpha.empty()){
246 setDstFrameWeight(dstTray.
getAlpha(0));
253 void setSrcFrameWeight(
const ImageFrame & srcW){
254 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
255 mout.
warn(
"Not implemented" );
260 Logger mout(getImgLog(),
"WindowCore", __FUNCTION__);
261 mout.
warn(
"Not implemented" );
279 void setSrcFrameWeight(
const ImageFrame & srcW){
315 void setSrcFrame(
const Channel & srcChannel){
317 srcChannels.
set(srcChannel);
322 void setDstFrame(
Channel & dstChannel){
324 dstChannels.
set(dstChannel);
331 drain::Logger mout(getImgLog(),
"MultiChannelWindowCore", __FUNCTION__);
333 mout.
debug(
"setting srcTray" );
336 this->srcTray.
copy(srcTray);
337 if (!srcTray.empty()){
341 mout.
warn(
"setting empty srcTray" );
345 if (!srcTray.alpha.empty()){
346 this->srcWeight.
setView(srcTray.alpha.get());
349 mout.
debug(
"no srcTray.alpha" );
352 mout.
debug2(this->srcTray );
359 drain::Logger mout(getImgLog(),
"MultiChannelWindowCore", __FUNCTION__);
361 mout.
debug(
"setting dstTray" );
364 this->dstTray.
copy(dstTray);
365 if (!dstTray.empty()){
369 mout.
warn(
"setting empty dstTray" );
373 if (!dstTray.alpha.empty()){
374 this->dstWeight.
setView(this->dstTray.alpha.get());
377 mout.
debug(
"no srcTray.alpha" );
381 mout.
debug2(this->dstTray );
403 template <
class C = WindowConfig,
class R = WindowCore>
418 Window(
size_t width=1,
size_t height=0) :
421 myFunctor(unicloner.getCloned(conf.getFunctorName())),
428 setSize(width, height==0 ? width : height);
437 myFunctor(unicloner.getCloned(conf.getFunctorName())),
444 setSize(conf.frame.width, conf.frame.height);
451 myFunctor(this->conf.
getFunctor(window.conf.getFunctorName())),
455 jRange(window.jRange)
457 setSize(conf.frame.width, conf.frame.height);
480 conf.frame.set(width, height);
487 return conf.frame.getArea();
520 bool isHorizontal()
const {
return (this->conf.frame.width > this->conf.frame.height); };
546 this->location.setLocation(0,0);
600 iRange.min = -(
static_cast<int>(width)-1)/2;
602 jRange.min = -(
static_cast<int>(height)-1)/2;
603 jRange.max = height/2;
618 bool debugDiag(
int bit = 4){
619 return (this->location.x == this->location.y) && ((this->location.x&((1<<bit)-1)) == 0);
625 template <
class C,
class R>
627 ostr <<
"Window: " << conf.frame <<
' ';
628 ostr <<
'[' << iRange <<
'|' << jRange <<
']';
630 ostr <<
'@' << location <<
',' << coordinateHandler <<
' ';
631 ostr <<
"functor: " << this->myFunctor <<
'\n';
641 template <
class P,
class R>
649 const Range<int> & horzRange = coordinateHandler.getXRange();
650 const Range<int> & vertRange = coordinateHandler.getYRange();
654 for (j = 0; j <= vertRange.max; ++j) {
655 for (i = 0; i <= horzRange.max; ++i) {
666 for (i = 0; i <= horzRange.max; ++i) {
667 for (j = 0; j <= vertRange.max; ++j) {
681 template <
class P,
class R>
691 template <
class P,
class R>
694 static const std::string & str(){
A Bank with additional support for brief, single char keys.
Definition: Bank.h:314
virtual const std::string & resolve(const key_t &value) const
Given brief or long key, returns the long key .
Definition: Bank.h:432
std::map< std::string, cloner_t * > map_t
Base class.
Definition: Bank.h:78
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition: BeanLike.h:131
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 & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
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
void importCastableMap(const drain::SmartMap< T2 > &m)
Assign values from a map, possibly extending the map.
Definition: SmartMap.h:271
Creates an entry of desired type and destroys it upon exit.
Definition: Bank.h:476
A map of Variables.
Definition: VariableMap.h:61
Image with static geometry.
Definition: ImageChannel.h:60
Definition: CoordinateHandler.h:62
Image with static geometry.
Definition: ImageFrame.h:67
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:357
void setSrcFrames(const ImageTray< const Channel > &srcTray)
virtual inline
Definition: Window.h:329
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
const VariableMap & getFunctorParams() const
Return the parameters to be set for proceeding getFunctor() calls.
Definition: Window.h:134
void setFunctor(const std::string &ftorKey)
Get the cloner of the current functor type.
Definition: Window.h:108
Container for source and target images, and their setters.
Definition: Window.h:156
Container for source and target images, and their setters.
Definition: Window.h:194
Base class for windows applied by WindowOp's.
Definition: Window.h:404
virtual void toStream(std::ostream &ostr) const
Definition: Window.h:626
bool resetAtEdges
To avoid accumulated numerical errors esp. with floats, reset the statistics at row/cols ends....
Definition: Window.h:529
virtual void run()
Main loop: traverses the source image and writes result to dst image.
Definition: Window.h:642
Window(const C &conf)
Constructor adapting given configuration.
Definition: Window.h:434
Point2D< int > location
Current location of this window.
Definition: Window.h:520
int samplingArea
Number of pixels in the window (frame width*height?).
Definition: Window.h:526
virtual void initialize()
Definition: Window.h:542
size_t getSamplingArea()
Returns the area which has eventually been scaled (in a non-linear coordinate system)
Definition: Window.h:492
virtual void setSize(size_t width, size_t height)
Sets the window size.
Definition: Window.h:479
virtual void setLoopLimits(int width, int height)
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition: Window.h:598
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:520
void setLoopLimits()
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition: Window.h:608
Window(size_t width=1, size_t height=0)
Constructor with geometry setting option.
Definition: Window.h:418
virtual bool reset()
Function determining whether array should be cleared at the edge(s). Needed for 1) cleaning numerical...
Definition: Window.h:570
virtual void update()
At each location, this is called to calculate and store something in members.
Definition: Window.h:551
virtual ~Window()
Destructor.
Definition: Window.h:471
Range< int > iRange
Studies source and destination images and decides whether scaling (SCALE=true) should be set.
Definition: Window.h:572
bool SCALE
If set, scaling is applied, potentially slowering the computation.
Definition: Window.h:532
size_t getArea()
Returns the nominal area in pixels.
Definition: Window.h:486
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
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition: Type.h:558
Definition: Functor.h:116