ViSP  2.6.2
vpDisplayX.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDisplayX.cpp 3590 2012-03-05 09:48:31Z ayol $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Image display.
36  *
37  * Authors:
38  * Fabien Spindler
39  * Anthony Saunier
40  *
41  *****************************************************************************/
42 
49 #include <visp/vpConfig.h>
50 #ifdef VISP_HAVE_X11
51 
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <iostream>
55 #include <cmath> // std::fabs
56 #include <limits> // numeric_limits
57 
58 // Display stuff
59 #include <visp/vpDisplay.h>
60 #include <visp/vpDisplayX.h>
61 
62 //debug / exception
63 #include <visp/vpDebug.h>
64 #include <visp/vpDisplayException.h>
65 
66 // math
67 #include <visp/vpMath.h>
68 
80  int x,
81  int y,
82  const char *title ) : vpDisplay()
83 {
84  x_color = NULL;
85  init ( I, x, y, title ) ;
86 }
87 
88 
89 
99  int x,
100  int y,
101  const char *title )
102 {
103  x_color = NULL;
104  title = NULL ;
105  init ( I, x, y, title ) ;
106 }
107 
130 vpDisplayX::vpDisplayX ( int x, int y, const char *title )
131 {
132  windowXPosition = x ;
133  windowYPosition = y ;
134 
135  this->x_color = NULL;
136  this->title = NULL ;
137 
138  if ( title != NULL )
139  {
140  this->title = new char[strlen ( title ) + 1] ; // Modif Fabien le 19/04/02
141  strcpy ( this->title, title ) ;
142  }
143 
144  ximage_data_init = false;
145 }
146 
167 {
168  x_color = NULL;
170 
171  title = NULL ;
172  title = new char[1] ;
173  strcpy ( title,"" ) ;
174 
175  displayHasBeenInitialized = false ;
176  ximage_data_init = false;
177 }
178 
183 {
184  closeDisplay() ;
185 }
186 
195 void
196 vpDisplayX::init ( vpImage<unsigned char> &I, int x, int y, const char *title )
197 {
198 
199  if (x_color == NULL) {
200  // id_unknown = number of predefined colors
201  x_color= new unsigned long [vpColor::id_unknown];
202  }
203 
204  XSizeHints hints;
205  windowXPosition = x ;
206  windowYPosition = y ;
207  {
208  if ( this->title != NULL )
209  {
210  // vpTRACE(" ") ;
211  delete [] this->title ;
212  this->title = NULL ;
213  }
214 
215  if ( title != NULL )
216  {
217  this->title = new char[strlen ( title ) + 1] ;
218  strcpy ( this->title, title ) ;
219  }
220  }
221 
222  // Positionnement de la fenetre dans l'�cran.
223  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
224  {
225  hints.flags = 0;
226  }
227  else
228  {
229  hints.flags = USPosition;
230  hints.x = windowXPosition;
231  hints.y = windowYPosition;
232  }
233 
234 
235  // setup X11 --------------------------------------------------
236  width = I.getWidth();
237  height = I.getHeight();
238  display = XOpenDisplay ( NULL );
239  if ( display == NULL )
240  {
241  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
243  "Can't connect display on server." ) ) ;
244  }
245 
246  screen = DefaultScreen ( display );
247  lut = DefaultColormap ( display, screen );
248  screen_depth = (unsigned int)DefaultDepth ( display, screen );
249 
250  if ( ( window =
251  XCreateSimpleWindow ( display, RootWindow ( display, screen ),
253  BlackPixel ( display, screen ),
254  WhitePixel ( display, screen ) ) ) == 0 )
255  {
256  vpERROR_TRACE ( "Can't create window." );
258  "Can't create window." ) ) ;
259  }
260 
261  //
262  // Create color table for 8 and 16 bits screen
263  //
264  if ( screen_depth == 8 )
265  {
266  lut = XCreateColormap ( display, window,
267  DefaultVisual ( display, screen ), AllocAll ) ;
268  xcolor.flags = DoRed | DoGreen | DoBlue ;
269 
270  for ( unsigned int i = 0 ; i < 256 ; i++ )
271  {
272  xcolor.pixel = i ;
273  xcolor.red = 256 * i;
274  xcolor.green = 256 * i;
275  xcolor.blue = 256 * i;
276  XStoreColor ( display, lut, &xcolor );
277  }
278 
279  XSetWindowColormap ( display, window, lut ) ;
280  XInstallColormap ( display, lut ) ;
281  }
282 
283  else if ( screen_depth == 16 )
284  {
285  for ( unsigned int i = 0; i < 256; i ++ )
286  {
287  xcolor.pad = 0;
288  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
289  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
290  {
291  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
293  "Can't allocate 256 colors." ) ) ;
294  }
295  colortable[i] = xcolor.pixel;
296  }
297 
298  XSetWindowColormap ( display, window, lut ) ;
299  XInstallColormap ( display, lut ) ;
300 
301  }
302 
303  //
304  // Create colors for overlay
305  //
306  switch ( screen_depth )
307  {
308  case 8:
309  // Color BLACK and WHITE are set properly by default.
310 
311  // Color LIGHT GRAY.
312  x_color[vpColor::id_lightGray] = 254;
313  xcolor.pixel = x_color[vpColor::id_lightGray] ;
314  xcolor.red = 256 * 192;
315  xcolor.green = 256 * 192;
316  xcolor.blue = 256 * 192;
317  XStoreColor ( display, lut, &xcolor );
318 
319  // Color GRAY.
320  x_color[vpColor::id_gray] = 253;
321  xcolor.pixel = x_color[vpColor::id_gray] ;
322  xcolor.red = 256 * 128;
323  xcolor.green = 256 * 128;
324  xcolor.blue = 256 * 128;
325  XStoreColor ( display, lut, &xcolor );
326 
327  // Color DARK GRAY.
328  x_color[vpColor::id_darkGray] = 252;
329  xcolor.pixel = x_color[vpColor::id_darkGray] ;
330  xcolor.red = 256 * 64;
331  xcolor.green = 256 * 64;
332  xcolor.blue = 256 * 64;
333  XStoreColor ( display, lut, &xcolor );
334 
335  // Color LIGHT RED.
336  x_color[vpColor::id_lightRed] = 251;
337  xcolor.pixel = x_color[vpColor::id_lightRed] ;
338  xcolor.red = 256 * 255;
339  xcolor.green = 256 * 140;
340  xcolor.blue = 256 * 140;
341  XStoreColor ( display, lut, &xcolor );
342 
343  // Color RED.
344  x_color[vpColor::id_red] = 250;
345  xcolor.pixel = x_color[vpColor::id_red] ;
346  xcolor.red = 256 * 255;
347  xcolor.green = 0;
348  xcolor.blue = 0;
349  XStoreColor ( display, lut, &xcolor );
350 
351  // Color DARK RED.
352  x_color[vpColor::id_darkRed] = 249;
353  xcolor.pixel = x_color[vpColor::id_darkRed] ;
354  xcolor.red = 256 * 128;
355  xcolor.green = 0;
356  xcolor.blue = 0;
357  XStoreColor ( display, lut, &xcolor );
358 
359  // Color LIGHT GREEN.
360  x_color[vpColor::id_lightGreen] = 248;
361  xcolor.pixel = x_color[vpColor::id_lightGreen] ;
362  xcolor.red = 256 * 140;
363  xcolor.green = 256 * 255;
364  xcolor.blue = 256 * 140;
365  XStoreColor ( display, lut, &xcolor );
366 
367  // Color GREEN.
368  x_color[vpColor::id_green] = 247;
369  xcolor.pixel = x_color[vpColor::id_green];
370  xcolor.red = 0;
371  xcolor.green = 256 * 255;
372  xcolor.blue = 0;
373  XStoreColor ( display, lut, &xcolor );
374 
375  // Color DARK GREEN.
376  x_color[vpColor::id_darkGreen] = 246;
377  xcolor.pixel = x_color[vpColor::id_darkGreen] ;
378  xcolor.red = 0;
379  xcolor.green = 256 * 128;
380  xcolor.blue = 0;
381  XStoreColor ( display, lut, &xcolor );
382 
383  // Color LIGHT BLUE.
384  x_color[vpColor::id_lightBlue] = 245;
385  xcolor.pixel = x_color[vpColor::id_lightBlue] ;
386  xcolor.red = 256 * 140;
387  xcolor.green = 256 * 140;
388  xcolor.blue = 256 * 255;
389  XStoreColor ( display, lut, &xcolor );
390 
391  // Color BLUE.
392  x_color[vpColor::id_blue] = 244;
393  xcolor.pixel = x_color[vpColor::id_blue];
394  xcolor.red = 0;
395  xcolor.green = 0;
396  xcolor.blue = 256 * 255;
397  XStoreColor ( display, lut, &xcolor );
398 
399  // Color DARK BLUE.
400  x_color[vpColor::id_darkBlue] = 243;
401  xcolor.pixel = x_color[vpColor::id_darkBlue] ;
402  xcolor.red = 0;
403  xcolor.green = 0;
404  xcolor.blue = 256 * 128;
405  XStoreColor ( display, lut, &xcolor );
406 
407  // Color YELLOW.
408  x_color[vpColor::id_yellow] = 242;
409  xcolor.pixel = x_color[vpColor::id_yellow];
410  xcolor.red = 256 * 255;
411  xcolor.green = 256 * 255;
412  xcolor.blue = 0;
413  XStoreColor ( display, lut, &xcolor );
414 
415  // Color ORANGE.
416  x_color[vpColor::id_orange] = 241;
417  xcolor.pixel = x_color[vpColor::id_orange];
418  xcolor.red = 256 * 255;
419  xcolor.green = 256 * 165;
420  xcolor.blue = 0;
421  XStoreColor ( display, lut, &xcolor );
422 
423  // Color CYAN.
424  x_color[vpColor::id_cyan] = 240;
425  xcolor.pixel = x_color[vpColor::id_cyan];
426  xcolor.red = 0;
427  xcolor.green = 256 * 255;
428  xcolor.blue = 256 * 255;
429  XStoreColor ( display, lut, &xcolor );
430 
431  // Color PURPLE.
432  x_color[vpColor::id_purple] = 239;
433  xcolor.pixel = x_color[vpColor::id_purple];
434  xcolor.red = 256 * 128;
435  xcolor.green = 0;
436  xcolor.blue = 256 * 128;
437  XStoreColor ( display, lut, &xcolor );
438 
439  break;
440 
441  case 16:
442  case 24:
443  {
444  xcolor.flags = DoRed | DoGreen | DoBlue ;
445 
446  // Couleur BLACK.
447  xcolor.pad = 0;
448  xcolor.red = 0;
449  xcolor.green = 0;
450  xcolor.blue = 0;
451  XAllocColor ( display, lut, &xcolor );
452  x_color[vpColor::id_black] = xcolor.pixel;
453 
454  // Couleur WHITE.
455  xcolor.pad = 0;
456  xcolor.red = 256* 255;
457  xcolor.green = 256* 255;
458  xcolor.blue = 256* 255;
459  XAllocColor ( display, lut, &xcolor );
460  x_color[vpColor::id_white] = xcolor.pixel;
461 
462  // Couleur LIGHT GRAY.
463  xcolor.pad = 0;
464  xcolor.red = 256 * 192;
465  xcolor.green = 256 * 192;
466  xcolor.blue = 256 * 192;
467  XAllocColor ( display, lut, &xcolor );
468  x_color[vpColor::id_lightGray] = xcolor.pixel;
469 
470  // Couleur GRAY.
471  xcolor.pad = 0;
472  xcolor.red = 256 * 128;
473  xcolor.green = 256 * 128;
474  xcolor.blue = 256 * 128;
475  XAllocColor ( display, lut, &xcolor );
476  x_color[vpColor::id_gray] = xcolor.pixel;
477 
478  // Couleur DARK GRAY.
479  xcolor.pad = 0;
480  xcolor.red = 256 * 64;
481  xcolor.green = 256 * 64;
482  xcolor.blue = 256 * 64;
483  XAllocColor ( display, lut, &xcolor );
484  x_color[vpColor::id_darkGray] = xcolor.pixel;
485 
486  // Couleur LIGHT RED.
487  xcolor.pad = 0;
488  xcolor.red = 256 * 255;
489  xcolor.green = 256 * 140;
490  xcolor.blue = 256 * 140;
491  XAllocColor ( display, lut, &xcolor );
492  x_color[vpColor::id_lightRed] = xcolor.pixel;
493 
494  // Couleur RED.
495  xcolor.pad = 0;
496  xcolor.red = 256* 255;
497  xcolor.green = 0;
498  xcolor.blue = 0;
499  XAllocColor ( display, lut, &xcolor );
500  x_color[vpColor::id_red] = xcolor.pixel;
501 
502  // Couleur DARK RED.
503  xcolor.pad = 0;
504  xcolor.red = 256* 128;
505  xcolor.green = 0;
506  xcolor.blue = 0;
507  XAllocColor ( display, lut, &xcolor );
508  x_color[vpColor::id_darkRed] = xcolor.pixel;
509 
510  // Couleur LIGHT GREEN.
511  xcolor.pad = 0;
512  xcolor.red = 256 * 140;
513  xcolor.green = 256 * 255;
514  xcolor.blue = 256 * 140;
515  XAllocColor ( display, lut, &xcolor );
516  x_color[vpColor::id_lightGreen] = xcolor.pixel;
517 
518  // Couleur GREEN.
519  xcolor.pad = 0;
520  xcolor.red = 0;
521  xcolor.green = 256*255;
522  xcolor.blue = 0;
523  XAllocColor ( display, lut, &xcolor );
524  x_color[vpColor::id_green] = xcolor.pixel;
525 
526  // Couleur DARK GREEN.
527  xcolor.pad = 0;
528  xcolor.red = 0;
529  xcolor.green = 256* 128;
530  xcolor.blue = 0;
531  XAllocColor ( display, lut, &xcolor );
532  x_color[vpColor::id_darkGreen] = xcolor.pixel;
533 
534  // Couleur LIGHT Blue.
535  xcolor.pad = 0;
536  xcolor.red = 256 * 140;
537  xcolor.green = 256 * 140;
538  xcolor.blue = 256 * 255;
539  XAllocColor ( display, lut, &xcolor );
540  x_color[vpColor::id_lightBlue] = xcolor.pixel;
541 
542  // Couleur BLUE.
543  xcolor.pad = 0;
544  xcolor.red = 0;
545  xcolor.green = 0;
546  xcolor.blue = 256* 255;
547  XAllocColor ( display, lut, &xcolor );
548  x_color[vpColor::id_blue] = xcolor.pixel;
549 
550  // Couleur DARK BLUE.
551  xcolor.pad = 0;
552  xcolor.red = 0;
553  xcolor.green = 0;
554  xcolor.blue = 256* 128;
555  XAllocColor ( display, lut, &xcolor );
556  x_color[vpColor::id_darkBlue] = xcolor.pixel;
557 
558  // Couleur YELLOW.
559  xcolor.pad = 0;
560  xcolor.red = 256 * 255;
561  xcolor.green = 256 * 255;
562  xcolor.blue = 0;
563  XAllocColor ( display, lut, &xcolor );
564  x_color[vpColor::id_yellow] = xcolor.pixel;
565 
566  // Couleur ORANGE.
567  xcolor.pad = 0;
568  xcolor.red = 256 * 255;
569  xcolor.green = 256 * 165;
570  xcolor.blue = 0;
571  XAllocColor ( display, lut, &xcolor );
572  x_color[vpColor::id_orange] = xcolor.pixel;
573 
574  // Couleur CYAN.
575  xcolor.pad = 0;
576  xcolor.red = 0;
577  xcolor.green = 256 * 255;
578  xcolor.blue = 256 * 255;
579  XAllocColor ( display, lut, &xcolor );
580  x_color[vpColor::id_cyan] = xcolor.pixel;
581 
582  // Couleur PURPLE.
583  xcolor.pad = 0;
584  xcolor.red = 256 * 128;
585  xcolor.green = 0;
586  xcolor.blue = 256 * 128;
587  XAllocColor ( display, lut, &xcolor );
588  x_color[vpColor::id_purple] = xcolor.pixel;
589  break;
590  }
591  }
592 
593  XSetStandardProperties ( display, window, title, title, None, 0, 0, &hints );
594  XMapWindow ( display, window ) ;
595  // Selection des evenements.
596  XSelectInput ( display, window,
597  ExposureMask |
598  ButtonPressMask | ButtonReleaseMask |
599  KeyPressMask | KeyReleaseMask |
600  StructureNotifyMask |
601  PointerMotionMask);
602 
603  // graphic context creation
604  values.plane_mask = AllPlanes;
605  values.fill_style = FillSolid;
606  values.foreground = WhitePixel ( display, screen );
607  values.background = BlackPixel ( display, screen );
608  context = XCreateGC ( display, window,
609  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
610  &values );
611 
612  if ( context == NULL )
613  {
614  vpERROR_TRACE ( "Can't create graphics context." );
616  "Can't create graphics context" ) ) ;
617 
618  }
619 
620  // Pixmap creation.
621  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
622 
623  do
624  XNextEvent ( display, &event );
625  while ( event.xany.type != Expose );
626 
627  {
628  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
629  screen_depth, ZPixmap, 0, NULL,
630  I.getWidth() , I.getHeight(), XBitmapPad ( display ), 0 );
631 
632  Ximage->data = ( char * ) malloc ( I.getWidth() * I.getHeight() * (unsigned int)Ximage->bits_per_pixel / 8 );
633  ximage_data_init = true;
634 
635  }
637  setTitle ( title ) ;
638  XSync ( display, 1 );
639 
640  I.display = this ;
641 }
642 
652 void
653 vpDisplayX::init ( vpImage<vpRGBa> &I, int x, int y, const char *title )
654 {
655 
656  XSizeHints hints;
657  windowXPosition = x ;
658  windowYPosition = y ;
659 
660  if (x_color == NULL) {
661  // id_unknown = number of predefined colors
662  x_color= new unsigned long [vpColor::id_unknown];
663  }
664 
665  {
666  if ( this->title != NULL )
667  {
668  delete [] this->title ;
669  this->title = NULL ;
670  }
671 
672  if ( title != NULL )
673  {
674  this->title = new char[strlen ( title ) + 1] ; // Modif Fabien le 19/04/02
675  strcpy ( this->title, title ) ;
676  }
677  }
678 
679  // Positionnement de la fenetre dans l'�cran.
680  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
681  {
682  hints.flags = 0;
683  }
684  else
685  {
686  hints.flags = USPosition;
687  hints.x = windowXPosition;
688  hints.y = windowYPosition;
689  }
690 
691 
692  // setup X11 --------------------------------------------------
693  width = I.getWidth();
694  height = I.getHeight();
695 
696  if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
697  {
698  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
700  "Can't connect display on server." ) ) ;
701  }
702 
703  screen = DefaultScreen ( display );
704  lut = DefaultColormap ( display, screen );
705  screen_depth = (unsigned int)DefaultDepth ( display, screen );
706 
707  vpDEBUG_TRACE ( 1, "Screen depth: %d\n", screen_depth );
708 
709  if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
711  width, height, 1,
712  BlackPixel ( display, screen ),
713  WhitePixel ( display, screen ) ) ) == 0 )
714  {
715  vpERROR_TRACE ( "Can't create window." );
717  "Can't create window." ) ) ;
718  }
719 
720  //
721  // Create color table for 8 and 16 bits screen
722  //
723  if ( screen_depth == 8 )
724  {
725  lut = XCreateColormap ( display, window,
726  DefaultVisual ( display, screen ), AllocAll ) ;
727  xcolor.flags = DoRed | DoGreen | DoBlue ;
728 
729  for ( unsigned int i = 0 ; i < 256 ; i++ )
730  {
731  xcolor.pixel = i ;
732  xcolor.red = 256 * i;
733  xcolor.green = 256 * i;
734  xcolor.blue = 256 * i;
735  XStoreColor ( display, lut, &xcolor );
736  }
737 
738  XSetWindowColormap ( display, window, lut ) ;
739  XInstallColormap ( display, lut ) ;
740  }
741 
742  else if ( screen_depth == 16 )
743  {
744  for ( unsigned int i = 0; i < 256; i ++ )
745  {
746  xcolor.pad = 0;
747  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
748  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
749  {
750  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
752  "Can't allocate 256 colors." ) ) ;
753  }
754  colortable[i] = xcolor.pixel;
755  }
756 
757  XSetWindowColormap ( display, window, lut ) ;
758  XInstallColormap ( display, lut ) ;
759 
760  }
761 
762 
763  //
764  // Create colors for overlay
765  //
766  switch ( screen_depth )
767  {
768 
769  case 8:
770  // Color BLACK and WHITE are set properly.
771 
772  // Color LIGHT GRAY.
773  x_color[vpColor::id_lightGray] = 254;
774  xcolor.pixel = x_color[vpColor::id_lightGray] ;
775  xcolor.red = 256 * 192;
776  xcolor.green = 256 * 192;
777  xcolor.blue = 256 * 192;
778  XStoreColor ( display, lut, &xcolor );
779 
780  // Color GRAY.
781  x_color[vpColor::id_gray] = 253;
782  xcolor.pixel = x_color[vpColor::id_gray] ;
783  xcolor.red = 256 * 128;
784  xcolor.green = 256 * 128;
785  xcolor.blue = 256 * 128;
786  XStoreColor ( display, lut, &xcolor );
787 
788  // Color DARK GRAY.
789  x_color[vpColor::id_darkGray] = 252;
790  xcolor.pixel = x_color[vpColor::id_darkGray] ;
791  xcolor.red = 256 * 64;
792  xcolor.green = 256 * 64;
793  xcolor.blue = 256 * 64;
794  XStoreColor ( display, lut, &xcolor );
795 
796  // Color LIGHT RED.
797  x_color[vpColor::id_lightRed] = 251;
798  xcolor.pixel = x_color[vpColor::id_lightRed] ;
799  xcolor.red = 256 * 255;
800  xcolor.green = 256 * 140;
801  xcolor.blue = 256 * 140;
802  XStoreColor ( display, lut, &xcolor );
803 
804  // Color RED.
805  x_color[vpColor::id_red] = 250;
806  xcolor.pixel = x_color[vpColor::id_red] ;
807  xcolor.red = 256 * 255;
808  xcolor.green = 0;
809  xcolor.blue = 0;
810  XStoreColor ( display, lut, &xcolor );
811 
812  // Color DARK RED.
813  x_color[vpColor::id_darkRed] = 249;
814  xcolor.pixel = x_color[vpColor::id_darkRed] ;
815  xcolor.red = 256 * 128;
816  xcolor.green = 0;
817  xcolor.blue = 0;
818  XStoreColor ( display, lut, &xcolor );
819 
820  // Color LIGHT GREEN.
821  x_color[vpColor::id_lightGreen] = 248;
822  xcolor.pixel = x_color[vpColor::id_lightGreen] ;
823  xcolor.red = 256 * 140;
824  xcolor.green = 256 * 255;
825  xcolor.blue = 256 * 140;
826  XStoreColor ( display, lut, &xcolor );
827 
828  // Color GREEN.
829  x_color[vpColor::id_green] = 247;
830  xcolor.pixel = x_color[vpColor::id_green];
831  xcolor.red = 0;
832  xcolor.green = 256 * 255;
833  xcolor.blue = 0;
834  XStoreColor ( display, lut, &xcolor );
835 
836  // Color DARK GREEN.
837  x_color[vpColor::id_darkGreen] = 246;
838  xcolor.pixel = x_color[vpColor::id_darkGreen] ;
839  xcolor.red = 0;
840  xcolor.green = 256 * 128;
841  xcolor.blue = 0;
842  XStoreColor ( display, lut, &xcolor );
843 
844  // Color LIGHT BLUE.
845  x_color[vpColor::id_lightBlue] = 245;
846  xcolor.pixel = x_color[vpColor::id_lightBlue] ;
847  xcolor.red = 256 * 140;
848  xcolor.green = 256 * 140;
849  xcolor.blue = 256 * 255;
850  XStoreColor ( display, lut, &xcolor );
851 
852  // Color BLUE.
853  x_color[vpColor::id_blue] = 244;
854  xcolor.pixel = x_color[vpColor::id_blue];
855  xcolor.red = 0;
856  xcolor.green = 0;
857  xcolor.blue = 256 * 255;
858  XStoreColor ( display, lut, &xcolor );
859 
860  // Color DARK BLUE.
861  x_color[vpColor::id_darkBlue] = 243;
862  xcolor.pixel = x_color[vpColor::id_darkBlue] ;
863  xcolor.red = 0;
864  xcolor.green = 0;
865  xcolor.blue = 256 * 128;
866  XStoreColor ( display, lut, &xcolor );
867 
868  // Color YELLOW.
869  x_color[vpColor::id_yellow] = 242;
870  xcolor.pixel = x_color[vpColor::id_yellow];
871  xcolor.red = 256 * 255;
872  xcolor.green = 256 * 255;
873  xcolor.blue = 0;
874  XStoreColor ( display, lut, &xcolor );
875 
876  // Color ORANGE.
877  x_color[vpColor::id_orange] = 241;
878  xcolor.pixel = x_color[vpColor::id_orange];
879  xcolor.red = 256 * 255;
880  xcolor.green = 256 * 165;
881  xcolor.blue = 0;
882  XStoreColor ( display, lut, &xcolor );
883 
884  // Color CYAN.
885  x_color[vpColor::id_cyan] = 240;
886  xcolor.pixel = x_color[vpColor::id_cyan];
887  xcolor.red = 0;
888  xcolor.green = 256 * 255;
889  xcolor.blue = 256 * 255;
890  XStoreColor ( display, lut, &xcolor );
891 
892  // Color PURPLE.
893  x_color[vpColor::id_purple] = 239;
894  xcolor.pixel = x_color[vpColor::id_purple];
895  xcolor.red = 256 * 128;
896  xcolor.green = 0;
897  xcolor.blue = 256 * 128;
898  XStoreColor ( display, lut, &xcolor );
899 
900  break;
901 
902  case 16:
903  case 24:
904  {
905  xcolor.flags = DoRed | DoGreen | DoBlue ;
906 
907  // Couleur BLACK.
908  xcolor.pad = 0;
909  xcolor.red = 0;
910  xcolor.green = 0;
911  xcolor.blue = 0;
912  XAllocColor ( display, lut, &xcolor );
913  x_color[vpColor::id_black] = xcolor.pixel;
914 
915  // Couleur WHITE.
916  xcolor.pad = 0;
917  xcolor.red = 256* 255;
918  xcolor.green = 256* 255;
919  xcolor.blue = 256* 255;
920  XAllocColor ( display, lut, &xcolor );
921  x_color[vpColor::id_white] = xcolor.pixel;
922 
923  // Couleur LIGHT GRAY.
924  xcolor.pad = 0;
925  xcolor.red = 256 * 192;
926  xcolor.green = 256 * 192;
927  xcolor.blue = 256 * 192;
928  XAllocColor ( display, lut, &xcolor );
929  x_color[vpColor::id_lightGray] = xcolor.pixel;
930 
931  // Couleur GRAY.
932  xcolor.pad = 0;
933  xcolor.red = 256 * 128;
934  xcolor.green = 256 * 128;
935  xcolor.blue = 256 * 128;
936  XAllocColor ( display, lut, &xcolor );
937  x_color[vpColor::id_gray] = xcolor.pixel;
938 
939  // Couleur DARK GRAY.
940  xcolor.pad = 0;
941  xcolor.red = 256 * 64;
942  xcolor.green = 256 * 64;
943  xcolor.blue = 256 * 64;
944  XAllocColor ( display, lut, &xcolor );
945  x_color[vpColor::id_darkGray] = xcolor.pixel;
946 
947  // Couleur LIGHT RED.
948  xcolor.pad = 0;
949  xcolor.red = 256 * 255;
950  xcolor.green = 256 * 140;
951  xcolor.blue = 256 * 140;
952  XAllocColor ( display, lut, &xcolor );
953  x_color[vpColor::id_lightRed] = xcolor.pixel;
954 
955  // Couleur RED.
956  xcolor.pad = 0;
957  xcolor.red = 256* 255;
958  xcolor.green = 0;
959  xcolor.blue = 0;
960  XAllocColor ( display, lut, &xcolor );
961  x_color[vpColor::id_red] = xcolor.pixel;
962 
963  // Couleur DARK RED.
964  xcolor.pad = 0;
965  xcolor.red = 256* 128;
966  xcolor.green = 0;
967  xcolor.blue = 0;
968  XAllocColor ( display, lut, &xcolor );
969  x_color[vpColor::id_darkRed] = xcolor.pixel;
970 
971  // Couleur LIGHT GREEN.
972  xcolor.pad = 0;
973  xcolor.red = 256 * 140;
974  xcolor.green = 256 * 255;
975  xcolor.blue = 256 * 140;
976  XAllocColor ( display, lut, &xcolor );
977  x_color[vpColor::id_lightGreen] = xcolor.pixel;
978 
979  // Couleur GREEN.
980  xcolor.pad = 0;
981  xcolor.red = 0;
982  xcolor.green = 256*255;
983  xcolor.blue = 0;
984  XAllocColor ( display, lut, &xcolor );
985  x_color[vpColor::id_green] = xcolor.pixel;
986 
987  // Couleur DARK GREEN.
988  xcolor.pad = 0;
989  xcolor.red = 0;
990  xcolor.green = 256* 128;
991  xcolor.blue = 0;
992  XAllocColor ( display, lut, &xcolor );
993  x_color[vpColor::id_darkGreen] = xcolor.pixel;
994 
995  // Couleur LIGHT Blue.
996  xcolor.pad = 0;
997  xcolor.red = 256 * 140;
998  xcolor.green = 256 * 140;
999  xcolor.blue = 256 * 255;
1000  XAllocColor ( display, lut, &xcolor );
1001  x_color[vpColor::id_lightBlue] = xcolor.pixel;
1002 
1003  // Couleur BLUE.
1004  xcolor.pad = 0;
1005  xcolor.red = 0;
1006  xcolor.green = 0;
1007  xcolor.blue = 256* 255;
1008  XAllocColor ( display, lut, &xcolor );
1009  x_color[vpColor::id_blue] = xcolor.pixel;
1010 
1011  // Couleur DARK BLUE.
1012  xcolor.pad = 0;
1013  xcolor.red = 0;
1014  xcolor.green = 0;
1015  xcolor.blue = 256* 128;
1016  XAllocColor ( display, lut, &xcolor );
1017  x_color[vpColor::id_darkBlue] = xcolor.pixel;
1018 
1019  // Couleur YELLOW.
1020  xcolor.pad = 0;
1021  xcolor.red = 256 * 255;
1022  xcolor.green = 256 * 255;
1023  xcolor.blue = 0;
1024  XAllocColor ( display, lut, &xcolor );
1025  x_color[vpColor::id_yellow] = xcolor.pixel;
1026 
1027  // Couleur ORANGE.
1028  xcolor.pad = 0;
1029  xcolor.red = 256 * 255;
1030  xcolor.green = 256 * 165;
1031  xcolor.blue = 0;
1032  XAllocColor ( display, lut, &xcolor );
1033  x_color[vpColor::id_orange] = xcolor.pixel;
1034 
1035  // Couleur CYAN.
1036  xcolor.pad = 0;
1037  xcolor.red = 0;
1038  xcolor.green = 256 * 255;
1039  xcolor.blue = 256 * 255;
1040  XAllocColor ( display, lut, &xcolor );
1041  x_color[vpColor::id_cyan] = xcolor.pixel;
1042 
1043  // Couleur PURPLE.
1044  xcolor.pad = 0;
1045  xcolor.red = 256 * 128;
1046  xcolor.green = 0;
1047  xcolor.blue = 256 * 128;
1048  XAllocColor ( display, lut, &xcolor );
1049  x_color[vpColor::id_purple] = xcolor.pixel;
1050  break;
1051  }
1052  }
1053 
1054  XSetStandardProperties ( display, window, title, title, None, 0, 0, &hints );
1055  XMapWindow ( display, window ) ;
1056  // Selection des evenements.
1057  XSelectInput ( display, window,
1058  ExposureMask |
1059  ButtonPressMask | ButtonReleaseMask |
1060  KeyPressMask | KeyReleaseMask |
1061  StructureNotifyMask |
1062  PointerMotionMask);
1063 
1064  // Creation du contexte graphique
1065  values.plane_mask = AllPlanes;
1066  values.fill_style = FillSolid;
1067  values.foreground = WhitePixel ( display, screen );
1068  values.background = BlackPixel ( display, screen );
1069  context = XCreateGC ( display, window,
1070  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1071  &values );
1072 
1073  if ( context == NULL )
1074  {
1075  vpERROR_TRACE ( "Can't create graphics context." );
1077  "Can't create graphics context" ) ) ;
1078  }
1079 
1080  // Pixmap creation.
1081  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1082 
1083  do
1084  XNextEvent ( display, &event );
1085  while ( event.xany.type != Expose );
1086 
1087 
1088  {
1089  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1090  screen_depth, ZPixmap, 0, NULL,
1091  I.getWidth() , I.getHeight(), XBitmapPad ( display ), 0 );
1092 
1093 
1094  Ximage->data = ( char * ) malloc ( I.getWidth() * I.getHeight()
1095  * (unsigned int)Ximage->bits_per_pixel / 8 );
1096  ximage_data_init = true;
1097 
1098  }
1099  displayHasBeenInitialized = true ;
1100 
1101  XSync ( display, true );
1102  setTitle ( title ) ;
1103 
1104  I.display = this ;
1105 }
1106 
1107 
1115 void vpDisplayX::init ( unsigned int width, unsigned int height,
1116  int x, int y, const char *title )
1117 {
1118 
1119  /* setup X11 ------------------------------------------------------------- */
1120  this->width = width;
1121  this->height = height;
1122 
1123  XSizeHints hints;
1124 
1125  windowXPosition = x ;
1126  windowYPosition = y ;
1127  // Positionnement de la fenetre dans l'�cran.
1128  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
1129  {
1130  hints.flags = 0;
1131  }
1132  else
1133  {
1134  hints.flags = USPosition;
1135  hints.x = windowXPosition;
1136  hints.y = windowYPosition;
1137  }
1138 
1139 
1140  {
1141  if ( this->title != NULL )
1142  {
1143  delete [] this->title ;
1144  this->title = NULL ;
1145  }
1146 
1147  if ( title != NULL )
1148  {
1149  this->title = new char[strlen ( title ) + 1] ; // Modif Fabien le 19/04/02
1150  strcpy ( this->title, title ) ;
1151  }
1152  }
1153 
1154 
1155  if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
1156  {
1157  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
1159  "Can't connect display on server." ) ) ;
1160  }
1161 
1162  screen = DefaultScreen ( display );
1163  lut = DefaultColormap ( display, screen );
1164  screen_depth = (unsigned int)DefaultDepth ( display, screen );
1165 
1166  vpTRACE ( "Screen depth: %d\n", screen_depth );
1167 
1168  if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
1170  width, height, 1,
1171  BlackPixel ( display, screen ),
1172  WhitePixel ( display, screen ) ) ) == 0 )
1173  {
1174  vpERROR_TRACE ( "Can't create window." );
1176  "Can't create window." ) ) ;
1177  }
1178 
1179 
1180  //
1181  // Create color table for 8 and 16 bits screen
1182  //
1183  if ( screen_depth == 8 )
1184  {
1185  lut = XCreateColormap ( display, window,
1186  DefaultVisual ( display, screen ), AllocAll ) ;
1187  xcolor.flags = DoRed | DoGreen | DoBlue ;
1188 
1189  for ( unsigned int i = 0 ; i < 256 ; i++ )
1190  {
1191  xcolor.pixel = i ;
1192  xcolor.red = 256 * i;
1193  xcolor.green = 256 * i;
1194  xcolor.blue = 256 * i;
1195  XStoreColor ( display, lut, &xcolor );
1196  }
1197 
1198  XSetWindowColormap ( display, window, lut ) ;
1199  XInstallColormap ( display, lut ) ;
1200  }
1201 
1202  else if ( screen_depth == 16 )
1203  {
1204  for ( unsigned int i = 0; i < 256; i ++ )
1205  {
1206  xcolor.pad = 0;
1207  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1208  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
1209  {
1210  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
1212  "Can't allocate 256 colors." ) ) ;
1213  }
1214  colortable[i] = xcolor.pixel;
1215  }
1216 
1217  XSetWindowColormap ( display, window, lut ) ;
1218  XInstallColormap ( display, lut ) ;
1219 
1220  }
1221 
1222  vpColor pcolor; // predefined colors
1223 
1224  //
1225  // Create colors for overlay
1226  //
1227  switch ( screen_depth )
1228  {
1229 
1230  case 8:
1231  // Color BLACK: default set to 0
1232 
1233  // Color WHITE: default set to 255
1234 
1235  // Color LIGHT GRAY.
1236  pcolor = vpColor::lightGray;
1237  xcolor.pixel = 254 ; // affected to 254
1238  xcolor.red = 256 * pcolor.R;
1239  xcolor.green = 256 * pcolor.G;
1240  xcolor.blue = 256 * pcolor.B;
1241  XStoreColor ( display, lut, &xcolor );
1242 
1243  // Color GRAY.
1244  pcolor = vpColor::gray;
1245  xcolor.pixel = 253 ; // affected to 253
1246  xcolor.red = 256 * pcolor.R;
1247  xcolor.green = 256 * pcolor.G;
1248  xcolor.blue = 256 * pcolor.B;
1249  XStoreColor ( display, lut, &xcolor );
1250 
1251  // Color DARK GRAY.
1252  pcolor = vpColor::darkGray;
1253  xcolor.pixel = 252 ; // affected to 252
1254  xcolor.red = 256 * pcolor.R;
1255  xcolor.green = 256 * pcolor.G;
1256  xcolor.blue = 256 * pcolor.B;
1257  XStoreColor ( display, lut, &xcolor );
1258 
1259  // Color LIGHT RED.
1260  pcolor = vpColor::lightRed;
1261  xcolor.pixel = 251 ; // affected to 251
1262  xcolor.red = 256 * pcolor.R;
1263  xcolor.green = 256 * pcolor.G;
1264  xcolor.blue = 256 * pcolor.B;
1265  XStoreColor ( display, lut, &xcolor );
1266 
1267  // Color RED.
1268  pcolor = vpColor::red;
1269  xcolor.pixel = 250 ; // affected to 250
1270  xcolor.red = 256 * pcolor.R;
1271  xcolor.green = 256 * pcolor.G;
1272  xcolor.blue = 256 * pcolor.B;
1273  XStoreColor ( display, lut, &xcolor );
1274 
1275  // Color DARK RED.
1276  pcolor = vpColor::darkRed;
1277  xcolor.pixel = 249 ; // affected to 249
1278  xcolor.red = 256 * pcolor.R;
1279  xcolor.green = 256 * pcolor.G;
1280  xcolor.blue = 256 * pcolor.B;
1281  XStoreColor ( display, lut, &xcolor );
1282 
1283  // Color LIGHT GREEN.
1284  pcolor = vpColor::lightGreen;
1285  xcolor.pixel = 248 ; // affected to 248
1286  xcolor.red = 256 * pcolor.R;
1287  xcolor.green = 256 * pcolor.G;
1288  xcolor.blue = 256 * pcolor.B;
1289  XStoreColor ( display, lut, &xcolor );
1290 
1291  // Color GREEN.
1292  pcolor = vpColor::green;
1293  xcolor.pixel = 247; // affected to 247
1294  xcolor.red = 256 * pcolor.R;
1295  xcolor.green = 256 * pcolor.G;
1296  xcolor.blue = 256 * pcolor.B;
1297  XStoreColor ( display, lut, &xcolor );
1298 
1299  // Color DARK GREEN.
1300  pcolor = vpColor::darkGreen;
1301  xcolor.pixel = 246 ; // affected to 246
1302  xcolor.red = 256 * pcolor.R;
1303  xcolor.green = 256 * pcolor.G;
1304  xcolor.blue = 256 * pcolor.B;
1305  XStoreColor ( display, lut, &xcolor );
1306 
1307  // Color LIGHT BLUE.
1308  pcolor = vpColor::lightBlue;
1309  xcolor.pixel = 245 ; // affected to 245
1310  xcolor.red = 256 * pcolor.R;
1311  xcolor.green = 256 * pcolor.G;
1312  xcolor.blue = 256 * pcolor.B;
1313  XStoreColor ( display, lut, &xcolor );
1314 
1315  // Color BLUE.
1316  pcolor = vpColor::blue;
1317  xcolor.pixel = 244; // affected to 244
1318  xcolor.red = 256 * pcolor.R;
1319  xcolor.green = 256 * pcolor.G;
1320  xcolor.blue = 256 * pcolor.B;
1321  XStoreColor ( display, lut, &xcolor );
1322 
1323  // Color DARK BLUE.
1324  pcolor = vpColor::darkBlue;
1325  xcolor.pixel = 243 ; // affected to 243
1326  xcolor.red = 256 * pcolor.R;
1327  xcolor.green = 256 * pcolor.G;
1328  xcolor.blue = 256 * pcolor.B;
1329  XStoreColor ( display, lut, &xcolor );
1330 
1331  // Color YELLOW.
1332  pcolor = vpColor::yellow;
1333  xcolor.pixel = 242; // affected to 242
1334  xcolor.red = 256 * pcolor.R;
1335  xcolor.green = 256 * pcolor.G;
1336  xcolor.blue = 256 * pcolor.B;
1337  XStoreColor ( display, lut, &xcolor );
1338 
1339  // Color ORANGE.
1340  pcolor = vpColor::orange;
1341  xcolor.pixel = 241; // affected to 241
1342  xcolor.red = 256 * pcolor.R;
1343  xcolor.green = 256 * pcolor.G;
1344  xcolor.blue = 256 * pcolor.B;
1345  XStoreColor ( display, lut, &xcolor );
1346 
1347  // Color CYAN.
1348  pcolor = vpColor::cyan;
1349  xcolor.pixel = 240; // affected to 240
1350  xcolor.red = 256 * pcolor.R;
1351  xcolor.green = 256 * pcolor.G;
1352  xcolor.blue = 256 * pcolor.B;
1353  XStoreColor ( display, lut, &xcolor );
1354 
1355  // Color PURPLE.
1356  pcolor = vpColor::purple;
1357  xcolor.pixel = 239; // affected to 239
1358  xcolor.red = 256 * pcolor.R;
1359  xcolor.green = 256 * pcolor.G;
1360  xcolor.blue = 256 * pcolor.B;
1361  XStoreColor ( display, lut, &xcolor );
1362 
1363  break;
1364 
1365  case 16:
1366  case 24:
1367  {
1368  xcolor.flags = DoRed | DoGreen | DoBlue ;
1369 
1370  // Couleur BLACK.
1371  pcolor = vpColor::black;
1372  xcolor.pad = 0;
1373  xcolor.red = 256 * pcolor.R;
1374  xcolor.green = 256 * pcolor.G;
1375  xcolor.blue = 256 * pcolor.B;
1376  XAllocColor ( display, lut, &xcolor );
1377  x_color[vpColor::id_black] = xcolor.pixel;
1378 
1379  // Color WHITE.
1380  pcolor = vpColor::white;
1381  xcolor.pad = 0;
1382  xcolor.red = 256 * pcolor.R;
1383  xcolor.green = 256 * pcolor.G;
1384  xcolor.blue = 256 * pcolor.B;
1385  XAllocColor ( display, lut, &xcolor );
1386  x_color[vpColor::id_white] = xcolor.pixel;
1387 
1388  // Color LIGHT GRAY.
1389  pcolor = vpColor::lightGray;
1390  xcolor.pad = 0;
1391  xcolor.red = 256 * pcolor.R;
1392  xcolor.green = 256 * pcolor.G;
1393  xcolor.blue = 256 * pcolor.B;
1394  XAllocColor ( display, lut, &xcolor );
1395  x_color[vpColor::id_lightGray] = xcolor.pixel;
1396 
1397  // Color GRAY.
1398  pcolor = vpColor::gray;
1399  xcolor.pad = 0;
1400  xcolor.red = 256 * pcolor.R;
1401  xcolor.green = 256 * pcolor.G;
1402  xcolor.blue = 256 * pcolor.B;
1403  XAllocColor ( display, lut, &xcolor );
1404  x_color[vpColor::id_gray] = xcolor.pixel;
1405 
1406  // Color DARK GRAY.
1407  pcolor = vpColor::darkGray;
1408  xcolor.pad = 0;
1409  xcolor.red = 256 * pcolor.R;
1410  xcolor.green = 256 * pcolor.G;
1411  xcolor.blue = 256 * pcolor.B;
1412  XAllocColor ( display, lut, &xcolor );
1413  x_color[vpColor::id_darkGray] = xcolor.pixel;
1414 
1415  // Color LIGHT RED.
1416  pcolor = vpColor::lightRed;
1417  xcolor.pad = 0;
1418  xcolor.red = 256 * pcolor.R;
1419  xcolor.green = 256 * pcolor.G;
1420  xcolor.blue = 256 * pcolor.B;
1421  XAllocColor ( display, lut, &xcolor );
1422  x_color[vpColor::id_lightRed] = xcolor.pixel;
1423 
1424  // Color RED.
1425  pcolor = vpColor::red;
1426  xcolor.pad = 0;
1427  xcolor.red = 256 * pcolor.R;
1428  xcolor.green = 256 * pcolor.G;
1429  xcolor.blue = 256 * pcolor.B;
1430  XAllocColor ( display, lut, &xcolor );
1431  x_color[vpColor::id_red] = xcolor.pixel;
1432 
1433  // Color DARK RED.
1434  pcolor = vpColor::darkRed;
1435  xcolor.pad = 0;
1436  xcolor.red = 256 * pcolor.R;
1437  xcolor.green = 256 * pcolor.G;
1438  xcolor.blue = 256 * pcolor.B;
1439  XAllocColor ( display, lut, &xcolor );
1440  x_color[vpColor::id_darkRed] = xcolor.pixel;
1441 
1442  // Color LIGHT GREEN.
1443  pcolor = vpColor::lightGreen;
1444  xcolor.pad = 0;
1445  xcolor.red = 256 * pcolor.R;
1446  xcolor.green = 256 * pcolor.G;
1447  xcolor.blue = 256 * pcolor.B;
1448  XAllocColor ( display, lut, &xcolor );
1449  x_color[vpColor::id_lightGreen] = xcolor.pixel;
1450 
1451  // Color GREEN.
1452  pcolor = vpColor::green;
1453  xcolor.pad = 0;
1454  xcolor.red = 256 * pcolor.R;
1455  xcolor.green = 256 * pcolor.G;
1456  xcolor.blue = 256 * pcolor.B;
1457  XAllocColor ( display, lut, &xcolor );
1458  x_color[vpColor::id_green] = xcolor.pixel;
1459 
1460  // Color DARK GREEN.
1461  pcolor = vpColor::darkGreen;
1462  xcolor.pad = 0;
1463  xcolor.red = 256 * pcolor.R;
1464  xcolor.green = 256 * pcolor.G;
1465  xcolor.blue = 256 * pcolor.B;
1466  XAllocColor ( display, lut, &xcolor );
1467  x_color[vpColor::id_darkGreen] = xcolor.pixel;
1468 
1469  // Color LIGHT BLUE.
1470  pcolor = vpColor::lightBlue;
1471  xcolor.pad = 0;
1472  xcolor.red = 256 * pcolor.R;
1473  xcolor.green = 256 * pcolor.G;
1474  xcolor.blue = 256 * pcolor.B;
1475  XAllocColor ( display, lut, &xcolor );
1476  x_color[vpColor::id_lightBlue] = xcolor.pixel;
1477 
1478  // Color BLUE.
1479  pcolor = vpColor::blue;
1480  xcolor.pad = 0;
1481  xcolor.red = 256 * pcolor.R;
1482  xcolor.green = 256 * pcolor.G;
1483  xcolor.blue = 256 * pcolor.B;
1484  XAllocColor ( display, lut, &xcolor );
1485  x_color[vpColor::id_blue] = xcolor.pixel;
1486 
1487  // Color DARK BLUE.
1488  pcolor = vpColor::darkBlue;
1489  xcolor.pad = 0;
1490  xcolor.red = 256 * pcolor.R;
1491  xcolor.green = 256 * pcolor.G;
1492  xcolor.blue = 256 * pcolor.B;
1493  XAllocColor ( display, lut, &xcolor );
1494  x_color[vpColor::id_darkBlue] = xcolor.pixel;
1495 
1496  // Color YELLOW.
1497  pcolor = vpColor::yellow;
1498  xcolor.pad = 0;
1499  xcolor.red = 256 * pcolor.R;
1500  xcolor.green = 256 * pcolor.G;
1501  xcolor.blue = 256 * pcolor.B;
1502  XAllocColor ( display, lut, &xcolor );
1503  x_color[vpColor::id_yellow] = xcolor.pixel;
1504 
1505  // Color ORANGE.
1506  pcolor = vpColor::orange;
1507  xcolor.pad = 0;
1508  xcolor.red = 256 * pcolor.R;
1509  xcolor.green = 256 * pcolor.G;
1510  xcolor.blue = 256 * pcolor.B;
1511  XAllocColor ( display, lut, &xcolor );
1512  x_color[vpColor::id_orange] = xcolor.pixel;
1513 
1514  // Color CYAN.
1515  pcolor = vpColor::cyan;
1516  xcolor.pad = 0;
1517  xcolor.red = 256 * pcolor.R;
1518  xcolor.green = 256 * pcolor.G;
1519  xcolor.blue = 256 * pcolor.B;
1520  XAllocColor ( display, lut, &xcolor );
1521  x_color[vpColor::id_cyan] = xcolor.pixel;
1522 
1523  // Color PURPLE.
1524  pcolor = vpColor::purple;
1525  xcolor.pad = 0;
1526  xcolor.red = 256 * pcolor.R;
1527  xcolor.green = 256 * pcolor.G;
1528  xcolor.blue = 256 * pcolor.B;
1529  XAllocColor ( display, lut, &xcolor );
1530  x_color[vpColor::id_purple] = xcolor.pixel;
1531  break;
1532  }
1533  }
1534 
1535 
1536  XSetStandardProperties ( display, window, title, title, None, 0, 0, &hints );
1537  XMapWindow ( display, window ) ;
1538  // Selection des evenements.
1539  XSelectInput ( display, window,
1540  ExposureMask |
1541  ButtonPressMask | ButtonReleaseMask |
1542  KeyPressMask | KeyReleaseMask |
1543  StructureNotifyMask |
1544  PointerMotionMask);
1545 
1546  /* Creation du contexte graphique */
1547  values.plane_mask = AllPlanes;
1548  values.fill_style = FillSolid;
1549  values.foreground = WhitePixel ( display, screen );
1550  values.background = BlackPixel ( display, screen );
1551  context = XCreateGC ( display, window,
1552  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1553  &values );
1554 
1555  if ( context == NULL )
1556  {
1557  vpERROR_TRACE ( "Can't create graphics context." );
1559  "Can't create graphics context" ) ) ;
1560  }
1561 
1562  // Pixmap creation.
1563  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1564 
1565  do
1566  XNextEvent ( display, &event );
1567  while ( event.xany.type != Expose );
1568 
1569  {
1570  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1571  screen_depth, ZPixmap, 0, NULL,
1572  width, height, XBitmapPad ( display ), 0 );
1573 
1574  Ximage->data = ( char * ) malloc ( width * height
1575  * (unsigned int)Ximage->bits_per_pixel / 8 );
1576  ximage_data_init = true;
1577  }
1578  displayHasBeenInitialized = true ;
1579 
1580  XSync ( display, true );
1581  setTitle ( title ) ;
1582 
1583 }
1584 
1599 void vpDisplayX::setFont( const char* font )
1600 {
1602  {
1603  if (font!=NULL)
1604  {
1605  try
1606  {
1607  Font stringfont;
1608  stringfont = XLoadFont (display, font) ; //"-adobe-times-bold-r-normal--18*");
1609  XSetFont (display, context, stringfont);
1610  }
1611  catch(...)
1612  {
1613  vpERROR_TRACE ( "Bad font " ) ;
1615  }
1616  }
1617  }
1618  else
1619  {
1620  vpERROR_TRACE ( "X not initialized " ) ;
1622  "X not initialized" ) ) ;
1623  }
1624 }
1625 
1630 void
1631 vpDisplayX::setTitle ( const char *title )
1632 {
1634  {
1635  XStoreName ( display, window, title );
1636  }
1637  else
1638  {
1639  vpERROR_TRACE ( "X not initialized " ) ;
1641  "X not initialized" ) ) ;
1642  }
1643 }
1644 
1653 void vpDisplayX::setWindowPosition(int winx, int winy)
1654 {
1655  if ( displayHasBeenInitialized ) {
1656  XMoveWindow(display, window, winx, winy);
1657  }
1658  else
1659  {
1660  vpERROR_TRACE ( "X not initialized " ) ;
1662  "X not initialized" ) ) ;
1663  }
1664 }
1665 
1678 {
1679 
1681  {
1682  switch ( screen_depth )
1683  {
1684  case 8:
1685  {
1686  unsigned char *src_8 = NULL;
1687  unsigned char *dst_8 = NULL;
1688  src_8 = ( unsigned char * ) I.bitmap;
1689  dst_8 = ( unsigned char * ) Ximage->data;
1690  // Correction de l'image de facon a liberer les niveaux de gris
1691  // ROUGE, VERT, BLEU, JAUNE
1692  {
1693  unsigned int i = 0;
1694  unsigned int size = width * height;
1695  unsigned char nivGris;
1696  unsigned char nivGrisMax = 255 - vpColor::id_unknown;
1697 
1698  while ( i < size )
1699  {
1700  nivGris = src_8[i] ;
1701  if ( nivGris > nivGrisMax )
1702  dst_8[i] = 255;
1703  else
1704  dst_8[i] = nivGris;
1705  i++ ;
1706  }
1707  }
1708 
1709  // Affichage de l'image dans la Pixmap.
1710  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1711  XSetWindowBackgroundPixmap ( display, window, pixmap );
1712 // XClearWindow ( display, window );
1713 // XSync ( display,1 );
1714  break;
1715  }
1716  case 16:
1717  {
1718  unsigned short *dst_16 = NULL;
1719  dst_16 = ( unsigned short* ) Ximage->data;
1720 
1721  for ( unsigned int i = 0; i < height ; i++ )
1722  {
1723  for ( unsigned int j=0 ; j < width; j++ )
1724  {
1725  * ( dst_16+ ( i*width+j ) ) = ( unsigned short ) colortable[I[i][j]] ;
1726  }
1727  }
1728 
1729  // Affichage de l'image dans la Pixmap.
1730  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1731  XSetWindowBackgroundPixmap ( display, window, pixmap );
1732 // XClearWindow ( display, window );
1733 // XSync ( display,1 );
1734  break;
1735  }
1736 
1737  case 24:
1738  default:
1739  {
1740  unsigned char *dst_32 = NULL;
1741  unsigned int size = width * height ;
1742  dst_32 = ( unsigned char* ) Ximage->data;
1743  unsigned char *bitmap = I.bitmap ;
1744  unsigned char *n = I.bitmap + size;
1745  //for (unsigned int i = 0; i < size; i++) // suppression de l'iterateur i
1746  while ( bitmap < n )
1747  {
1748  unsigned char val = * ( bitmap++ );
1749  * ( dst_32 ++ ) = val; // Composante Rouge.
1750  * ( dst_32 ++ ) = val; // Composante Verte.
1751  * ( dst_32 ++ ) = val; // Composante Bleue.
1752  * ( dst_32 ++ ) = val;
1753  }
1754 
1755  // Affichage de l'image dans la Pixmap.
1756  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1757  XSetWindowBackgroundPixmap ( display, window, pixmap );
1758 // XClearWindow ( display, window );
1759 // XSync ( display,1 );
1760  break;
1761  }
1762  }
1763  }
1764  else
1765  {
1766  vpERROR_TRACE ( "X not initialized " ) ;
1768  "X not initialized" ) ) ;
1769  }
1770 }
1783 {
1784 
1786  {
1787 
1788  switch ( screen_depth )
1789  {
1790  case 24:
1791  case 32:
1792  {
1793  /*
1794  * 32-bit source, 24/32-bit destination
1795  */
1796 
1797  unsigned char *dst_32 = NULL;
1798  dst_32 = ( unsigned char* ) Ximage->data;
1799  vpRGBa* bitmap = I.bitmap;
1800  unsigned int sizeI = I.getWidth() * I.getHeight();
1801 #ifdef BIGENDIAN
1802  // little indian/big indian
1803  for ( unsigned int i = 0; i < sizeI ; i++ )
1804  {
1805  *(dst_32++) = bitmap->A;
1806  *(dst_32++) = bitmap->R;
1807  *(dst_32++) = bitmap->G;
1808  *(dst_32++) = bitmap->B;
1809  bitmap++;
1810  }
1811 #else
1812  for ( unsigned int i = 0; i < sizeI; i++ )
1813  {
1814  *(dst_32++) = bitmap->B;
1815  *(dst_32++) = bitmap->G;
1816  *(dst_32++) = bitmap->R;
1817  *(dst_32++) = bitmap->A;
1818  bitmap++;
1819  }
1820 #endif
1821  // Affichage de l'image dans la Pixmap.
1822  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1823  XSetWindowBackgroundPixmap ( display, window, pixmap );
1824 // XClearWindow ( display, window );
1825 // XSync ( display,1 );
1826  break;
1827 
1828  }
1829  default:
1830  vpERROR_TRACE ( "Unsupported depth (%d bpp) for color display",
1831  screen_depth ) ;
1833  "Unsupported depth for color display" ) ) ;
1834  }
1835  }
1836  else
1837  {
1838  vpERROR_TRACE ( "X not initialized " ) ;
1840  "X not initialized" ) ) ;
1841  }
1842 }
1843 
1855 void vpDisplayX::displayImage ( const unsigned char *I )
1856 {
1857  unsigned char *dst_32 = NULL;
1858 
1860  {
1861 
1862  dst_32 = ( unsigned char* ) Ximage->data;
1863 
1864  for ( unsigned int i = 0; i < width * height; i++ )
1865  {
1866  * ( dst_32 ++ ) = *I; // red component.
1867  * ( dst_32 ++ ) = *I; // green component.
1868  * ( dst_32 ++ ) = *I; // blue component.
1869  * ( dst_32 ++ ) = *I; // luminance component.
1870  I++;
1871  }
1872 
1873  // Affichage de l'image dans la Pixmap.
1874  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1875  XSetWindowBackgroundPixmap ( display, window, pixmap );
1876 // XClearWindow ( display, window );
1877 // XSync ( display,1 );
1878  }
1879  else
1880  {
1881  vpERROR_TRACE ( "X not initialized " ) ;
1883  "X not initialized" ) ) ;
1884  }
1885 }
1886 
1887 
1905 void vpDisplayX::displayImageROI ( const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height )
1906 {
1908  {
1909  switch ( screen_depth )
1910  {
1911  case 8:
1912  {
1913  unsigned char *src_8 = NULL;
1914  unsigned char *dst_8 = NULL;
1915  src_8 = ( unsigned char * ) I.bitmap;
1916  dst_8 = ( unsigned char * ) Ximage->data;
1917  // Correction de l'image de facon a liberer les niveaux de gris
1918  // ROUGE, VERT, BLEU, JAUNE
1919  {
1920  //int size = width * height;
1921  unsigned char nivGris;
1922  unsigned char nivGrisMax = 255 - vpColor::id_unknown;
1923 
1924  //unsigned int iwidth = I.getWidth();
1925  unsigned int iwidth = I.getWidth();
1926 
1927  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1928  dst_8 = dst_8 + (int)(iP.get_i()*this->height+ iP.get_j());
1929 
1930  unsigned int i = 0;
1931  while (i < height)
1932  {
1933  unsigned int j = 0;
1934  while (j < width)
1935  {
1936  nivGris = *(src_8+j);
1937  if ( nivGris > nivGrisMax )
1938  *(dst_8+j) = 255;
1939  else
1940  *(dst_8+j) = nivGris;
1941  j++;
1942  }
1943  src_8 = src_8 + iwidth;
1944  dst_8 = dst_8 + this->height;
1945  i++;
1946  }
1947  }
1948 
1949  // Affichage de l'image dans la Pixmap.
1950  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
1951  XSetWindowBackgroundPixmap ( display, window, pixmap );
1952 // XClearWindow ( display, window );
1953 // XSync ( display,1 );
1954  break;
1955  }
1956  case 16:
1957  {
1958  unsigned short *dst_16 = NULL;
1959  dst_16 = ( unsigned short* ) Ximage->data;
1960  unsigned char *src_8 = NULL;
1961  src_8 = ( unsigned char * ) I.bitmap;
1962 
1963  unsigned int iwidth = I.getWidth();
1964 
1965  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1966  dst_16 = dst_16 + (int)(iP.get_i()*this->height+ iP.get_j());
1967 
1968  unsigned int i = 0;
1969  while (i < height)
1970  {
1971  unsigned int j = 0;
1972  while (j < width)
1973  {
1974  *(dst_16+j) = ( unsigned short ) colortable[*(src_8+j)];
1975  j++;
1976  }
1977  src_8 = src_8 + iwidth;
1978  dst_16 = dst_16 + this->height;
1979  i++;
1980  }
1981 
1982  // Affichage de l'image dans la Pixmap.
1983  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
1984  XSetWindowBackgroundPixmap ( display, window, pixmap );
1985 // XClearWindow ( display, window );
1986 // XSync ( display,1 );
1987  break;
1988  }
1989 
1990  case 24:
1991  default:
1992  {
1993  unsigned char *dst_32 = NULL;
1994  //unsigned int size = width * height ;
1995  dst_32 = ( unsigned char* ) Ximage->data;
1996  unsigned char *src_8 = I.bitmap ;
1997  //unsigned char *n = I.bitmap + size;
1998 
1999  unsigned int iwidth = I.getWidth();
2000 
2001  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
2002  dst_32 = dst_32 + (int)(iP.get_i()*4*this->width+ iP.get_j()*4);
2003 
2004  unsigned int i = 0;
2005  while (i < height)
2006  {
2007  unsigned int j = 0;
2008  while (j < width)
2009  {
2010  unsigned char val = *(src_8+j);
2011  *(dst_32+4*j) = val;
2012  *(dst_32+4*j+1) = val;
2013  *(dst_32+4*j+2) = val;
2014  *(dst_32+4*j+3) = val;
2015  j++;
2016  }
2017  src_8 = src_8 + iwidth;
2018  dst_32 = dst_32 + 4*this->width;
2019  i++;
2020  }
2021 
2022  // Affichage de l'image dans la Pixmap.
2023  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
2024  XSetWindowBackgroundPixmap ( display, window, pixmap );
2025 // XClearWindow ( display, window );
2026 // XSync ( display,1 );
2027  break;
2028  }
2029  }
2030  }
2031  else
2032  {
2033  vpERROR_TRACE ( "X not initialized " ) ;
2035  "X not initialized" ) ) ;
2036  }
2037 }
2038 
2039 
2057 void vpDisplayX::displayImageROI ( const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height )
2058 {
2059 
2061  {
2062 
2063  switch ( screen_depth )
2064  {
2065  case 24:
2066  case 32:
2067  {
2068  /*
2069  * 32-bit source, 24/32-bit destination
2070  */
2071 
2072  unsigned char *dst_32 = NULL;
2073  dst_32 = ( unsigned char* ) Ximage->data;
2074  vpRGBa* src_32 = I.bitmap;
2075  //unsigned int sizeI = I.getWidth() * I.getHeight();
2076 
2077  unsigned int iwidth = I.getWidth();
2078 
2079  src_32 = src_32 + (int)(iP.get_i()*iwidth+ iP.get_j());
2080  dst_32 = dst_32 + (int)(iP.get_i()*4*this->width+ iP.get_j()*4);
2081 
2082  unsigned int i = 0;
2083  while (i < height)
2084  {
2085  unsigned int j = 0;
2086  while (j < width)
2087  {
2088 #ifdef BIGENDIAN
2089  *(dst_32+4*j) = (src_32+j)->A;
2090  *(dst_32+4*j+1) = (src_32+j)->R;
2091  *(dst_32+4*j+2) = (src_32+j)->G;
2092  *(dst_32+4*j+3) = (src_32+j)->B;
2093 #else
2094  *(dst_32+4*j) = (src_32+j)->B;
2095  *(dst_32+4*j+1) = (src_32+j)->G;
2096  *(dst_32+4*j+2) = (src_32+j)->R;
2097  *(dst_32+4*j+3) = (src_32+j)->A;
2098 #endif
2099  j++;
2100  }
2101  src_32 = src_32 + iwidth;
2102  dst_32 = dst_32 + 4*this->width;
2103  i++;
2104  }
2105 
2106  // Affichage de l'image dans la Pixmap.
2107  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
2108  XSetWindowBackgroundPixmap ( display, window, pixmap );
2109 // XClearWindow ( display, window );
2110 // XSync ( display,1 );
2111  break;
2112 
2113  }
2114  default:
2115  vpERROR_TRACE ( "Unsupported depth (%d bpp) for color display",
2116  screen_depth ) ;
2118  "Unsupported depth for color display" ) ) ;
2119  }
2120  }
2121  else
2122  {
2123  vpERROR_TRACE ( "X not initialized " ) ;
2125  "X not initialized" ) ) ;
2126  }
2127 }
2128 
2137 {
2139  {
2140  if ( ximage_data_init == true )
2141  free ( Ximage->data );
2142 
2143  Ximage->data = NULL;
2144  XDestroyImage ( Ximage );
2145 
2146  XFreePixmap ( display, pixmap );
2147 
2148  XFreeGC ( display, context );
2149  XDestroyWindow ( display, window );
2150  XCloseDisplay ( display );
2151 
2152  displayHasBeenInitialized = false;
2153  if ( title != NULL )
2154  {
2155  delete [] title ;
2156  title = NULL ;
2157  }
2158 
2159  if (x_color != NULL) {
2160  delete [] x_color;
2161  x_color = NULL;
2162  }
2163 
2164  }
2165  else
2166  {
2167  if ( title != NULL )
2168  {
2169  delete [] title ;
2170  title = NULL ;
2171  }
2172  }
2173 }
2174 
2175 
2182 {
2184  {
2185  XClearWindow ( display, window );
2186  //XClearArea ( display, window,0,0,100,100,0 );
2187  XFlush ( display );
2188  }
2189  else
2190  {
2191  vpERROR_TRACE ( "X not initialized " ) ;
2193  "X not initialized" ) ) ;
2194  }
2195 }
2196 
2205 void vpDisplayX::flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
2206 {
2208  {
2209  //XClearWindow ( display, window );
2210  XClearArea ( display, window,iP.get_u(),iP.get_v(),width,height,0 );
2211  XFlush ( display );
2212  }
2213  else
2214  {
2215  vpERROR_TRACE ( "X not initialized " ) ;
2217  "X not initialized" ) ) ;
2218  }
2219 }
2220 
2221 
2226 void vpDisplayX::clearDisplay ( const vpColor &color )
2227 {
2229  {
2230 
2231  if (color.id < vpColor::id_unknown)
2232  XSetWindowBackground ( display, window, x_color[color.id] );
2233  else {
2234  xcolor.pad = 0;
2235  xcolor.red = 256 * color.R;
2236  xcolor.green = 256 * color.G;
2237  xcolor.blue = 256 * color.B;
2238  XAllocColor ( display, lut, &xcolor );
2239  XSetForeground ( display, context, xcolor.pixel );
2240  }
2241 
2242  XClearWindow ( display, window );
2243 
2244  XFreePixmap ( display, pixmap );
2245  // Pixmap creation.
2246  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
2247  }
2248  else
2249  {
2250  vpERROR_TRACE ( "X not initialized " ) ;
2252  "X not initialized" ) ) ;
2253  }
2254 }
2255 
2264  const vpImagePoint &ip2,
2265  const vpColor &color,
2266  unsigned int w, unsigned int h,
2267  unsigned int thickness)
2268 {
2270  {
2271  try
2272  {
2273  double a = ip2.get_i() - ip1.get_i() ;
2274  double b = ip2.get_j() - ip1.get_j() ;
2275  double lg = sqrt ( vpMath::sqr ( a ) + vpMath::sqr ( b ) ) ;
2276 
2277  //if ( ( a==0 ) && ( b==0 ) )
2278  if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
2279  {
2280  // DisplayCrossLarge(i1,j1,3,col) ;
2281  }
2282  else
2283  {
2284  a /= lg ;
2285  b /= lg ;
2286 
2287  vpImagePoint ip3;
2288  ip3.set_i(ip2.get_i() - w*a);
2289  ip3.set_j(ip2.get_j() - w*b);
2290 
2291  vpImagePoint ip4;
2292  ip4.set_i( ip3.get_i() - b*h );
2293  ip4.set_j( ip3.get_j() + a*h );
2294 
2295  displayLine ( ip2, ip4, color, thickness ) ;
2296 
2297  ip4.set_i( ip3.get_i() + b*h );
2298  ip4.set_j( ip3.get_j() - a*h );
2299 
2300  displayLine ( ip2, ip4, color, thickness ) ;
2301  displayLine ( ip1, ip2, color, thickness ) ;
2302  }
2303  }
2304  catch ( ... )
2305  {
2306  vpERROR_TRACE ( "Error caught" ) ;
2307  throw ;
2308  }
2309  }
2310  else
2311  {
2312  vpERROR_TRACE ( "X not initialized " ) ;
2314  "X not initialized" ) ) ;
2315  }
2316 }
2317 
2330  const char *text,
2331  const vpColor &color )
2332 {
2334  {
2335  if (color.id < vpColor::id_unknown)
2336  XSetForeground ( display, context, x_color[color.id] );
2337  else {
2338  xcolor.pad = 0;
2339  xcolor.red = 256 * color.R;
2340  xcolor.green = 256 * color.G;
2341  xcolor.blue = 256 * color.B;
2342  XAllocColor ( display, lut, &xcolor );
2343  XSetForeground ( display, context, xcolor.pixel );
2344  }
2345  XDrawString ( display, pixmap, context,
2346  (int)ip.get_u(), (int)ip.get_v(),
2347  text, (int)strlen ( text ) );
2348  }
2349  else
2350  {
2351  vpERROR_TRACE ( "X not initialized " ) ;
2353  "X not initialized" ) ) ;
2354  }
2355 }
2356 
2367  unsigned int radius,
2368  const vpColor &color,
2369  bool fill,
2370  unsigned int thickness )
2371 {
2373  {
2374  if ( thickness == 1 ) thickness = 0;
2375  if (color.id < vpColor::id_unknown)
2376  XSetForeground ( display, context, x_color[color.id] );
2377  else {
2378  xcolor.pad = 0;
2379  xcolor.red = 256 * color.R;
2380  xcolor.green = 256 * color.G;
2381  xcolor.blue = 256 * color.B;
2382  XAllocColor ( display, lut, &xcolor );
2383  XSetForeground ( display, context, xcolor.pixel );
2384  }
2385 
2386  XSetLineAttributes ( display, context, thickness,
2387  LineSolid, CapButt, JoinBevel );
2388 
2389  if ( fill == false )
2390  {
2391  XDrawArc ( display, pixmap, context,
2392  vpMath::round( center.get_u()-radius ),
2393  vpMath::round( center.get_v()-radius ),
2394  radius*2, radius*2, 0, 23040 ); /* 23040 = 360*64 */
2395  }
2396  else
2397  {
2398  XFillArc ( display, pixmap, context,
2399  vpMath::round( center.get_u()-radius ),
2400  vpMath::round( center.get_v()-radius ),
2401  radius*2, radius*2, 0, 23040 ); /* 23040 = 360*64 */
2402  }
2403  }
2404  else
2405  {
2406  vpERROR_TRACE ( "X not initialized " ) ;
2408  "X not initialized" ) ) ;
2409  }
2410 }
2411 
2420  unsigned int size,
2421  const vpColor &color,
2422  unsigned int thickness)
2423 {
2425  {
2426  try
2427  {
2428  double i = ip.get_i();
2429  double j = ip.get_j();
2430  vpImagePoint ip1, ip2;
2431 
2432  ip1.set_i( i-size/2 );
2433  ip1.set_j( j );
2434  ip2.set_i( i+size/2 );
2435  ip2.set_j( j );
2436  displayLine ( ip1, ip2, color, thickness ) ;
2437 
2438  ip1.set_i( i );
2439  ip1.set_j( j-size/2 );
2440  ip2.set_i( i );
2441  ip2.set_j( j+size/2 );
2442 
2443  displayLine ( ip1, ip2, color, thickness ) ;
2444  }
2445  catch ( ... )
2446  {
2447  vpERROR_TRACE ( "Error caught" ) ;
2448  throw ;
2449  }
2450  }
2451 
2452  else
2453  {
2454  vpERROR_TRACE ( "X not initialized " ) ;
2456  "X not initialized" ) ) ;
2457  }
2458 
2459 }
2467  const vpImagePoint &ip2,
2468  const vpColor &color,
2469  unsigned int thickness )
2470 {
2471 
2473  {
2474  if ( thickness == 1 ) thickness = 0;
2475 
2476  if (color.id < vpColor::id_unknown)
2477  XSetForeground ( display, context, x_color[color.id] );
2478  else {
2479  xcolor.pad = 0;
2480  xcolor.red = 256 * color.R;
2481  xcolor.green = 256 * color.G;
2482  xcolor.blue = 256 * color.B;
2483  XAllocColor ( display, lut, &xcolor );
2484  XSetForeground ( display, context, xcolor.pixel );
2485  }
2486 
2487  XSetLineAttributes ( display, context, thickness,
2488  LineOnOffDash, CapButt, JoinBevel );
2489 
2490  XDrawLine ( display, pixmap, context,
2491  vpMath::round( ip1.get_u() ),
2492  vpMath::round( ip1.get_v() ),
2493  vpMath::round( ip2.get_u() ),
2494  vpMath::round( ip2.get_v() ) );
2495  }
2496  else
2497  {
2498  vpERROR_TRACE ( "X not initialized " ) ;
2500  "X not initialized" ) ) ;
2501  }
2502 }
2503 
2511  const vpImagePoint &ip2,
2512  const vpColor &color,
2513  unsigned int thickness )
2514 {
2516  {
2517  if ( thickness == 1 ) thickness = 0;
2518 
2519  if (color.id < vpColor::id_unknown)
2520  XSetForeground ( display, context, x_color[color.id] );
2521  else {
2522  xcolor.pad = 0;
2523  xcolor.red = 256 * color.R;
2524  xcolor.green = 256 * color.G;
2525  xcolor.blue = 256 * color.B;
2526  XAllocColor ( display, lut, &xcolor );
2527  XSetForeground ( display, context, xcolor.pixel );
2528  }
2529 
2530  XSetLineAttributes ( display, context, thickness,
2531  LineSolid, CapButt, JoinBevel );
2532 
2533  XDrawLine ( display, pixmap, context,
2534  vpMath::round( ip1.get_u() ),
2535  vpMath::round( ip1.get_v() ),
2536  vpMath::round( ip2.get_u() ),
2537  vpMath::round( ip2.get_v() ) );
2538  }
2539  else
2540  {
2541  vpERROR_TRACE ( "X not initialized " ) ;
2543  "X not initialized" ) ) ;
2544  }
2545 }
2546 
2553  const vpColor &color )
2554 {
2556  {
2557  if (color.id < vpColor::id_unknown)
2558  XSetForeground ( display, context, x_color[color.id] );
2559  else {
2560  xcolor.pad = 0;
2561  xcolor.red = 256 * color.R;
2562  xcolor.green = 256 * color.G;
2563  xcolor.blue = 256 * color.B;
2564  XAllocColor ( display, lut, &xcolor );
2565  XSetForeground ( display, context, xcolor.pixel );
2566  }
2567 
2568  XDrawPoint ( display, pixmap, context,
2569  vpMath::round( ip.get_u() ),
2570  vpMath::round( ip.get_v() ) );
2571  }
2572  else
2573  {
2574  vpERROR_TRACE ( "X not initialized " ) ;
2576  "X not initialized" ) ) ;
2577  }
2578 }
2579 
2593 void
2595  unsigned int width, unsigned int height,
2596  const vpColor &color, bool fill,
2597  unsigned int thickness )
2598 {
2600  {
2601  if ( thickness == 1 ) thickness = 0;
2602  if (color.id < vpColor::id_unknown)
2603  XSetForeground ( display, context, x_color[color.id] );
2604  else {
2605  xcolor.pad = 0;
2606  xcolor.red = 256 * color.R;
2607  xcolor.green = 256 * color.G;
2608  xcolor.blue = 256 * color.B;
2609  XAllocColor ( display, lut, &xcolor );
2610  XSetForeground ( display, context, xcolor.pixel );
2611  }
2612  XSetLineAttributes ( display, context, thickness,
2613  LineSolid, CapButt, JoinBevel );
2614  if ( fill == false )
2615  {
2616  XDrawRectangle ( display, pixmap, context,
2617  vpMath::round( topLeft.get_u() ),
2618  vpMath::round( topLeft.get_v() ),
2619  width-1, height-1 );
2620  }
2621  else
2622  {
2623  XFillRectangle ( display, pixmap, context,
2624  vpMath::round( topLeft.get_u() ),
2625  vpMath::round( topLeft.get_v() ),
2626  width, height );
2627  }
2628  }
2629  else
2630  {
2631  vpERROR_TRACE ( "X not initialized " ) ;
2633  "X not initialized" ) ) ;
2634  }
2635 }
2636 
2649 void
2651  const vpImagePoint &bottomRight,
2652  const vpColor &color, bool fill,
2653  unsigned int thickness )
2654 {
2656  {
2657  if ( thickness == 1 ) thickness = 0;
2658  if (color.id < vpColor::id_unknown)
2659  XSetForeground ( display, context, x_color[color.id] );
2660  else {
2661  xcolor.pad = 0;
2662  xcolor.red = 256 * color.R;
2663  xcolor.green = 256 * color.G;
2664  xcolor.blue = 256 * color.B;
2665  XAllocColor ( display, lut, &xcolor );
2666  XSetForeground ( display, context, xcolor.pixel );
2667  }
2668 
2669  XSetLineAttributes ( display, context, thickness,
2670  LineSolid, CapButt, JoinBevel );
2671 
2672  unsigned int width = (unsigned int)vpMath::round( bottomRight.get_u() - topLeft.get_u() );
2673  unsigned int height = (unsigned int)vpMath::round( bottomRight.get_v() - topLeft.get_v() );
2674  if ( fill == false )
2675  {
2676  XDrawRectangle ( display, pixmap, context,
2677  vpMath::round( topLeft.get_u() ),
2678  vpMath::round( topLeft.get_v() ),
2679  width-1, height-1 );
2680  }
2681  else
2682  {
2683  XFillRectangle ( display, pixmap, context,
2684  vpMath::round( topLeft.get_u() ),
2685  vpMath::round( topLeft.get_v() ),
2686  width, height );
2687  }
2688  }
2689  else
2690  {
2691  vpERROR_TRACE ( "X not initialized " ) ;
2693  "X not initialized" ) ) ;
2694  }
2695 }
2696 
2709 void
2711  const vpColor &color, bool fill,
2712  unsigned int thickness )
2713 {
2715  {
2716  if ( thickness == 1 ) thickness = 0;
2717  if (color.id < vpColor::id_unknown)
2718  XSetForeground ( display, context, x_color[color.id] );
2719  else {
2720  xcolor.pad = 0;
2721  xcolor.red = 256 * color.R;
2722  xcolor.green = 256 * color.G;
2723  xcolor.blue = 256 * color.B;
2724  XAllocColor ( display, lut, &xcolor );
2725  XSetForeground ( display, context, xcolor.pixel );
2726  }
2727 
2728  XSetLineAttributes ( display, context, thickness,
2729  LineSolid, CapButt, JoinBevel );
2730 
2731  if ( fill == false )
2732  {
2733  XDrawRectangle ( display, pixmap, context,
2734  vpMath::round( rectangle.getLeft() ),
2735  vpMath::round( rectangle.getTop() ),
2736  (unsigned int)vpMath::round( rectangle.getWidth()-1 ),
2737  (unsigned int)vpMath::round( rectangle.getHeight()-1 ) );
2738  }
2739  else
2740  {
2741  XFillRectangle ( display, pixmap, context,
2742  vpMath::round( rectangle.getLeft() ),
2743  vpMath::round( rectangle.getTop() ),
2744  (unsigned int)vpMath::round( rectangle.getWidth() ),
2745  (unsigned int)vpMath::round( rectangle.getHeight() ) );
2746  }
2747 
2748  }
2749  else
2750  {
2751  vpERROR_TRACE ( "X not initialized " ) ;
2753  "X not initialized" ) ) ;
2754  }
2755 }
2756 
2773 bool
2774 vpDisplayX::getClick(bool blocking)
2775 {
2776 
2777  bool ret = false;
2778 
2779  if ( displayHasBeenInitialized ) {
2780  Window rootwin, childwin ;
2781  int root_x, root_y, win_x, win_y ;
2782  unsigned int modifier ;
2783 
2784  // Event testing
2785  if(blocking){
2786  XCheckMaskEvent(display , ButtonPressMask, &event);
2787  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2788  XMaskEvent ( display, ButtonPressMask ,&event );
2789  ret = true;
2790  }
2791  else{
2792  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2793  }
2794 
2795  if(ret){
2796  /* Recuperation de la coordonnee du pixel cliqu�. */
2797  if ( XQueryPointer ( display,
2798  window,
2799  &rootwin, &childwin,
2800  &root_x, &root_y,
2801  &win_x, &win_y,
2802  &modifier ) ) {}
2803  }
2804  }
2805  else {
2806  vpERROR_TRACE ( "X not initialized " ) ;
2808  "X not initialized" ) ) ;
2809  }
2810  return ret;
2811 }
2812 
2829 bool
2830 vpDisplayX::getClick ( vpImagePoint &ip, bool blocking )
2831 {
2832 
2833  bool ret = false;
2834  if ( displayHasBeenInitialized ) {
2835 
2836  Window rootwin, childwin ;
2837  int root_x, root_y, win_x, win_y ;
2838  unsigned int modifier ;
2839  // Event testing
2840  if(blocking){
2841  XCheckMaskEvent(display , ButtonPressMask, &event);
2842  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2843  XMaskEvent ( display, ButtonPressMask ,&event );
2844  ret = true;
2845  }
2846  else{
2847  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2848  }
2849 
2850  if(ret){
2851  // Get mouse position
2852  if ( XQueryPointer ( display,
2853  window,
2854  &rootwin, &childwin,
2855  &root_x, &root_y,
2856  &win_x, &win_y,
2857  &modifier ) ) {
2858  ip.set_u( (double)event.xbutton.x );
2859  ip.set_v( (double)event.xbutton.y );
2860  }
2861  }
2862  }
2863  else {
2864  vpERROR_TRACE ( "X not initialized " ) ;
2866  "X not initialized" ) ) ;
2867  }
2868  return ret ;
2869 }
2870 
2890 bool
2893  bool blocking )
2894 {
2895 
2896  bool ret = false;
2897  if ( displayHasBeenInitialized ) {
2898 
2899  Window rootwin, childwin ;
2900  int root_x, root_y, win_x, win_y ;
2901  unsigned int modifier ;
2902 
2903  // Event testing
2904  if(blocking){
2905  XCheckMaskEvent(display , ButtonPressMask, &event);
2906  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2907  XMaskEvent ( display, ButtonPressMask ,&event );
2908  ret = true;
2909  }
2910  else{
2911  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2912  }
2913 
2914  if(ret){
2915  // Get mouse position
2916  if ( XQueryPointer ( display,
2917  window,
2918  &rootwin, &childwin,
2919  &root_x, &root_y,
2920  &win_x, &win_y,
2921  &modifier ) ) {
2922  ip.set_u( (double)event.xbutton.x );
2923  ip.set_v( (double)event.xbutton.y );
2924  switch ( event.xbutton.button ) {
2925  case Button1: button = vpMouseButton::button1; break;
2926  case Button2: button = vpMouseButton::button2; break;
2927  case Button3: button = vpMouseButton::button3; break;
2928  }
2929  }
2930  }
2931  }
2932  else {
2933  vpERROR_TRACE ( "X not initialized " ) ;
2935  "X not initialized" ) ) ;
2936  }
2937  return ret ;
2938 }
2939 
2963 bool
2966  bool blocking )
2967 {
2968 
2969  bool ret = false;
2970  if ( displayHasBeenInitialized ) {
2971  Window rootwin, childwin ;
2972  int root_x, root_y, win_x, win_y ;
2973  unsigned int modifier ;
2974 
2975  // Event testing
2976  if(blocking){
2977  XCheckMaskEvent(display , ButtonPressMask, &event);
2978  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2979  XMaskEvent ( display, ButtonReleaseMask ,&event );
2980  ret = true;
2981  }
2982  else{
2983  ret = XCheckMaskEvent(display , ButtonReleaseMask, &event);
2984  }
2985 
2986  if(ret){
2987  /* Recuperation de la coordonnee du pixel cliqu�. */
2988  if ( XQueryPointer ( display,
2989  window,
2990  &rootwin, &childwin,
2991  &root_x, &root_y,
2992  &win_x, &win_y,
2993  &modifier ) ) {
2994  ip.set_u( (double)event.xbutton.x );
2995  ip.set_v( (double)event.xbutton.y );
2996  switch ( event.xbutton.button ) {
2997  case Button1: button = vpMouseButton::button1; break;
2998  case Button2: button = vpMouseButton::button2; break;
2999  case Button3: button = vpMouseButton::button3; break;
3000  }
3001  }
3002  }
3003  }
3004  else {
3005  vpERROR_TRACE ( "X not initialized " ) ;
3007  "X not initialized" ) ) ;
3008  }
3009  return ret ;
3010 }
3011 
3012 /*
3013  Gets the displayed image (including the overlay plane)
3014  and returns an RGBa image.
3015 
3016  \param I : Image to get.
3017 */
3019 {
3020 
3022  {
3023 
3024 
3025  XImage *xi ;
3026  //xi= XGetImage ( display,window, 0,0, getWidth(), getHeight(),
3027  // AllPlanes, ZPixmap ) ;
3028 
3029  XCopyArea (display,window, pixmap, context,
3030  0,0, getWidth(), getHeight(), 0, 0);
3031 
3032  xi= XGetImage ( display,pixmap, 0,0, getWidth(), getHeight(),
3033  AllPlanes, ZPixmap ) ;
3034 
3035  try
3036  {
3037  I.resize ( getHeight(), getWidth() ) ;
3038  }
3039  catch ( ... )
3040  {
3041  vpERROR_TRACE ( "Error caught" ) ;
3042  throw ;
3043  }
3044 
3045  unsigned char *src_32 = NULL;
3046  src_32 = ( unsigned char* ) xi->data;
3047 
3048 #ifdef BIGENDIAN
3049  // little indian/big indian
3050  for ( unsigned int i = 0; i < I.getWidth() * I.getHeight() ; i++ )
3051  {
3052  I.bitmap[i].A = src_32[i*4] ;
3053  I.bitmap[i].R = src_32[i*4 + 1] ;
3054  I.bitmap[i].G = src_32[i*4 + 2] ;
3055  I.bitmap[i].B = src_32[i*4 + 3] ;
3056  }
3057 #else
3058  for ( unsigned int i = 0; i < I.getWidth() * I.getHeight() ; i++ )
3059  {
3060  I.bitmap[i].B = src_32[i*4] ;
3061  I.bitmap[i].G = src_32[i*4 + 1] ;
3062  I.bitmap[i].R = src_32[i*4 + 2] ;
3063  I.bitmap[i].A = src_32[i*4 + 3] ;
3064  }
3065 #endif
3066 
3067 
3068  XDestroyImage ( xi ) ;
3069 
3070  }
3071  else
3072  {
3073  vpERROR_TRACE ( "X not initialized " ) ;
3075  "X not initialized" ) ) ;
3076  }
3077 }
3078 
3083 {
3084  Display *_display;
3085  int screen;
3086  unsigned int depth;
3087 
3088  if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3089  {
3090  vpERROR_TRACE ( "Can't connect display on server %s.",
3091  XDisplayName ( NULL ) );
3093  "Can't connect display on server." ) ) ;
3094  }
3095  screen = DefaultScreen ( _display );
3096  depth = (unsigned int)DefaultDepth ( _display, screen );
3097 
3098  XCloseDisplay ( _display );
3099 
3100  return ( depth );
3101 }
3102 
3107 void vpDisplayX::getScreenSize ( unsigned int &width, unsigned int &height )
3108 {
3109  Display *_display;
3110  int screen;
3111 
3112  if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3113  {
3114  vpERROR_TRACE ( "Can't connect display on server %s.",
3115  XDisplayName ( NULL ) );
3117  "Can't connect display on server." ) ) ;
3118  }
3119  screen = DefaultScreen ( _display );
3120  width = (unsigned int)DisplayWidth ( _display, screen );
3121  height = (unsigned int)DisplayHeight ( _display, screen );
3122 
3123  XCloseDisplay ( _display );
3124 }
3145 bool
3147 {
3148 
3149  bool ret = false;
3150 
3151  if ( displayHasBeenInitialized ) {
3152  // Event testing
3153  if(blocking){
3154  XMaskEvent ( display, KeyPressMask ,&event );
3155  ret = true;
3156  }
3157  else{
3158  ret = XCheckMaskEvent(display , KeyPressMask, &event);
3159  }
3160  }
3161  else {
3162  vpERROR_TRACE ( "X not initialized " ) ;
3164  "X not initialized" ) ) ;
3165  }
3166  return ret;
3167 }
3191 bool
3192 vpDisplayX::getKeyboardEvent(char *string, bool blocking)
3193 {
3194 
3195  bool ret = false;
3196  KeySym keysym;
3197 // int count;
3198  XComposeStatus compose_status;
3199  char buffer;
3200 
3201  if ( displayHasBeenInitialized ) {
3202  // Event testing
3203  if(blocking){
3204  XMaskEvent ( display, KeyPressMask ,&event );
3205  /* count = */ XLookupString ((XKeyEvent *)&event, &buffer, 1,
3206  &keysym, &compose_status);
3207  //std::cout <<"count: " << count << " get \"" << buffer << "\"" << std::endl;
3208  sprintf(string, "%c", buffer);
3209  ret = true;
3210  }
3211  else{
3212  ret = XCheckMaskEvent(display , KeyPressMask, &event);
3213  if (ret) {
3214  /* count = */ XLookupString ((XKeyEvent *)&event, &buffer, 1,
3215  &keysym, &compose_status);
3216  sprintf(string, "%c", buffer);
3217  }
3218  }
3219  }
3220  else {
3221  vpERROR_TRACE ( "X not initialized " ) ;
3223  "X not initialized" ) ) ;
3224  }
3225  return ret;
3226 }
3239 bool
3241 {
3242 
3243  bool ret = false;
3244  if ( displayHasBeenInitialized ) {
3245 
3246  Window rootwin, childwin ;
3247  int root_x, root_y, win_x, win_y ;
3248  unsigned int modifier ;
3249  // Event testing
3250  ret = XCheckMaskEvent(display , PointerMotionMask, &event);
3251 
3252  if(ret){
3253  // Get mouse position
3254  if ( XQueryPointer ( display,
3255  window,
3256  &rootwin, &childwin,
3257  &root_x, &root_y,
3258  &win_x, &win_y,
3259  &modifier ) ) {
3260  ip.set_u( (double)event.xbutton.x );
3261  ip.set_v( (double)event.xbutton.y );
3262  }
3263  }
3264  }
3265  else {
3266  vpERROR_TRACE ( "X not initialized " ) ;
3268  "X not initialized" ) ) ;
3269  }
3270  return ret ;
3271 }
3272 
3283 bool
3285 {
3286 
3287  bool ret = false;
3288  if ( displayHasBeenInitialized ) {
3289 
3290  Window rootwin, childwin ;
3291  int root_x, root_y, win_x, win_y ;
3292  unsigned int modifier ;
3293  // Event testing
3294  ret = true;
3295 
3296  if(ret){
3297  // Get mouse position
3298  if ( XQueryPointer ( display,
3299  window,
3300  &rootwin, &childwin,
3301  &root_x, &root_y,
3302  &win_x, &win_y,
3303  &modifier ) ) {
3304  ip.set_u( (double)win_x );
3305  ip.set_v( (double)win_y );
3306  }
3307  }
3308  }
3309  else {
3310  vpERROR_TRACE ( "X not initialized " ) ;
3312  "X not initialized" ) ) ;
3313  }
3314  return ret ;
3315 }
3316 
3317 #endif
3318 
3319 /*
3320  * Local variables:
3321  * c-basic-offset: 2
3322  * End:
3323  */
void closeDisplay()
void set_j(const double j)
Definition: vpImagePoint.h:156
void clearDisplay(const vpColor &color=vpColor::white)
vpDisplay * display
Definition: vpImage.h:116
#define vpDEBUG_TRACE
Definition: vpDebug.h:454
double getTop() const
Definition: vpRect.h:169
double get_v() const
Definition: vpImagePoint.h:250
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:167
unsigned int getScreenDepth()
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setFont(const char *font)
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
unsigned int width
Definition: vpDisplay.h:179
double get_i() const
Definition: vpImagePoint.h:181
unsigned int getWidth() const
Definition: vpImage.h:154
void displayImage(const vpImage< vpRGBa > &I)
#define vpERROR_TRACE
Definition: vpDebug.h:379
unsigned char B
Blue component.
Definition: vpRGBa.h:155
#define vpTRACE
Definition: vpDebug.h:401
Type * bitmap
points toward the bitmap
Definition: vpImage.h:115
static const vpColor black
Definition: vpColor.h:159
static const vpColor darkRed
Definition: vpColor.h:166
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
double get_u() const
Definition: vpImagePoint.h:239
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:530
void set_i(const double i)
Definition: vpImagePoint.h:145
static const vpColor lightGray
Definition: vpColor.h:161
double getHeight() const
Definition: vpRect.h:150
void flushDisplay()
char * title
display title
Definition: vpDisplay.h:177
static const vpColor darkBlue
Definition: vpColor.h:172
bool displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:171
unsigned char G
Green component.
Definition: vpRGBa.h:154
static const vpColor green
Definition: vpColor.h:168
unsigned int getHeight() const
Definition: vpDisplayX.h:270
static int round(const double x)
Definition: vpMath.h:228
double get_j() const
Definition: vpImagePoint.h:192
static const vpColor lightRed
Definition: vpColor.h:164
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
static const vpColor red
Definition: vpColor.h:165
bool getPointerPosition(vpImagePoint &ip)
static const vpColor orange
Definition: vpColor.h:175
bool getClick(bool blocking=true)
vpColorIdentifier id
Definition: vpColor.h:154
double getWidth() const
Definition: vpRect.h:188
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)
static const vpColor cyan
Definition: vpColor.h:174
static const vpColor lightGreen
Definition: vpColor.h:167
void set_u(const double u)
Definition: vpImagePoint.h:203
static double sqr(double x)
Definition: vpMath.h:106
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
unsigned int height
Definition: vpDisplay.h:180
void getScreenSize(unsigned int &width, unsigned int &height)
void set_v(const double v)
Definition: vpImagePoint.h:214
unsigned char A
Additionnal component.
Definition: vpRGBa.h:156
bool getKeyboardEvent(bool blocking=true)
static const vpColor gray
Definition: vpColor.h:162
void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
void setWindowPosition(int winx, int winy)
virtual ~vpDisplayX()
Definition: vpDisplayX.cpp:182
static const vpColor darkGray
Definition: vpColor.h:163
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
void setTitle(const char *title)
Error that can be emited by the vpDisplay class and its derivates.
void displayPoint(const vpImagePoint &ip, const vpColor &color)
int windowXPosition
display position
Definition: vpDisplay.h:173
unsigned char R
Red component.
Definition: vpRGBa.h:153
unsigned int getWidth() const
Definition: vpDisplayX.h:269
unsigned int getHeight() const
Definition: vpImage.h:145
Defines a rectangle in the plane.
Definition: vpRect.h:82
static const vpColor darkGreen
Definition: vpColor.h:169
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Definition: vpDisplayX.cpp:196
static const vpColor yellow
Definition: vpColor.h:173
static const vpColor lightBlue
Definition: vpColor.h:170
int windowYPosition
display position
Definition: vpDisplay.h:175
static const vpColor purple
Definition: vpColor.h:176
static const vpColor white
Definition: vpColor.h:160
double getLeft() const
Definition: vpRect.h:156
void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
bool getPointerMotionEvent(vpImagePoint &ip)
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
static const vpColor blue
Definition: vpColor.h:171
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)