1 #ifndef LICORNEA_COMMON_H_ 2 #define LICORNEA_COMMON_H_ 10 #include <initializer_list> 12 #include <opencv2/core/core.hpp> 22 using vec2 = cv::Vec<real, 2>;
23 using vec3 = cv::Vec<real, 3>;
24 using vec4 = cv::Vec<real, 4>;
26 using mat33 = cv::Matx<real, 3, 3>;
27 using mat44 = cv::Matx<real, 4, 4>;
30 vec4 in(vec[0], vec[1], vec[2], 1.0);
33 return vec3(out[0], out[1], out[2]);
36 vec3 in(vec[0], vec[1], 1.0);
39 return vec2(out[0], out[1]);
44 template<
typename In,
typename Out,
typename Func>
46 std::vector<Out> out(in.size());
47 auto out_it = out.begin();
48 auto in_it = in.cbegin();
49 for(; out_it != out.end(); ++out_it, ++in_it) *out_it = func(*in_it);
54 #define POINT_CONVERT(__name__, __in__, __out__, __expr__) \ 55 inline __out__ __name__(const __in__& pt) { \ 58 inline std::vector<__out__> __name__(const std::vector<__in__>& pts) { \ 59 return point_vec_conv_tpl<__in__, __out__>(pts, static_cast<__out__(*)(const __in__&)>(&__name__)); \ 77 constexpr
real pi = 3.14159265358979323846;
83 constexpr
inline long double operator"" _deg (
long double deg) {
92 explicit index_2d(
int x_= -1,
int y_ = -1) : x(x_), y(y_) { }
93 index_2d(std::initializer_list<int> lst) : x(*lst.begin()), y(*(lst.begin() + 1)) { }
96 return (a.
y == b.
y) && (a.
x == b.
x);
99 return (a.
y != b.
y) || (a.
x != b.
x);
102 if(a.
y == b.
y)
return (a.
x < b.
x);
103 else return (a.
y < b.
y);
106 return (a == b) || (a < b);
112 return (a == b) || (a > b);
118 explicit operator bool ()
const {
return is_valid(); }
index_2d(int x_=-1, int y_=-1)
bool operator!=(const rgb_color &a, const rgb_color &b)
view_index(int x_=-1, int y_=-1)
constexpr real deg_per_rad
index_2d(std::initializer_list< int > lst)
constexpr real golden_ratio
std::string encode_view_index(view_index idx)
std::vector< Out > point_vec_conv_tpl(const std::vector< In > &in, Func func)
std::ostream & operator<<(std::ostream &, const view_index &)
vec3 mul_h(const mat44 &mat, const vec3 &vec)
#define POINT_CONVERT(__name__, __in__, __out__, __expr__)
bool operator<(const index_2d &a, const index_2d &b)
cv::Matx< real, 3, 3 > mat33
constexpr int escape_keycode
bool operator<=(const index_2d &a, const index_2d &b)
constexpr int enter_keycode
bool operator>=(const index_2d &a, const index_2d &b)
bool operator==(const rgb_color &a, const rgb_color &b)
constexpr real rad_per_deg
view_index decode_view_index(const std::string &key)
bool operator>(const index_2d &a, const index_2d &b)
cv::Matx< real, 4, 4 > mat44