32 #ifndef COORD_HANDLER_H_
33 #define COORD_HANDLER_H_
35 #include <drain/image/CoordinatePolicy.h>
36 #include <drain/Log.h>
40 #include "drain/util/Flags.h"
41 #include "drain/util/Frame.h"
44 #include "ImageFrame.h"
45 #include "Direction.h"
56 typedef drain::Flags::ivalue_t coord_overflow_t;
68 static const coord_overflow_t UNCHANGED = 0;
69 static const coord_overflow_t X_OVERFLOW = 1;
70 static const coord_overflow_t X_UNDERFLOW = 2;
71 static const coord_overflow_t Y_OVERFLOW = 4;
72 static const coord_overflow_t Y_UNDERFLOW = 8;
93 xRange.set(handler.getXRange());
94 yRange.set(handler.getYRange());
95 area.set(handler.area);
123 setLimits(src.getWidth(), src.getHeight());
129 setLimits(area.getWidth(), area.getHeight());
135 void setLimits(
int xMin,
int yMin,
int xUpperLimit,
int yUpperLimit){
136 xRange.set(xMin, xUpperLimit - 1);
137 yRange.set(yMin, yUpperLimit - 1);
138 area.set(xUpperLimit, yUpperLimit);
143 setLimits(0, 0, xUpperLimit, yUpperLimit);
161 setPolicy(p.xUnderFlowPolicy, p.yUnderFlowPolicy, p.xOverFlowPolicy, p.yOverFlowPolicy);
165 void setPolicy(EdgePolicy::index_t xUnderFlowPolicy, EdgePolicy::index_t yUnderFlowPolicy, EdgePolicy::index_t xOverFlowPolicy, EdgePolicy::index_t yOverFlowPolicy);
190 coord_overflow_t
handle(
int &x,
int &y)
const {
195 result |= (this->*handleXUnderFlow)(x,y);
198 result |= (this->*handleXOverFlow)(x,y);
201 result |= (this->*handleYUnderFlow)(x,y);
203 if (y >= area.height)
204 result |= (this->*handleYOverFlow)(x,y);
235 mutable coord_overflow_t result;
256 coord_overflow_t limitXUnderFlow(
int &x,
int &y)
const {
262 coord_overflow_t limitYUnderFlow(
int &x,
int &y)
const {
267 coord_overflow_t limitXOverFlow(
int &x,
int &y)
const {
272 coord_overflow_t limitYOverFlow(
int &x,
int &y)
const {
279 coord_overflow_t wrapXUnderFlow(
int &x,
int &y)
const {
281 x = x % area.width + area.width;
286 coord_overflow_t wrapYUnderFlow(
int &x,
int &y)
const {
288 y = y % area.height + area.height;
293 coord_overflow_t wrapXOverFlow(
int &x,
int &y)
const {
300 coord_overflow_t wrapYOverFlow(
int &x,
int &y)
const {
308 coord_overflow_t mirrorXUnderFlow(
int &x,
int &y)
const {
314 coord_overflow_t mirrorYUnderFlow(
int &x,
int &y)
const {
320 coord_overflow_t mirrorXOverFlow(
int &x,
int &y)
const {
321 x = 2*xRange.max - x;
326 coord_overflow_t mirrorYOverFlow(
int &x,
int &y)
const {
327 y = 2*yRange.max - y;
338 x = xRange.min - x - 1;
339 y = (y + area.height/2) % area.height;
350 y = yRange.min - y - 1;
351 x = (x + area.width/2) % area.width;
356 coord_overflow_t polarXOverFlow(
int &x,
int &y)
const {
357 x = 2*xRange.max - x + 1;
358 y = (y + area.height/2) % area.height;
363 coord_overflow_t polarYOverFlow(
int &x,
int &y)
const {
364 y = 2*yRange.max - y + 1;
365 x = (x + area.width/2) % area.width;
386 std::ostream & operator<<(std::ostream & ostr,
const CoordinateHandler2D & handler);
Flags using a global dictionary.
Definition: GlobalFlags.h:81
Definition: CoordinateHandler.h:62
bool validate(int &x, int &y) const
Handles the coordinate, returning true if the position is reversible.
Definition: CoordinateHandler.h:229
void setPolicy(EdgePolicy::index_t p)
Set the same policy in all the directions.
Definition: CoordinateHandler.h:169
CoordinateHandler2D(int xUpperLimit, int yUpperLimit, const CoordinatePolicy &policy=CoordinatePolicy())
Constructor.
Definition: CoordinateHandler.h:112
static const coord_overflow_t IRREVERSIBLE
Equal move in inverse direction would not result original position.
Definition: CoordinateHandler.h:74
coord_overflow_t polarXUnderFlow(int &x, int &y) const
Definition: CoordinateHandler.h:337
coord_overflow_t polarYUnderFlow(int &x, int &y) const
Definition: CoordinateHandler.h:349
coord_overflow_t handle(Point2D< int > &p) const
Calls handle(int &x,int &y)
Definition: CoordinateHandler.h:212
void setLimits(int xMin, int yMin, int xUpperLimit, int yUpperLimit)
Sets minimum values and outer upper limits for x and y.
Definition: CoordinateHandler.h:135
coord_overflow_t skipUndefined(int &x, int &y) const
Does nothing to the coordinates.
Definition: CoordinateHandler.h:250
virtual coord_overflow_t handle(int &x, int &y) const
Ensures the validity of the coordinates. If inside limits, arguments (x,y) remain intact and 0 is ret...
Definition: CoordinateHandler.h:190
CoordinateHandler2D(const drain::image::AreaGeometry &area=AreaGeometry(), const CoordinatePolicy &policy=CoordinatePolicy())
Default constructor.
Definition: CoordinateHandler.h:84
bool validate(Point2D< int > &p) const
Handles the coordinate, returning true if the position is reversible.
Definition: CoordinateHandler.h:223
void setPolicy(const CoordinatePolicy &p)
Assigns internal function pointers.
Definition: CoordinateHandler.h:160
void setLimits(int xUpperLimit, int yUpperLimit)
Sets outer upper limits for x and y.
Definition: CoordinateHandler.h:142
Policies for coordinate underflows and overflows.
Definition: CoordinatePolicy.h:106
Struct for image (excluding data)
Definition: ImageConf.h:333
Image with static geometry.
Definition: ImageFrame.h:67
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
Definition: DataSelector.cpp:1277
Definition: Direction.h:46