Debian Codegraph @

cvd/vector_image_ref.h

raw symbols SCIP
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 /// Convert an image co-ordinate into a Vector
11 /// @param ir The ImageRef to convert
12 /// @ingroup gImage
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 /// Convert a Vector into an image co-ordinate. Numbers are truncated, not rounded
22 /// @param v The Vector to convert
23 /// @ingroup gImage
24 inline ImageRef ir(const TooN::Vector<2>& v)
25 {
26 return ImageRef((int)v[0], (int)v[1]);
27 }
28
29 /// Convert a Vector into an image co-ordinate.
30 /// @param v The Vector to convert
31 /// @ingroup gImage
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 /// Convert a Vector into an image co-ordinate. Numbers are rounded
38 /// @param v The Vector to convert
39 /// @ingroup gImage
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 /// Rescale an ImageRef by a scaling factor
48 /// @param v The Vector to convert
49 /// @ingroup gImage
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