Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / include / opencv2 / gapi / own / types.hpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2018-2019 Intel Corporation
6
7
8 #ifndef OPENCV_GAPI_TYPES_HPP
9 #define OPENCV_GAPI_TYPES_HPP
10
11 #include <algorithm>              // std::max, std::min
12 #include <ostream>
13
14 namespace cv
15 {
16 namespace gapi
17 {
18 namespace own
19 {
20
21 class Point
22 {
23 public:
24     Point() = default;
25     Point(int _x, int _y) : x(_x),  y(_y)  {};
26
27     int x = 0;
28     int y = 0;
29 };
30
31 class Rect
32 {
33 public:
34     Rect() = default;
35     Rect(int _x, int _y, int _width, int _height) : x(_x), y(_y),   width(_width),  height(_height)  {};
36 #if !defined(GAPI_STANDALONE)
37     Rect(const cv::Rect& other) : x(other.x), y(other.y), width(other.width), height(other.height) {};
38     inline Rect& operator=(const cv::Rect& other)
39     {
40         x = other.x;
41         y = other.x;
42         width  = other.width;
43         height = other.height;
44         return *this;
45     }
46 #endif // !defined(GAPI_STANDALONE)
47
48     int x      = 0; //!< x coordinate of the top-left corner
49     int y      = 0; //!< y coordinate of the top-left corner
50     int width  = 0; //!< width of the rectangle
51     int height = 0; //!< height of the rectangle
52 };
53
54 inline bool operator==(const Rect& lhs, const Rect& rhs)
55 {
56     return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
57 }
58
59 inline bool operator!=(const Rect& lhs, const Rect& rhs)
60 {
61     return !(lhs == rhs);
62 }
63
64 inline Rect& operator&=(Rect& lhs, const Rect& rhs)
65 {
66     int x1 = std::max(lhs.x, rhs.x);
67     int y1 = std::max(lhs.y, rhs.y);
68     lhs.width  = std::min(lhs.x + lhs.width,  rhs.x + rhs.width) -  x1;
69     lhs.height = std::min(lhs.y + lhs.height, rhs.y + rhs.height) - y1;
70     lhs.x = x1;
71     lhs.y = y1;
72     if( lhs.width <= 0 || lhs.height <= 0 )
73         lhs = Rect();
74     return lhs;
75 }
76
77 inline const Rect operator&(const Rect& lhs, const Rect& rhs)
78 {
79     Rect result = lhs;
80     return result &= rhs;
81 }
82
83 inline std::ostream& operator<<(std::ostream& o, const Rect& rect)
84 {
85     return o << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]";
86 }
87
88 class Size
89 {
90 public:
91     Size() = default;
92     Size(int _width, int _height) : width(_width),  height(_height)  {};
93 #if !defined(GAPI_STANDALONE)
94     Size(const cv::Size& other) : width(other.width), height(other.height) {};
95     inline Size& operator=(const cv::Size& rhs)
96     {
97         width  = rhs.width;
98         height = rhs.height;
99         return *this;
100     }
101 #endif // !defined(GAPI_STANDALONE)
102
103     int width  = 0;
104     int height = 0;
105 };
106
107 inline Size& operator+=(Size& lhs, const Size& rhs)
108 {
109     lhs.width  += rhs.width;
110     lhs.height += rhs.height;
111     return lhs;
112 }
113
114 inline bool operator==(const Size& lhs, const Size& rhs)
115 {
116     return lhs.width == rhs.width && lhs.height == rhs.height;
117 }
118
119 inline bool operator!=(const Size& lhs, const Size& rhs)
120 {
121     return !(lhs == rhs);
122 }
123
124
125 inline std::ostream& operator<<(std::ostream& o, const Size& s)
126 {
127     o << "[" << s.width << " x " << s.height << "]";
128     return o;
129 }
130
131 } // namespace own
132 } // namespace gapi
133 } // namespace cv
134
135 #endif // OPENCV_GAPI_TYPES_HPP