| 1 |
#ifndef CVD_VECTOR_IMAGE_REF_H |
| 2 |
#define CVD_VECTOR_IMAGE_REF_H |
| 3 |
|
| 4 |
#include <TooN/TooN.h> |
| 5 |
#include <cmath> |
| 6 |
#include <cvd/image_ref.h> |
| 7 |
|
| 8 |
namespace CVD |
| 9 |
{ |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
inline TooN::Vector<2> vec(const ImageRef& ir) |
| 14 |
{ |
| 15 |
TooN::Vector<2> r; |
| 16 |
r[0] = ir.x; |
| 17 |
r[1] = ir.y; |
| 18 |
return r; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
inline ImageRef ir(const TooN::Vector<2>& v) |
| 25 |
{ |
| 26 |
return ImageRef((int)v[0], (int)v[1]); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
inline ImageRef ir_floor(const TooN::Vector<2>& v) |
| 33 |
{ |
| 34 |
return ImageRef((int)std::floor(v[0]), (int)std::floor(v[1])); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
inline ImageRef ir_rounded(const TooN::Vector<2>& v) |
| 41 |
{ |
| 42 |
return ImageRef( |
| 43 |
static_cast<int>(v[0] > 0.0 ? v[0] + 0.5 : v[0] - 0.5), |
| 44 |
static_cast<int>(v[1] > 0.0 ? v[1] + 0.5 : v[1] - 0.5)); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
inline ImageRef ir_rescale_rounded(const ImageRef& v, double rescaling_factor) |
| 51 |
{ |
| 52 |
return ir_rounded(vec(v) * rescaling_factor); |
| 53 |
} |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
#endif |