/*! Wait for a click from one of the mouse button. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a mouse button is pressed and then returns always true. - When set to false, returns true only if a mouse button is pressed, otherwise returns false. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayGTK::getClick(bool blocking) { bool ret = false; if (displayHasBeenInitialized) { // flushDisplay() ; //int cpt =0; do { GdkEvent *ev = NULL; while ((ev = gdk_event_get())!=NULL){ //cpt++; // printf("event %d type %d on window %p My window %p\n", //cpt, ev->type, ev->any.window, widget->window); if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){ ret = true ; //printf("Click detection\n"); } gdk_event_free(ev) ; } if (blocking){ flushDisplay(); vpTime::wait(100); } } while ( ret == false && blocking == true); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } return ret; }
/*! Display a line from image point \e ip1 to image point \e ip2. \param ip1,ip2 : Initial and final image points. \param color : Line color. \param thickness : Line thickness. */ void vpDisplayGTK::displayLine ( const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness ) { if (displayHasBeenInitialized) { if ( thickness == 1 ) thickness = 0; if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL) ; gdk_draw_line(background, gc, vpMath::round( ip1.get_u() ), vpMath::round( ip1.get_v() ), vpMath::round( ip2.get_u() ), vpMath::round( ip2.get_v() ) ); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Display the gray level image \e I (8bits). \warning Display has to be initialized. \warning Suppress the overlay drawing. \param I : Image to display. \sa init(), closeDisplay() */ void vpDisplayGTK::displayImage(const vpImage<unsigned char> &I) { if (displayHasBeenInitialized) { /* Copie de l'image dans le pixmap fond */ gdk_draw_gray_image(background, gc, 0, 0, (gint)width, (gint)height, GDK_RGB_DITHER_NONE, I.bitmap, (gint)width); /* Le pixmap background devient le fond de la zone de dessin */ gdk_window_set_back_pixmap(widget->window, background, FALSE); /* Affichage */ //gdk_window_clear(GTK_WINDOW(widget)); //gdk_flush(); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Wait for a click from one of the mouse button. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a mouse button is pressed and then returns always true. - When set to false, returns true only if a mouse button is pressed, otherwise returns false. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayOpenCV::getClick(bool blocking) { bool ret = false; if (displayHasBeenInitialized) { flushDisplay() ; if (blocking){ lbuttondown = false; mbuttondown = false; rbuttondown = false; } do { if (lbuttondown){ ret = true ; lbuttondown = false; } if (mbuttondown){ ret = true ; mbuttondown = false; } if (rbuttondown){ ret = true ; rbuttondown = false; } if (blocking) cvWaitKey(10); } while ( ret == false && blocking == true); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } return ret; }
/*! Get a keyboard event. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a key is pressed and then returns always true. - When set to false, returns true only if a key is pressed, otherwise returns false. \param string [out]: If possible, an ISO Latin-1 character corresponding to the keyboard key. \return - true if a key was pressed. This is always the case if blocking is set to \e true. - false if no key was pressed. This can occur if blocking is set to \e false. */ bool vpDisplayOpenCV::getKeyboardEvent(char *string, bool blocking) { int key_pressed; int delay; if (displayHasBeenInitialized) { flushDisplay() ; if (blocking) delay = 0; else delay = 10; key_pressed = cvWaitKey(delay); if (key_pressed == -1) return false; else { //std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl; sprintf(string, "%c", key_pressed); } return true; } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } //return false; // Never reached after throw() }
/*! Display a point at the image point \e ip location. \param ip : Point location. \param color : Point color. */ void vpDisplayGTK::displayPoint ( const vpImagePoint &ip, const vpColor &color ) { if (displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } gdk_draw_point(background,gc, vpMath::round( ip.get_u() ), vpMath::round( ip.get_v() ) ); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Display a selection of the gray level image \e I (8bits). \warning Display has to be initialized. \warning Suppress the overlay drawing in the region of interest. \param I : Image to display. \param iP : Top left corner of the region of interest \param w : Width of the region of interest \param h : Height of the region of interest \sa init(), closeDisplay() */ void vpDisplayGTK::displayImageROI ( const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int w, const unsigned int h ) { if (displayHasBeenInitialized) { vpImage<unsigned char> Itemp; vpImageTools::crop(I,(unsigned int)iP.get_i(),(unsigned int)iP.get_j(), h, w,Itemp); /* Copie de l'image dans le pixmap fond */ gdk_draw_gray_image(background, gc, (gint)iP.get_u(), (gint)iP.get_v(), (gint)w, (gint)h, GDK_RGB_DITHER_NONE, I.bitmap, (gint)w); /* Le pixmap background devient le fond de la zone de dessin */ gdk_window_set_back_pixmap(widget->window, background, FALSE); /* Affichage */ //gdk_window_clear(GTK_WINDOW(widget)); //gdk_flush(); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Display a dashed line from image point \e ip1 to image point \e ip2. \warning Dot lines are not yet implemented in OpenCV. We display a normal line instead. \param ip1,ip2 : Initial and final image points. \param color : Line color. \param thickness : Line thickness. */ void vpDisplayOpenCV::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness) { if (displayHasBeenInitialized) { vpTRACE("Dot lines are not yet implemented"); if (color.id < vpColor::id_unknown) { cvLine( background, cvPoint( vpMath::round( ip1.get_u() ), vpMath::round( ip1.get_v() ) ), cvPoint( vpMath::round( ip2.get_u() ), vpMath::round( ip2.get_v() ) ), col[color.id], (int) thickness); } else { cvcolor = CV_RGB(color.R, color.G, color.B) ; cvLine( background, cvPoint( vpMath::round( ip1.get_u() ), vpMath::round( ip1.get_v() ) ), cvPoint( vpMath::round( ip2.get_u() ), vpMath::round( ip2.get_v() ) ), cvcolor, (int) thickness); } } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! Display the color image \e I in RGBa format (32bits). \warning Display has to be initialized. \warning Suppress the overlay drawing. \param I : Image to display. \sa init(), closeDisplay() */ void vpDisplayGTK::displayImage(const vpImage<vpRGBa> &I) { if (displayHasBeenInitialized) { /* Copie de l'image dans le pixmap fond */ gdk_draw_rgb_32_image(background, gc, 0, 0, (gint)width, (gint)height, GDK_RGB_DITHER_NONE, (unsigned char *)I.bitmap, (gint)(4*width)); /* Permet de fermer la fenetre si besoin (cas des sequences d'images) */ //while (g_main_iteration(FALSE)); /* Le pixmap background devient le fond de la zone de dessin */ gdk_window_set_back_pixmap(widget->window, background, FALSE); /* Affichage */ //gdk_window_clear(GTK_WINDOW(widget)); //flushDisplay() ; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Display a selection of the color image \e I in RGBa format (32bits). \warning Display has to be initialized. \warning Suppress the overlay drawing in the region of interest. \param I : Image to display. \param iP : Top left corner of the region of interest \param w : Width of the region of interest \param h : Height of the region of interest \sa init(), closeDisplay() */ void vpDisplayGTK::displayImageROI ( const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int w, const unsigned int h ) { if (displayHasBeenInitialized) { vpImage<vpRGBa> Itemp; vpImageTools::crop(I,(unsigned int)iP.get_i(), (unsigned int)iP.get_j(), h, w, Itemp); /* Copie de l'image dans le pixmap fond */ gdk_draw_rgb_32_image(background, gc, (gint)iP.get_u(), (gint)iP.get_v(), (gint)w, (gint)h, GDK_RGB_DITHER_NONE, (unsigned char *)Itemp.bitmap, (gint)(4*w)); /* Permet de fermer la fenetre si besoin (cas des sequences d'images) */ //while (g_main_iteration(FALSE)); /* Le pixmap background devient le fond de la zone de dessin */ gdk_window_set_back_pixmap(widget->window, background, FALSE); /* Affichage */ //gdk_window_clear(GTK_WINDOW(widget)); //flushDisplay() ; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Display a string at the image point \e ip location. To select the font used to display the string, use setFont(). \param ip : Upper left image point location of the string in the display. \param text : String to display in overlay. \param color : String color. \sa setFont() */ void vpDisplayOpenCV::displayCharString( const vpImagePoint &ip, const char *text, const vpColor &color ) { if (displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) { cvPutText( background, text, cvPoint( vpMath::round( ip.get_u() ), vpMath::round( ip.get_v()+fontHeight ) ), font, col[color.id] ); } else { cvcolor = CV_RGB(color.R, color.G, color.B) ; cvPutText( background, text, cvPoint( vpMath::round( ip.get_u() ), vpMath::round( ip.get_v()+fontHeight ) ), font, cvcolor ); } } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! Display a string at the image point \e ip location. To select the font used to display the string, use setFont(). \param ip : Upper left image point location of the string in the display. \param text : String to display in overlay. \param color : String color. \sa setFont() */ void vpDisplayGTK::displayCharString ( const vpImagePoint &ip, const char *text, const vpColor &color ) { if (displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } if (font != NULL) gdk_draw_string(background, font, gc, vpMath::round( ip.get_u() ), vpMath::round( ip.get_v() ), (const gchar *)text); else std::cout << "Cannot draw string: no font is selected" << std::endl; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Set the window title. \warning This method is not implemented yet. \param title : Window title. */ void vpDisplayOpenCV::setTitle(const char * /* title */) { static bool warn_displayed = false; if (! warn_displayed) { vpTRACE("Not implemented"); warn_displayed = true; } #if 0 if (displayHasBeenInitialized) { if (this->title != NULL) { delete [] this->title ; this->title = NULL ; } // fprintf(stdout, "len: %d\n", strlen(windowtitle)); fflush(stdout); this->title = new char[strlen(windowtitle) + 1] ; strcpy(this->title, windowtitle) ; //cvMoveWindow( this->title, windowXPosition, windowYPosition); cvMoveWindow(windowtitle , windowXPosition, windowYPosition); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } #endif }
/*! Get the coordinates of the mouse pointer. \warning Not implemented yet. \param ip [out] : The coordinates of the mouse pointer. \return true if a pointer motion event was received, false otherwise. \exception vpDisplayException::notInitializedError : If the display was not initialized. */ bool vpDisplayOpenCV::getPointerMotionEvent (vpImagePoint &ip ) { bool ret = false; if (displayHasBeenInitialized) { //flushDisplay() ; double u, v; if (move){ ret = true ; u = (unsigned int)x_move; v = (unsigned int)y_move; ip.set_u( u ); ip.set_v( v ); move = false; } } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } return ret; }
/*! Initialize the display (size, position and title) of a color image in RGBa format. \param I : Image to be displayed (not that image has to be initialized) \param x, y : The window is set at position x,y (column index, row index). \param title : Window title. */ void vpDisplayGTK::init(vpImage<vpRGBa> &I, int x, int y, const std::string &title) { if ((I.getHeight() == 0) || (I.getWidth()==0)) { vpERROR_TRACE("Image not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "Image not initialized")) ; } if (x != -1) windowXPosition = x ; if (y != -1) windowYPosition = y ; if (! title.empty()) title_ = title; init (I.getWidth(), I.getHeight(), windowXPosition, windowYPosition, title_) ; I.display = this ; displayHasBeenInitialized = true ; }
/*! Wait for a click from one of the mouse button and get the position of the clicked image point. \param ip [out] : The coordinates of the clicked image point. \param blocking [in] : true for a blocking behaviour waiting a mouse button click, false for a non blocking behaviour. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayGTK::getClick(vpImagePoint &ip, bool blocking) { bool ret = false; if (displayHasBeenInitialized) { double u, v ; do { GdkEvent *ev = NULL; while ((ev = gdk_event_get())!=NULL){ if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) { u = ((GdkEventButton *)ev)->x ; v = ((GdkEventButton *)ev)->y ; ip.set_u( u ); ip.set_v( v ); ret = true ; } gdk_event_free(ev) ; } if (blocking){ flushDisplay(); vpTime::wait(100); } } while ( ret == false && blocking == true); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } return ret ; }
/*! Display a selection of the gray level image \e I (8bits). \warning Display has to be initialized. \warning Suppress the overlay drawing in the region of interest. \param I : Image to display. \param iP : Top left corner of the region of interest \param width : Width of the region of interest \param height : Height of the region of interest \sa init(), closeDisplay() */ void vpDisplayOpenCV::displayImageROI ( const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height ) { if (displayHasBeenInitialized) { vpImage<unsigned char> Itemp; vpImageTools::createSubImage(I,(unsigned int)iP.get_i(),(unsigned int)iP.get_j(),height,width,Itemp); vpImage<vpRGBa> Ic; vpImageConvert::convert(Itemp,Ic); CvSize size = cvSize((int)this->width, (int)this->height); int depth = 8; int channels = 3; if (background != NULL){ if(background->nChannels != channels || background->depth != depth || background->height != (int) I.getHeight() || background->width != (int) I.getWidth()){ if(background->nChannels != 0) cvReleaseImage(&background); background = cvCreateImage( size, depth, channels ); } } else background = cvCreateImage( size, depth, channels ); IplImage* Ip = NULL; vpImageConvert::convert(Ic, Ip); unsigned char * input = (unsigned char*)Ip->imageData; unsigned char * output = (unsigned char*)background->imageData; unsigned int iwidth = Ic.getWidth(); input = input; output = output + (int)(iP.get_i()*3*this->width+ iP.get_j()*3); unsigned int i = 0; while (i < height) { unsigned int j = 0; while (j < width) { *(output+3*j) = *(input+j*3); *(output+3*j+1) = *(input+j*3+1); *(output+3*j+2) = *(input+j*3+2); j++; } input = input + 3*iwidth; output = output + 3*this->width; i++; } cvReleaseImage(&Ip); } else { vpERROR_TRACE("openCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! Display an arrow from image point \e ip1 to image point \e ip2. \param ip1,ip2 : Initial and final image point. \param color : Arrow color. \param w,h : Width and height of the arrow. \param thickness : Thickness of the lines used to display the arrow. */ void vpDisplayGTK::displayArrow ( const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness) { if (displayHasBeenInitialized) { try{ double a = ip2.get_i() - ip1.get_i() ; double b = ip2.get_j() - ip1.get_j() ; double lg = sqrt(vpMath::sqr(a)+vpMath::sqr(b)) ; //if ((a==0)&&(b==0)) if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) ) { // DisplayCrossLarge(i1,j1,3,col) ; } else { a /= lg ; b /= lg ; vpImagePoint ip3; ip3.set_i(ip2.get_i() - w*a); ip3.set_j(ip2.get_j() - w*b); vpImagePoint ip4; ip4.set_i( ip3.get_i() - b*h ); ip4.set_j( ip3.get_j() + a*h ); if (lg > 2*vpImagePoint::distance(ip2, ip4) ) displayLine ( ip2, ip4, color, thickness ) ; ip4.set_i( ip3.get_i() + b*h ); ip4.set_j( ip3.get_j() - a*h ); if (lg > 2*vpImagePoint::distance(ip2, ip4) ) displayLine ( ip2, ip4, color, thickness ) ; displayLine ( ip1, ip2, color, thickness ) ; } } catch (...) { vpERROR_TRACE("Error caught") ; throw ; } } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Display a rectangle. \param topLeft : Top-left corner of the rectangle. \param bottomRight : Bottom-right corner of the rectangle. \param color : Rectangle color. \param fill : When set to true fill the rectangle. \param thickness : Thickness of the four lines used to display the rectangle. This parameter is only useful when \e fill is set to false. */ void vpDisplayOpenCV::displayRectangle ( const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, bool fill, unsigned int thickness ) { if (displayHasBeenInitialized) { if (fill == false) { if (color.id < vpColor::id_unknown) { cvRectangle( background, cvPoint( vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ) ), cvPoint( vpMath::round( bottomRight.get_u() ), vpMath::round( bottomRight.get_v() ) ), col[color.id], (int)thickness); } else { cvcolor = CV_RGB(color.R, color.G, color.B) ; cvRectangle( background, cvPoint( vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ) ), cvPoint( vpMath::round( bottomRight.get_u() ), vpMath::round( bottomRight.get_v() ) ), cvcolor, (int)thickness); } } else { if (color.id < vpColor::id_unknown) { cvRectangle( background, cvPoint( vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ) ), cvPoint( vpMath::round( bottomRight.get_u() ), vpMath::round( bottomRight.get_v() ) ), col[color.id], CV_FILLED); } else { cvcolor = CV_RGB(color.R, color.G, color.B) ; cvRectangle( background, cvPoint( vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ) ), cvPoint( vpMath::round( bottomRight.get_u() ), vpMath::round( bottomRight.get_v() ) ), cvcolor, CV_FILLED); } } } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! If the window is not initialized yet, wait a little (MAX_INIT_DELAY). \exception notInitializedError : the window isn't initialized */ void vpDisplayWin32::waitForInit() { //if the window is not initialized yet if(!window.isInitialized()) { //wait if( WAIT_OBJECT_0 != WaitForSingleObject(window.semaInit,MAX_INIT_DELAY)) throw(vpDisplayException(vpDisplayException::notInitializedError, "Window not initialized")) ; //problem : the window is not initialized } }
/*! Wait for a mouse button click and get the position of the clicked pixel. The button used to click is also set. \param ip [out] : The coordinates of the clicked image point. \param button [out] : The button used to click. \param blocking [in] : - When set to true, this method waits until a mouse button is pressed and then returns always true. - When set to false, returns true only if a mouse button is pressed, otherwise returns false. \return true if a mouse button is pressed, false otherwise. If a button is pressed, the location of the mouse pointer is updated in \e ip. */ bool vpDisplayOpenCV::getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType& button, bool blocking) { bool ret = false; if (displayHasBeenInitialized) { //flushDisplay() ; double u, v; if (blocking){ lbuttondown = false; mbuttondown = false; rbuttondown = false; } do { if (lbuttondown){ ret = true ; u = (unsigned int)x_lbuttondown; v = (unsigned int)y_lbuttondown; ip.set_u( u ); ip.set_v( v ); button = vpMouseButton::button1; lbuttondown = false; } if (mbuttondown){ ret = true ; u = (unsigned int)x_mbuttondown; v = (unsigned int)y_mbuttondown; ip.set_u( u ); ip.set_v( v ); button = vpMouseButton::button2; mbuttondown = false; } if (rbuttondown){ ret = true ; u = (unsigned int)x_rbuttondown; v = (unsigned int)y_rbuttondown; ip.set_u( u ); ip.set_v( v ); button = vpMouseButton::button3; rbuttondown = false; } if (blocking) cvWaitKey(10); } while ( ret == false && blocking == true); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } return ret; }
/*! Set the window position in the screen. \param winx, winy : Position of the upper-left window's border in the screen. \exception vpDisplayException::notInitializedError : If the video device is not initialized. */ void vpDisplayGTK::setWindowPosition(int winx, int winy) { if (displayHasBeenInitialized) { gtk_window_move(GTK_WINDOW(widget), winx, winy); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Set the window position in the screen. \param winx, winy : Position of the upper-left window's border in the screen. \exception vpDisplayException::notInitializedError : If the video device is not initialized. */ void vpDisplayOpenCV::setWindowPosition(int winx, int winy) { if (displayHasBeenInitialized) { this->windowXPosition = winx; this->windowYPosition = winy; cvMoveWindow( this->title, winx, winy ); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! Flushes the OpenCV buffer. It's necessary to use this function to see the results of any drawing. */ void vpDisplayOpenCV::flushDisplay() { if (displayHasBeenInitialized) { cvShowImage(title, background ); cvWaitKey(5); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! Flushes the display buffer. It's necessary to use this function to see the results of any drawing. */ void vpDisplayGTK::flushDisplayROI(const vpImagePoint &/*iP*/, const unsigned int /*width*/, const unsigned int /*height*/) { if (displayHasBeenInitialized) { gdk_window_clear(widget->window); gdk_flush(); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Flushes the display buffer. It's necessary to use this function to see the results of any drawing. */ void vpDisplayGTK::flushDisplay() { if (displayHasBeenInitialized) { gdk_window_clear(widget->window); gdk_flush(); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Flushes the OpenCV buffer. It's necessary to use this function to see the results of any drawing. */ void vpDisplayOpenCV::flushDisplayROI(const vpImagePoint &/*iP*/, const unsigned int /*width*/, const unsigned int /*height*/) { if (displayHasBeenInitialized) { cvShowImage(title, background ); cvWaitKey(5); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } }
/*! Display a rectangle. \param topLeft : Top-left corner of the rectangle. \param bottomRight : Bottom-right corner of the rectangle. \param color : Rectangle color. \param fill : When set to true fill the rectangle. \param thickness : Thickness of the four lines used to display the rectangle. This parameter is only useful when \e fill is set to false. */ void vpDisplayGTK::displayRectangle ( const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, bool fill, unsigned int thickness ) { if (displayHasBeenInitialized) { if ( thickness == 1 ) thickness = 0; if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL) ; int w = vpMath::round( bottomRight.get_u() - topLeft.get_u() ); int h = vpMath::round( bottomRight.get_v() - topLeft.get_v() ); if (fill == false) gdk_draw_rectangle(background, gc, FALSE, vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ), w-1,h-1); else gdk_draw_rectangle(background, gc, TRUE, vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ), w, h); if (thickness > 1) gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL) ; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Set the window title. \param title : Window title. */ void vpDisplayGTK::setTitle(const std::string &title) { if (displayHasBeenInitialized) { title_ = title; if(!title.empty()) gdk_window_set_title(widget->window, title_.c_str()); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/*! Wait for a mouse button click release and get the position of the image point were the click release occurs. The button used to click is also set. Same method as getClick(unsigned int&, unsigned int&, vpMouseButton::vpMouseButtonType &, bool). \param ip [out] : Position of the clicked image point. \param button [in] : Button used to click. \param blocking [in] : true for a blocking behaviour waiting a mouse button click, false for a non blocking behaviour. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. \sa getClick(vpImagePoint &, vpMouseButton::vpMouseButtonType &, bool) */ bool vpDisplayGTK::getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType& button, bool blocking) { bool ret = false; if ( displayHasBeenInitialized ) { //flushDisplay() ; double u, v ; do { GdkEvent *ev = NULL; while ((ev = gdk_event_get())!=NULL){ if ( ev->any.window == widget->window && ev->type == GDK_BUTTON_RELEASE) { u = ((GdkEventButton *)ev)->x ; v = ((GdkEventButton *)ev)->y ; ip.set_u( u ); ip.set_v( v ); switch ( ( int ) ( ( GdkEventButton * ) ev )->button ) { case 1: button = vpMouseButton::button1; break; case 2: button = vpMouseButton::button2; break; case 3: button = vpMouseButton::button3; break; } ret = true ; } gdk_event_free(ev) ; } if (blocking){ flushDisplay(); vpTime::wait(100); } } while ( ret == false && blocking == true); } else { vpERROR_TRACE ( "GTK not initialized " ) ; throw ( vpDisplayException ( vpDisplayException::notInitializedError, "GTK not initialized" ) ) ; } return ret; }