Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / include / opencv2 / gapi / gmat.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_GMAT_HPP
9 #define OPENCV_GAPI_GMAT_HPP
10
11 #include <ostream>
12 #include <memory>                 // std::shared_ptr
13
14 #include <opencv2/gapi/opencv_includes.hpp>
15 #include <opencv2/gapi/gcommon.hpp> // GShape
16
17 #include "opencv2/gapi/own/types.hpp" // cv::gapi::own::Size
18 #include "opencv2/gapi/own/convert.hpp" // to_own
19 #include "opencv2/gapi/own/assert.hpp"
20
21 // TODO GAPI_EXPORTS or so
22 namespace cv
23 {
24 // Forward declaration; GNode and GOrigin are an internal
25 // (user-inaccessible) classes.
26 class GNode;
27 struct GOrigin;
28
29 /** \addtogroup gapi_data_objects
30  * @{
31  *
32  * @brief Data-representing objects which can be used to build G-API
33  * expressions.
34  */
35
36 class GAPI_EXPORTS GMat
37 {
38 public:
39     GMat();                                 // Empty constructor
40     GMat(const GNode &n, std::size_t out);  // Operation result constructor
41
42     GOrigin& priv();                        // Internal use only
43     const GOrigin& priv()  const;           // Internal use only
44
45 private:
46     std::shared_ptr<GOrigin> m_priv;
47 };
48
49 /** @} */
50
51 /**
52  * \addtogroup gapi_meta_args
53  * @{
54  */
55 struct GAPI_EXPORTS GMatDesc
56 {
57     // FIXME: Default initializers in C++14
58     int depth;
59     int chan;
60     cv::gapi::own::Size size; // NB.: no multi-dimensional cases covered yet
61
62     inline bool operator== (const GMatDesc &rhs) const
63     {
64         return depth == rhs.depth && chan == rhs.chan && size == rhs.size;
65     }
66
67     inline bool operator!= (const GMatDesc &rhs) const
68     {
69         return !(*this == rhs);
70     }
71
72     // Meta combinator: return a new GMatDesc which differs in size by delta
73     // (all other fields are taken unchanged from this GMatDesc)
74     // FIXME: a better name?
75     GMatDesc withSizeDelta(cv::gapi::own::Size delta) const
76     {
77         GMatDesc desc(*this);
78         desc.size += delta;
79         return desc;
80     }
81 #if !defined(GAPI_STANDALONE)
82     GMatDesc withSizeDelta(cv::Size delta) const
83     {
84         return withSizeDelta(to_own(delta));
85     }
86
87     GMatDesc withSize(cv::Size sz) const
88     {
89         return withSize(to_own(sz));
90     }
91 #endif // !defined(GAPI_STANDALONE)
92     // Meta combinator: return a new GMatDesc which differs in size by delta
93     // (all other fields are taken unchanged from this GMatDesc)
94     //
95     // This is an overload.
96     GMatDesc withSizeDelta(int dx, int dy) const
97     {
98         return withSizeDelta(cv::gapi::own::Size{dx,dy});
99     }
100
101     GMatDesc withSize(cv::gapi::own::Size sz) const
102     {
103         GMatDesc desc(*this);
104         desc.size = sz;
105         return desc;
106     }
107
108     // Meta combinator: return a new GMatDesc with specified data depth.
109     // (all other fields are taken unchanged from this GMatDesc)
110     GMatDesc withDepth(int ddepth) const
111     {
112         GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1);
113         GMatDesc desc(*this);
114         if (ddepth != -1) desc.depth = ddepth;
115         return desc;
116     }
117
118     // Meta combinator: return a new GMatDesc with specified data depth
119     // and number of channels.
120     // (all other fields are taken unchanged from this GMatDesc)
121     GMatDesc withType(int ddepth, int dchan) const
122     {
123         GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1);
124         GMatDesc desc = withDepth(ddepth);
125         desc.chan = dchan;
126         return desc;
127     }
128 };
129
130 static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; }
131
132 #if !defined(GAPI_STANDALONE)
133 class Mat;
134 GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat);
135 GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat);
136 #endif // !defined(GAPI_STANDALONE)
137
138 /** @} */
139
140 namespace gapi { namespace own {
141     class Mat;
142     GAPI_EXPORTS GMatDesc descr_of(const Mat &mat);
143 }}//gapi::own
144
145 GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc);
146
147 } // namespace cv
148
149 #endif // OPENCV_GAPI_GMAT_HPP