Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/highgui/src/window_winrt_bridge.hpp
16337 views
1
// highgui to XAML bridge for OpenCV
2
3
// Copyright (c) Microsoft Open Technologies, Inc.
4
// All rights reserved.
5
//
6
// (3 - clause BSD License)
7
//
8
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
9
// the following conditions are met:
10
//
11
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
12
// following disclaimer.
13
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14
// following disclaimer in the documentation and/or other materials provided with the distribution.
15
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
16
// promote products derived from this software without specific prior written permission.
17
//
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
21
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
22
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
// POSSIBILITY OF SUCH DAMAGE.
26
27
#pragma once
28
29
#include <map>
30
#include <opencv2\core.hpp>
31
32
using namespace Windows::UI::Xaml::Controls;
33
34
class CvWindow;
35
class CvTrackbar;
36
37
class HighguiBridge
38
{
39
public:
40
41
/** @brief Instantiates a Highgui singleton (Meyers type).
42
43
The function Instantiates a Highgui singleton (Meyers type) and returns reference to that instance.
44
*/
45
static HighguiBridge& getInstance();
46
47
/** @brief Finds window by name and returns the reference to it.
48
49
@param name Name of the window.
50
51
The function finds window by name and returns the reference to it. Returns nullptr
52
if window with specified name is not found or name argument is null.
53
*/
54
CvWindow* findWindowByName(cv::String name);
55
56
/** @brief Returns reference to the trackbar(slider) registered within window with a provided name.
57
58
@param name Name of the window.
59
60
The function returns reference to the trackbar(slider) registered within window with a provided name.
61
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
62
*/
63
CvTrackbar* findTrackbarByName(cv::String trackbarName, cv::String windowName);
64
65
/** @brief Converts cv::String to Platform::String.
66
67
@param name String to convert.
68
69
The function converts cv::String to Platform::String.
70
Returns nullptr if conversion fails.
71
*/
72
Platform::String^ convertString(cv::String name);
73
74
/** @brief Creates window if there is no window with this name, otherwise returns existing window.
75
76
@param name Window name.
77
78
The function creates window if there is no window with this name, otherwise returns existing window.
79
*/
80
CvWindow* namedWindow(cv::String name);
81
82
/** @brief Shows provided window.
83
84
The function shows provided window: makes provided window current, removes current container
85
contents and shows current window by putting it as a container content.
86
*/
87
void showWindow(CvWindow* window);
88
89
/** @brief Destroys window if there exists window with this name, otherwise does nothing.
90
91
@param name Window name.
92
93
The function destroys window if there exists window with this name, otherwise does nothing.
94
If window being destroyed is the current one, it will be hidden by clearing the window container.
95
*/
96
void destroyWindow(cv::String name);
97
98
/** @brief Destroys all windows.
99
100
The function destroys all windows.
101
*/
102
void destroyAllWindows();
103
104
/** @brief Assigns container used to display windows.
105
106
@param _container Container reference.
107
108
The function assigns container used to display windows.
109
*/
110
void setContainer(Windows::UI::Xaml::Controls::Panel^ _container);
111
112
private:
113
114
// Meyers singleton
115
HighguiBridge(const HighguiBridge &);
116
void operator=(HighguiBridge &);
117
HighguiBridge() {
118
windowsMap = new std::map<cv::String, CvWindow*>();
119
};
120
121
/** @brief Creates window if there is no window with this name.
122
123
@param name Window name.
124
125
The function creates window if there is no window with this name.
126
*/
127
CvWindow* createWindow(cv::String name);
128
129
/** @brief Cleans current container contents.
130
131
The function cleans current container contents.
132
*/
133
void cleanContainer();
134
135
// see https://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh700103.aspx
136
// see https://msdn.microsoft.com/ru-ru/library/windows.foundation.collections.aspx
137
std::map<cv::String, CvWindow*>* windowsMap;
138
CvWindow* currentWindow;
139
140
// Holds current container/content to manipulate with
141
Windows::UI::Xaml::Controls::Panel^ container;
142
};
143
144
class CvTrackbar
145
{
146
public:
147
CvTrackbar(cv::String name, Slider^ slider, CvWindow* parent);
148
~CvTrackbar();
149
150
double getPosition();
151
void setPosition(double pos);
152
double getMaxPosition();
153
void setMaxPosition(double pos);
154
double getMinPosition();
155
void setMinPosition(double pos);
156
Slider^ getSlider();
157
void setSlider(Slider^ pos);
158
159
CvTrackbarCallback2 callback;
160
161
private:
162
cv::String name;
163
Slider^ slider;
164
CvWindow* parent;
165
};
166
167
class CvWindow
168
{
169
public:
170
CvWindow(cv::String name, int flag = CV_WINDOW_NORMAL);
171
~CvWindow();
172
173
/** @brief NOTE: prototype.
174
175
Should create button if there is no button with this name already.
176
*/
177
void createButton(cv::String name);
178
179
/** @brief Creates slider if there is no slider with this name already.
180
181
The function creates slider if there is no slider with this name already OR resets
182
provided values for the existing one.
183
*/
184
void createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata);
185
186
/** @brief Updates window image.
187
188
@param src Image data object reference.
189
190
The function updates window image. If argument is null or image control is not found - does nothing.
191
*/
192
void updateImage(CvMat* arr);
193
194
/** @brief Returns reference to the trackbar(slider) registered within provided window.
195
196
@param name Name of the window.
197
198
The function returns reference to the trackbar(slider) registered within provided window.
199
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
200
*/
201
CvTrackbar* findTrackbarByName(cv::String name);
202
Page^ getPage();
203
204
private:
205
cv::String name;
206
207
// Holds image data in CV format
208
CvMat* imageData;
209
210
// Map of all sliders assigned to this window
211
std::map<cv::String, CvTrackbar*>* sliderMap;
212
213
// Window contents holder
214
Page^ page;
215
216
// Image control displayed by this window
217
Image^ imageControl;
218
219
// Container for sliders
220
Panel^ sliderPanel;
221
222
// Container for buttons
223
// TODO: prototype, not available via API
224
Panel^ buttonPanel;
225
226
// Holds image width to arrange other UI elements.
227
// Required since imageData->width value gets recalculated when processing
228
int imageWidth;
229
230
// Default markup for the container content allowing for proper components placement
231
static const Platform::String^ markupContent;
232
233
// Default Slider size, fallback solution for unexpected edge cases
234
static const double sliderDefaultWidth;
235
};
236