31 #ifndef DRAIN_SLIDING_WINDOW
32 #define DRAIN_SLIDING_WINDOW
48 template <
class C = WindowConfig,
class R = WindowCore>
58 SlidingWindow(
int width=0,
int height=0,
bool horzMultiple=
true,
bool vertMultiple=
true) :
Window<C,R>(width,height){
59 setSlidingMode(horzMultiple, vertMultiple);
62 SlidingWindow(
const C & conf,
bool horzMultiple=
true,
bool vertMultiple=
true) :
Window<C,R>(conf){
63 setSlidingMode(horzMultiple, vertMultiple);
68 void setSlidingMode(
bool horzMultiple,
bool vertMultiple){
71 modeStr.at(0) = horzMultiple?
'H':
'h';
72 modeStr.at(1) = vertMultiple?
'V':
'v';
77 if (horzMultiple && vertMultiple)
79 else if (horzMultiple)
81 else if (vertMultiple)
85 mout <<
"illegal sliding mode single-horz, single-vert" << mout.endl;
109 mout.debug3(
"SCALE=" , (
int)this->
SCALE );
110 mout.debug3(
"calling initialize" );
126 mout.
debug2(
"start slideHorz" );
128 mout.
debug2(
"end slideHorz" );
131 mout.
debug2(
"start slideVert" );
143 mout.debug3(
"start" );
144 mout.debug3(
"SCALE=" , (
int)this->
SCALE );
145 mout.debug3(
"initialize" );
148 mout.debug3((*
this) );
153 mout.debug3(
"slideHorz");
164 mout.debug3(
"start" );
165 mout.debug3(
"SCALE=" , (
int)this->
SCALE );
166 mout.debug3(
"initialize" );
169 mout.debug3((*
this) );
174 mout.debug3(
"slideVert");
183 mout.warn(
"Using apply() recommended for debugging only." );
195 const std::string & getModeStr(){
301 if (this->
location.y <= this->coordinateHandler.getYRange().max){
302 locationLead.y = this->
location.y + this->jRange.max;
303 locationTrail.y = this->
location.y + this->jRange.min - 1;
324 locationLead.y = this->
location.y + this->jRange.min;
325 locationTrail.y = this->
location.y + this->jRange.max + 1;
345 if (this->
location.x <= this->coordinateHandler.getXRange().max){
385 std::cerr << __FUNCTION__ <<
" (plain) " << std::endl;
400 for (
int i = this->
iRange.min; i <= this->
iRange.max; i++) {
401 for (
int j = this->jRange.min; j <= this->jRange.max; j++) {
402 this->locationTmp.setLocation(this->
location.x+i, this->location.y+j);
416 for (
int i = this->
iRange.min; i <= this->
iRange.max; i++) {
417 this->locationTmp.setLocation(this->
location.x+i, this->location.y);
430 for (
int j = this->jRange.min; j <= this->jRange.max; j++) {
431 this->locationTmp.setLocation(this->
location.x, this->location.y+j);
464 for (
int j = this->jRange.min; j <= this->jRange.max; j++) {
466 locationTmp.setLocation(locationTrail.x, this->location.y + j);
469 locationTmp.setLocation(locationLead.x, this->location.y + j);
475 void updateHorzSingle(){
477 this->locationTmp.setLocation(this->locationTrail.x, this->location.y);
480 this->locationTmp.setLocation(this->locationLead.x, this->location.y);
488 for (
int i=this->
iRange.min; i<=this->
iRange.max; i++) {
490 locationTmp.setLocation(this->
location.x + i, locationTrail.y);
493 locationTmp.setLocation(this->
location.x + i, locationLead.y);
504 this->locationTmp.setLocation(this->
location.x, this->locationTrail.y);
507 this->locationTmp.setLocation(this->
location.x, this->locationLead.y);
563 template <
class C = WindowConfig,
class R = WindowCore,
bool DIR=true>
573 void setSize(
size_t width = 1){
582 drain::Logger mout(getImgLog(),
"SlidingStripe", __FUNCTION__);
588 mout.
warn(
"horz stripe, height(" , height ,
") discarded" );
593 mout.
warn(
"vert stripe, width(" , width ,
") discarded" );
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
A horizontal, one-dimensional SlidingWindow (Nx1).
Definition: SlidingWindow.h:564
virtual void setSize(size_t width, size_t height)
Sets the window size.
Definition: SlidingWindow.h:580
Window implementation that uses incremental update of state.
Definition: SlidingWindow.h:50
virtual void removePixel(Point2D< int > &p)=0
Removes a pixel from window statistics. Unvalidated location.
SlidingWindow(int width=0, int height=0, bool horzMultiple=true, bool vertMultiple=true)
Definition: SlidingWindow.h:58
void updateVertSingle()
For 1 x n sized windows.
Definition: SlidingWindow.h:502
void updateHorzMultiple()
In moving horizontally, updates the window centered at current location. Calls removePixel() and addP...
Definition: SlidingWindow.h:462
void run()
Sets coord handler, calls initialise, sets pos(0,0), fills, writes and slides.
Definition: SlidingWindow.h:95
void(SlidingWindow< C, R >::* updateVert)()
Pointer to update function invoked at each vertical move.
Definition: SlidingWindow.h:458
void runHorz()
Sets coord handler, calls initialise, sets pos(0,0), fills, writes and slides.
Definition: SlidingWindow.h:140
void fillVert()
Clears and computes the statistics for the current location. FINAL.
Definition: SlidingWindow.h:428
bool moveDown()
Moves one pixel down. Stops at the edge, and returns false.
Definition: SlidingWindow.h:298
virtual void write()=0
Write the result in the target image.
void(SlidingWindow< C, R >::* fill)()
Pointer to fill operation preformed at initial location (0,0)
Definition: SlidingWindow.h:440
void slideHorz()
High-level functionality of a sliding window. FINAL.
Definition: SlidingWindow.h:219
virtual void initialize()=0
Sets class-specific initial values. Does not change general window state (e.g. location)....
bool moveLeft()
Moves one pixel left. Stops at the edge, and returns false.
Definition: SlidingWindow.h:365
void updateVertMultiple()
In moving vertically, updates the window centered at current location. Calls removePixel() and addPix...
Definition: SlidingWindow.h:486
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: SlidingWindow.h:384
void slideVert()
High-level functionality of a sliding window. FINAL.
Definition: SlidingWindow.h:251
virtual bool reset()
Returns false, if traversal should be ended.
Definition: SlidingWindow.h:212
virtual void addPixel(Point2D< int > &p)=0
Adds a pixel to window statistics. Unvalidated location.
void fillHorz()
Clears and computes the statistics for the current location. FINAL.
Definition: SlidingWindow.h:414
virtual void fillBoth()
Clears and computes the statistics for the current location.
Definition: SlidingWindow.h:396
bool moveRight()
Moves one pixel right. Stops at the edge, and returns false.
Definition: SlidingWindow.h:342
bool moveUp()
Moves one pixel up. Stops at the edge, and returns false.
Definition: SlidingWindow.h:320
void(SlidingWindow< C, R >::* updateHorz)()
Pointer to update function invoked at each horizontal move.
Definition: SlidingWindow.h:449
void runVert()
Sets coord handler, calls initialise, sets pos(0,0), fills, writes and slides.
Definition: SlidingWindow.h:161
Base class for windows applied by WindowOp's.
Definition: Window.h:404
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
Point2D< int > location
Current location of this window.
Definition: Window.h:520
virtual void setSize(size_t width, size_t height)
Sets the window size.
Definition: Window.h:479
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
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
Definition: DataSelector.cpp:1277