Signed-off-by: Maxim Kostin <v-maxkos@microsoft.com>pull/4155/head
parent
8298644b85
commit
face069874
8 changed files with 857 additions and 336 deletions
@ -0,0 +1,48 @@ |
||||
// highgui (UX) support for Windows Runtime
|
||||
|
||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// (3 - clause BSD License)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
||||
// the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
// following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
||||
// following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
|
||||
// promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using namespace Windows::UI::Xaml::Controls; |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
//! @addtogroup highgui_winrt
|
||||
//! @{
|
||||
|
||||
/********************************** WinRT Specific API *************************************************/ |
||||
|
||||
/** @brief Initializes container component that will be used to hold generated window content.
|
||||
|
||||
@param container Container (Panel^) reference that will be used to hold generated window content: controls and image. |
||||
|
||||
@note |
||||
Must be called to assign WinRT container that will hold created windows content. |
||||
*/ |
||||
CV_EXPORTS void winrt_initContainer(::Windows::UI::Xaml::Controls::Panel^ container); |
||||
|
||||
//! @} videoio_winrt
|
||||
|
||||
} // cv
|
@ -0,0 +1,346 @@ |
||||
// highgui to XAML bridge for OpenCV
|
||||
|
||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// (3 - clause BSD License)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
||||
// the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
// following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
||||
// following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
|
||||
// promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "opencv2\highgui\highgui_winrt.hpp" |
||||
#include "window_winrt_bridge.hpp" |
||||
|
||||
#include <collection.h> |
||||
#include <Robuffer.h> // Windows::Storage::Streams::IBufferByteAccess |
||||
|
||||
using namespace Microsoft::WRL; // ComPtr
|
||||
using namespace Windows::Storage::Streams; // IBuffer
|
||||
using namespace Windows::UI::Xaml; |
||||
using namespace Windows::UI::Xaml::Controls; |
||||
using namespace Windows::UI::Xaml::Media::Imaging; |
||||
|
||||
using namespace ::std; |
||||
|
||||
/***************************** Constants ****************************************/ |
||||
|
||||
// Default markup for the container content allowing for proper components placement
|
||||
const Platform::String^ CvWindow::markupContent = |
||||
"<Page \n" \
|
||||
" xmlns = \"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n" \
|
||||
" xmlns:x = \"http://schemas.microsoft.com/winfx/2006/xaml\" >\n" \
|
||||
" <StackPanel Name=\"Container\" Orientation=\"Vertical\" Width=\"Auto\" Height=\"Auto\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" Visibility=\"Visible\">\n" \
|
||||
" <Image Name=\"cvImage\" Width=\"Auto\" Height=\"Auto\" Margin=\"10\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" Visibility=\"Visible\"/>\n" \
|
||||
" <StackPanel Name=\"cvTrackbar\" Height=\"Auto\" Width=\"Auto\" Orientation=\"Vertical\" Visibility=\"Visible\"/>\n" \
|
||||
" <StackPanel Name=\"cvButton\" Height=\"Auto\" Width=\"Auto\" Orientation=\"Horizontal\" Visibility=\"Visible\"/>\n" \
|
||||
" </StackPanel>\n" \
|
||||
"</Page>"; |
||||
|
||||
const double CvWindow::sliderDefaultWidth = 100; |
||||
|
||||
/***************************** HighguiBridge class ******************************/ |
||||
|
||||
HighguiBridge& HighguiBridge::getInstance() |
||||
{ |
||||
static HighguiBridge instance; |
||||
return instance; |
||||
} |
||||
|
||||
void HighguiBridge::setContainer(Windows::UI::Xaml::Controls::Panel^ container) |
||||
{ |
||||
this->container = container; |
||||
} |
||||
|
||||
CvWindow* HighguiBridge::findWindowByName(cv::String name) |
||||
{ |
||||
auto search = windowsMap->find(name); |
||||
if (search != windowsMap->end()) { |
||||
return search->second; |
||||
} |
||||
|
||||
return nullptr; |
||||
} |
||||
|
||||
CvTrackbar* HighguiBridge::findTrackbarByName(cv::String trackbar_name, cv::String window_name) |
||||
{ |
||||
CvWindow* window = findWindowByName(window_name); |
||||
|
||||
if (window) |
||||
return window->findTrackbarByName(trackbar_name); |
||||
|
||||
return nullptr; |
||||
} |
||||
|
||||
Platform::String^ HighguiBridge::convertString(cv::String name) |
||||
{ |
||||
auto data = name.c_str(); |
||||
int bufferSize = MultiByteToWideChar(CP_UTF8, 0, data, -1, nullptr, 0); |
||||
auto wide = std::make_unique<wchar_t[]>(bufferSize); |
||||
if (0 == MultiByteToWideChar(CP_UTF8, 0, data, -1, wide.get(), bufferSize)) |
||||
return nullptr; |
||||
|
||||
std::wstring* stdStr = new std::wstring(wide.get()); |
||||
return ref new Platform::String(stdStr->c_str()); |
||||
} |
||||
|
||||
void HighguiBridge::cleanContainer() |
||||
{ |
||||
container->Children->Clear(); |
||||
} |
||||
|
||||
void HighguiBridge::showWindow(CvWindow* window) |
||||
{ |
||||
currentWindow = window; |
||||
cleanContainer(); |
||||
HighguiBridge::getInstance().container->Children->Append(window->getPage()); |
||||
} |
||||
|
||||
CvWindow* HighguiBridge::namedWindow(cv::String name) { |
||||
|
||||
CvWindow* window = HighguiBridge::getInstance().findWindowByName(name.c_str()); |
||||
if (!window) |
||||
{ |
||||
window = createWindow(name); |
||||
} |
||||
|
||||
return window; |
||||
} |
||||
|
||||
void HighguiBridge::destroyWindow(cv::String name) |
||||
{ |
||||
auto window = windowsMap->find(name); |
||||
if (window != windowsMap->end()) |
||||
{ |
||||
// Check if deleted window is the one currently displayed
|
||||
// and clear container if this is the case
|
||||
if (window->second == currentWindow) |
||||
{ |
||||
cleanContainer(); |
||||
} |
||||
|
||||
windowsMap->erase(window); |
||||
} |
||||
} |
||||
|
||||
void HighguiBridge::destroyAllWindows() |
||||
{ |
||||
cleanContainer(); |
||||
windowsMap->clear(); |
||||
} |
||||
|
||||
CvWindow* HighguiBridge::createWindow(cv::String name) |
||||
{ |
||||
CvWindow* window = new CvWindow(name); |
||||
windowsMap->insert(std::pair<cv::String, CvWindow*>(name, window)); |
||||
|
||||
return window; |
||||
} |
||||
|
||||
/***************************** CvTrackbar class *********************************/ |
||||
|
||||
CvTrackbar::CvTrackbar(cv::String name, Slider^ slider, CvWindow* parent) : name(name), slider(slider), parent(parent) {} |
||||
|
||||
CvTrackbar::~CvTrackbar() {} |
||||
|
||||
void CvTrackbar::setPosition(double pos) |
||||
{ |
||||
if (pos < 0) |
||||
pos = 0; |
||||
|
||||
if (pos > slider->Maximum) |
||||
pos = slider->Maximum; |
||||
|
||||
slider->Value = pos; |
||||
} |
||||
|
||||
void CvTrackbar::setMaxPosition(double pos) |
||||
{ |
||||
if (pos < 0) |
||||
pos = 0; |
||||
|
||||
slider->Maximum = pos; |
||||
} |
||||
|
||||
void CvTrackbar::setSlider(Slider^ slider) { |
||||
if (slider) |
||||
this->slider = slider; |
||||
} |
||||
|
||||
double CvTrackbar::getPosition() |
||||
{ |
||||
return slider->Value; |
||||
} |
||||
|
||||
double CvTrackbar::getMaxPosition() |
||||
{ |
||||
return slider->Maximum; |
||||
} |
||||
|
||||
Slider^ CvTrackbar::getSlider() |
||||
{ |
||||
return slider; |
||||
} |
||||
|
||||
/***************************** CvWindow class ***********************************/ |
||||
|
||||
CvWindow::CvWindow(cv::String name, int flags) : name(name) |
||||
{ |
||||
this->page = (Page^)Windows::UI::Xaml::Markup::XamlReader::Load(const_cast<Platform::String^>(markupContent)); |
||||
this->sliderMap = new std::map<cv::String, CvTrackbar*>(); |
||||
|
||||
sliderPanel = (Panel^)page->FindName("cvTrackbar"); |
||||
imageControl = (Image^)page->FindName("cvImage"); |
||||
buttonPanel = (Panel^)page->FindName("cvButton"); |
||||
|
||||
// Required to adapt controls to the size of the image.
|
||||
// System calculates image control width first, after that we can
|
||||
// update other controls
|
||||
imageControl->Loaded += ref new Windows::UI::Xaml::RoutedEventHandler( |
||||
[=](Platform::Object^ sender, |
||||
Windows::UI::Xaml::RoutedEventArgs^ e) |
||||
{ |
||||
// Need to update sliders with appropriate width
|
||||
for (auto iter = sliderMap->begin(); iter != sliderMap->end(); ++iter) { |
||||
iter->second->getSlider()->Width = imageControl->ActualWidth; |
||||
} |
||||
|
||||
// Need to update buttons with appropriate width
|
||||
// TODO: implement when adding buttons
|
||||
}); |
||||
|
||||
} |
||||
|
||||
CvWindow::~CvWindow() {} |
||||
|
||||
void CvWindow::createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata) |
||||
{ |
||||
CvTrackbar* trackbar = findTrackbarByName(name); |
||||
|
||||
// Creating slider if name is new or reusing the existing one
|
||||
Slider^ slider = !trackbar ? ref new Slider() : trackbar->getSlider(); |
||||
|
||||
slider->Header = HighguiBridge::getInstance().convertString(name); |
||||
|
||||
// Making slider the same size as the image control or setting minimal size.
|
||||
// This is added to cover potential edge cases because:
|
||||
// 1. Fist clause will not be true until the second call to any container-updating API
|
||||
// e.g. cv::createTrackbar, cv:imshow or cv::namedWindow
|
||||
// 2. Second clause will work but should be immediately overridden by Image->Loaded callback,
|
||||
// see CvWindow ctor.
|
||||
if (this->imageControl->ActualWidth > 0) { |
||||
// One would use double.NaN for auto-stretching but there is no such constant in C++/CX
|
||||
// see https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.frameworkelement.width
|
||||
slider->Width = this->imageControl->ActualWidth; |
||||
} else { |
||||
// This value would never be used/seen on the screen unless there is something wrong with the image.
|
||||
// Although this code actually gets called, slider width will be overridden in the callback after
|
||||
// Image control is loaded. See callback implementation in CvWindow ctor.
|
||||
slider->Width = sliderDefaultWidth; |
||||
} |
||||
slider->Value = *val; |
||||
slider->Maximum = count; |
||||
slider->Visibility = Windows::UI::Xaml::Visibility::Visible; |
||||
slider->Margin = Windows::UI::Xaml::ThicknessHelper::FromLengths(10, 10, 10, 0); |
||||
slider->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Left; |
||||
|
||||
if (!trackbar) |
||||
{ |
||||
if (!sliderPanel) return; |
||||
|
||||
// Adding slider to the list for current window
|
||||
CvTrackbar* trackbar = new CvTrackbar(name, slider, this); |
||||
trackbar->callback = on_notify; |
||||
slider->ValueChanged += |
||||
ref new Controls::Primitives::RangeBaseValueChangedEventHandler( |
||||
[=](Platform::Object^ sender, |
||||
Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e) |
||||
{ |
||||
Slider^ slider = (Slider^)sender; |
||||
trackbar->callback(slider->Value, nullptr); |
||||
}); |
||||
this->sliderMap->insert(std::pair<cv::String, CvTrackbar*>(name, trackbar)); |
||||
|
||||
// Adding slider to the window
|
||||
sliderPanel->Children->Append(slider); |
||||
} |
||||
} |
||||
|
||||
CvTrackbar* CvWindow::findTrackbarByName(cv::String name) |
||||
{ |
||||
auto search = sliderMap->find(name); |
||||
if (search != sliderMap->end()) { |
||||
return search->second; |
||||
} |
||||
|
||||
return nullptr; |
||||
} |
||||
|
||||
void CvWindow::updateImage(CvMat* src) |
||||
{ |
||||
if (!imageControl) return; |
||||
|
||||
this->imageData = src; |
||||
this->imageWidth = src->width; |
||||
|
||||
// Create the WriteableBitmap
|
||||
WriteableBitmap^ bitmap = ref new WriteableBitmap(src->cols, src->rows); |
||||
|
||||
// Get access to the pixels
|
||||
IBuffer^ buffer = bitmap->PixelBuffer; |
||||
unsigned char* dstPixels; |
||||
|
||||
// Obtain IBufferByteAccess
|
||||
ComPtr<IBufferByteAccess> pBufferByteAccess; |
||||
ComPtr<IInspectable> pBuffer((IInspectable*)buffer); |
||||
pBuffer.As(&pBufferByteAccess); |
||||
|
||||
// Get pointer to pixel bytes
|
||||
pBufferByteAccess->Buffer(&dstPixels); |
||||
memcpy(dstPixels, src->data.ptr, CV_ELEM_SIZE(src->type) * src->cols*src->rows); |
||||
|
||||
// Set the bitmap to the Image element
|
||||
imageControl->Source = bitmap; |
||||
} |
||||
|
||||
Page^ CvWindow::getPage() |
||||
{ |
||||
return page; |
||||
} |
||||
|
||||
//TODO: prototype, not in use yet
|
||||
void CvWindow::createButton(cv::String name) |
||||
{ |
||||
if (!buttonPanel) return; |
||||
|
||||
Button^ b = ref new Button(); |
||||
b->Content = HighguiBridge::getInstance().convertString(name); |
||||
b->Width = 260; |
||||
b->Height = 80; |
||||
b->Click += ref new Windows::UI::Xaml::RoutedEventHandler( |
||||
[=](Platform::Object^ sender, |
||||
Windows::UI::Xaml::RoutedEventArgs^ e) |
||||
{ |
||||
Button^ button = (Button^)sender; |
||||
// TODO: more logic here...
|
||||
}); |
||||
|
||||
buttonPanel->Children->Append(b); |
||||
} |
||||
|
||||
// end
|
@ -0,0 +1,233 @@ |
||||
// highgui to XAML bridge for OpenCV
|
||||
|
||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// (3 - clause BSD License)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
||||
// the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
// following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
||||
// following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
|
||||
// promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once |
||||
|
||||
#include <map> |
||||
#include <opencv2\core.hpp> |
||||
|
||||
using namespace Windows::UI::Xaml::Controls; |
||||
|
||||
class CvWindow; |
||||
class CvTrackbar; |
||||
|
||||
class HighguiBridge |
||||
{ |
||||
public: |
||||
|
||||
/** @brief Instantiates a Highgui singleton (Meyers type).
|
||||
|
||||
The function Instantiates a Highgui singleton (Meyers type) and returns reference to that instance. |
||||
*/ |
||||
static HighguiBridge& getInstance(); |
||||
|
||||
/** @brief Finds window by name and returns the reference to it.
|
||||
|
||||
@param name Name of the window. |
||||
|
||||
The function finds window by name and returns the reference to it. Returns nullptr |
||||
if window with specified name is not found or name argument is null. |
||||
*/ |
||||
CvWindow* findWindowByName(cv::String name); |
||||
|
||||
/** @brief Returns reference to the trackbar(slider) registered within window with a provided name.
|
||||
|
||||
@param name Name of the window. |
||||
|
||||
The function returns reference to the trackbar(slider) registered within window with a provided name. |
||||
Returns nullptr if trackbar with specified name is not found or window reference is nullptr. |
||||
*/ |
||||
CvTrackbar* findTrackbarByName(cv::String trackbarName, cv::String windowName); |
||||
|
||||
/** @brief Converts cv::String to Platform::String.
|
||||
|
||||
@param name String to convert. |
||||
|
||||
The function converts cv::String to Platform::String. |
||||
Returns nullptr if conversion fails. |
||||
*/ |
||||
Platform::String^ convertString(cv::String name); |
||||
|
||||
/** @brief Creates window if there is no window with this name, otherwise returns existing window.
|
||||
|
||||
@param name Window name. |
||||
|
||||
The function creates window if there is no window with this name, otherwise returns existing window. |
||||
*/ |
||||
CvWindow* namedWindow(cv::String name); |
||||
|
||||
/** @brief Shows provided window.
|
||||
|
||||
The function shows provided window: makes provided window current, removes current container |
||||
contents and shows current window by putting it as a container content. |
||||
*/ |
||||
void showWindow(CvWindow* window); |
||||
|
||||
/** @brief Destroys window if there exists window with this name, otherwise does nothing.
|
||||
|
||||
@param name Window name. |
||||
|
||||
The function destroys window if there exists window with this name, otherwise does nothing. |
||||
If window being destroyed is the current one, it will be hidden by clearing the window container. |
||||
*/ |
||||
void destroyWindow(cv::String name); |
||||
|
||||
/** @brief Destroys all windows.
|
||||
|
||||
The function destroys all windows. |
||||
*/ |
||||
void destroyAllWindows(); |
||||
|
||||
/** @brief Assigns container used to display windows.
|
||||
|
||||
@param _container Container reference. |
||||
|
||||
The function assigns container used to display windows. |
||||
*/ |
||||
void setContainer(Windows::UI::Xaml::Controls::Panel^ _container); |
||||
|
||||
private: |
||||
|
||||
// Meyers singleton
|
||||
HighguiBridge(const HighguiBridge &); |
||||
void operator=(HighguiBridge &); |
||||
HighguiBridge() { |
||||
windowsMap = new std::map<cv::String, CvWindow*>(); |
||||
}; |
||||
|
||||
/** @brief Creates window if there is no window with this name.
|
||||
|
||||
@param name Window name. |
||||
|
||||
The function creates window if there is no window with this name. |
||||
*/ |
||||
CvWindow* createWindow(cv::String name); |
||||
|
||||
/** @brief Cleans current container contents.
|
||||
|
||||
The function cleans current container contents. |
||||
*/ |
||||
void cleanContainer(); |
||||
|
||||
// see https://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh700103.aspx
|
||||
// see https://msdn.microsoft.com/ru-ru/library/windows.foundation.collections.aspx
|
||||
std::map<cv::String, CvWindow*>* windowsMap; |
||||
CvWindow* currentWindow; |
||||
|
||||
// Holds current container/content to manipulate with
|
||||
Windows::UI::Xaml::Controls::Panel^ container; |
||||
}; |
||||
|
||||
class CvTrackbar |
||||
{ |
||||
public: |
||||
CvTrackbar(cv::String name, Slider^ slider, CvWindow* parent); |
||||
~CvTrackbar(); |
||||
|
||||
double getPosition(); |
||||
void setPosition(double pos); |
||||
double getMaxPosition(); |
||||
void setMaxPosition(double pos); |
||||
Slider^ getSlider(); |
||||
void setSlider(Slider^ pos); |
||||
|
||||
CvTrackbarCallback2 callback; |
||||
|
||||
private: |
||||
cv::String name; |
||||
Slider^ slider; |
||||
CvWindow* parent; |
||||
}; |
||||
|
||||
class CvWindow |
||||
{ |
||||
public: |
||||
CvWindow(cv::String name, int flag = CV_WINDOW_NORMAL); |
||||
~CvWindow(); |
||||
|
||||
/** @brief NOTE: prototype.
|
||||
|
||||
Should create button if there is no button with this name already. |
||||
*/ |
||||
void createButton(cv::String name); |
||||
|
||||
/** @brief Creates slider if there is no slider with this name already.
|
||||
|
||||
The function creates slider if there is no slider with this name already OR resets |
||||
provided values for the existing one. |
||||
*/ |
||||
void createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata); |
||||
|
||||
/** @brief Updates window image.
|
||||
|
||||
@param src Image data object reference. |
||||
|
||||
The function updates window image. If argument is null or image control is not found - does nothing. |
||||
*/ |
||||
void updateImage(CvMat* arr); |
||||
|
||||
/** @brief Returns reference to the trackbar(slider) registered within provided window.
|
||||
|
||||
@param name Name of the window. |
||||
|
||||
The function returns reference to the trackbar(slider) registered within provided window. |
||||
Returns nullptr if trackbar with specified name is not found or window reference is nullptr. |
||||
*/ |
||||
CvTrackbar* findTrackbarByName(cv::String name); |
||||
Page^ getPage(); |
||||
|
||||
private: |
||||
cv::String name; |
||||
|
||||
// Holds image data in CV format
|
||||
CvMat* imageData; |
||||
|
||||
// Map of all sliders assigned to this window
|
||||
std::map<cv::String, CvTrackbar*>* sliderMap; |
||||
|
||||
// Window contents holder
|
||||
Page^ page; |
||||
|
||||
// Image control displayed by this window
|
||||
Image^ imageControl; |
||||
|
||||
// Container for sliders
|
||||
Panel^ sliderPanel; |
||||
|
||||
// Container for buttons
|
||||
// TODO: prototype, not available via API
|
||||
Panel^ buttonPanel; |
||||
|
||||
// Holds image width to arrange other UI elements.
|
||||
// Required since imageData->width value gets recalculated when processing
|
||||
int imageWidth; |
||||
|
||||
// Default markup for the container content allowing for proper components placement
|
||||
static const Platform::String^ markupContent; |
||||
|
||||
// Default Slider size, fallback solution for unexpected edge cases
|
||||
static const double sliderDefaultWidth; |
||||
}; |
Loading…
Reference in new issue