2010-06-10 22:03:52 +02:00
|
|
|
//IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
|
|
|
|
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
|
|
|
|
//Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
//Copyright (C) 2008-2010, Willow Garage Inc., all rights reserved.
|
|
|
|
//Third party copyrights are property of their respective owners.
|
|
|
|
|
|
|
|
//Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
//are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
// * Redistribution's 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.
|
|
|
|
|
|
|
|
// * The name of the copyright holders may not 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 Intel Corporation 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.
|
|
|
|
|
|
|
|
//--------------------Google Code 2010 -- Yannick Verdie--------------------//
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_QT
|
|
|
|
|
|
|
|
#include <window_QT.h>
|
|
|
|
|
|
|
|
//Static and global first
|
|
|
|
static GuiReceiver guiMainThread;
|
2010-06-14 18:00:38 +02:00
|
|
|
static int parameterSystemC = 1;
|
|
|
|
static char* parameterSystemV[] = {""};
|
2010-06-10 22:03:52 +02:00
|
|
|
static bool multiThreads = false;
|
|
|
|
static int last_key = -1;
|
|
|
|
QWaitCondition key_pressed;
|
|
|
|
QMutex mutexKey;
|
2010-07-16 11:12:15 +02:00
|
|
|
static const unsigned int threshold_zoom_img_region = 15;
|
|
|
|
//the minimum zoom value to start displaying the values in the grid
|
|
|
|
//that is also the number of pixel per grid
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
//end static and global
|
|
|
|
|
2010-07-12 13:04:26 +02:00
|
|
|
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
CvFont cvFont_Qt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing)
|
2010-07-12 13:04:26 +02:00
|
|
|
{
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
/*
|
2010-07-12 13:04:26 +02:00
|
|
|
//nameFont <- only Qt
|
|
|
|
//CvScalar color <- only Qt (blue_component, green_component, red\_component[, alpha_component])
|
|
|
|
int font_face;//<- style in Qt
|
|
|
|
const int* ascii;
|
|
|
|
const int* greek;
|
|
|
|
const int* cyrillic;
|
|
|
|
float hscale, vscale;
|
|
|
|
float shear;
|
|
|
|
int thickness;//<- weight in Qt
|
|
|
|
float dx;//spacing letter in Qt (0 default) in pixel
|
|
|
|
int line_type;//<- pointSize in Qt
|
|
|
|
*/
|
2010-07-16 14:51:29 +02:00
|
|
|
CvFont f = {nameFont,color,style,NULL,NULL,NULL,0,0,0,weight,spacing,pointSize};
|
2010-07-12 13:04:26 +02:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvAddText( CvArr* img, const char* text, CvPoint org, CvFont* font)
|
2010-07-12 13:04:26 +02:00
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"putText",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(void*, (void*) img),
|
|
|
|
Q_ARG(QString,QString(text)),
|
|
|
|
Q_ARG(QPoint, QPoint(org.x,org.y)),
|
|
|
|
Q_ARG(void*,(void*) font));
|
2010-07-12 13:04:26 +02:00
|
|
|
}
|
|
|
|
|
2010-06-27 00:36:41 +02:00
|
|
|
double cvGetRatioWindow_QT(const char* name)
|
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
double result = -1;
|
2010-06-27 00:36:41 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"getRatioWindow",
|
|
|
|
//Qt::DirectConnection,
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_RETURN_ARG(double, result),
|
|
|
|
Q_ARG(QString, QString(name)));
|
2010-06-27 00:36:41 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cvSetRatioWindow_QT(const char* name,double prop_value)
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"setRatioWindow",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(double, prop_value));
|
2010-06-27 00:36:41 +02:00
|
|
|
}
|
2010-06-12 20:08:27 +02:00
|
|
|
|
|
|
|
double cvGetPropWindow_QT(const char* name)
|
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
double result = -1;
|
2010-06-12 20:08:27 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"getPropWindow",
|
|
|
|
//Qt::DirectConnection,
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_RETURN_ARG(double, result),
|
|
|
|
Q_ARG(QString, QString(name)));
|
2010-06-12 20:08:27 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cvSetPropWindow_QT(const char* name,double prop_value)
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"setPropWindow",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(double, prop_value));
|
2010-06-12 20:08:27 +02:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:56:01 +02:00
|
|
|
void cvSetModeWindow_QT(const char* name, double prop_value)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-12 18:36:46 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"toggleFullScreen",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(double, prop_value));
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:56:01 +02:00
|
|
|
double cvGetModeWindow_QT(const char* name)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
double result = -1;
|
2010-06-12 18:36:46 +02:00
|
|
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"isFullScreen",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_RETURN_ARG(double, result),
|
|
|
|
Q_ARG(QString, QString(name)));
|
2010-06-12 18:36:46 +02:00
|
|
|
return result;
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvDisplayOverlay(const char* name, const char* text, int delayms)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
|
2010-06-12 18:36:46 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"displayInfo",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
//Qt::DirectConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(QString, QString(text)),
|
|
|
|
Q_ARG(int, delayms));
|
|
|
|
|
2010-06-12 18:36:46 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvSaveWindowParameters(const char* name)
|
2010-06-30 00:14:24 +02:00
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
"saveWindowParameters",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)));
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvLoadWindowParameters(const char* name)
|
2010-06-30 00:14:24 +02:00
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
"loadWindowParameters",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)));
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvDisplayStatusBar(const char* name, const char* text, int delayms)
|
2010-06-22 19:15:49 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"displayStatusBar",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
//Qt::DirectConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(QString, QString(text)),
|
|
|
|
Q_ARG(int, delayms));
|
2010-06-22 19:15:49 +02:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvInitSystem( int, char** )
|
2010-06-19 18:26:22 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
return 0;
|
2010-06-19 18:26:22 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvWaitKey( int arg )
|
2010-06-12 18:36:46 +02:00
|
|
|
{
|
2010-06-10 22:03:52 +02:00
|
|
|
int result = -1;
|
2010-06-11 09:35:36 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
unsigned long delayms;//in milliseconds
|
|
|
|
if (arg<=0)
|
2010-07-16 14:51:29 +02:00
|
|
|
delayms = ULONG_MAX;
|
2010-06-10 22:03:52 +02:00
|
|
|
else
|
2010-07-16 14:51:29 +02:00
|
|
|
delayms = arg;
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
if (multiThreads)
|
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
mutexKey.lock();
|
|
|
|
if(key_pressed.wait(&mutexKey,delayms))//false if timeout
|
|
|
|
{
|
|
|
|
result = last_key;
|
|
|
|
}
|
|
|
|
last_key = -1;
|
|
|
|
mutexKey.unlock();
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
}else{
|
2010-07-16 14:51:29 +02:00
|
|
|
//cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)
|
|
|
|
//so I create a Thread for the QTimer
|
|
|
|
|
|
|
|
QTimer timer(&guiMainThread);
|
|
|
|
QObject::connect(&timer, SIGNAL(timeout()), &guiMainThread, SLOT(timeOut()));
|
|
|
|
timer.setSingleShot(true);
|
|
|
|
|
|
|
|
if (arg>0)
|
|
|
|
timer.start(arg);
|
|
|
|
|
|
|
|
//QMutex dummy;
|
|
|
|
|
|
|
|
while(!guiMainThread._bTimeOut)
|
|
|
|
{
|
|
|
|
qApp->processEvents(QEventLoop::AllEvents);
|
|
|
|
|
|
|
|
mutexKey.lock();
|
|
|
|
if (last_key != -1)
|
|
|
|
{
|
|
|
|
result = last_key;
|
|
|
|
last_key = -1;
|
|
|
|
timer.stop();
|
|
|
|
//printf("keypressed\n");
|
|
|
|
}
|
|
|
|
mutexKey.unlock();
|
|
|
|
|
|
|
|
if (result!=-1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2010-07-12 17:24:15 +02:00
|
|
|
* //will not work, I broke the event loop !!!!
|
|
|
|
dummy.lock();
|
|
|
|
QWaitCondition waitCondition;
|
|
|
|
waitCondition.wait(&dummy, 2);
|
|
|
|
*/
|
2010-07-16 14:51:29 +02:00
|
|
|
|
|
|
|
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
|
|
|
|
sleep(2);
|
|
|
|
#else
|
|
|
|
usleep(2);//to decrease CPU usage
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guiMainThread._bTimeOut = false;
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
//Yannick Verdie
|
|
|
|
//This function is experimental and some functions (such as cvSet/getWindowProperty will not work)
|
|
|
|
//We recommend not using this function for now
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
multiThreads = true;
|
|
|
|
QFuture<int> future = QtConcurrent::run(pt2Func,argc,argv);
|
|
|
|
return guiMainThread.start();
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvStopLoop()
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
qApp->exit();
|
|
|
|
}
|
2010-07-16 14:51:29 +02:00
|
|
|
|
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
CvWindow* icvFindWindowByName( const char* arg )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
|
2010-06-11 09:35:36 +02:00
|
|
|
QPointer<CvWindow> window = NULL;
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
if( !arg )
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Error( CV_StsNullPtr, "NULL name string" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
QString name(arg);
|
|
|
|
QPointer<CvWindow> w;
|
|
|
|
foreach (QWidget *widget, QApplication::topLevelWidgets())
|
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
|
|
|
|
if (widget->isWindow() && !widget->parentWidget ())//is a window without parent
|
|
|
|
{
|
|
|
|
w = (CvWindow*) widget;
|
|
|
|
if (w->param_name==name)
|
|
|
|
{
|
|
|
|
window = w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2010-06-12 18:36:46 +02:00
|
|
|
CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
|
2010-06-11 09:35:36 +02:00
|
|
|
QPointer<CvTrackbar> result = NULL;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name_window );
|
|
|
|
|
|
|
|
if( !w )
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Error( CV_StsNullPtr, "NULL window handler" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
QString nameQt = QString(name_trackbar);
|
|
|
|
QPointer<CvTrackbar> t;
|
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
int start_index = 1;
|
|
|
|
if (w->myToolBar)
|
|
|
|
start_index = 2;
|
|
|
|
//Warning ---- , asume the location 0 is toolbar, 1 is myview and max-1 the status bar
|
2010-06-30 00:14:24 +02:00
|
|
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
2010-07-16 14:51:29 +02:00
|
|
|
for (int i = start_index; i < w->myLayout->layout()->count()-1; ++i)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
t = (CvTrackbar*) w->myLayout->layout()->itemAt(i);
|
|
|
|
if (t->trackbar_name==nameQt)
|
|
|
|
{
|
|
|
|
result = t;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int icvInitSystem()
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-14 18:00:38 +02:00
|
|
|
static int wasInitialized = 0;
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
// check initialization status
|
|
|
|
if( !wasInitialized)
|
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
new QApplication(parameterSystemC,parameterSystemV);
|
|
|
|
|
|
|
|
wasInitialized = 1;
|
|
|
|
qDebug()<<"init done";
|
|
|
|
|
|
|
|
#if defined(OPENCV_GL)//OK tested !
|
|
|
|
qDebug()<<"opengl support available";
|
|
|
|
#endif
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvNamedWindow( const char* name, int flags )
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
if (multiThreads)
|
2010-07-16 14:51:29 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
"createWindow",
|
|
|
|
//Qt::AutoConnection,
|
|
|
|
Qt::BlockingQueuedConnection,
|
|
|
|
//TypeConnection,
|
|
|
|
//Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(int, flags));
|
2010-06-10 22:03:52 +02:00
|
|
|
else
|
2010-07-16 14:51:29 +02:00
|
|
|
guiMainThread.createWindow(QString(name),flags);
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
return 1;//Dummy value
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvDestroyWindow( const char* name )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"destroyWindow",
|
|
|
|
//Qt::BlockingQueuedConnection,
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name))
|
|
|
|
);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvDestroyAllWindows(void)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"destroyAllWindow",
|
|
|
|
//Qt::BlockingQueuedConnection,
|
|
|
|
Qt::AutoConnection
|
|
|
|
);
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void* cvGetWindowHandle( const char* name )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
if( !name )
|
2010-07-16 14:51:29 +02:00
|
|
|
CV_Error( CV_StsNullPtr, "NULL name string" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
return (void*) icvFindWindowByName( name );
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
const char* cvGetWindowName( void* window_handle )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
if( !window_handle )
|
2010-07-16 14:51:29 +02:00
|
|
|
CV_Error( CV_StsNullPtr, "NULL window handler" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
return ((CvWindow*)window_handle)->windowTitle().toLatin1().data();
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvMoveWindow( const char* name, int x, int y )
|
|
|
|
{
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"moveWindow",
|
|
|
|
//Qt::BlockingQueuedConnection,
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(int, x),
|
|
|
|
Q_ARG(int, y)
|
|
|
|
);
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvResizeWindow(const char* name, int width, int height )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
2010-07-16 14:51:29 +02:00
|
|
|
"resizeWindow",
|
|
|
|
//Qt::BlockingQueuedConnection,
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(int, width),
|
|
|
|
Q_ARG(int, height)
|
|
|
|
);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvCreateTrackbar2( const char* trackbar_name, const char* window_name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-12 18:36:46 +02:00
|
|
|
//TODO: implement the real one, not a wrapper
|
2010-06-10 22:03:52 +02:00
|
|
|
return cvCreateTrackbar( trackbar_name, window_name, val, count, (CvTrackbarCallback)on_notify );
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvStartWindowThread()
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvCreateTrackbar( const char* trackbar_name, const char* window_name, int* value, int count, CvTrackbarCallback on_change)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
if (multiThreads)
|
2010-07-16 14:51:29 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
"addSlider",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(trackbar_name)),
|
|
|
|
Q_ARG(QString, QString(window_name)),
|
|
|
|
Q_ARG(void*, (void*)value),
|
|
|
|
Q_ARG(int, count),
|
|
|
|
Q_ARG(void*, (void*)on_change)
|
|
|
|
);
|
2010-06-10 22:03:52 +02:00
|
|
|
else
|
2010-07-16 14:51:29 +02:00
|
|
|
guiMainThread.addSlider(QString(trackbar_name),QString(window_name),(void*)value,count,(void*)on_change);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
return 1;//dummy value
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata)
|
2010-07-07 19:53:59 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
"setOpenGLCallback",
|
|
|
|
Qt::AutoConnection,
|
|
|
|
Q_ARG(QString, QString(window_name)),
|
|
|
|
Q_ARG(void*, (void*)callbackOpenGL),
|
|
|
|
Q_ARG(void*, userdata)
|
|
|
|
);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int cvGetTrackbarPos( const char* trackbar_name, const char* window_name )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
int result = -1;
|
2010-07-16 14:51:29 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QPointer<CvTrackbar> t = icvFindTrackbarByName( trackbar_name, window_name );
|
|
|
|
|
|
|
|
if (t)
|
2010-07-16 14:51:29 +02:00
|
|
|
result = t->slider->value();
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QPointer<CvTrackbar> t = icvFindTrackbarByName( trackbar_name, window_name );
|
|
|
|
|
|
|
|
if (t)
|
2010-07-16 14:51:29 +02:00
|
|
|
t->slider->setValue(pos);
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* assign callback for mouse events */
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,void* param )
|
|
|
|
{
|
2010-06-10 22:03:52 +02:00
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( window_name );
|
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 14:51:29 +02:00
|
|
|
CV_Error(CV_StsNullPtr, "NULL window handler" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
w->setMouseCallBack(on_mouse, param);
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void cvShowImage( const char* name, const CvArr* arr )
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-12 18:36:46 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
"showImage",
|
|
|
|
//Qt::BlockingQueuedConnection,
|
|
|
|
Qt::DirectConnection,
|
|
|
|
Q_ARG(QString, QString(name)),
|
|
|
|
Q_ARG(void*, (void*)arr)
|
|
|
|
);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------OBJECT----------------
|
|
|
|
|
|
|
|
GuiReceiver::GuiReceiver() : _bTimeOut(false)
|
2010-06-16 09:58:53 +02:00
|
|
|
{
|
2010-06-14 18:00:38 +02:00
|
|
|
icvInitSystem();
|
2010-06-10 22:03:52 +02:00
|
|
|
qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting
|
|
|
|
}
|
|
|
|
|
2010-07-12 13:04:26 +02:00
|
|
|
void GuiReceiver::putText(void* arg1, QString text, QPoint org, void* arg2)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Assert(arg1)
|
|
|
|
|
|
|
|
IplImage* img = (IplImage*)arg1;
|
|
|
|
|
|
|
|
//for now, only support QImage::Format_RGB888
|
|
|
|
if (img->depth !=IPL_DEPTH_8U || img->nChannels != 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CvFont* font = (CvFont*)arg2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QImage qimg((uchar*) img->imageData, img->width, img->height,QImage::Format_RGB888);
|
|
|
|
QPainter qp(&qimg);
|
|
|
|
if (font)
|
|
|
|
{
|
|
|
|
QFont f(font->nameFont, font->line_type/*PointSize*/, font->thickness/*weight*/);
|
|
|
|
f.setStyle((QFont::Style)font->font_face/*style*/);
|
|
|
|
f.setLetterSpacing ( QFont::AbsoluteSpacing, font->dx/*spacing*/ );
|
|
|
|
//cvScalar(blue_component, green_component, red\_component[, alpha_component])
|
|
|
|
//Qt map non-transparent to 0xFF and transparent to 0
|
|
|
|
//OpenCV scalar is the reverse, so 255-font->color.val[3]
|
|
|
|
qp.setPen(QColor(font->color.val[2],font->color.val[1],font->color.val[0],255-font->color.val[3]));
|
|
|
|
qp.setFont ( f );
|
|
|
|
}
|
|
|
|
qp.drawText (org, text );
|
|
|
|
qp.end();
|
2010-07-12 13:04:26 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
void GuiReceiver::saveWindowParameters(QString name)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->writeSettings();
|
2010-06-30 00:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::loadWindowParameters(QString name)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->readSettings();
|
2010-06-30 00:14:24 +02:00
|
|
|
}
|
|
|
|
|
2010-06-27 00:36:41 +02:00
|
|
|
double GuiReceiver::getRatioWindow(QString name)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return -1;
|
2010-06-27 00:36:41 +02:00
|
|
|
|
|
|
|
return (double)w->getView()->getRatio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::setRatioWindow(QString name, double arg2 )
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-27 00:36:41 +02:00
|
|
|
|
|
|
|
int flags = (int) arg2;
|
|
|
|
|
|
|
|
if (w->getView()->getRatio() == flags)//nothing to do
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-27 00:36:41 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//if valid flags
|
|
|
|
if (flags == CV_WINDOW_FREERATIO || flags == CV_WINDOW_KEEPRATIO)
|
|
|
|
w->getView()->setRatio(flags);
|
2010-06-27 00:36:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-12 20:08:27 +02:00
|
|
|
double GuiReceiver::getPropWindow(QString name)
|
|
|
|
{
|
2010-06-16 09:58:53 +02:00
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
2010-06-12 20:08:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return -1;
|
2010-06-16 09:58:53 +02:00
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
return (double)w->param_flags;
|
2010-06-12 20:08:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::setPropWindow(QString name, double arg2 )
|
|
|
|
{
|
2010-06-16 09:58:53 +02:00
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
2010-06-12 20:08:27 +02:00
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-16 09:58:53 +02:00
|
|
|
|
|
|
|
int flags = (int) arg2;
|
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
if (w->param_flags == flags)//nothing to do
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-16 09:58:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
switch(flags)
|
|
|
|
{
|
|
|
|
case CV_WINDOW_NORMAL:
|
2010-07-16 14:51:29 +02:00
|
|
|
w->myLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
2010-07-16 11:12:15 +02:00
|
|
|
w->param_flags = flags;
|
|
|
|
break;
|
2010-06-16 09:58:53 +02:00
|
|
|
case CV_WINDOW_AUTOSIZE:
|
2010-07-16 14:51:29 +02:00
|
|
|
w->myLayout->setSizeConstraint(QLayout::SetFixedSize);
|
2010-07-16 11:12:15 +02:00
|
|
|
w->param_flags = flags;
|
|
|
|
break;
|
2010-06-16 09:58:53 +02:00
|
|
|
default:;
|
|
|
|
}
|
2010-06-12 20:08:27 +02:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:36:46 +02:00
|
|
|
double GuiReceiver::isFullScreen(QString name)
|
|
|
|
{
|
2010-06-16 09:58:53 +02:00
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
2010-06-12 18:36:46 +02:00
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return -1;
|
2010-06-16 09:58:53 +02:00
|
|
|
|
|
|
|
if (w->isFullScreen())
|
2010-07-16 11:12:15 +02:00
|
|
|
return CV_WINDOW_FULLSCREEN;
|
2010-06-16 09:58:53 +02:00
|
|
|
else
|
2010-07-16 11:12:15 +02:00
|
|
|
return CV_WINDOW_NORMAL;
|
2010-06-12 18:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//accept CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN
|
|
|
|
void GuiReceiver::toggleFullScreen(QString name, double flags )
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-16 09:58:53 +02:00
|
|
|
|
|
|
|
if (w->isFullScreen() && flags == CV_WINDOW_NORMAL)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->showNormal();
|
2010-06-16 09:58:53 +02:00
|
|
|
|
|
|
|
if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->showFullScreen();
|
2010-06-12 18:36:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void GuiReceiver::createWindow( QString name, int flags )
|
|
|
|
{
|
|
|
|
if (!qApp)
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Error(CV_StsNullPtr, "NULL session handler" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
// Check the name in the storage
|
|
|
|
if( icvFindWindowByName( name.toLatin1().data() ))
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//QPointer<CvWindow> w1 =
|
|
|
|
new CvWindow(name, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::timeOut()
|
|
|
|
{
|
|
|
|
_bTimeOut = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::displayInfo( QString name, QString text, int delayms )
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w && delayms > 0)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->displayInfo(text,delayms);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
void GuiReceiver::displayStatusBar( QString name, QString text, int delayms )
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w && delayms > 0)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->displayStatusBar(text,delayms);
|
2010-06-22 19:15:49 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void GuiReceiver::showImage(QString name, void* arr)
|
|
|
|
{
|
|
|
|
//qDebug()<<"inshowimage"<<endl;
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (!w)//as observed in the previous implementation (W32, GTK or Carbon), create a new window is the pointer returned is null
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
cvNamedWindow( name.toLatin1().data() );
|
|
|
|
w = icvFindWindowByName( name.toLatin1().data() );
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( w && arr )
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
w->updateImage(arr);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
qDebug()<<"Do nothing (Window or Image NULL)"<<endl;
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::destroyWindow(QString name)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
w->close();
|
|
|
|
//in not-multiThreads mode, looks like the window is hidden but not deleted
|
|
|
|
//so I do it manually
|
|
|
|
//otherwise QApplication do it for me if the exec command was executed (in multiThread mode)
|
|
|
|
if (!multiThreads)
|
|
|
|
delete w;
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::destroyAllWindow()
|
|
|
|
{
|
|
|
|
if (!qApp)
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Error(CV_StsNullPtr, "NULL session handler" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
if (multiThreads)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
qApp->closeAllWindows();
|
2010-06-10 22:03:52 +02:00
|
|
|
}else{
|
2010-07-16 11:12:15 +02:00
|
|
|
QPointer<CvWindow> w;
|
|
|
|
foreach (QWidget *widget, QApplication::topLevelWidgets())
|
|
|
|
{
|
|
|
|
w = (CvWindow*) widget;
|
|
|
|
w->close();
|
|
|
|
delete w;
|
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
void GuiReceiver::setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
|
2010-07-07 19:53:59 +02:00
|
|
|
|
|
|
|
if (w && callbackOpenGL)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->setOpenGLCallback((CvOpenGLCallback) callbackOpenGL, userdata);
|
2010-07-07 19:53:59 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void GuiReceiver::moveWindow(QString name, int x, int y)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->move(x,y);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::resizeWindow(QString name, int width, int height)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (w)
|
2010-07-16 11:12:15 +02:00
|
|
|
w->resize(width, height);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiReceiver::addSlider(QString trackbar_name, QString window_name, void* value, int count, void* on_change)
|
|
|
|
{
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
|
|
|
|
|
|
|
|
if (!w)
|
2010-07-16 11:12:15 +02:00
|
|
|
return;
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
if (!value)
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Error(CV_StsNullPtr, "NULL value pointer" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
if (count<= 0)//count is the max value of the slider, so must be bigger than 0
|
2010-07-16 11:12:15 +02:00
|
|
|
CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" );
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
w->addSlider(trackbar_name,(int*)value,count,(CvTrackbarCallback) on_change);
|
|
|
|
}
|
|
|
|
|
|
|
|
int GuiReceiver::start()
|
|
|
|
{
|
|
|
|
return qApp->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback on_change )
|
|
|
|
{
|
|
|
|
setObjectName(trackbar_name);
|
|
|
|
parent = arg;
|
|
|
|
trackbar_name = name;
|
|
|
|
dataSlider = value;
|
|
|
|
|
|
|
|
callback = on_change;
|
|
|
|
slider = new QSlider(Qt::Horizontal);
|
|
|
|
slider->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
slider->setMinimum(0);
|
|
|
|
slider->setMaximum(count);
|
|
|
|
slider->setPageStep(5);
|
|
|
|
slider->setValue(*value);
|
|
|
|
slider->setTickPosition(QSlider::TicksBelow);
|
|
|
|
|
|
|
|
|
|
|
|
//Change style of the Slider
|
2010-07-16 11:12:15 +02:00
|
|
|
//slider->setStyleSheet(str_Trackbar_css);
|
2010-06-16 09:58:53 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
QFile qss(":/stylesheet-trackbar");
|
|
|
|
if (qss.open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
slider->setStyleSheet(QLatin1String(qss.readAll()));
|
|
|
|
qss.close();
|
|
|
|
}
|
2010-06-16 09:58:53 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-06-11 11:02:57 +02:00
|
|
|
//this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?)
|
2010-06-10 22:03:52 +02:00
|
|
|
//slider->setTickPosition(QSlider::TicksBelow);
|
|
|
|
label = new QPushButton;
|
|
|
|
label->setFlat(true);
|
|
|
|
setLabel(slider->value());
|
|
|
|
|
|
|
|
|
|
|
|
QObject::connect( slider, SIGNAL( valueChanged( int ) ),this, SLOT( update( int ) ) );
|
|
|
|
|
2010-06-12 20:08:27 +02:00
|
|
|
QObject::connect( label, SIGNAL( clicked() ),this, SLOT( createDialog() ));
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-06-12 20:08:27 +02:00
|
|
|
//label->setStyleSheet("QPushButton:disabled {color: black}");
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
addWidget(label);//name + value
|
|
|
|
addWidget(slider);//slider
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvTrackbar::createDialog()
|
|
|
|
{
|
|
|
|
|
|
|
|
bool ok= false;
|
|
|
|
|
2010-07-12 13:04:26 +02:00
|
|
|
//crash if I access the values directly and give them to QInputDialog, so do a copy first.
|
2010-06-10 22:03:52 +02:00
|
|
|
int value = slider->value();
|
|
|
|
int step = slider->singleStep();
|
|
|
|
int min = slider->minimum();
|
|
|
|
int max = slider->maximum();
|
|
|
|
|
2010-07-08 13:24:32 +02:00
|
|
|
int i =
|
2010-07-16 11:12:15 +02:00
|
|
|
#if QT_VERSION >= 0x040500
|
|
|
|
QInputDialog::getInt
|
2010-07-08 13:24:32 +02:00
|
|
|
#else
|
2010-07-16 11:12:15 +02:00
|
|
|
QInputDialog::getInteger
|
2010-07-08 13:24:32 +02:00
|
|
|
#endif
|
2010-07-16 11:12:15 +02:00
|
|
|
(this->parentWidget(),
|
|
|
|
tr("Slider %1").arg(trackbar_name),
|
|
|
|
tr("New value:"),
|
|
|
|
value,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
step,
|
|
|
|
&ok);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
if (ok)
|
2010-06-30 00:14:24 +02:00
|
|
|
slider->setValue(i);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvTrackbar::update(int myvalue)
|
|
|
|
{
|
|
|
|
setLabel(myvalue);
|
|
|
|
|
|
|
|
*dataSlider = myvalue;
|
|
|
|
if (callback)
|
2010-06-30 00:14:24 +02:00
|
|
|
callback(myvalue);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CvTrackbar::setLabel(int myvalue)
|
|
|
|
{
|
|
|
|
QString nameNormalized = trackbar_name.leftJustified( 10, ' ', true );
|
|
|
|
QString valueMaximum = QString("%1").arg(slider->maximum());
|
|
|
|
QString str = QString("%1 (%2/%3)").arg(nameNormalized).arg(myvalue,valueMaximum.length(),10,QChar('0')).arg(valueMaximum);
|
|
|
|
label->setText(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
CvTrackbar::~CvTrackbar()
|
|
|
|
{
|
|
|
|
delete slider;
|
|
|
|
delete label;
|
|
|
|
}
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//here CvWinProperties class
|
|
|
|
CvWinProperties::CvWinProperties(QString name_paraWindow, QWidget* parent)
|
|
|
|
{
|
|
|
|
setParent(parent);
|
|
|
|
setWindowFlags(Qt::Tool);
|
|
|
|
setContentsMargins(0,0,0,0);
|
|
|
|
setWindowTitle(name_paraWindow);
|
|
|
|
setObjectName(name_paraWindow);
|
|
|
|
//parameters_window->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
|
|
|
resize(100,50);
|
|
|
|
|
|
|
|
myLayout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
myLayout->setObjectName(QString::fromUtf8("boxLayout"));
|
|
|
|
myLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
myLayout->setSpacing(0);
|
|
|
|
myLayout->setMargin(0);
|
|
|
|
myLayout->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
setLayout(myLayout);
|
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWinProperties::closeEvent ( QCloseEvent * e )
|
|
|
|
{
|
|
|
|
e->accept();//intersept the close event (not sure I really need it)
|
|
|
|
//an hide event is also sent. I will intercept it and do some processing
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWinProperties::showEvent ( QShowEvent * event )
|
|
|
|
{
|
|
|
|
//why -1,-1 ?: do this trick because the first time the code is run,
|
|
|
|
//no value pos was saved so we let Qt move the window in the middle of its parent (event ignored).
|
|
|
|
//then hide will save the last position and thus, we want to retreive it (event accepted).
|
|
|
|
QPoint mypos(-1,-1);
|
|
|
|
QSettings settings("OpenCV2", this->windowTitle());
|
|
|
|
mypos = settings.value("pos", mypos).toPoint();
|
|
|
|
|
|
|
|
if (mypos.x()>=0)
|
|
|
|
{
|
|
|
|
move(mypos);
|
|
|
|
event->accept();
|
|
|
|
}else{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWinProperties::hideEvent ( QHideEvent * event )
|
|
|
|
{
|
|
|
|
QSettings settings("OpenCV2", this->windowTitle());
|
|
|
|
settings.setValue("pos", pos());
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
CvWinProperties::~CvWinProperties()
|
|
|
|
{
|
|
|
|
//clear the setting pos
|
|
|
|
QSettings settings("OpenCV2", this->windowTitle());
|
|
|
|
settings.clear();
|
|
|
|
|
|
|
|
QLayoutItem *child;
|
|
|
|
if (myLayout)
|
|
|
|
{
|
|
|
|
while ((child = myLayout->takeAt(0)) != 0)
|
|
|
|
delete child;
|
|
|
|
|
|
|
|
delete myLayout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
//Here CvWindow class
|
2010-06-10 22:03:52 +02:00
|
|
|
CvWindow::CvWindow(QString arg, int arg2)
|
|
|
|
{
|
|
|
|
moveToThread(qApp->instance()->thread());
|
2010-06-30 00:14:24 +02:00
|
|
|
param_name = arg;
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
//the first bit is for normal or autoresize
|
|
|
|
//CV_WINDOW_NORMAL = 0x00000000 and CV_WINDOW_AUTOSIZE = 0x00000001
|
2010-07-16 14:51:29 +02:00
|
|
|
//the secont bit is for the gui mode (normal or EXPANDED)
|
|
|
|
//CV_GUI_EXPANDED = 0x00000000 and CV_GUI_NORMAL = 0x00000010
|
2010-07-16 11:12:15 +02:00
|
|
|
param_flags = arg2 & 0x0000000F;
|
|
|
|
param_gui_mode = arg2 & 0x000000F0;
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory
|
|
|
|
setContentsMargins(0,0,0,0);
|
2010-06-30 00:14:24 +02:00
|
|
|
setWindowTitle(param_name);
|
|
|
|
setObjectName(param_name);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
|
|
|
resize(400,300);
|
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
createLayout();
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//1: my view
|
|
|
|
int mode_display = CV_MODE_NORMAL;
|
|
|
|
#if defined(OPENCV_GL)
|
|
|
|
mode_display = CV_MODE_OPENGL;
|
|
|
|
#endif
|
|
|
|
createView(mode_display);
|
2010-06-19 20:57:04 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//2: shortcuts
|
|
|
|
createShortcuts();
|
2010-06-19 20:57:04 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//toolBar and statusbar
|
2010-07-16 14:51:29 +02:00
|
|
|
if (param_gui_mode == CV_GUI_EXPANDED)
|
2010-07-16 11:12:15 +02:00
|
|
|
{
|
|
|
|
createToolBar();
|
|
|
|
createStatusBar();
|
2010-07-16 14:51:29 +02:00
|
|
|
createParameterWindow();
|
2010-07-16 11:12:15 +02:00
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//Now attach everything
|
|
|
|
if (myToolBar)
|
2010-07-16 14:51:29 +02:00
|
|
|
myLayout->addWidget(myToolBar,Qt::AlignCenter);
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
myLayout->addWidget(myview,Qt::AlignCenter);
|
2010-06-22 19:15:49 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
if (myStatusBar)
|
2010-07-16 14:51:29 +02:00
|
|
|
myLayout->addWidget(myStatusBar,Qt::AlignCenter);
|
2010-06-22 19:15:49 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
setLayout(myLayout);
|
2010-06-10 22:03:52 +02:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
CvWindow::~CvWindow()
|
|
|
|
{
|
|
|
|
QLayoutItem *child;
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
if (myLayout)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
while ((child = myLayout->takeAt(0)) != 0)
|
2010-06-30 00:14:24 +02:00
|
|
|
delete child;
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
delete myLayout;
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
2010-06-22 19:15:49 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
if (myStatusBar)
|
|
|
|
{
|
|
|
|
delete myStatusBar;
|
|
|
|
delete myStatusBar_msg;
|
|
|
|
}
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
if (myToolBar)
|
|
|
|
{
|
|
|
|
for (int i=0;i<vect_QActions.count();i++)
|
|
|
|
delete vect_QActions[i];
|
|
|
|
|
|
|
|
delete myToolBar;
|
|
|
|
}
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
for (int i=0;i<vect_QShortcuts.count();i++)
|
|
|
|
delete vect_QShortcuts[i];
|
2010-07-16 14:51:29 +02:00
|
|
|
}
|
2010-06-22 19:15:49 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void CvWindow::createParameterWindow()
|
|
|
|
{
|
|
|
|
QString name_paraWindow=param_name+" window parameters";
|
|
|
|
parameters_window = new CvWinProperties(name_paraWindow,this);
|
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
void CvWindow::displayPropertiesWin()
|
|
|
|
{
|
|
|
|
if (parameters_window->isHidden())
|
|
|
|
parameters_window->show();
|
|
|
|
else
|
|
|
|
parameters_window->hide();
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
void CvWindow::createToolBar()
|
|
|
|
{
|
|
|
|
myToolBar = new QToolBar;
|
|
|
|
myToolBar->setFloatable(false);//is not a window
|
|
|
|
myToolBar->setMaximumHeight(28);
|
|
|
|
|
|
|
|
vect_QActions.resize(10);
|
|
|
|
|
|
|
|
//if the shortcuts are changed in window_QT.h, we need to update the tooltip manually
|
|
|
|
vect_QActions[0] = new QAction(QIcon(":/left-icon"),"Panning left (CTRL+arrowLEFT)",this);
|
|
|
|
QObject::connect( vect_QActions[0],SIGNAL(triggered()),myview, SLOT( siftWindowOnLeft() ));
|
|
|
|
myToolBar->addAction(vect_QActions[0]);
|
|
|
|
|
|
|
|
vect_QActions[1] = new QAction(QIcon(":/right-icon"),"Panning right (CTRL+arrowRIGHT)",this);
|
|
|
|
QObject::connect( vect_QActions[1],SIGNAL(triggered()),myview, SLOT( siftWindowOnRight() ));
|
|
|
|
myToolBar->addAction(vect_QActions[1]);
|
|
|
|
|
|
|
|
vect_QActions[2] = new QAction(QIcon(":/up-icon"),"Panning up (CTRL+arrowUP)",this);
|
|
|
|
QObject::connect( vect_QActions[2],SIGNAL(triggered()),myview, SLOT( siftWindowOnUp() ));
|
|
|
|
myToolBar->addAction(vect_QActions[2]);
|
|
|
|
|
|
|
|
vect_QActions[3] = new QAction(QIcon(":/down-icon"),"Panning down (CTRL+arrowDOWN)",this);
|
|
|
|
QObject::connect( vect_QActions[3],SIGNAL(triggered()),myview, SLOT( siftWindowOnDown() ));
|
|
|
|
myToolBar->addAction(vect_QActions[3]);
|
|
|
|
|
|
|
|
vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"),"Zoom x1 (CTRL+P)",this);
|
|
|
|
QObject::connect( vect_QActions[4],SIGNAL(triggered()),myview, SLOT( resetZoom() ));
|
|
|
|
myToolBar->addAction(vect_QActions[4]);
|
|
|
|
|
|
|
|
vect_QActions[5] = new QAction(QIcon(":/imgRegion-icon"),tr("Zoom x%1 (see label) (CTRL+X)")
|
|
|
|
.arg(threshold_zoom_img_region)
|
|
|
|
,this);
|
|
|
|
QObject::connect( vect_QActions[5],SIGNAL(triggered()),myview, SLOT( imgRegion() ));
|
|
|
|
myToolBar->addAction(vect_QActions[5]);
|
|
|
|
|
|
|
|
vect_QActions[6] = new QAction(QIcon(":/zoom_in-icon"),tr("Zoom in (CTRL++)"),this);
|
|
|
|
QObject::connect( vect_QActions[6],SIGNAL(triggered()),myview, SLOT( ZoomIn() ));
|
|
|
|
myToolBar->addAction(vect_QActions[6]);
|
|
|
|
|
|
|
|
vect_QActions[7] = new QAction(QIcon(":/zoom_out-icon"),tr("Zoom out (CTRL+-)"),this);
|
|
|
|
QObject::connect( vect_QActions[7],SIGNAL(triggered()),myview, SLOT( ZoomOut() ));
|
|
|
|
myToolBar->addAction(vect_QActions[7]);
|
|
|
|
|
|
|
|
vect_QActions[8] = new QAction(QIcon(":/save-icon"),tr("Save current image (CTRL+S)"),this);
|
|
|
|
QObject::connect( vect_QActions[8],SIGNAL(triggered()),myview, SLOT( saveView() ));
|
|
|
|
myToolBar->addAction(vect_QActions[8]);
|
|
|
|
|
|
|
|
vect_QActions[9] = new QAction(QIcon(":/properties-icon"),tr("Display properties window (CTRL+P)"),this);
|
2010-07-16 14:51:29 +02:00
|
|
|
QObject::connect( vect_QActions[9],SIGNAL(triggered()),this, SLOT( displayPropertiesWin() ));
|
2010-07-16 11:12:15 +02:00
|
|
|
myToolBar->addAction(vect_QActions[9]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::createStatusBar()
|
|
|
|
{
|
|
|
|
myStatusBar = new QStatusBar;
|
|
|
|
myStatusBar->setSizeGripEnabled(false);
|
|
|
|
myStatusBar->setMaximumHeight(20);
|
|
|
|
myStatusBar_msg = new QLabel;
|
|
|
|
myStatusBar_msg->setFrameStyle(QFrame::Raised);
|
|
|
|
myStatusBar_msg->setAlignment(Qt::AlignHCenter);
|
|
|
|
myStatusBar->addWidget(myStatusBar_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::createLayout()
|
|
|
|
{
|
2010-07-16 14:51:29 +02:00
|
|
|
myLayout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
myLayout->setObjectName(QString::fromUtf8("boxLayout"));
|
|
|
|
myLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
myLayout->setSpacing(0);
|
|
|
|
myLayout->setMargin(0);
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
if (param_flags == CV_WINDOW_AUTOSIZE)
|
2010-07-16 14:51:29 +02:00
|
|
|
myLayout->setSizeConstraint(QLayout::SetFixedSize);
|
2010-07-16 11:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::createShortcuts()
|
|
|
|
{
|
|
|
|
vect_QShortcuts.resize(10);
|
|
|
|
|
|
|
|
vect_QShortcuts[0] = new QShortcut(shortcut_panning_left, this);
|
|
|
|
QObject::connect( vect_QShortcuts[0], SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
|
|
|
|
vect_QShortcuts[1] = new QShortcut(shortcut_panning_right, this);
|
|
|
|
QObject::connect( vect_QShortcuts[1], SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
|
|
|
|
vect_QShortcuts[2] = new QShortcut(shortcut_panning_up, this);
|
|
|
|
QObject::connect(vect_QShortcuts[2], SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
|
|
|
|
vect_QShortcuts[3] = new QShortcut(shortcut_panning_down, this);
|
|
|
|
QObject::connect(vect_QShortcuts[3], SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
|
|
|
|
|
|
|
|
vect_QShortcuts[4] = new QShortcut(shortcut_zoom_normal, this);
|
|
|
|
QObject::connect( vect_QShortcuts[4], SIGNAL( activated ()),myview, SLOT( resetZoom( ) ));
|
|
|
|
vect_QShortcuts[5] = new QShortcut(shortcut_zoom_imgRegion, this);
|
|
|
|
QObject::connect( vect_QShortcuts[5], SIGNAL( activated ()),myview, SLOT( imgRegion( ) ));
|
|
|
|
vect_QShortcuts[6] = new QShortcut(shortcut_zoom_in, this);
|
|
|
|
QObject::connect( vect_QShortcuts[6], SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
|
|
|
|
vect_QShortcuts[7] = new QShortcut(shortcut_zoom_out, this);
|
|
|
|
QObject::connect(vect_QShortcuts[7], SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
|
|
|
|
vect_QShortcuts[8] = new QShortcut(shortcut_save_img, this);
|
|
|
|
QObject::connect( vect_QShortcuts[8], SIGNAL( activated ()),myview, SLOT( saveView( ) ));
|
|
|
|
vect_QShortcuts[9] = new QShortcut(shortcut_properties_win, this);
|
2010-07-16 14:51:29 +02:00
|
|
|
QObject::connect( vect_QShortcuts[9], SIGNAL( activated ()),this, SLOT( displayPropertiesWin() ));
|
2010-07-16 11:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::createView(int mode)
|
|
|
|
{
|
|
|
|
//mode = CV_MODE_NORMAL or CV_MODE_OPENGL
|
|
|
|
myview = new ViewPort(this, mode,CV_WINDOW_KEEPRATIO);//parent, mode_display, keep_aspect_ratio
|
|
|
|
myview->setAlignment(Qt::AlignHCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata)
|
|
|
|
{
|
|
|
|
myview->setOpenGLCallback(func,userdata);
|
|
|
|
}
|
2010-07-07 19:53:59 +02:00
|
|
|
|
2010-06-27 00:36:41 +02:00
|
|
|
ViewPort* CvWindow::getView()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
return myview;
|
2010-06-27 00:36:41 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void CvWindow::displayInfo(QString text,int delayms)
|
|
|
|
{
|
|
|
|
myview->startDisplayInfo(text, delayms);
|
|
|
|
}
|
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
void CvWindow::displayStatusBar(QString text,int delayms)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
myStatusBar->showMessage(text,delayms);
|
2010-06-22 19:15:49 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void CvWindow::updateImage(void* arr)
|
|
|
|
{
|
|
|
|
myview->updateImage(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::setMouseCallBack(CvMouseCallback m, void* param)
|
|
|
|
{
|
2010-06-16 09:58:53 +02:00
|
|
|
myview->setMouseCallBack(m,param);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::addSlider(QString name, int* value, int count,CvTrackbarCallback on_change)
|
|
|
|
{
|
|
|
|
QPointer<CvTrackbar> t = new CvTrackbar(this,name,value, count, on_change);
|
|
|
|
t->setAlignment(Qt::AlignHCenter);
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int position_insert;
|
|
|
|
if (param_gui_mode == CV_GUI_NORMAL)
|
|
|
|
{
|
|
|
|
position_insert = myLayout->count();
|
|
|
|
|
|
|
|
if (myStatusBar)
|
|
|
|
position_insert--;//max-1 means add trackbar between myview and statusbar
|
|
|
|
|
|
|
|
myLayout->insertLayout(position_insert,t);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param_gui_mode == CV_GUI_EXPANDED)
|
|
|
|
{
|
|
|
|
position_insert = parameters_window->myLayout->count();
|
|
|
|
parameters_window->myLayout->insertLayout(position_insert,t);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
//Need more test here !
|
2010-06-10 22:03:52 +02:00
|
|
|
void CvWindow::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
2010-06-19 20:57:04 +02:00
|
|
|
//see http://doc.trolltech.com/4.6/qt.html#Key-enum
|
|
|
|
int key = event->key();
|
|
|
|
bool goodKey = false;
|
|
|
|
|
|
|
|
if (key>=20 && key<=255 )
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
key = (int)event->text().toLocal8Bit().at(0);
|
|
|
|
goodKey = true;
|
2010-06-19 20:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key == Qt::Key_Escape)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
key = 27;
|
|
|
|
goodKey = true;
|
2010-06-19 20:57:04 +02:00
|
|
|
}
|
|
|
|
|
2010-06-19 23:01:27 +02:00
|
|
|
//control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
|
2010-06-19 20:57:04 +02:00
|
|
|
if (event->modifiers() != Qt::ControlModifier && goodKey)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
mutexKey.lock();
|
|
|
|
last_key = key;
|
|
|
|
//last_key = event->nativeVirtualKey ();
|
|
|
|
mutexKey.unlock();
|
|
|
|
key_pressed.wakeAll();
|
|
|
|
//event->accept();
|
2010-06-19 20:57:04 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
//TODO: load CV_GUI flag (done) and act accordingly (create win property if needed and attach trackbars)
|
2010-06-30 00:14:24 +02:00
|
|
|
void CvWindow::readSettings()
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
//organisation and application's name
|
2010-06-30 00:14:24 +02:00
|
|
|
QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
|
2010-06-14 18:00:38 +02:00
|
|
|
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
|
|
|
QSize size = settings.value("size", QSize(400, 400)).toSize();
|
2010-07-07 19:53:59 +02:00
|
|
|
//param_name = settings.value("name_window",param_name).toString();
|
|
|
|
param_flags = settings.value("mode_resize",param_flags).toInt();
|
2010-07-16 14:51:29 +02:00
|
|
|
param_gui_mode = settings.value("mode_gui",param_gui_mode).toInt();
|
2010-07-07 19:53:59 +02:00
|
|
|
myview->param_keepRatio = settings.value("view_aspectRatio",myview->param_keepRatio).toInt();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
param_flags = settings.value("mode_resize",param_flags).toInt();
|
2010-07-08 13:24:32 +02:00
|
|
|
qreal m11 = settings.value("matrix_view.m11",myview->param_matrixWorld.m11()).toDouble();
|
|
|
|
qreal m12 = settings.value("matrix_view.m12",myview->param_matrixWorld.m12()).toDouble();
|
|
|
|
qreal m13 = settings.value("matrix_view.m13",myview->param_matrixWorld.m13()).toDouble();
|
|
|
|
qreal m21 = settings.value("matrix_view.m21",myview->param_matrixWorld.m21()).toDouble();
|
|
|
|
qreal m22 = settings.value("matrix_view.m22",myview->param_matrixWorld.m22()).toDouble();
|
|
|
|
qreal m23 = settings.value("matrix_view.m23",myview->param_matrixWorld.m23()).toDouble();
|
|
|
|
qreal m31 = settings.value("matrix_view.m31",myview->param_matrixWorld.m31()).toDouble();
|
|
|
|
qreal m32 = settings.value("matrix_view.m32",myview->param_matrixWorld.m32()).toDouble();
|
|
|
|
qreal m33 = settings.value("matrix_view.m33",myview->param_matrixWorld.m33()).toDouble();
|
2010-06-30 00:14:24 +02:00
|
|
|
myview->param_matrixWorld = QTransform(m11,m12,m13,m21,m22,m23,m31,m32,m33);
|
|
|
|
|
|
|
|
//trackbar here
|
|
|
|
icvLoadTrackbars(&settings);
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
resize(size);
|
|
|
|
move(pos);
|
|
|
|
}
|
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
void CvWindow::writeSettings()
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
//organisation and application's name
|
2010-06-30 00:14:24 +02:00
|
|
|
QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
|
2010-07-07 19:53:59 +02:00
|
|
|
//settings.setValue("name_window",param_name);
|
2010-06-14 18:00:38 +02:00
|
|
|
settings.setValue("pos", pos());
|
|
|
|
settings.setValue("size", size());
|
2010-06-30 00:14:24 +02:00
|
|
|
settings.setValue("mode_resize",param_flags);
|
2010-07-16 14:51:29 +02:00
|
|
|
settings.setValue("mode_gui",param_gui_mode);
|
2010-06-30 00:14:24 +02:00
|
|
|
settings.setValue("view_aspectRatio",myview->param_keepRatio);
|
|
|
|
|
|
|
|
settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11());
|
|
|
|
settings.setValue("matrix_view.m12",myview->param_matrixWorld.m12());
|
|
|
|
settings.setValue("matrix_view.m13",myview->param_matrixWorld.m13());
|
|
|
|
settings.setValue("matrix_view.m21",myview->param_matrixWorld.m21());
|
|
|
|
settings.setValue("matrix_view.m22",myview->param_matrixWorld.m22());
|
|
|
|
settings.setValue("matrix_view.m23",myview->param_matrixWorld.m23());
|
|
|
|
settings.setValue("matrix_view.m31",myview->param_matrixWorld.m31());
|
|
|
|
settings.setValue("matrix_view.m32",myview->param_matrixWorld.m32());
|
|
|
|
settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33());
|
|
|
|
|
|
|
|
icvSaveTrackbars(&settings);
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
void CvWindow::icvLoadTrackbars(QSettings *settings)
|
|
|
|
{
|
|
|
|
int size = settings->beginReadArray("trackbars");
|
|
|
|
QPointer<CvTrackbar> t;
|
2010-07-16 11:12:15 +02:00
|
|
|
//Warning ---- , asume the location 0 is toolbar, 1 is myview and max-1 the status bar
|
2010-06-30 00:14:24 +02:00
|
|
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
//trackbar are saved in the same order, so no need to use icvFindTrackbarByName
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
int start_index = 1;//index 0 is myview
|
|
|
|
if (myToolBar)
|
|
|
|
start_index ++;//index 0 is statusbar, 1 is myview
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
int stop_index = myLayout->layout()->count() - start_index ;
|
2010-07-16 11:12:15 +02:00
|
|
|
if (myStatusBar)
|
|
|
|
stop_index --;// index max-1 is the statusbar
|
|
|
|
|
|
|
|
//(in expended mode) nbTrackbar = count() - (toolbar + myview + statusbar) (3) = stop_index - start_index
|
|
|
|
|
|
|
|
if (stop_index-start_index == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)
|
|
|
|
for (int i = start_index; i < size+start_index; ++i)
|
|
|
|
{
|
|
|
|
settings->setArrayIndex(i-start_index);
|
2010-07-16 14:51:29 +02:00
|
|
|
t = (CvTrackbar*) myLayout->layout()->itemAt(i);
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
if (t->trackbar_name == settings->value("name").toString())
|
|
|
|
{
|
|
|
|
t->slider->setValue(settings->value("value").toInt());
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
settings->endArray();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CvWindow::icvSaveTrackbars(QSettings *settings)
|
|
|
|
{
|
|
|
|
QPointer<CvTrackbar> t;
|
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//Warning ---- , asume the location 0 is toolbar, 1 is myview and max-1 the status bar
|
2010-06-30 00:14:24 +02:00
|
|
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
|
|
|
settings->beginWriteArray("trackbars");
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
int start_index = 2;
|
|
|
|
if (myToolBar)
|
|
|
|
start_index=3;
|
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
for (int i = start_index; i < myLayout->layout()->count()-1; ++i) {
|
|
|
|
t = (CvTrackbar*) myLayout->layout()->itemAt(i);
|
2010-07-16 11:12:15 +02:00
|
|
|
settings->setArrayIndex(i-start_index);
|
2010-06-30 00:14:24 +02:00
|
|
|
settings->setValue("name", t->trackbar_name);
|
|
|
|
settings->setValue("value", t->slider->value());
|
|
|
|
}
|
|
|
|
settings->endArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Here is ViewPort class
|
2010-06-27 00:36:41 +02:00
|
|
|
ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
|
|
|
centralWidget = arg,
|
2010-07-16 11:12:15 +02:00
|
|
|
setParent(centralWidget);
|
2010-06-30 00:14:24 +02:00
|
|
|
mode_display = arg2;
|
|
|
|
param_keepRatio = arg3;
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
setupViewport(centralWidget);
|
2010-06-19 20:57:04 +02:00
|
|
|
setContentsMargins(0,0,0,0);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
setObjectName(QString::fromUtf8("graphicsView"));
|
|
|
|
timerDisplay = new QTimer(this);
|
|
|
|
timerDisplay->setSingleShot(true);
|
|
|
|
connect(timerDisplay, SIGNAL(timeout()), this, SLOT(stopDisplayInfo()));
|
|
|
|
drawInfo = false;
|
2010-06-16 09:58:53 +02:00
|
|
|
positionGrabbing = QPointF(0,0);
|
2010-06-17 18:41:48 +02:00
|
|
|
positionCorners = QRect(0,0,size().width(),size().height());
|
2010-06-19 23:01:27 +02:00
|
|
|
on_mouse = NULL;
|
2010-06-22 19:15:49 +02:00
|
|
|
mouseCoordinate = QPoint(-1,-1);
|
2010-07-12 13:04:26 +02:00
|
|
|
on_openGL_draw3D = NULL;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
#if defined(OPENCV_GL)
|
2010-06-30 00:14:24 +02:00
|
|
|
if ( mode_display == CV_MODE_OPENGL)
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
//QGLWidget* wGL = new QGLWidget(QGLFormat(QGL::SampleBuffers));
|
|
|
|
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
|
|
|
initGL();
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
2010-06-19 20:57:04 +02:00
|
|
|
#endif
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
image2Draw_ipl=cvCreateImage(cvSize(centralWidget->width(),centralWidget->height()),IPL_DEPTH_8U,3);
|
2010-07-07 19:53:59 +02:00
|
|
|
image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);
|
|
|
|
image2Draw_qt_resized = image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
nbChannelOriginImage = 0;
|
2010-06-22 19:15:49 +02:00
|
|
|
cvZero(image2Draw_ipl);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
setInteractive(false);
|
2010-06-22 19:15:49 +02:00
|
|
|
setMouseTracking (true);//receive mouse event everytime
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewPort::~ViewPort()
|
|
|
|
{
|
2010-06-22 19:15:49 +02:00
|
|
|
if (image2Draw_ipl)
|
2010-06-28 23:01:37 +02:00
|
|
|
cvReleaseImage(&image2Draw_ipl);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-16 09:58:53 +02:00
|
|
|
delete timerDisplay;
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
//can save as JPG, JPEG, BMP, PNG
|
|
|
|
void ViewPort::saveView()
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
QDate date_d = QDate::currentDate ();
|
|
|
|
QString date_s = date_d.toString("dd.MM.yyyy");
|
|
|
|
QString name_s = centralWidget->param_name+"_screenshot_"+date_s;
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File %1").arg(name_s),
|
|
|
|
name_s+".png",
|
|
|
|
tr("Images (*.png *.jpg *.bmp *.jpeg)"));
|
2010-07-07 19:53:59 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
if (!fileName.isEmpty ())//save the picture
|
|
|
|
{
|
|
|
|
QString extension = fileName.right(3);
|
|
|
|
|
|
|
|
// Save it..
|
|
|
|
if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)
|
2010-07-07 19:53:59 +02:00
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
image2Draw_qt_resized.save(fileName, "PNG");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
image2Draw_qt_resized.save(fileName, "JPG");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
image2Draw_qt_resized.save(fileName, "BMP");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
image2Draw_qt_resized.save(fileName, "JPEG");
|
|
|
|
return;
|
2010-07-07 19:53:59 +02:00
|
|
|
}
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
qDebug()<<"file extension not recognized, please choose between JPG, JPEG, BMP or PNG";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
|
2010-06-27 00:36:41 +02:00
|
|
|
void ViewPort::setRatio(int flags)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_keepRatio = flags;
|
2010-06-27 00:36:41 +02:00
|
|
|
updateGeometry();
|
|
|
|
viewport()->update();
|
|
|
|
}
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
void ViewPort::imgRegion()
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
scaleView( (threshold_zoom_img_region/param_matrixWorld.m11()-1)*5,QPointF(size().width()/2,size().height()/2));
|
2010-07-07 19:53:59 +02:00
|
|
|
}
|
|
|
|
|
2010-06-27 00:36:41 +02:00
|
|
|
int ViewPort::getRatio()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
return param_keepRatio;
|
2010-06-27 00:36:41 +02:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
void ViewPort::resetZoom()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.reset();
|
2010-06-22 19:15:49 +02:00
|
|
|
controlImagePosition();
|
2010-06-19 20:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::ZoomIn()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
scaleView( 0.5,QPointF(size().width()/2,size().height()/2));
|
2010-06-19 20:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::ZoomOut()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
scaleView( -0.5,QPointF(size().width()/2,size().height()/2));
|
2010-06-19 20:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
void ViewPort::siftWindowOnLeft()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
float delta = 2*width()/(100.0*param_matrixWorld.m11());
|
2010-06-19 20:57:04 +02:00
|
|
|
moveView(QPointF(delta,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
void ViewPort::siftWindowOnRight()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
float delta = -2*width()/(100.0*param_matrixWorld.m11());
|
2010-06-19 20:57:04 +02:00
|
|
|
moveView(QPointF(delta,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
void ViewPort::siftWindowOnUp()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
float delta = 2*height()/(100.0*param_matrixWorld.m11());
|
2010-06-19 20:57:04 +02:00
|
|
|
moveView(QPointF(0,delta));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
void ViewPort::siftWindowOnDown()
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
float delta = -2*height()/(100.0*param_matrixWorld.m11());
|
2010-06-19 20:57:04 +02:00
|
|
|
moveView(QPointF(0,delta));
|
|
|
|
}
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
void ViewPort::startDisplayInfo(QString text, int delayms)
|
|
|
|
{
|
|
|
|
if (timerDisplay->isActive())
|
2010-06-28 23:01:37 +02:00
|
|
|
stopDisplayInfo();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
infoText = text;
|
|
|
|
timerDisplay->start(delayms);
|
|
|
|
drawInfo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::stopDisplayInfo()
|
|
|
|
{
|
|
|
|
timerDisplay->stop();
|
|
|
|
drawInfo = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool ViewPort::isSameSize(IplImage* img1,IplImage* img2)
|
|
|
|
{
|
|
|
|
return img1->width == img2->width && img1->height == img2->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::updateImage(void* arr)
|
|
|
|
{
|
2010-07-12 13:04:26 +02:00
|
|
|
//if (!arr)
|
2010-07-16 11:12:15 +02:00
|
|
|
//CV_Error(CV_StsNullPtr, "NULL arr pointer (in showImage)" );
|
2010-07-16 14:51:29 +02:00
|
|
|
CV_Assert(arr)
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-07-16 14:51:29 +02:00
|
|
|
IplImage* tempImage = (IplImage*)arr;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
if (!isSameSize(image2Draw_ipl,tempImage))
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
2010-06-28 23:01:37 +02:00
|
|
|
cvReleaseImage(&image2Draw_ipl);
|
|
|
|
image2Draw_ipl=cvCreateImage(cvGetSize(tempImage),IPL_DEPTH_8U,3);
|
2010-07-07 19:53:59 +02:00
|
|
|
image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);
|
|
|
|
image2Draw_qt_resized = image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
nbChannelOriginImage = tempImage->nChannels;
|
|
|
|
updateGeometry();
|
2010-06-16 09:58:53 +02:00
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
cvConvertImage(tempImage,image2Draw_ipl,CV_CVTIMG_SWAP_RB );
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
viewport()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::setMouseCallBack(CvMouseCallback m, void* param)
|
|
|
|
{
|
|
|
|
on_mouse = m;
|
|
|
|
on_mouse_param = param;
|
|
|
|
}
|
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
void ViewPort::setOpenGLCallback(CvOpenGLCallback func,void* userdata)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
on_openGL_draw3D = func;
|
|
|
|
on_openGL_param = userdata;
|
|
|
|
}
|
|
|
|
|
2010-06-16 09:58:53 +02:00
|
|
|
void ViewPort::controlImagePosition()
|
|
|
|
{
|
|
|
|
qreal left, top, right, bottom;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
//after check top-left, bottom right corner to avoid getting "out" during zoom/panning
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.map(0,0,&left,&top);
|
|
|
|
|
2010-06-17 18:41:48 +02:00
|
|
|
if (left > 0)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.translate(-left,0);
|
2010-06-28 23:01:37 +02:00
|
|
|
left = 0;
|
2010-06-17 18:41:48 +02:00
|
|
|
}
|
|
|
|
if (top > 0)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.translate(0,-top);
|
2010-06-28 23:01:37 +02:00
|
|
|
top = 0;
|
2010-06-17 18:41:48 +02:00
|
|
|
}
|
2010-06-22 19:15:49 +02:00
|
|
|
//-------
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-16 09:58:53 +02:00
|
|
|
QSize sizeImage = size();
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
|
2010-06-17 18:41:48 +02:00
|
|
|
if (right < sizeImage.width())
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.translate(sizeImage.width()-right,0);
|
2010-06-28 23:01:37 +02:00
|
|
|
right = sizeImage.width();
|
2010-06-17 18:41:48 +02:00
|
|
|
}
|
|
|
|
if (bottom < sizeImage.height())
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.translate(0,sizeImage.height()-bottom);
|
2010-06-28 23:01:37 +02:00
|
|
|
bottom = sizeImage.height();
|
2010-06-17 18:41:48 +02:00
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
//save corner position
|
|
|
|
positionCorners.setTopLeft(QPoint(left,top));
|
|
|
|
positionCorners.setBottomRight(QPoint(right,bottom));
|
2010-06-17 22:44:18 +02:00
|
|
|
//save also the inv matrix
|
2010-06-30 00:14:24 +02:00
|
|
|
matrixWorld_inv = param_matrixWorld.inverted();
|
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
viewport()->update();
|
2010-06-16 09:58:53 +02:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
void ViewPort::moveView(QPointF delta)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
param_matrixWorld.translate(delta.x(),delta.y());
|
2010-06-19 20:57:04 +02:00
|
|
|
controlImagePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
//factor is -0.5 (zoom out) or 0.5 (zoom in)
|
2010-06-30 00:14:24 +02:00
|
|
|
void ViewPort::scaleView(qreal factor,QPointF center)
|
2010-06-16 09:58:53 +02:00
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
factor/=5;//-0.1 <-> 0.1
|
|
|
|
factor+=1;//0.9 <-> 1.1
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
//limit zoom out ---
|
2010-06-30 00:14:24 +02:00
|
|
|
if (param_matrixWorld.m11()==1 && factor < 1)
|
2010-06-28 23:01:37 +02:00
|
|
|
return;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
if (param_matrixWorld.m11()*factor<1)
|
|
|
|
factor = 1/param_matrixWorld.m11();
|
|
|
|
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
//limit zoom int ---
|
2010-06-30 00:14:24 +02:00
|
|
|
if (param_matrixWorld.m11()>100 && factor > 1)
|
2010-06-28 23:01:37 +02:00
|
|
|
return;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-17 18:41:48 +02:00
|
|
|
//inverse the transform
|
|
|
|
int a, b;
|
2010-06-17 22:44:18 +02:00
|
|
|
matrixWorld_inv.map(center.x(),center.y(),&a,&b);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
param_matrixWorld.translate(a-factor*a,b-factor*b);
|
|
|
|
param_matrixWorld.scale(factor,factor);
|
|
|
|
|
2010-06-17 18:41:48 +02:00
|
|
|
controlImagePosition();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-22 19:15:49 +02:00
|
|
|
//display new zoom
|
2010-07-16 11:12:15 +02:00
|
|
|
if (centralWidget->myStatusBar)
|
|
|
|
centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
2010-06-28 23:01:37 +02:00
|
|
|
setCursor(Qt::OpenHandCursor);
|
2010-06-16 09:58:53 +02:00
|
|
|
else
|
2010-06-28 23:01:37 +02:00
|
|
|
unsetCursor();
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
scaleView( -event->delta() / 240.0,event->pos());
|
2010-06-14 18:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::mousePressEvent(QMouseEvent *event)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
int cv_event = -1, flags = 0;
|
2010-06-25 19:19:11 +02:00
|
|
|
QPoint pt = event->pos();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
//icvmouseHandler: pass parameters for cv_event, flags
|
|
|
|
icvmouseHandler(event, mouse_down, cv_event, flags);
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
2010-06-16 09:58:53 +02:00
|
|
|
{
|
2010-06-28 23:01:37 +02:00
|
|
|
setCursor(Qt::ClosedHandCursor);
|
|
|
|
positionGrabbing = event->pos();
|
2010-06-16 09:58:53 +02:00
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
void ViewPort::mouseReleaseEvent(QMouseEvent *event)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
int cv_event = -1, flags = 0;
|
2010-06-25 19:19:11 +02:00
|
|
|
QPoint pt = event->pos();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
//icvmouseHandler: pass parameters for cv_event, flags
|
|
|
|
icvmouseHandler(event, mouse_up, cv_event, flags);
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
2010-06-28 23:01:37 +02:00
|
|
|
setCursor(Qt::OpenHandCursor);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QWidget::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
void ViewPort::mouseDoubleClickEvent(QMouseEvent *event)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
|
|
|
int cv_event = -1, flags = 0;
|
2010-06-25 19:19:11 +02:00
|
|
|
QPoint pt = event->pos();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
//icvmouseHandler: pass parameters for cv_event, flags
|
|
|
|
icvmouseHandler(event, mouse_dbclick, cv_event, flags);
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
QWidget::mouseDoubleClickEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
int cv_event = -1, flags = 0;
|
|
|
|
QPoint pt = event->pos();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
//icvmouseHandler: pass parameters for cv_event, flags
|
|
|
|
icvmouseHandler(event, mouse_move, cv_event, flags);
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (param_matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();
|
|
|
|
positionGrabbing = event->pos();
|
|
|
|
moveView(dxy);
|
2010-06-25 19:19:11 +02:00
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
//I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp)
|
|
|
|
//the status bar will only be repaint when a click occurs.
|
2010-07-16 11:12:15 +02:00
|
|
|
if (centralWidget->myStatusBar)
|
|
|
|
viewport()->update();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
QWidget::mouseMoveEvent(event);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
2010-06-22 19:15:49 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
//up, down, dclick, move
|
|
|
|
void ViewPort::icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
switch(event->modifiers())
|
|
|
|
{
|
|
|
|
case Qt::ShiftModifier:
|
2010-06-25 19:19:11 +02:00
|
|
|
flags = CV_EVENT_FLAG_SHIFTKEY;
|
|
|
|
break;
|
2010-06-10 22:03:52 +02:00
|
|
|
case Qt::ControlModifier:
|
2010-06-25 19:19:11 +02:00
|
|
|
flags = CV_EVENT_FLAG_CTRLKEY;
|
|
|
|
break;
|
2010-06-10 22:03:52 +02:00
|
|
|
case Qt::AltModifier:
|
2010-06-25 19:19:11 +02:00
|
|
|
flags = CV_EVENT_FLAG_ALTKEY;
|
|
|
|
break;
|
2010-06-10 22:03:52 +02:00
|
|
|
case Qt::NoModifier :
|
2010-06-25 19:19:11 +02:00
|
|
|
break;
|
2010-06-10 22:03:52 +02:00
|
|
|
case Qt::MetaModifier:
|
2010-06-25 19:19:11 +02:00
|
|
|
break;
|
2010-06-10 22:03:52 +02:00
|
|
|
case Qt::KeypadModifier:
|
2010-06-25 19:19:11 +02:00
|
|
|
break;
|
2010-06-10 22:03:52 +02:00
|
|
|
default:;
|
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
switch(event->button())
|
2010-06-19 23:01:27 +02:00
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2010-06-25 19:19:11 +02:00
|
|
|
cv_event = tableMouseButtons[category][0];
|
|
|
|
flags |= CV_EVENT_FLAG_LBUTTON;
|
|
|
|
break;
|
2010-06-19 23:01:27 +02:00
|
|
|
case Qt::RightButton:
|
2010-06-25 19:19:11 +02:00
|
|
|
cv_event = tableMouseButtons[category][1];
|
|
|
|
flags |= CV_EVENT_FLAG_RBUTTON;
|
|
|
|
break;
|
2010-06-19 23:01:27 +02:00
|
|
|
case Qt::MidButton:
|
2010-06-25 19:19:11 +02:00
|
|
|
cv_event = tableMouseButtons[category][2];
|
|
|
|
flags |= CV_EVENT_FLAG_MBUTTON;
|
|
|
|
break;
|
2010-06-19 23:01:27 +02:00
|
|
|
default:;
|
|
|
|
}
|
2010-06-25 19:19:11 +02:00
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
void ViewPort::icvmouseProcessing(QPointF pt, int cv_event, int flags)
|
|
|
|
{
|
2010-06-22 19:15:49 +02:00
|
|
|
//to convert mouse coordinate
|
2010-06-25 19:19:11 +02:00
|
|
|
qreal pfx, pfy;
|
|
|
|
matrixWorld_inv.map(pt.x(),pt.y(),&pfx,&pfy);
|
2010-06-28 23:01:37 +02:00
|
|
|
mouseCoordinate.rx()=floor(pfx);
|
|
|
|
mouseCoordinate.ry()=floor(pfy);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-25 19:19:11 +02:00
|
|
|
if (on_mouse)
|
|
|
|
on_mouse( cv_event, mouseCoordinate.x(),mouseCoordinate.y(), flags, on_mouse_param );
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize ViewPort::sizeHint() const
|
|
|
|
{
|
2010-06-22 19:15:49 +02:00
|
|
|
if(image2Draw_ipl)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-06-28 23:01:37 +02:00
|
|
|
return QSize(image2Draw_ipl->width,image2Draw_ipl->height);
|
2010-06-10 22:03:52 +02:00
|
|
|
} else {
|
2010-06-28 23:01:37 +02:00
|
|
|
return QGraphicsView::sizeHint();
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-17 22:44:18 +02:00
|
|
|
void ViewPort::resizeEvent ( QResizeEvent *event)
|
2010-07-16 11:12:15 +02:00
|
|
|
{
|
|
|
|
image2Draw_qt_resized = image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
controlImagePosition();
|
2010-06-28 23:01:37 +02:00
|
|
|
ratioX=width()/float(image2Draw_ipl->width);
|
|
|
|
ratioY=height()/float(image2Draw_ipl->height);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
if(param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
|
2010-06-27 00:36:41 +02:00
|
|
|
{
|
2010-06-28 23:01:37 +02:00
|
|
|
QSize newSize = QSize(image2Draw_ipl->width,image2Draw_ipl->height);
|
|
|
|
newSize.scale(event->size(),Qt::KeepAspectRatio);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
//imageWidth/imageHeight = newWidth/newHeight +/- epsilon
|
|
|
|
//ratioX = ratioY +/- epsilon
|
|
|
|
//||ratioX - ratioY|| = epsilon
|
|
|
|
if (fabs(ratioX - ratioY)*100> ratioX)//avoid infinity loop / epsilon = 1% of ratioX
|
|
|
|
{
|
|
|
|
resize(newSize);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
//move to the middle
|
|
|
|
//newSize get the delta offset to place the picture in the middle of its parent
|
|
|
|
newSize= (event->size()-newSize)/2;
|
2010-07-16 11:12:15 +02:00
|
|
|
|
|
|
|
//if the toolbar is displayed, avoid drawing myview on top of it
|
|
|
|
if (centralWidget->myToolBar)
|
|
|
|
newSize +=QSize(0,centralWidget->myToolBar->height());
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
move(newSize.width(),newSize.height());
|
|
|
|
}
|
2010-06-27 00:36:41 +02:00
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-19 20:57:04 +02:00
|
|
|
return QGraphicsView::resizeEvent(event);
|
2010-06-17 22:44:18 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void ViewPort::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
//first paint on a file (to be able to save it if needed)
|
|
|
|
// --------- START PAINTING FILE -------------- //
|
2010-07-07 19:53:59 +02:00
|
|
|
QPainter myPainter(&image2Draw_qt_resized);
|
2010-06-30 00:14:24 +02:00
|
|
|
myPainter.setWorldTransform(param_matrixWorld);
|
|
|
|
|
2010-06-14 18:00:38 +02:00
|
|
|
draw2D(&myPainter);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-17 22:44:18 +02:00
|
|
|
#if defined(OPENCV_GL)
|
2010-07-12 13:04:26 +02:00
|
|
|
if ( mode_display == CV_MODE_OPENGL && on_openGL_draw3D)
|
2010-06-10 22:03:52 +02:00
|
|
|
{
|
2010-07-12 16:39:31 +02:00
|
|
|
//myPainter.beginNativePainting();
|
2010-07-12 13:04:26 +02:00
|
|
|
|
2010-07-07 19:53:59 +02:00
|
|
|
setGL(width(),height());
|
2010-07-12 13:04:26 +02:00
|
|
|
on_openGL_draw3D(on_openGL_param);
|
|
|
|
//draw3D();
|
2010-06-28 23:01:37 +02:00
|
|
|
unsetGL();
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-07-12 16:39:31 +02:00
|
|
|
//myPainter.endNativePainting();
|
2010-06-17 22:44:18 +02:00
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
#endif
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//Now disable matrixWorld for overlay display
|
|
|
|
myPainter.setWorldMatrixEnabled (false );
|
|
|
|
|
2010-06-17 22:44:18 +02:00
|
|
|
//in mode zoom/panning
|
2010-06-30 00:14:24 +02:00
|
|
|
if (param_matrixWorld.m11()>1)
|
2010-06-17 22:44:18 +02:00
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
if (param_matrixWorld.m11()>=threshold_zoom_img_region)
|
|
|
|
drawImgRegion(&myPainter);
|
|
|
|
|
|
|
|
drawViewOverview(&myPainter);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-17 22:44:18 +02:00
|
|
|
//for information overlay
|
2010-06-10 22:03:52 +02:00
|
|
|
if (drawInfo)
|
2010-07-16 11:12:15 +02:00
|
|
|
drawInstructions(&myPainter);
|
|
|
|
|
|
|
|
// --------- END PAINTING FILE -------------- //
|
|
|
|
myPainter.end();
|
|
|
|
|
|
|
|
|
|
|
|
//and now display the file
|
|
|
|
myPainter.begin(viewport());
|
|
|
|
myPainter.drawImage(0, 0, image2Draw_qt_resized);
|
|
|
|
//end display
|
|
|
|
|
|
|
|
//for statusbar
|
|
|
|
if (centralWidget->myStatusBar)
|
|
|
|
drawStatusBar();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QGraphicsView::paintEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::draw2D(QPainter *painter)
|
2010-06-14 18:00:38 +02:00
|
|
|
{
|
2010-06-27 00:36:41 +02:00
|
|
|
painter->drawImage(0,0,image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
|
2010-06-22 19:15:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::drawStatusBar()
|
|
|
|
{
|
2010-06-28 23:01:37 +02:00
|
|
|
if (mouseCoordinate.x()>=0 &&
|
|
|
|
mouseCoordinate.y()>=0 &&
|
|
|
|
mouseCoordinate.x()<image2Draw_ipl->width &&
|
|
|
|
mouseCoordinate.y()<image2Draw_ipl->height)
|
|
|
|
{
|
|
|
|
QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
if (nbChannelOriginImage==3)
|
|
|
|
{
|
2010-07-16 11:12:15 +02:00
|
|
|
centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
|
|
|
|
.arg(mouseCoordinate.x())
|
|
|
|
.arg(mouseCoordinate.y())+
|
|
|
|
tr("<font color='red'>R:%3 </font>").arg(qRed(rgbValue))+//.arg(value.val[0])+
|
|
|
|
tr("<font color='green'>G:%4 </font>").arg(qGreen(rgbValue))+//.arg(value.val[1])+
|
|
|
|
tr("<font color='blue'>B:%5</font>").arg(qBlue(rgbValue))//.arg(value.val[2])
|
|
|
|
);
|
2010-06-28 23:01:37 +02:00
|
|
|
}else{
|
|
|
|
//all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed
|
2010-07-16 11:12:15 +02:00
|
|
|
centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
|
|
|
|
.arg(mouseCoordinate.x())
|
|
|
|
.arg(mouseCoordinate.y())+
|
|
|
|
tr("<font color='grey'>grey:%3 </font>").arg(qRed(rgbValue))
|
|
|
|
);
|
2010-06-28 23:01:37 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
void ViewPort::drawImgRegion(QPainter *painter)
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11();
|
2010-06-28 23:01:37 +02:00
|
|
|
offsetX = offsetX - floor(offsetX);
|
2010-06-30 00:14:24 +02:00
|
|
|
qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11();
|
2010-06-28 23:01:37 +02:00
|
|
|
offsetY = offsetY - floor(offsetY);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
QSize view = size();
|
|
|
|
QVarLengthArray<QLineF, 30> linesX;
|
2010-06-30 00:14:24 +02:00
|
|
|
for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() )
|
|
|
|
linesX.append(QLineF(x, 0, x, view.height()));
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
QVarLengthArray<QLineF, 30> linesY;
|
2010-06-30 00:14:24 +02:00
|
|
|
for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() )
|
2010-06-28 23:01:37 +02:00
|
|
|
linesY.append(QLineF(0, y, view.width(), y));
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
QFont f = painter->font();
|
2010-07-16 11:12:15 +02:00
|
|
|
int original_font_size = f.pointSize();
|
|
|
|
//change font size
|
|
|
|
//f.setPointSize(4+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
|
2010-06-30 00:14:24 +02:00
|
|
|
f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
|
2010-06-28 23:01:37 +02:00
|
|
|
painter->setFont(f);
|
|
|
|
QString val;
|
|
|
|
QRgb rgbValue;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
QPointF point1;//sorry, I do not know how to name it
|
|
|
|
QPointF point2;//idem
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
for (int j=-1;j<view.height()/param_matrixWorld.m11();j++)
|
|
|
|
for (int i=-1;i<view.width()/param_matrixWorld.m11();i++)
|
2010-06-28 23:01:37 +02:00
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
point1.setX((i+offsetX)*param_matrixWorld.m11());
|
|
|
|
point1.setY((j+offsetY)*param_matrixWorld.m11());
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
if (point2.x() >= 0 && point2.y() >= 0)
|
|
|
|
rgbValue = image2Draw_qt.pixel(QPoint(point2.x(),point2.y()));
|
|
|
|
else
|
|
|
|
rgbValue = qRgb(0,0,0);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
if (nbChannelOriginImage==3)
|
|
|
|
{
|
|
|
|
val = tr("%1").arg(qRed(rgbValue));
|
|
|
|
painter->setPen(QPen(Qt::red, 1));
|
2010-06-30 00:14:24 +02:00
|
|
|
painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
2010-06-28 23:01:37 +02:00
|
|
|
Qt::AlignCenter, val);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
val = tr("%1").arg(qGreen(rgbValue));
|
|
|
|
painter->setPen(QPen(Qt::green, 1));
|
2010-06-30 00:14:24 +02:00
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
2010-06-28 23:01:37 +02:00
|
|
|
Qt::AlignCenter, val);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
val = tr("%1").arg(qBlue(rgbValue));
|
|
|
|
painter->setPen(QPen(Qt::blue, 1));
|
2010-06-30 00:14:24 +02:00
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
2010-06-28 23:01:37 +02:00
|
|
|
Qt::AlignCenter, val);
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
val = tr("%1").arg(qRed(rgbValue));
|
2010-06-30 00:14:24 +02:00
|
|
|
painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()),
|
2010-06-28 23:01:37 +02:00
|
|
|
Qt::AlignCenter, val);
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
painter->setPen(QPen(Qt::black, 1));
|
|
|
|
painter->drawLines(linesX.data(), linesX.size());
|
|
|
|
painter->drawLines(linesY.data(), linesY.size());
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-07-16 11:12:15 +02:00
|
|
|
//restore font size
|
|
|
|
f.setPointSize(original_font_size);
|
|
|
|
painter->setFont(f);
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::drawViewOverview(QPainter *painter)
|
2010-06-17 22:44:18 +02:00
|
|
|
{
|
|
|
|
QSize viewSize = size();
|
|
|
|
viewSize.scale ( 100, 100,Qt::KeepAspectRatio );
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-17 22:44:18 +02:00
|
|
|
const int margin = 5;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
//draw the image's location
|
2010-06-19 20:57:04 +02:00
|
|
|
painter->setBrush(QColor(0, 0, 0, 127));
|
2010-06-17 22:44:18 +02:00
|
|
|
painter->setPen(Qt::darkGreen);
|
|
|
|
painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
//daw the view's location inside the image
|
2010-06-30 00:14:24 +02:00
|
|
|
qreal ratioSize = 1/param_matrixWorld.m11();
|
2010-06-17 22:44:18 +02:00
|
|
|
qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
|
|
|
|
painter->setPen(Qt::darkBlue);
|
|
|
|
painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
|
2010-06-28 23:01:37 +02:00
|
|
|
-positionCorners.top()*ratioSize*ratioWindow,
|
|
|
|
(viewSize.width()-1)*ratioSize,
|
|
|
|
(viewSize.height()-1)*ratioSize)
|
|
|
|
);
|
2010-06-17 22:44:18 +02:00
|
|
|
}
|
2010-06-14 18:00:38 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void ViewPort::drawInstructions(QPainter *painter)
|
|
|
|
{
|
|
|
|
QFontMetrics metrics = QFontMetrics(font());
|
|
|
|
int border = qMax(4, metrics.leading());
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),
|
2010-06-28 23:01:37 +02:00
|
|
|
Qt::AlignCenter | Qt::TextWordWrap, infoText);
|
2010-06-10 22:03:52 +02:00
|
|
|
painter->setRenderHint(QPainter::TextAntialiasing);
|
|
|
|
painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
|
2010-06-28 23:01:37 +02:00
|
|
|
QColor(0, 0, 0, 127));
|
2010-06-10 22:03:52 +02:00
|
|
|
painter->setPen(Qt::white);
|
|
|
|
painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
|
2010-06-28 23:01:37 +02:00
|
|
|
QColor(0, 0, 0, 127));
|
2010-07-16 11:12:15 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
painter->drawText((width() - rect.width())/2, border,
|
2010-06-28 23:01:37 +02:00
|
|
|
rect.width(), rect.height(),
|
|
|
|
Qt::AlignCenter | Qt::TextWordWrap, infoText);
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-16 09:58:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
#if defined(OPENCV_GL)//all this section -> not tested
|
|
|
|
|
|
|
|
void ViewPort::initGL()
|
|
|
|
{
|
|
|
|
glShadeModel( GL_SMOOTH );
|
|
|
|
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glEnable( GL_CULL_FACE );
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:36:41 +02:00
|
|
|
//from http://steinsoft.net/index.php?site=Programming/Code%20Snippets/OpenGL/gluperspective
|
|
|
|
//do not want to link glu
|
|
|
|
void ViewPort::icvgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
|
|
|
|
{
|
2010-06-28 23:01:37 +02:00
|
|
|
GLdouble xmin, xmax, ymin, ymax;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
ymax = zNear * tan(fovy * M_PI / 360.0);
|
|
|
|
ymin = -ymax;
|
|
|
|
xmin = ymin * aspect;
|
|
|
|
xmax = ymax * aspect;
|
2010-06-30 00:14:24 +02:00
|
|
|
|
|
|
|
|
2010-06-28 23:01:37 +02:00
|
|
|
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
|
2010-06-27 00:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
void ViewPort::setGL(int width, int height)
|
|
|
|
{
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2010-06-27 00:36:41 +02:00
|
|
|
icvgluPerspective(45, float(width) / float(height), 0.01, 1000);
|
2010-06-10 22:03:52 +02:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::unsetGL()
|
|
|
|
{
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPort::draw3D()
|
|
|
|
{
|
|
|
|
//draw scene here
|
|
|
|
glLoadIdentity();
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-07-12 13:04:26 +02:00
|
|
|
glTranslated(10.0, 10.0, -1.0);
|
|
|
|
// QVector3D p = convert(mouseCoordinate);
|
2010-06-10 22:03:52 +02:00
|
|
|
//glTranslated(p.x(),p.y(),p.z());
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
glRotatef( 55, 1, 0, 0 );
|
|
|
|
glRotatef( 45, 0, 1, 0 );
|
|
|
|
glRotatef( 0, 0, 0, 1 );
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
static const int coords[6][4][3] = {
|
2010-06-28 23:01:37 +02:00
|
|
|
{ { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
|
|
|
|
{ { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } },
|
|
|
|
{ { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
|
|
|
|
{ { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
|
|
|
|
{ { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
|
|
|
|
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
|
2010-06-10 22:03:52 +02:00
|
|
|
};
|
2010-06-30 00:14:24 +02:00
|
|
|
|
2010-06-10 22:03:52 +02:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
2010-07-16 11:12:15 +02:00
|
|
|
glColor3ub( i*20, 100+i*10, i*42 );
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]);
|
|
|
|
}
|
|
|
|
glEnd();
|
2010-06-10 22:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|