ViSP  2.9.0
vpDisplayX.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDisplayX.cpp 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 )
83 {
84  size = 0;
85  x_color = NULL;
86  init ( I, x, y, title ) ;
87 }
88 
89 
90 
100  int x,
101  int y,
102  const char *title )
103 {
104  size = 0;
105  x_color = NULL;
106  init ( I, x, y, title ) ;
107 }
108 
131 vpDisplayX::vpDisplayX ( int x, int y, const char *title )
132 {
133  windowXPosition = x ;
134  windowYPosition = y ;
135 
136  this->x_color = NULL;
137 
138  if (title != NULL)
139  title_ = std::string(title);
140  else
141  title_ = std::string(" ");
142 
143  ximage_data_init = false;
144 
145  size = 0;
146 }
147 
168 {
169  x_color = NULL;
170  ximage_data_init = false;
171  size = 0;
172 }
173 
178 {
179  closeDisplay() ;
180 }
181 
190 void
191 vpDisplayX::init ( vpImage<unsigned char> &I, int x, int y, const char *title )
192 {
193 
194  if (x_color == NULL) {
195  // id_unknown = number of predefined colors
196  x_color= new unsigned long [vpColor::id_unknown];
197  }
198 
199  XSizeHints hints;
200  if (x != -1)
201  windowXPosition = x ;
202  if (y != -1)
203  windowYPosition = y ;
204 
205  if (title != NULL)
206  title_ = std::string(title);
207  else
208  title_ = std::string(" ");
209 
210  // Positionnement de la fenetre dans l'�cran.
211  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
212  {
213  hints.flags = 0;
214  }
215  else
216  {
217  hints.flags = USPosition;
218  hints.x = windowXPosition;
219  hints.y = windowYPosition;
220  }
221 
222  // setup X11 --------------------------------------------------
223  width = I.getWidth();
224  height = I.getHeight();
225  display = XOpenDisplay ( NULL );
226  if ( display == NULL )
227  {
228  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
230  "Can't connect display on server." ) ) ;
231  }
232 
233  screen = DefaultScreen ( display );
234  lut = DefaultColormap ( display, screen );
235  screen_depth = (unsigned int)DefaultDepth ( display, screen );
236 
237  if ( ( window =
238  XCreateSimpleWindow ( display, RootWindow ( display, screen ),
240  BlackPixel ( display, screen ),
241  WhitePixel ( display, screen ) ) ) == 0 )
242  {
243  vpERROR_TRACE ( "Can't create window." );
245  "Can't create window." ) ) ;
246  }
247 
248  //
249  // Create color table for 8 and 16 bits screen
250  //
251  if ( screen_depth == 8 )
252  {
253  lut = XCreateColormap ( display, window,
254  DefaultVisual ( display, screen ), AllocAll ) ;
255  xcolor.flags = DoRed | DoGreen | DoBlue ;
256 
257  for ( unsigned int i = 0 ; i < 256 ; i++ )
258  {
259  xcolor.pixel = i ;
260  xcolor.red = 256 * i;
261  xcolor.green = 256 * i;
262  xcolor.blue = 256 * i;
263  XStoreColor ( display, lut, &xcolor );
264  }
265 
266  XSetWindowColormap ( display, window, lut ) ;
267  XInstallColormap ( display, lut ) ;
268  }
269 
270  else if ( screen_depth == 16 )
271  {
272  for ( unsigned int i = 0; i < 256; i ++ )
273  {
274  xcolor.pad = 0;
275  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
276  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
277  {
278  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
280  "Can't allocate 256 colors." ) ) ;
281  }
282  colortable[i] = xcolor.pixel;
283  }
284 
285  XSetWindowColormap ( display, window, lut ) ;
286  XInstallColormap ( display, lut ) ;
287 
288  }
289 
290  //
291  // Create colors for overlay
292  //
293  switch ( screen_depth )
294  {
295  case 8:
296  // Color BLACK and WHITE are set properly by default.
297 
298  // Color LIGHT GRAY.
299  x_color[vpColor::id_lightGray] = 254;
300  xcolor.pixel = x_color[vpColor::id_lightGray] ;
301  xcolor.red = 256 * 192;
302  xcolor.green = 256 * 192;
303  xcolor.blue = 256 * 192;
304  XStoreColor ( display, lut, &xcolor );
305 
306  // Color GRAY.
307  x_color[vpColor::id_gray] = 253;
308  xcolor.pixel = x_color[vpColor::id_gray] ;
309  xcolor.red = 256 * 128;
310  xcolor.green = 256 * 128;
311  xcolor.blue = 256 * 128;
312  XStoreColor ( display, lut, &xcolor );
313 
314  // Color DARK GRAY.
315  x_color[vpColor::id_darkGray] = 252;
316  xcolor.pixel = x_color[vpColor::id_darkGray] ;
317  xcolor.red = 256 * 64;
318  xcolor.green = 256 * 64;
319  xcolor.blue = 256 * 64;
320  XStoreColor ( display, lut, &xcolor );
321 
322  // Color LIGHT RED.
323  x_color[vpColor::id_lightRed] = 251;
324  xcolor.pixel = x_color[vpColor::id_lightRed] ;
325  xcolor.red = 256 * 255;
326  xcolor.green = 256 * 140;
327  xcolor.blue = 256 * 140;
328  XStoreColor ( display, lut, &xcolor );
329 
330  // Color RED.
331  x_color[vpColor::id_red] = 250;
332  xcolor.pixel = x_color[vpColor::id_red] ;
333  xcolor.red = 256 * 255;
334  xcolor.green = 0;
335  xcolor.blue = 0;
336  XStoreColor ( display, lut, &xcolor );
337 
338  // Color DARK RED.
339  x_color[vpColor::id_darkRed] = 249;
340  xcolor.pixel = x_color[vpColor::id_darkRed] ;
341  xcolor.red = 256 * 128;
342  xcolor.green = 0;
343  xcolor.blue = 0;
344  XStoreColor ( display, lut, &xcolor );
345 
346  // Color LIGHT GREEN.
347  x_color[vpColor::id_lightGreen] = 248;
348  xcolor.pixel = x_color[vpColor::id_lightGreen] ;
349  xcolor.red = 256 * 140;
350  xcolor.green = 256 * 255;
351  xcolor.blue = 256 * 140;
352  XStoreColor ( display, lut, &xcolor );
353 
354  // Color GREEN.
355  x_color[vpColor::id_green] = 247;
356  xcolor.pixel = x_color[vpColor::id_green];
357  xcolor.red = 0;
358  xcolor.green = 256 * 255;
359  xcolor.blue = 0;
360  XStoreColor ( display, lut, &xcolor );
361 
362  // Color DARK GREEN.
363  x_color[vpColor::id_darkGreen] = 246;
364  xcolor.pixel = x_color[vpColor::id_darkGreen] ;
365  xcolor.red = 0;
366  xcolor.green = 256 * 128;
367  xcolor.blue = 0;
368  XStoreColor ( display, lut, &xcolor );
369 
370  // Color LIGHT BLUE.
371  x_color[vpColor::id_lightBlue] = 245;
372  xcolor.pixel = x_color[vpColor::id_lightBlue] ;
373  xcolor.red = 256 * 140;
374  xcolor.green = 256 * 140;
375  xcolor.blue = 256 * 255;
376  XStoreColor ( display, lut, &xcolor );
377 
378  // Color BLUE.
379  x_color[vpColor::id_blue] = 244;
380  xcolor.pixel = x_color[vpColor::id_blue];
381  xcolor.red = 0;
382  xcolor.green = 0;
383  xcolor.blue = 256 * 255;
384  XStoreColor ( display, lut, &xcolor );
385 
386  // Color DARK BLUE.
387  x_color[vpColor::id_darkBlue] = 243;
388  xcolor.pixel = x_color[vpColor::id_darkBlue] ;
389  xcolor.red = 0;
390  xcolor.green = 0;
391  xcolor.blue = 256 * 128;
392  XStoreColor ( display, lut, &xcolor );
393 
394  // Color YELLOW.
395  x_color[vpColor::id_yellow] = 242;
396  xcolor.pixel = x_color[vpColor::id_yellow];
397  xcolor.red = 256 * 255;
398  xcolor.green = 256 * 255;
399  xcolor.blue = 0;
400  XStoreColor ( display, lut, &xcolor );
401 
402  // Color ORANGE.
403  x_color[vpColor::id_orange] = 241;
404  xcolor.pixel = x_color[vpColor::id_orange];
405  xcolor.red = 256 * 255;
406  xcolor.green = 256 * 165;
407  xcolor.blue = 0;
408  XStoreColor ( display, lut, &xcolor );
409 
410  // Color CYAN.
411  x_color[vpColor::id_cyan] = 240;
412  xcolor.pixel = x_color[vpColor::id_cyan];
413  xcolor.red = 0;
414  xcolor.green = 256 * 255;
415  xcolor.blue = 256 * 255;
416  XStoreColor ( display, lut, &xcolor );
417 
418  // Color PURPLE.
419  x_color[vpColor::id_purple] = 239;
420  xcolor.pixel = x_color[vpColor::id_purple];
421  xcolor.red = 256 * 128;
422  xcolor.green = 0;
423  xcolor.blue = 256 * 128;
424  XStoreColor ( display, lut, &xcolor );
425 
426  break;
427 
428  case 16:
429  case 24:
430  {
431  xcolor.flags = DoRed | DoGreen | DoBlue ;
432 
433  // Couleur BLACK.
434  xcolor.pad = 0;
435  xcolor.red = 0;
436  xcolor.green = 0;
437  xcolor.blue = 0;
438  XAllocColor ( display, lut, &xcolor );
439  x_color[vpColor::id_black] = xcolor.pixel;
440 
441  // Couleur WHITE.
442  xcolor.pad = 0;
443  xcolor.red = 256* 255;
444  xcolor.green = 256* 255;
445  xcolor.blue = 256* 255;
446  XAllocColor ( display, lut, &xcolor );
447  x_color[vpColor::id_white] = xcolor.pixel;
448 
449  // Couleur LIGHT GRAY.
450  xcolor.pad = 0;
451  xcolor.red = 256 * 192;
452  xcolor.green = 256 * 192;
453  xcolor.blue = 256 * 192;
454  XAllocColor ( display, lut, &xcolor );
455  x_color[vpColor::id_lightGray] = xcolor.pixel;
456 
457  // Couleur GRAY.
458  xcolor.pad = 0;
459  xcolor.red = 256 * 128;
460  xcolor.green = 256 * 128;
461  xcolor.blue = 256 * 128;
462  XAllocColor ( display, lut, &xcolor );
463  x_color[vpColor::id_gray] = xcolor.pixel;
464 
465  // Couleur DARK GRAY.
466  xcolor.pad = 0;
467  xcolor.red = 256 * 64;
468  xcolor.green = 256 * 64;
469  xcolor.blue = 256 * 64;
470  XAllocColor ( display, lut, &xcolor );
471  x_color[vpColor::id_darkGray] = xcolor.pixel;
472 
473  // Couleur LIGHT RED.
474  xcolor.pad = 0;
475  xcolor.red = 256 * 255;
476  xcolor.green = 256 * 140;
477  xcolor.blue = 256 * 140;
478  XAllocColor ( display, lut, &xcolor );
479  x_color[vpColor::id_lightRed] = xcolor.pixel;
480 
481  // Couleur RED.
482  xcolor.pad = 0;
483  xcolor.red = 256* 255;
484  xcolor.green = 0;
485  xcolor.blue = 0;
486  XAllocColor ( display, lut, &xcolor );
487  x_color[vpColor::id_red] = xcolor.pixel;
488 
489  // Couleur DARK RED.
490  xcolor.pad = 0;
491  xcolor.red = 256* 128;
492  xcolor.green = 0;
493  xcolor.blue = 0;
494  XAllocColor ( display, lut, &xcolor );
495  x_color[vpColor::id_darkRed] = xcolor.pixel;
496 
497  // Couleur LIGHT GREEN.
498  xcolor.pad = 0;
499  xcolor.red = 256 * 140;
500  xcolor.green = 256 * 255;
501  xcolor.blue = 256 * 140;
502  XAllocColor ( display, lut, &xcolor );
503  x_color[vpColor::id_lightGreen] = xcolor.pixel;
504 
505  // Couleur GREEN.
506  xcolor.pad = 0;
507  xcolor.red = 0;
508  xcolor.green = 256*255;
509  xcolor.blue = 0;
510  XAllocColor ( display, lut, &xcolor );
511  x_color[vpColor::id_green] = xcolor.pixel;
512 
513  // Couleur DARK GREEN.
514  xcolor.pad = 0;
515  xcolor.red = 0;
516  xcolor.green = 256* 128;
517  xcolor.blue = 0;
518  XAllocColor ( display, lut, &xcolor );
519  x_color[vpColor::id_darkGreen] = xcolor.pixel;
520 
521  // Couleur LIGHT Blue.
522  xcolor.pad = 0;
523  xcolor.red = 256 * 140;
524  xcolor.green = 256 * 140;
525  xcolor.blue = 256 * 255;
526  XAllocColor ( display, lut, &xcolor );
527  x_color[vpColor::id_lightBlue] = xcolor.pixel;
528 
529  // Couleur BLUE.
530  xcolor.pad = 0;
531  xcolor.red = 0;
532  xcolor.green = 0;
533  xcolor.blue = 256* 255;
534  XAllocColor ( display, lut, &xcolor );
535  x_color[vpColor::id_blue] = xcolor.pixel;
536 
537  // Couleur DARK BLUE.
538  xcolor.pad = 0;
539  xcolor.red = 0;
540  xcolor.green = 0;
541  xcolor.blue = 256* 128;
542  XAllocColor ( display, lut, &xcolor );
543  x_color[vpColor::id_darkBlue] = xcolor.pixel;
544 
545  // Couleur YELLOW.
546  xcolor.pad = 0;
547  xcolor.red = 256 * 255;
548  xcolor.green = 256 * 255;
549  xcolor.blue = 0;
550  XAllocColor ( display, lut, &xcolor );
551  x_color[vpColor::id_yellow] = xcolor.pixel;
552 
553  // Couleur ORANGE.
554  xcolor.pad = 0;
555  xcolor.red = 256 * 255;
556  xcolor.green = 256 * 165;
557  xcolor.blue = 0;
558  XAllocColor ( display, lut, &xcolor );
559  x_color[vpColor::id_orange] = xcolor.pixel;
560 
561  // Couleur CYAN.
562  xcolor.pad = 0;
563  xcolor.red = 0;
564  xcolor.green = 256 * 255;
565  xcolor.blue = 256 * 255;
566  XAllocColor ( display, lut, &xcolor );
567  x_color[vpColor::id_cyan] = xcolor.pixel;
568 
569  // Couleur PURPLE.
570  xcolor.pad = 0;
571  xcolor.red = 256 * 128;
572  xcolor.green = 0;
573  xcolor.blue = 256 * 128;
574  XAllocColor ( display, lut, &xcolor );
575  x_color[vpColor::id_purple] = xcolor.pixel;
576  break;
577  }
578  }
579 
580  XSetStandardProperties ( display, window, this->title_.c_str(), this->title_.c_str(), None, 0, 0, &hints );
581  XMapWindow ( display, window ) ;
582  // Selection des evenements.
583  XSelectInput ( display, window,
584  ExposureMask |
585  ButtonPressMask | ButtonReleaseMask |
586  KeyPressMask | KeyReleaseMask |
587  StructureNotifyMask |
588  PointerMotionMask);
589 
590  // graphic context creation
591  values.plane_mask = AllPlanes;
592  values.fill_style = FillSolid;
593  values.foreground = WhitePixel ( display, screen );
594  values.background = BlackPixel ( display, screen );
595  context = XCreateGC ( display, window,
596  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
597  &values );
598 
599  if ( context == NULL )
600  {
601  vpERROR_TRACE ( "Can't create graphics context." );
603  "Can't create graphics context" ) ) ;
604 
605  }
606 
607  // Pixmap creation.
608  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
609 
610  do
611  XNextEvent ( display, &event );
612  while ( event.xany.type != Expose );
613 
614  {
615  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
616  screen_depth, ZPixmap, 0, NULL,
617  I.getWidth() , I.getHeight(), XBitmapPad ( display ), 0 );
618 
619  Ximage->data = ( char * ) malloc ( I.getWidth() * I.getHeight() * (unsigned int)Ximage->bits_per_pixel / 8 );
620  ximage_data_init = true;
621 
622  }
624 
625  XStoreName ( display, window, title_.c_str() );
626 
627  XSync ( display, 1 );
628 
629  I.display = this ;
630 }
631 
641 void
642 vpDisplayX::init ( vpImage<vpRGBa> &I, int x, int y, const char *title )
643 {
644 
645  XSizeHints hints;
646  if (x != -1)
647  windowXPosition = x ;
648  if (y != -1)
649  windowYPosition = y ;
650 
651  if (x_color == NULL) {
652  // id_unknown = number of predefined colors
653  x_color= new unsigned long [vpColor::id_unknown];
654  }
655 
656  if (title != NULL)
657  title_ = std::string(title);
658  else
659  title_ = std::string(" ");
660 
661  // Positionnement de la fenetre dans l'ecran.
662  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
663  {
664  hints.flags = 0;
665  }
666  else
667  {
668  hints.flags = USPosition;
669  hints.x = windowXPosition;
670  hints.y = windowYPosition;
671  }
672 
673  // setup X11 --------------------------------------------------
674  width = I.getWidth();
675  height = I.getHeight();
676 
677  if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
678  {
679  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
681  "Can't connect display on server." ) ) ;
682  }
683 
684  screen = DefaultScreen ( display );
685  lut = DefaultColormap ( display, screen );
686  screen_depth = (unsigned int)DefaultDepth ( display, screen );
687 
688  vpDEBUG_TRACE ( 1, "Screen depth: %d\n", screen_depth );
689 
690  if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
692  width, height, 1,
693  BlackPixel ( display, screen ),
694  WhitePixel ( display, screen ) ) ) == 0 )
695  {
696  vpERROR_TRACE ( "Can't create window." );
698  "Can't create window." ) ) ;
699  }
700 
701  //
702  // Create color table for 8 and 16 bits screen
703  //
704  if ( screen_depth == 8 )
705  {
706  lut = XCreateColormap ( display, window,
707  DefaultVisual ( display, screen ), AllocAll ) ;
708  xcolor.flags = DoRed | DoGreen | DoBlue ;
709 
710  for ( unsigned int i = 0 ; i < 256 ; i++ )
711  {
712  xcolor.pixel = i ;
713  xcolor.red = 256 * i;
714  xcolor.green = 256 * i;
715  xcolor.blue = 256 * i;
716  XStoreColor ( display, lut, &xcolor );
717  }
718 
719  XSetWindowColormap ( display, window, lut ) ;
720  XInstallColormap ( display, lut ) ;
721  }
722 
723  else if ( screen_depth == 16 )
724  {
725  for ( unsigned int i = 0; i < 256; i ++ )
726  {
727  xcolor.pad = 0;
728  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
729  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
730  {
731  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
733  "Can't allocate 256 colors." ) ) ;
734  }
735  colortable[i] = xcolor.pixel;
736  }
737 
738  XSetWindowColormap ( display, window, lut ) ;
739  XInstallColormap ( display, lut ) ;
740 
741  }
742 
743 
744  //
745  // Create colors for overlay
746  //
747  switch ( screen_depth )
748  {
749 
750  case 8:
751  // Color BLACK and WHITE are set properly.
752 
753  // Color LIGHT GRAY.
754  x_color[vpColor::id_lightGray] = 254;
755  xcolor.pixel = x_color[vpColor::id_lightGray] ;
756  xcolor.red = 256 * 192;
757  xcolor.green = 256 * 192;
758  xcolor.blue = 256 * 192;
759  XStoreColor ( display, lut, &xcolor );
760 
761  // Color GRAY.
762  x_color[vpColor::id_gray] = 253;
763  xcolor.pixel = x_color[vpColor::id_gray] ;
764  xcolor.red = 256 * 128;
765  xcolor.green = 256 * 128;
766  xcolor.blue = 256 * 128;
767  XStoreColor ( display, lut, &xcolor );
768 
769  // Color DARK GRAY.
770  x_color[vpColor::id_darkGray] = 252;
771  xcolor.pixel = x_color[vpColor::id_darkGray] ;
772  xcolor.red = 256 * 64;
773  xcolor.green = 256 * 64;
774  xcolor.blue = 256 * 64;
775  XStoreColor ( display, lut, &xcolor );
776 
777  // Color LIGHT RED.
778  x_color[vpColor::id_lightRed] = 251;
779  xcolor.pixel = x_color[vpColor::id_lightRed] ;
780  xcolor.red = 256 * 255;
781  xcolor.green = 256 * 140;
782  xcolor.blue = 256 * 140;
783  XStoreColor ( display, lut, &xcolor );
784 
785  // Color RED.
786  x_color[vpColor::id_red] = 250;
787  xcolor.pixel = x_color[vpColor::id_red] ;
788  xcolor.red = 256 * 255;
789  xcolor.green = 0;
790  xcolor.blue = 0;
791  XStoreColor ( display, lut, &xcolor );
792 
793  // Color DARK RED.
794  x_color[vpColor::id_darkRed] = 249;
795  xcolor.pixel = x_color[vpColor::id_darkRed] ;
796  xcolor.red = 256 * 128;
797  xcolor.green = 0;
798  xcolor.blue = 0;
799  XStoreColor ( display, lut, &xcolor );
800 
801  // Color LIGHT GREEN.
802  x_color[vpColor::id_lightGreen] = 248;
803  xcolor.pixel = x_color[vpColor::id_lightGreen] ;
804  xcolor.red = 256 * 140;
805  xcolor.green = 256 * 255;
806  xcolor.blue = 256 * 140;
807  XStoreColor ( display, lut, &xcolor );
808 
809  // Color GREEN.
810  x_color[vpColor::id_green] = 247;
811  xcolor.pixel = x_color[vpColor::id_green];
812  xcolor.red = 0;
813  xcolor.green = 256 * 255;
814  xcolor.blue = 0;
815  XStoreColor ( display, lut, &xcolor );
816 
817  // Color DARK GREEN.
818  x_color[vpColor::id_darkGreen] = 246;
819  xcolor.pixel = x_color[vpColor::id_darkGreen] ;
820  xcolor.red = 0;
821  xcolor.green = 256 * 128;
822  xcolor.blue = 0;
823  XStoreColor ( display, lut, &xcolor );
824 
825  // Color LIGHT BLUE.
826  x_color[vpColor::id_lightBlue] = 245;
827  xcolor.pixel = x_color[vpColor::id_lightBlue] ;
828  xcolor.red = 256 * 140;
829  xcolor.green = 256 * 140;
830  xcolor.blue = 256 * 255;
831  XStoreColor ( display, lut, &xcolor );
832 
833  // Color BLUE.
834  x_color[vpColor::id_blue] = 244;
835  xcolor.pixel = x_color[vpColor::id_blue];
836  xcolor.red = 0;
837  xcolor.green = 0;
838  xcolor.blue = 256 * 255;
839  XStoreColor ( display, lut, &xcolor );
840 
841  // Color DARK BLUE.
842  x_color[vpColor::id_darkBlue] = 243;
843  xcolor.pixel = x_color[vpColor::id_darkBlue] ;
844  xcolor.red = 0;
845  xcolor.green = 0;
846  xcolor.blue = 256 * 128;
847  XStoreColor ( display, lut, &xcolor );
848 
849  // Color YELLOW.
850  x_color[vpColor::id_yellow] = 242;
851  xcolor.pixel = x_color[vpColor::id_yellow];
852  xcolor.red = 256 * 255;
853  xcolor.green = 256 * 255;
854  xcolor.blue = 0;
855  XStoreColor ( display, lut, &xcolor );
856 
857  // Color ORANGE.
858  x_color[vpColor::id_orange] = 241;
859  xcolor.pixel = x_color[vpColor::id_orange];
860  xcolor.red = 256 * 255;
861  xcolor.green = 256 * 165;
862  xcolor.blue = 0;
863  XStoreColor ( display, lut, &xcolor );
864 
865  // Color CYAN.
866  x_color[vpColor::id_cyan] = 240;
867  xcolor.pixel = x_color[vpColor::id_cyan];
868  xcolor.red = 0;
869  xcolor.green = 256 * 255;
870  xcolor.blue = 256 * 255;
871  XStoreColor ( display, lut, &xcolor );
872 
873  // Color PURPLE.
874  x_color[vpColor::id_purple] = 239;
875  xcolor.pixel = x_color[vpColor::id_purple];
876  xcolor.red = 256 * 128;
877  xcolor.green = 0;
878  xcolor.blue = 256 * 128;
879  XStoreColor ( display, lut, &xcolor );
880 
881  break;
882 
883  case 16:
884  case 24:
885  {
886  xcolor.flags = DoRed | DoGreen | DoBlue ;
887 
888  // Couleur BLACK.
889  xcolor.pad = 0;
890  xcolor.red = 0;
891  xcolor.green = 0;
892  xcolor.blue = 0;
893  XAllocColor ( display, lut, &xcolor );
894  x_color[vpColor::id_black] = xcolor.pixel;
895 
896  // Couleur WHITE.
897  xcolor.pad = 0;
898  xcolor.red = 256* 255;
899  xcolor.green = 256* 255;
900  xcolor.blue = 256* 255;
901  XAllocColor ( display, lut, &xcolor );
902  x_color[vpColor::id_white] = xcolor.pixel;
903 
904  // Couleur LIGHT GRAY.
905  xcolor.pad = 0;
906  xcolor.red = 256 * 192;
907  xcolor.green = 256 * 192;
908  xcolor.blue = 256 * 192;
909  XAllocColor ( display, lut, &xcolor );
910  x_color[vpColor::id_lightGray] = xcolor.pixel;
911 
912  // Couleur GRAY.
913  xcolor.pad = 0;
914  xcolor.red = 256 * 128;
915  xcolor.green = 256 * 128;
916  xcolor.blue = 256 * 128;
917  XAllocColor ( display, lut, &xcolor );
918  x_color[vpColor::id_gray] = xcolor.pixel;
919 
920  // Couleur DARK GRAY.
921  xcolor.pad = 0;
922  xcolor.red = 256 * 64;
923  xcolor.green = 256 * 64;
924  xcolor.blue = 256 * 64;
925  XAllocColor ( display, lut, &xcolor );
926  x_color[vpColor::id_darkGray] = xcolor.pixel;
927 
928  // Couleur LIGHT RED.
929  xcolor.pad = 0;
930  xcolor.red = 256 * 255;
931  xcolor.green = 256 * 140;
932  xcolor.blue = 256 * 140;
933  XAllocColor ( display, lut, &xcolor );
934  x_color[vpColor::id_lightRed] = xcolor.pixel;
935 
936  // Couleur RED.
937  xcolor.pad = 0;
938  xcolor.red = 256* 255;
939  xcolor.green = 0;
940  xcolor.blue = 0;
941  XAllocColor ( display, lut, &xcolor );
942  x_color[vpColor::id_red] = xcolor.pixel;
943 
944  // Couleur DARK RED.
945  xcolor.pad = 0;
946  xcolor.red = 256* 128;
947  xcolor.green = 0;
948  xcolor.blue = 0;
949  XAllocColor ( display, lut, &xcolor );
950  x_color[vpColor::id_darkRed] = xcolor.pixel;
951 
952  // Couleur LIGHT GREEN.
953  xcolor.pad = 0;
954  xcolor.red = 256 * 140;
955  xcolor.green = 256 * 255;
956  xcolor.blue = 256 * 140;
957  XAllocColor ( display, lut, &xcolor );
958  x_color[vpColor::id_lightGreen] = xcolor.pixel;
959 
960  // Couleur GREEN.
961  xcolor.pad = 0;
962  xcolor.red = 0;
963  xcolor.green = 256*255;
964  xcolor.blue = 0;
965  XAllocColor ( display, lut, &xcolor );
966  x_color[vpColor::id_green] = xcolor.pixel;
967 
968  // Couleur DARK GREEN.
969  xcolor.pad = 0;
970  xcolor.red = 0;
971  xcolor.green = 256* 128;
972  xcolor.blue = 0;
973  XAllocColor ( display, lut, &xcolor );
974  x_color[vpColor::id_darkGreen] = xcolor.pixel;
975 
976  // Couleur LIGHT Blue.
977  xcolor.pad = 0;
978  xcolor.red = 256 * 140;
979  xcolor.green = 256 * 140;
980  xcolor.blue = 256 * 255;
981  XAllocColor ( display, lut, &xcolor );
982  x_color[vpColor::id_lightBlue] = xcolor.pixel;
983 
984  // Couleur BLUE.
985  xcolor.pad = 0;
986  xcolor.red = 0;
987  xcolor.green = 0;
988  xcolor.blue = 256* 255;
989  XAllocColor ( display, lut, &xcolor );
990  x_color[vpColor::id_blue] = xcolor.pixel;
991 
992  // Couleur DARK BLUE.
993  xcolor.pad = 0;
994  xcolor.red = 0;
995  xcolor.green = 0;
996  xcolor.blue = 256* 128;
997  XAllocColor ( display, lut, &xcolor );
998  x_color[vpColor::id_darkBlue] = xcolor.pixel;
999 
1000  // Couleur YELLOW.
1001  xcolor.pad = 0;
1002  xcolor.red = 256 * 255;
1003  xcolor.green = 256 * 255;
1004  xcolor.blue = 0;
1005  XAllocColor ( display, lut, &xcolor );
1006  x_color[vpColor::id_yellow] = xcolor.pixel;
1007 
1008  // Couleur ORANGE.
1009  xcolor.pad = 0;
1010  xcolor.red = 256 * 255;
1011  xcolor.green = 256 * 165;
1012  xcolor.blue = 0;
1013  XAllocColor ( display, lut, &xcolor );
1014  x_color[vpColor::id_orange] = xcolor.pixel;
1015 
1016  // Couleur CYAN.
1017  xcolor.pad = 0;
1018  xcolor.red = 0;
1019  xcolor.green = 256 * 255;
1020  xcolor.blue = 256 * 255;
1021  XAllocColor ( display, lut, &xcolor );
1022  x_color[vpColor::id_cyan] = xcolor.pixel;
1023 
1024  // Couleur PURPLE.
1025  xcolor.pad = 0;
1026  xcolor.red = 256 * 128;
1027  xcolor.green = 0;
1028  xcolor.blue = 256 * 128;
1029  XAllocColor ( display, lut, &xcolor );
1030  x_color[vpColor::id_purple] = xcolor.pixel;
1031  break;
1032  }
1033  }
1034 
1035  XSetStandardProperties ( display, window, this->title_.c_str(), this->title_.c_str(), None, 0, 0, &hints );
1036  XMapWindow ( display, window ) ;
1037  // Selection des evenements.
1038  XSelectInput ( display, window,
1039  ExposureMask |
1040  ButtonPressMask | ButtonReleaseMask |
1041  KeyPressMask | KeyReleaseMask |
1042  StructureNotifyMask |
1043  PointerMotionMask);
1044 
1045  // Creation du contexte graphique
1046  values.plane_mask = AllPlanes;
1047  values.fill_style = FillSolid;
1048  values.foreground = WhitePixel ( display, screen );
1049  values.background = BlackPixel ( display, screen );
1050  context = XCreateGC ( display, window,
1051  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1052  &values );
1053 
1054  if ( context == NULL )
1055  {
1056  vpERROR_TRACE ( "Can't create graphics context." );
1058  "Can't create graphics context" ) ) ;
1059  }
1060 
1061  // Pixmap creation.
1062  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1063 
1064  do
1065  XNextEvent ( display, &event );
1066  while ( event.xany.type != Expose );
1067 
1068 
1069  {
1070  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1071  screen_depth, ZPixmap, 0, NULL,
1072  I.getWidth() , I.getHeight(), XBitmapPad ( display ), 0 );
1073 
1074 
1075  Ximage->data = ( char * ) malloc ( I.getWidth() * I.getHeight()
1076  * (unsigned int)Ximage->bits_per_pixel / 8 );
1077  ximage_data_init = true;
1078 
1079  }
1080  displayHasBeenInitialized = true ;
1081 
1082  XSync ( display, true );
1083 
1084  XStoreName ( display, window, title_.c_str() );
1085 
1086  I.display = this ;
1087 }
1088 
1089 
1097 void vpDisplayX::init ( unsigned int w, unsigned int h, int x, int y, const char *title )
1098 {
1099  /* setup X11 ------------------------------------------------------------- */
1100  this->width = w;
1101  this->height = h;
1102 
1103  XSizeHints hints;
1104 
1105  if (x != -1)
1106  windowXPosition = x ;
1107  if (y != -1)
1108  windowYPosition = y ;
1109  // Positionnement de la fenetre dans l'�cran.
1110  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
1111  {
1112  hints.flags = 0;
1113  }
1114  else
1115  {
1116  hints.flags = USPosition;
1117  hints.x = windowXPosition;
1118  hints.y = windowYPosition;
1119  }
1120 
1121  if (title != NULL)
1122  title_ = std::string(title);
1123  else
1124  title_ = std::string(" ");
1125 
1126  if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
1127  {
1128  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
1130  "Can't connect display on server." ) ) ;
1131  }
1132 
1133  screen = DefaultScreen ( display );
1134  lut = DefaultColormap ( display, screen );
1135  screen_depth = (unsigned int)DefaultDepth ( display, screen );
1136 
1137  vpTRACE ( "Screen depth: %d\n", screen_depth );
1138 
1139  if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
1141  width, height, 1,
1142  BlackPixel ( display, screen ),
1143  WhitePixel ( display, screen ) ) ) == 0 )
1144  {
1145  vpERROR_TRACE ( "Can't create window." );
1147  "Can't create window." ) ) ;
1148  }
1149 
1150 
1151  //
1152  // Create color table for 8 and 16 bits screen
1153  //
1154  if ( screen_depth == 8 )
1155  {
1156  lut = XCreateColormap ( display, window,
1157  DefaultVisual ( display, screen ), AllocAll ) ;
1158  xcolor.flags = DoRed | DoGreen | DoBlue ;
1159 
1160  for ( unsigned int i = 0 ; i < 256 ; i++ )
1161  {
1162  xcolor.pixel = i ;
1163  xcolor.red = 256 * i;
1164  xcolor.green = 256 * i;
1165  xcolor.blue = 256 * i;
1166  XStoreColor ( display, lut, &xcolor );
1167  }
1168 
1169  XSetWindowColormap ( display, window, lut ) ;
1170  XInstallColormap ( display, lut ) ;
1171  }
1172 
1173  else if ( screen_depth == 16 )
1174  {
1175  for ( unsigned int i = 0; i < 256; i ++ )
1176  {
1177  xcolor.pad = 0;
1178  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1179  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
1180  {
1181  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
1183  "Can't allocate 256 colors." ) ) ;
1184  }
1185  colortable[i] = xcolor.pixel;
1186  }
1187 
1188  XSetWindowColormap ( display, window, lut ) ;
1189  XInstallColormap ( display, lut ) ;
1190 
1191  }
1192 
1193  vpColor pcolor; // predefined colors
1194 
1195  //
1196  // Create colors for overlay
1197  //
1198  switch ( screen_depth )
1199  {
1200 
1201  case 8:
1202  // Color BLACK: default set to 0
1203 
1204  // Color WHITE: default set to 255
1205 
1206  // Color LIGHT GRAY.
1207  pcolor = vpColor::lightGray;
1208  xcolor.pixel = 254 ; // affected to 254
1209  xcolor.red = 256 * pcolor.R;
1210  xcolor.green = 256 * pcolor.G;
1211  xcolor.blue = 256 * pcolor.B;
1212  XStoreColor ( display, lut, &xcolor );
1213 
1214  // Color GRAY.
1215  pcolor = vpColor::gray;
1216  xcolor.pixel = 253 ; // affected to 253
1217  xcolor.red = 256 * pcolor.R;
1218  xcolor.green = 256 * pcolor.G;
1219  xcolor.blue = 256 * pcolor.B;
1220  XStoreColor ( display, lut, &xcolor );
1221 
1222  // Color DARK GRAY.
1223  pcolor = vpColor::darkGray;
1224  xcolor.pixel = 252 ; // affected to 252
1225  xcolor.red = 256 * pcolor.R;
1226  xcolor.green = 256 * pcolor.G;
1227  xcolor.blue = 256 * pcolor.B;
1228  XStoreColor ( display, lut, &xcolor );
1229 
1230  // Color LIGHT RED.
1231  pcolor = vpColor::lightRed;
1232  xcolor.pixel = 251 ; // affected to 251
1233  xcolor.red = 256 * pcolor.R;
1234  xcolor.green = 256 * pcolor.G;
1235  xcolor.blue = 256 * pcolor.B;
1236  XStoreColor ( display, lut, &xcolor );
1237 
1238  // Color RED.
1239  pcolor = vpColor::red;
1240  xcolor.pixel = 250 ; // affected to 250
1241  xcolor.red = 256 * pcolor.R;
1242  xcolor.green = 256 * pcolor.G;
1243  xcolor.blue = 256 * pcolor.B;
1244  XStoreColor ( display, lut, &xcolor );
1245 
1246  // Color DARK RED.
1247  pcolor = vpColor::darkRed;
1248  xcolor.pixel = 249 ; // affected to 249
1249  xcolor.red = 256 * pcolor.R;
1250  xcolor.green = 256 * pcolor.G;
1251  xcolor.blue = 256 * pcolor.B;
1252  XStoreColor ( display, lut, &xcolor );
1253 
1254  // Color LIGHT GREEN.
1255  pcolor = vpColor::lightGreen;
1256  xcolor.pixel = 248 ; // affected to 248
1257  xcolor.red = 256 * pcolor.R;
1258  xcolor.green = 256 * pcolor.G;
1259  xcolor.blue = 256 * pcolor.B;
1260  XStoreColor ( display, lut, &xcolor );
1261 
1262  // Color GREEN.
1263  pcolor = vpColor::green;
1264  xcolor.pixel = 247; // affected to 247
1265  xcolor.red = 256 * pcolor.R;
1266  xcolor.green = 256 * pcolor.G;
1267  xcolor.blue = 256 * pcolor.B;
1268  XStoreColor ( display, lut, &xcolor );
1269 
1270  // Color DARK GREEN.
1271  pcolor = vpColor::darkGreen;
1272  xcolor.pixel = 246 ; // affected to 246
1273  xcolor.red = 256 * pcolor.R;
1274  xcolor.green = 256 * pcolor.G;
1275  xcolor.blue = 256 * pcolor.B;
1276  XStoreColor ( display, lut, &xcolor );
1277 
1278  // Color LIGHT BLUE.
1279  pcolor = vpColor::lightBlue;
1280  xcolor.pixel = 245 ; // affected to 245
1281  xcolor.red = 256 * pcolor.R;
1282  xcolor.green = 256 * pcolor.G;
1283  xcolor.blue = 256 * pcolor.B;
1284  XStoreColor ( display, lut, &xcolor );
1285 
1286  // Color BLUE.
1287  pcolor = vpColor::blue;
1288  xcolor.pixel = 244; // affected to 244
1289  xcolor.red = 256 * pcolor.R;
1290  xcolor.green = 256 * pcolor.G;
1291  xcolor.blue = 256 * pcolor.B;
1292  XStoreColor ( display, lut, &xcolor );
1293 
1294  // Color DARK BLUE.
1295  pcolor = vpColor::darkBlue;
1296  xcolor.pixel = 243 ; // affected to 243
1297  xcolor.red = 256 * pcolor.R;
1298  xcolor.green = 256 * pcolor.G;
1299  xcolor.blue = 256 * pcolor.B;
1300  XStoreColor ( display, lut, &xcolor );
1301 
1302  // Color YELLOW.
1303  pcolor = vpColor::yellow;
1304  xcolor.pixel = 242; // affected to 242
1305  xcolor.red = 256 * pcolor.R;
1306  xcolor.green = 256 * pcolor.G;
1307  xcolor.blue = 256 * pcolor.B;
1308  XStoreColor ( display, lut, &xcolor );
1309 
1310  // Color ORANGE.
1311  pcolor = vpColor::orange;
1312  xcolor.pixel = 241; // affected to 241
1313  xcolor.red = 256 * pcolor.R;
1314  xcolor.green = 256 * pcolor.G;
1315  xcolor.blue = 256 * pcolor.B;
1316  XStoreColor ( display, lut, &xcolor );
1317 
1318  // Color CYAN.
1319  pcolor = vpColor::cyan;
1320  xcolor.pixel = 240; // affected to 240
1321  xcolor.red = 256 * pcolor.R;
1322  xcolor.green = 256 * pcolor.G;
1323  xcolor.blue = 256 * pcolor.B;
1324  XStoreColor ( display, lut, &xcolor );
1325 
1326  // Color PURPLE.
1327  pcolor = vpColor::purple;
1328  xcolor.pixel = 239; // affected to 239
1329  xcolor.red = 256 * pcolor.R;
1330  xcolor.green = 256 * pcolor.G;
1331  xcolor.blue = 256 * pcolor.B;
1332  XStoreColor ( display, lut, &xcolor );
1333 
1334  break;
1335 
1336  case 16:
1337  case 24:
1338  {
1339  xcolor.flags = DoRed | DoGreen | DoBlue ;
1340 
1341  // Couleur BLACK.
1342  pcolor = vpColor::black;
1343  xcolor.pad = 0;
1344  xcolor.red = 256 * pcolor.R;
1345  xcolor.green = 256 * pcolor.G;
1346  xcolor.blue = 256 * pcolor.B;
1347  XAllocColor ( display, lut, &xcolor );
1348  x_color[vpColor::id_black] = xcolor.pixel;
1349 
1350  // Color WHITE.
1351  pcolor = vpColor::white;
1352  xcolor.pad = 0;
1353  xcolor.red = 256 * pcolor.R;
1354  xcolor.green = 256 * pcolor.G;
1355  xcolor.blue = 256 * pcolor.B;
1356  XAllocColor ( display, lut, &xcolor );
1357  x_color[vpColor::id_white] = xcolor.pixel;
1358 
1359  // Color LIGHT GRAY.
1360  pcolor = vpColor::lightGray;
1361  xcolor.pad = 0;
1362  xcolor.red = 256 * pcolor.R;
1363  xcolor.green = 256 * pcolor.G;
1364  xcolor.blue = 256 * pcolor.B;
1365  XAllocColor ( display, lut, &xcolor );
1366  x_color[vpColor::id_lightGray] = xcolor.pixel;
1367 
1368  // Color GRAY.
1369  pcolor = vpColor::gray;
1370  xcolor.pad = 0;
1371  xcolor.red = 256 * pcolor.R;
1372  xcolor.green = 256 * pcolor.G;
1373  xcolor.blue = 256 * pcolor.B;
1374  XAllocColor ( display, lut, &xcolor );
1375  x_color[vpColor::id_gray] = xcolor.pixel;
1376 
1377  // Color DARK GRAY.
1378  pcolor = vpColor::darkGray;
1379  xcolor.pad = 0;
1380  xcolor.red = 256 * pcolor.R;
1381  xcolor.green = 256 * pcolor.G;
1382  xcolor.blue = 256 * pcolor.B;
1383  XAllocColor ( display, lut, &xcolor );
1384  x_color[vpColor::id_darkGray] = xcolor.pixel;
1385 
1386  // Color LIGHT RED.
1387  pcolor = vpColor::lightRed;
1388  xcolor.pad = 0;
1389  xcolor.red = 256 * pcolor.R;
1390  xcolor.green = 256 * pcolor.G;
1391  xcolor.blue = 256 * pcolor.B;
1392  XAllocColor ( display, lut, &xcolor );
1393  x_color[vpColor::id_lightRed] = xcolor.pixel;
1394 
1395  // Color RED.
1396  pcolor = vpColor::red;
1397  xcolor.pad = 0;
1398  xcolor.red = 256 * pcolor.R;
1399  xcolor.green = 256 * pcolor.G;
1400  xcolor.blue = 256 * pcolor.B;
1401  XAllocColor ( display, lut, &xcolor );
1402  x_color[vpColor::id_red] = xcolor.pixel;
1403 
1404  // Color DARK RED.
1405  pcolor = vpColor::darkRed;
1406  xcolor.pad = 0;
1407  xcolor.red = 256 * pcolor.R;
1408  xcolor.green = 256 * pcolor.G;
1409  xcolor.blue = 256 * pcolor.B;
1410  XAllocColor ( display, lut, &xcolor );
1411  x_color[vpColor::id_darkRed] = xcolor.pixel;
1412 
1413  // Color LIGHT GREEN.
1414  pcolor = vpColor::lightGreen;
1415  xcolor.pad = 0;
1416  xcolor.red = 256 * pcolor.R;
1417  xcolor.green = 256 * pcolor.G;
1418  xcolor.blue = 256 * pcolor.B;
1419  XAllocColor ( display, lut, &xcolor );
1420  x_color[vpColor::id_lightGreen] = xcolor.pixel;
1421 
1422  // Color GREEN.
1423  pcolor = vpColor::green;
1424  xcolor.pad = 0;
1425  xcolor.red = 256 * pcolor.R;
1426  xcolor.green = 256 * pcolor.G;
1427  xcolor.blue = 256 * pcolor.B;
1428  XAllocColor ( display, lut, &xcolor );
1429  x_color[vpColor::id_green] = xcolor.pixel;
1430 
1431  // Color DARK GREEN.
1432  pcolor = vpColor::darkGreen;
1433  xcolor.pad = 0;
1434  xcolor.red = 256 * pcolor.R;
1435  xcolor.green = 256 * pcolor.G;
1436  xcolor.blue = 256 * pcolor.B;
1437  XAllocColor ( display, lut, &xcolor );
1438  x_color[vpColor::id_darkGreen] = xcolor.pixel;
1439 
1440  // Color LIGHT BLUE.
1441  pcolor = vpColor::lightBlue;
1442  xcolor.pad = 0;
1443  xcolor.red = 256 * pcolor.R;
1444  xcolor.green = 256 * pcolor.G;
1445  xcolor.blue = 256 * pcolor.B;
1446  XAllocColor ( display, lut, &xcolor );
1447  x_color[vpColor::id_lightBlue] = xcolor.pixel;
1448 
1449  // Color BLUE.
1450  pcolor = vpColor::blue;
1451  xcolor.pad = 0;
1452  xcolor.red = 256 * pcolor.R;
1453  xcolor.green = 256 * pcolor.G;
1454  xcolor.blue = 256 * pcolor.B;
1455  XAllocColor ( display, lut, &xcolor );
1456  x_color[vpColor::id_blue] = xcolor.pixel;
1457 
1458  // Color DARK BLUE.
1459  pcolor = vpColor::darkBlue;
1460  xcolor.pad = 0;
1461  xcolor.red = 256 * pcolor.R;
1462  xcolor.green = 256 * pcolor.G;
1463  xcolor.blue = 256 * pcolor.B;
1464  XAllocColor ( display, lut, &xcolor );
1465  x_color[vpColor::id_darkBlue] = xcolor.pixel;
1466 
1467  // Color YELLOW.
1468  pcolor = vpColor::yellow;
1469  xcolor.pad = 0;
1470  xcolor.red = 256 * pcolor.R;
1471  xcolor.green = 256 * pcolor.G;
1472  xcolor.blue = 256 * pcolor.B;
1473  XAllocColor ( display, lut, &xcolor );
1474  x_color[vpColor::id_yellow] = xcolor.pixel;
1475 
1476  // Color ORANGE.
1477  pcolor = vpColor::orange;
1478  xcolor.pad = 0;
1479  xcolor.red = 256 * pcolor.R;
1480  xcolor.green = 256 * pcolor.G;
1481  xcolor.blue = 256 * pcolor.B;
1482  XAllocColor ( display, lut, &xcolor );
1483  x_color[vpColor::id_orange] = xcolor.pixel;
1484 
1485  // Color CYAN.
1486  pcolor = vpColor::cyan;
1487  xcolor.pad = 0;
1488  xcolor.red = 256 * pcolor.R;
1489  xcolor.green = 256 * pcolor.G;
1490  xcolor.blue = 256 * pcolor.B;
1491  XAllocColor ( display, lut, &xcolor );
1492  x_color[vpColor::id_cyan] = xcolor.pixel;
1493 
1494  // Color PURPLE.
1495  pcolor = vpColor::purple;
1496  xcolor.pad = 0;
1497  xcolor.red = 256 * pcolor.R;
1498  xcolor.green = 256 * pcolor.G;
1499  xcolor.blue = 256 * pcolor.B;
1500  XAllocColor ( display, lut, &xcolor );
1501  x_color[vpColor::id_purple] = xcolor.pixel;
1502  break;
1503  }
1504  }
1505 
1506  XSetStandardProperties ( display, window, this->title_.c_str(), this->title_.c_str(), None, 0, 0, &hints );
1507  XMapWindow ( display, window ) ;
1508  // Selection des evenements.
1509  XSelectInput ( display, window,
1510  ExposureMask |
1511  ButtonPressMask | ButtonReleaseMask |
1512  KeyPressMask | KeyReleaseMask |
1513  StructureNotifyMask |
1514  PointerMotionMask);
1515 
1516  /* Creation du contexte graphique */
1517  values.plane_mask = AllPlanes;
1518  values.fill_style = FillSolid;
1519  values.foreground = WhitePixel ( display, screen );
1520  values.background = BlackPixel ( display, screen );
1521  context = XCreateGC ( display, window,
1522  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1523  &values );
1524 
1525  if ( context == NULL )
1526  {
1527  vpERROR_TRACE ( "Can't create graphics context." );
1529  "Can't create graphics context" ) ) ;
1530  }
1531 
1532  // Pixmap creation.
1533  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1534 
1535  do
1536  XNextEvent ( display, &event );
1537  while ( event.xany.type != Expose );
1538 
1539  {
1540  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1541  screen_depth, ZPixmap, 0, NULL,
1542  width, height, XBitmapPad ( display ), 0 );
1543 
1544  Ximage->data = ( char * ) malloc ( width * height
1545  * (unsigned int)Ximage->bits_per_pixel / 8 );
1546  ximage_data_init = true;
1547  }
1548  displayHasBeenInitialized = true ;
1549 
1550  XSync ( display, true );
1551 
1552  XStoreName ( display, window, title_.c_str() );
1553 }
1554 
1569 void vpDisplayX::setFont( const char* font )
1570 {
1572  {
1573  if (font!=NULL)
1574  {
1575  try
1576  {
1577  Font stringfont;
1578  stringfont = XLoadFont (display, font) ; //"-adobe-times-bold-r-normal--18*");
1579  XSetFont (display, context, stringfont);
1580  }
1581  catch(...)
1582  {
1583  vpERROR_TRACE ( "Bad font " ) ;
1585  }
1586  }
1587  }
1588  else
1589  {
1590  vpERROR_TRACE ( "X not initialized " ) ;
1592  "X not initialized" ) ) ;
1593  }
1594 }
1595 
1600 void
1601 vpDisplayX::setTitle ( const char *title )
1602 {
1604  {
1605  if(title != NULL)
1606  title_ = std::string(title);
1607  else
1608  title_ = std::string(" ");
1609  XStoreName ( display, window, title_.c_str() );
1610  }
1611  else
1612  {
1613  vpERROR_TRACE ( "X not initialized " ) ;
1615  "X not initialized" ) ) ;
1616  }
1617 }
1618 
1627 void vpDisplayX::setWindowPosition(int winx, int winy)
1628 {
1629  if ( displayHasBeenInitialized ) {
1630  XMoveWindow(display, window, winx, winy);
1631  }
1632  else
1633  {
1634  vpERROR_TRACE ( "X not initialized " ) ;
1636  "X not initialized" ) ) ;
1637  }
1638 }
1639 
1652 {
1653 
1655  {
1656  switch ( screen_depth )
1657  {
1658  case 8:
1659  {
1660  unsigned char *src_8 = NULL;
1661  unsigned char *dst_8 = NULL;
1662  src_8 = ( unsigned char * ) I.bitmap;
1663  dst_8 = ( unsigned char * ) Ximage->data;
1664  // Correction de l'image de facon a liberer les niveaux de gris
1665  // ROUGE, VERT, BLEU, JAUNE
1666  {
1667  unsigned int i = 0;
1668  unsigned int size_ = width * height;
1669  unsigned char nivGris;
1670  unsigned char nivGrisMax = 255 - vpColor::id_unknown;
1671 
1672  while ( i < size_ )
1673  {
1674  nivGris = src_8[i] ;
1675  if ( nivGris > nivGrisMax )
1676  dst_8[i] = 255;
1677  else
1678  dst_8[i] = nivGris;
1679  i++ ;
1680  }
1681  }
1682 
1683  // Affichage de l'image dans la Pixmap.
1684  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1685  XSetWindowBackgroundPixmap ( display, window, pixmap );
1686 // XClearWindow ( display, window );
1687 // XSync ( display,1 );
1688  break;
1689  }
1690  case 16:
1691  {
1692  unsigned short *dst_16 = NULL;
1693  dst_16 = ( unsigned short* ) Ximage->data;
1694 
1695  for ( unsigned int i = 0; i < height ; i++ )
1696  {
1697  for ( unsigned int j=0 ; j < width; j++ )
1698  {
1699  * ( dst_16+ ( i*width+j ) ) = ( unsigned short ) colortable[I[i][j]] ;
1700  }
1701  }
1702 
1703  // Affichage de l'image dans la Pixmap.
1704  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1705  XSetWindowBackgroundPixmap ( display, window, pixmap );
1706 // XClearWindow ( display, window );
1707 // XSync ( display,1 );
1708  break;
1709  }
1710 
1711  case 24:
1712  default:
1713  {
1714  unsigned char *dst_32 = NULL;
1715  unsigned int size_ = width * height ;
1716  dst_32 = ( unsigned char* ) Ximage->data;
1717  unsigned char *bitmap = I.bitmap ;
1718  unsigned char *n = I.bitmap + size_;
1719  //for (unsigned int i = 0; i < size; i++) // suppression de l'iterateur i
1720  while ( bitmap < n )
1721  {
1722  unsigned char val = * ( bitmap++ );
1723  * ( dst_32 ++ ) = val; // Composante Rouge.
1724  * ( dst_32 ++ ) = val; // Composante Verte.
1725  * ( dst_32 ++ ) = val; // Composante Bleue.
1726  * ( dst_32 ++ ) = val;
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  }
1738  else
1739  {
1740  vpERROR_TRACE ( "X not initialized " ) ;
1742  "X not initialized" ) ) ;
1743  }
1744 }
1757 {
1758 
1760  {
1761 
1762  switch ( screen_depth )
1763  {
1764  case 24:
1765  case 32:
1766  {
1767  /*
1768  * 32-bit source, 24/32-bit destination
1769  */
1770 
1771  unsigned char *dst_32 = NULL;
1772  dst_32 = ( unsigned char* ) Ximage->data;
1773  vpRGBa* bitmap = I.bitmap;
1774  unsigned int sizeI = I.getWidth() * I.getHeight();
1775 #ifdef BIGENDIAN
1776  // little indian/big indian
1777  for ( unsigned int i = 0; i < sizeI ; i++ )
1778  {
1779  *(dst_32++) = bitmap->A;
1780  *(dst_32++) = bitmap->R;
1781  *(dst_32++) = bitmap->G;
1782  *(dst_32++) = bitmap->B;
1783  bitmap++;
1784  }
1785 #else
1786  for ( unsigned int i = 0; i < sizeI; i++ )
1787  {
1788  *(dst_32++) = bitmap->B;
1789  *(dst_32++) = bitmap->G;
1790  *(dst_32++) = bitmap->R;
1791  *(dst_32++) = bitmap->A;
1792  bitmap++;
1793  }
1794 #endif
1795  // Affichage de l'image dans la Pixmap.
1796  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1797  XSetWindowBackgroundPixmap ( display, window, pixmap );
1798 // XClearWindow ( display, window );
1799 // XSync ( display,1 );
1800  break;
1801 
1802  }
1803  default:
1804  vpERROR_TRACE ( "Unsupported depth (%d bpp) for color display",
1805  screen_depth ) ;
1807  "Unsupported depth for color display" ) ) ;
1808  }
1809  }
1810  else
1811  {
1812  vpERROR_TRACE ( "X not initialized " ) ;
1814  "X not initialized" ) ) ;
1815  }
1816 }
1817 
1829 void vpDisplayX::displayImage ( const unsigned char *I )
1830 {
1831  unsigned char *dst_32 = NULL;
1832 
1834  {
1835 
1836  dst_32 = ( unsigned char* ) Ximage->data;
1837 
1838  for ( unsigned int i = 0; i < width * height; i++ )
1839  {
1840  * ( dst_32 ++ ) = *I; // red component.
1841  * ( dst_32 ++ ) = *I; // green component.
1842  * ( dst_32 ++ ) = *I; // blue component.
1843  * ( dst_32 ++ ) = *I; // luminance component.
1844  I++;
1845  }
1846 
1847  // Affichage de l'image dans la Pixmap.
1848  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1849  XSetWindowBackgroundPixmap ( display, window, pixmap );
1850 // XClearWindow ( display, window );
1851 // XSync ( display,1 );
1852  }
1853  else
1854  {
1855  vpERROR_TRACE ( "X not initialized " ) ;
1857  "X not initialized" ) ) ;
1858  }
1859 }
1860 
1861 
1878  const unsigned int w, const unsigned int h )
1879 {
1881  {
1882  switch ( screen_depth )
1883  {
1884  case 8:
1885  {
1886  unsigned char *src_8 = NULL;
1887  unsigned char *dst_8 = NULL;
1888  src_8 = ( unsigned char * ) I.bitmap;
1889  dst_8 = ( unsigned char * ) Ximage->data;
1890  // Correction de l'image de facon a liberer les niveaux de gris
1891  // ROUGE, VERT, BLEU, JAUNE
1892  {
1893  //int size = width * height;
1894  unsigned char nivGris;
1895  unsigned char nivGrisMax = 255 - vpColor::id_unknown;
1896 
1897  //unsigned int iwidth = I.getWidth();
1898  unsigned int iwidth = I.getWidth();
1899 
1900  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1901  dst_8 = dst_8 + (int)(iP.get_i()*this->height+ iP.get_j());
1902 
1903  unsigned int i = 0;
1904  while (i < h)
1905  {
1906  unsigned int j = 0;
1907  while (j < w)
1908  {
1909  nivGris = *(src_8+j);
1910  if ( nivGris > nivGrisMax )
1911  *(dst_8+j) = 255;
1912  else
1913  *(dst_8+j) = nivGris;
1914  j++;
1915  }
1916  src_8 = src_8 + iwidth;
1917  dst_8 = dst_8 + this->height;
1918  i++;
1919  }
1920  }
1921 
1922  // Affichage de l'image dans la Pixmap.
1923  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), w, h );
1924  XSetWindowBackgroundPixmap ( display, window, pixmap );
1925  // XClearWindow ( display, window );
1926  // XSync ( display,1 );
1927  break;
1928  }
1929  case 16:
1930  {
1931  unsigned short *dst_16 = NULL;
1932  dst_16 = ( unsigned short* ) Ximage->data;
1933  unsigned char *src_8 = NULL;
1934  src_8 = ( unsigned char * ) I.bitmap;
1935 
1936  unsigned int iwidth = I.getWidth();
1937 
1938  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1939  dst_16 = dst_16 + (int)(iP.get_i()*this->height+ iP.get_j());
1940 
1941  unsigned int i = 0;
1942  while (i < h)
1943  {
1944  unsigned int j = 0;
1945  while (j < w)
1946  {
1947  *(dst_16+j) = ( unsigned short ) colortable[*(src_8+j)];
1948  j++;
1949  }
1950  src_8 = src_8 + iwidth;
1951  dst_16 = dst_16 + this->height;
1952  i++;
1953  }
1954 
1955  // Affichage de l'image dans la Pixmap.
1956  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), w, h );
1957  XSetWindowBackgroundPixmap ( display, window, pixmap );
1958  // XClearWindow ( display, window );
1959  // XSync ( display,1 );
1960  break;
1961  }
1962 
1963  case 24:
1964  default:
1965  {
1966  unsigned char *dst_32 = NULL;
1967  //unsigned int size = width * height ;
1968  dst_32 = ( unsigned char* ) Ximage->data;
1969  unsigned char *src_8 = I.bitmap ;
1970  //unsigned char *n = I.bitmap + size;
1971 
1972  unsigned int iwidth = I.getWidth();
1973 
1974  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1975  dst_32 = dst_32 + (int)(iP.get_i()*4*this->width+ iP.get_j()*4);
1976 
1977  unsigned int i = 0;
1978  while (i < h)
1979  {
1980  unsigned int j = 0;
1981  while (j < w)
1982  {
1983  unsigned char val = *(src_8+j);
1984  *(dst_32+4*j) = val;
1985  *(dst_32+4*j+1) = val;
1986  *(dst_32+4*j+2) = val;
1987  *(dst_32+4*j+3) = val;
1988  j++;
1989  }
1990  src_8 = src_8 + iwidth;
1991  dst_32 = dst_32 + 4*this->width;
1992  i++;
1993  }
1994 
1995  // Affichage de l'image dans la Pixmap.
1996  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), w, h );
1997  XSetWindowBackgroundPixmap ( display, window, pixmap );
1998  // XClearWindow ( display, window );
1999  // XSync ( display,1 );
2000  break;
2001  }
2002  }
2003  }
2004  else
2005  {
2006  vpERROR_TRACE ( "X not initialized " ) ;
2008  "X not initialized" ) ) ;
2009  }
2010 }
2011 
2012 
2029  const unsigned int w, const unsigned int h )
2030 {
2032  {
2033 
2034  switch ( screen_depth )
2035  {
2036  case 24:
2037  case 32:
2038  {
2039  /*
2040  * 32-bit source, 24/32-bit destination
2041  */
2042 
2043  unsigned char *dst_32 = NULL;
2044  dst_32 = ( unsigned char* ) Ximage->data;
2045  vpRGBa* src_32 = I.bitmap;
2046  //unsigned int sizeI = I.getWidth() * I.getHeight();
2047 
2048  unsigned int iwidth = I.getWidth();
2049 
2050  src_32 = src_32 + (int)(iP.get_i()*iwidth+ iP.get_j());
2051  dst_32 = dst_32 + (int)(iP.get_i()*4*this->width+ iP.get_j()*4);
2052 
2053  unsigned int i = 0;
2054  while (i < h)
2055  {
2056  unsigned int j = 0;
2057  while (j < w)
2058  {
2059 #ifdef BIGENDIAN
2060  *(dst_32+4*j) = (src_32+j)->A;
2061  *(dst_32+4*j+1) = (src_32+j)->R;
2062  *(dst_32+4*j+2) = (src_32+j)->G;
2063  *(dst_32+4*j+3) = (src_32+j)->B;
2064 #else
2065  *(dst_32+4*j) = (src_32+j)->B;
2066  *(dst_32+4*j+1) = (src_32+j)->G;
2067  *(dst_32+4*j+2) = (src_32+j)->R;
2068  *(dst_32+4*j+3) = (src_32+j)->A;
2069 #endif
2070  j++;
2071  }
2072  src_32 = src_32 + iwidth;
2073  dst_32 = dst_32 + 4*this->width;
2074  i++;
2075  }
2076 
2077  // Affichage de l'image dans la Pixmap.
2078  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), w, h );
2079  XSetWindowBackgroundPixmap ( display, window, pixmap );
2080  // XClearWindow ( display, window );
2081  // XSync ( display,1 );
2082  break;
2083 
2084  }
2085  default:
2086  vpERROR_TRACE ( "Unsupported depth (%d bpp) for color display",
2087  screen_depth ) ;
2089  "Unsupported depth for color display" ) ) ;
2090  }
2091  }
2092  else
2093  {
2094  vpERROR_TRACE ( "X not initialized " ) ;
2096  "X not initialized" ) ) ;
2097  }
2098 }
2099 
2108 {
2110  {
2111  if ( ximage_data_init == true )
2112  free ( Ximage->data );
2113 
2114  Ximage->data = NULL;
2115  XDestroyImage ( Ximage );
2116 
2117  XFreePixmap ( display, pixmap );
2118 
2119  XFreeGC ( display, context );
2120  XDestroyWindow ( display, window );
2121  XCloseDisplay ( display );
2122 
2123  displayHasBeenInitialized = false;
2124 
2125  if (x_color != NULL) {
2126  delete [] x_color;
2127  x_color = NULL;
2128  }
2129  }
2130 }
2131 
2132 
2139 {
2141  {
2142  XClearWindow ( display, window );
2143  //XClearArea ( display, window,0,0,100,100,0 );
2144  XFlush ( display );
2145  }
2146  else
2147  {
2148  vpERROR_TRACE ( "X not initialized " ) ;
2150  "X not initialized" ) ) ;
2151  }
2152 }
2153 
2161 void vpDisplayX::flushDisplayROI(const vpImagePoint &iP, const unsigned int w, const unsigned int h)
2162 {
2164  {
2165  //XClearWindow ( display, window );
2166  XClearArea ( display, window,iP.get_u(),iP.get_v(),w,h,0 );
2167  XFlush ( display );
2168  }
2169  else
2170  {
2171  vpERROR_TRACE ( "X not initialized " ) ;
2173  "X not initialized" ) ) ;
2174  }
2175 }
2176 
2177 
2182 void vpDisplayX::clearDisplay ( const vpColor &color )
2183 {
2185  {
2186 
2187  if (color.id < vpColor::id_unknown)
2188  XSetWindowBackground ( display, window, x_color[color.id] );
2189  else {
2190  xcolor.pad = 0;
2191  xcolor.red = 256 * color.R;
2192  xcolor.green = 256 * color.G;
2193  xcolor.blue = 256 * color.B;
2194  XAllocColor ( display, lut, &xcolor );
2195  XSetForeground ( display, context, xcolor.pixel );
2196  }
2197 
2198  XClearWindow ( display, window );
2199 
2200  XFreePixmap ( display, pixmap );
2201  // Pixmap creation.
2202  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
2203  }
2204  else
2205  {
2206  vpERROR_TRACE ( "X not initialized " ) ;
2208  "X not initialized" ) ) ;
2209  }
2210 }
2211 
2220  const vpImagePoint &ip2,
2221  const vpColor &color,
2222  unsigned int w, unsigned int h,
2223  unsigned int thickness)
2224 {
2226  {
2227  try
2228  {
2229  double a = ip2.get_i() - ip1.get_i() ;
2230  double b = ip2.get_j() - ip1.get_j() ;
2231  double lg = sqrt ( vpMath::sqr ( a ) + vpMath::sqr ( b ) ) ;
2232 
2233  //if ( ( a==0 ) && ( b==0 ) )
2234  if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
2235  {
2236  // DisplayCrossLarge(i1,j1,3,col) ;
2237  }
2238  else
2239  {
2240  a /= lg ;
2241  b /= lg ;
2242 
2243  vpImagePoint ip3;
2244  ip3.set_i(ip2.get_i() - w*a);
2245  ip3.set_j(ip2.get_j() - w*b);
2246 
2247  vpImagePoint ip4;
2248  ip4.set_i( ip3.get_i() - b*h );
2249  ip4.set_j( ip3.get_j() + a*h );
2250 
2251  displayLine ( ip2, ip4, color, thickness ) ;
2252 
2253  ip4.set_i( ip3.get_i() + b*h );
2254  ip4.set_j( ip3.get_j() - a*h );
2255 
2256  displayLine ( ip2, ip4, color, thickness ) ;
2257  displayLine ( ip1, ip2, color, thickness ) ;
2258  }
2259  }
2260  catch ( ... )
2261  {
2262  vpERROR_TRACE ( "Error caught" ) ;
2263  throw ;
2264  }
2265  }
2266  else
2267  {
2268  vpERROR_TRACE ( "X not initialized " ) ;
2270  "X not initialized" ) ) ;
2271  }
2272 }
2273 
2286  const char *text,
2287  const vpColor &color )
2288 {
2290  {
2291  if (color.id < vpColor::id_unknown)
2292  XSetForeground ( display, context, x_color[color.id] );
2293  else {
2294  xcolor.pad = 0;
2295  xcolor.red = 256 * color.R;
2296  xcolor.green = 256 * color.G;
2297  xcolor.blue = 256 * color.B;
2298  XAllocColor ( display, lut, &xcolor );
2299  XSetForeground ( display, context, xcolor.pixel );
2300  }
2301  XDrawString ( display, pixmap, context,
2302  (int)ip.get_u(), (int)ip.get_v(),
2303  text, (int)strlen ( text ) );
2304  }
2305  else
2306  {
2307  vpERROR_TRACE ( "X not initialized " ) ;
2309  "X not initialized" ) ) ;
2310  }
2311 }
2312 
2323  unsigned int radius,
2324  const vpColor &color,
2325  bool fill,
2326  unsigned int thickness )
2327 {
2329  {
2330  if ( thickness == 1 ) thickness = 0;
2331  if (color.id < vpColor::id_unknown)
2332  XSetForeground ( display, context, x_color[color.id] );
2333  else {
2334  xcolor.pad = 0;
2335  xcolor.red = 256 * color.R;
2336  xcolor.green = 256 * color.G;
2337  xcolor.blue = 256 * color.B;
2338  XAllocColor ( display, lut, &xcolor );
2339  XSetForeground ( display, context, xcolor.pixel );
2340  }
2341 
2342  XSetLineAttributes ( display, context, thickness,
2343  LineSolid, CapButt, JoinBevel );
2344 
2345  if ( fill == false )
2346  {
2347  XDrawArc ( display, pixmap, context,
2348  vpMath::round( center.get_u()-radius ),
2349  vpMath::round( center.get_v()-radius ),
2350  radius*2, radius*2, 0, 23040 ); /* 23040 = 360*64 */
2351  }
2352  else
2353  {
2354  XFillArc ( display, pixmap, context,
2355  vpMath::round( center.get_u()-radius ),
2356  vpMath::round( center.get_v()-radius ),
2357  radius*2, radius*2, 0, 23040 ); /* 23040 = 360*64 */
2358  }
2359  }
2360  else
2361  {
2362  vpERROR_TRACE ( "X not initialized " ) ;
2364  "X not initialized" ) ) ;
2365  }
2366 }
2367 
2376  unsigned int cross_size,
2377  const vpColor &color,
2378  unsigned int thickness)
2379 {
2381  {
2382  try
2383  {
2384  double i = ip.get_i();
2385  double j = ip.get_j();
2386  vpImagePoint ip1, ip2;
2387 
2388  ip1.set_i( i-cross_size/2 );
2389  ip1.set_j( j );
2390  ip2.set_i( i+cross_size/2 );
2391  ip2.set_j( j );
2392  displayLine ( ip1, ip2, color, thickness ) ;
2393 
2394  ip1.set_i( i );
2395  ip1.set_j( j-cross_size/2 );
2396  ip2.set_i( i );
2397  ip2.set_j( j+cross_size/2 );
2398 
2399  displayLine ( ip1, ip2, color, thickness ) ;
2400  }
2401  catch ( ... )
2402  {
2403  vpERROR_TRACE ( "Error caught" ) ;
2404  throw ;
2405  }
2406  }
2407 
2408  else
2409  {
2410  vpERROR_TRACE ( "X not initialized " ) ;
2412  "X not initialized" ) ) ;
2413  }
2414 
2415 }
2423  const vpImagePoint &ip2,
2424  const vpColor &color,
2425  unsigned int thickness )
2426 {
2427 
2429  {
2430  if ( thickness == 1 ) thickness = 0;
2431 
2432  if (color.id < vpColor::id_unknown)
2433  XSetForeground ( display, context, x_color[color.id] );
2434  else {
2435  xcolor.pad = 0;
2436  xcolor.red = 256 * color.R;
2437  xcolor.green = 256 * color.G;
2438  xcolor.blue = 256 * color.B;
2439  XAllocColor ( display, lut, &xcolor );
2440  XSetForeground ( display, context, xcolor.pixel );
2441  }
2442 
2443  XSetLineAttributes ( display, context, thickness,
2444  LineOnOffDash, CapButt, JoinBevel );
2445 
2446  XDrawLine ( display, pixmap, context,
2447  vpMath::round( ip1.get_u() ),
2448  vpMath::round( ip1.get_v() ),
2449  vpMath::round( ip2.get_u() ),
2450  vpMath::round( ip2.get_v() ) );
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 {
2472  {
2473  if ( thickness == 1 ) thickness = 0;
2474 
2475  if (color.id < vpColor::id_unknown)
2476  XSetForeground ( display, context, x_color[color.id] );
2477  else {
2478  xcolor.pad = 0;
2479  xcolor.red = 256 * color.R;
2480  xcolor.green = 256 * color.G;
2481  xcolor.blue = 256 * color.B;
2482  XAllocColor ( display, lut, &xcolor );
2483  XSetForeground ( display, context, xcolor.pixel );
2484  }
2485 
2486  XSetLineAttributes ( display, context, thickness,
2487  LineSolid, CapButt, JoinBevel );
2488 
2489  XDrawLine ( display, pixmap, context,
2490  vpMath::round( ip1.get_u() ),
2491  vpMath::round( ip1.get_v() ),
2492  vpMath::round( ip2.get_u() ),
2493  vpMath::round( ip2.get_v() ) );
2494  }
2495  else
2496  {
2497  vpERROR_TRACE ( "X not initialized " ) ;
2499  "X not initialized" ) ) ;
2500  }
2501 }
2502 
2509  const vpColor &color )
2510 {
2512  {
2513  if (color.id < vpColor::id_unknown)
2514  XSetForeground ( display, context, x_color[color.id] );
2515  else {
2516  xcolor.pad = 0;
2517  xcolor.red = 256 * color.R;
2518  xcolor.green = 256 * color.G;
2519  xcolor.blue = 256 * color.B;
2520  XAllocColor ( display, lut, &xcolor );
2521  XSetForeground ( display, context, xcolor.pixel );
2522  }
2523 
2524  XDrawPoint ( display, pixmap, context,
2525  vpMath::round( ip.get_u() ),
2526  vpMath::round( ip.get_v() ) );
2527  }
2528  else
2529  {
2530  vpERROR_TRACE ( "X not initialized " ) ;
2532  "X not initialized" ) ) ;
2533  }
2534 }
2535 
2549 void
2551  unsigned int w, unsigned int h,
2552  const vpColor &color, bool fill,
2553  unsigned int thickness )
2554 {
2556  {
2557  if ( thickness == 1 ) thickness = 0;
2558  if (color.id < vpColor::id_unknown)
2559  XSetForeground ( display, context, x_color[color.id] );
2560  else {
2561  xcolor.pad = 0;
2562  xcolor.red = 256 * color.R;
2563  xcolor.green = 256 * color.G;
2564  xcolor.blue = 256 * color.B;
2565  XAllocColor ( display, lut, &xcolor );
2566  XSetForeground ( display, context, xcolor.pixel );
2567  }
2568  XSetLineAttributes ( display, context, thickness,
2569  LineSolid, CapButt, JoinBevel );
2570  if ( fill == false )
2571  {
2572  XDrawRectangle ( display, pixmap, context,
2573  vpMath::round( topLeft.get_u() ),
2574  vpMath::round( topLeft.get_v() ),
2575  w-1, h-1 );
2576  }
2577  else
2578  {
2579  XFillRectangle ( display, pixmap, context,
2580  vpMath::round( topLeft.get_u() ),
2581  vpMath::round( topLeft.get_v() ),
2582  w, h );
2583  }
2584  }
2585  else
2586  {
2587  vpERROR_TRACE ( "X not initialized " ) ;
2589  "X not initialized" ) ) ;
2590  }
2591 }
2592 
2605 void
2607  const vpImagePoint &bottomRight,
2608  const vpColor &color, bool fill,
2609  unsigned int thickness )
2610 {
2612  {
2613  if ( thickness == 1 ) thickness = 0;
2614  if (color.id < vpColor::id_unknown)
2615  XSetForeground ( display, context, x_color[color.id] );
2616  else {
2617  xcolor.pad = 0;
2618  xcolor.red = 256 * color.R;
2619  xcolor.green = 256 * color.G;
2620  xcolor.blue = 256 * color.B;
2621  XAllocColor ( display, lut, &xcolor );
2622  XSetForeground ( display, context, xcolor.pixel );
2623  }
2624 
2625  XSetLineAttributes ( display, context, thickness,
2626  LineSolid, CapButt, JoinBevel );
2627 
2628  unsigned int w = (unsigned int)vpMath::round( std::fabs(bottomRight.get_u() - topLeft.get_u()) );
2629  unsigned int h = (unsigned int)vpMath::round( std::fabs(bottomRight.get_v() - topLeft.get_v()) );
2630  if ( fill == false )
2631  {
2632 
2633  XDrawRectangle ( display, pixmap, context,
2634  vpMath::round( topLeft.get_u() < bottomRight.get_u() ? topLeft.get_u() : bottomRight.get_u() ),
2635  vpMath::round( topLeft.get_v() < bottomRight.get_v() ? topLeft.get_v() : bottomRight.get_v() ),
2636  w > 0 ? w-1 : 1, h > 0 ? h : 1 );
2637  }
2638  else
2639  {
2640  XFillRectangle ( display, pixmap, context,
2641  vpMath::round( topLeft.get_u() < bottomRight.get_u() ? topLeft.get_u() : bottomRight.get_u() ),
2642  vpMath::round( topLeft.get_v() < bottomRight.get_v() ? topLeft.get_v() : bottomRight.get_v() ),
2643  w, h );
2644  }
2645  }
2646  else
2647  {
2648  vpERROR_TRACE ( "X not initialized " ) ;
2650  "X not initialized" ) ) ;
2651  }
2652 }
2653 
2666 void
2668  const vpColor &color, bool fill,
2669  unsigned int thickness )
2670 {
2672  {
2673  if ( thickness == 1 ) thickness = 0;
2674  if (color.id < vpColor::id_unknown)
2675  XSetForeground ( display, context, x_color[color.id] );
2676  else {
2677  xcolor.pad = 0;
2678  xcolor.red = 256 * color.R;
2679  xcolor.green = 256 * color.G;
2680  xcolor.blue = 256 * color.B;
2681  XAllocColor ( display, lut, &xcolor );
2682  XSetForeground ( display, context, xcolor.pixel );
2683  }
2684 
2685  XSetLineAttributes ( display, context, thickness,
2686  LineSolid, CapButt, JoinBevel );
2687 
2688  if ( fill == false )
2689  {
2690  XDrawRectangle ( display, pixmap, context,
2691  vpMath::round( rectangle.getLeft() ),
2692  vpMath::round( rectangle.getTop() ),
2693  (unsigned int)vpMath::round( rectangle.getWidth()-1 ),
2694  (unsigned int)vpMath::round( rectangle.getHeight()-1 ) );
2695  }
2696  else
2697  {
2698  XFillRectangle ( display, pixmap, context,
2699  vpMath::round( rectangle.getLeft() ),
2700  vpMath::round( rectangle.getTop() ),
2701  (unsigned int)vpMath::round( rectangle.getWidth() ),
2702  (unsigned int)vpMath::round( rectangle.getHeight() ) );
2703  }
2704 
2705  }
2706  else
2707  {
2708  vpERROR_TRACE ( "X not initialized " ) ;
2710  "X not initialized" ) ) ;
2711  }
2712 }
2713 
2730 bool
2731 vpDisplayX::getClick(bool blocking)
2732 {
2733 
2734  bool ret = false;
2735 
2736  if ( displayHasBeenInitialized ) {
2737  Window rootwin, childwin ;
2738  int root_x, root_y, win_x, win_y ;
2739  unsigned int modifier ;
2740 
2741  // Event testing
2742  if(blocking){
2743  XCheckMaskEvent(display , ButtonPressMask, &event);
2744  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2745  XMaskEvent ( display, ButtonPressMask ,&event );
2746  ret = true;
2747  }
2748  else{
2749  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2750  }
2751 
2752  if(ret){
2753  /* Recuperation de la coordonnee du pixel cliqu�. */
2754  if ( XQueryPointer ( display,
2755  window,
2756  &rootwin, &childwin,
2757  &root_x, &root_y,
2758  &win_x, &win_y,
2759  &modifier ) ) {}
2760  }
2761  }
2762  else {
2763  vpERROR_TRACE ( "X not initialized " ) ;
2765  "X not initialized" ) ) ;
2766  }
2767  return ret;
2768 }
2769 
2786 bool
2787 vpDisplayX::getClick ( vpImagePoint &ip, bool blocking )
2788 {
2789 
2790  bool ret = false;
2791  if ( displayHasBeenInitialized ) {
2792 
2793  Window rootwin, childwin ;
2794  int root_x, root_y, win_x, win_y ;
2795  unsigned int modifier ;
2796  // Event testing
2797  if(blocking){
2798  XCheckMaskEvent(display , ButtonPressMask, &event);
2799  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2800  XMaskEvent ( display, ButtonPressMask ,&event );
2801  ret = true;
2802  }
2803  else{
2804  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2805  }
2806 
2807  if(ret){
2808  // Get mouse position
2809  if ( XQueryPointer ( display,
2810  window,
2811  &rootwin, &childwin,
2812  &root_x, &root_y,
2813  &win_x, &win_y,
2814  &modifier ) ) {
2815  ip.set_u( (double)event.xbutton.x );
2816  ip.set_v( (double)event.xbutton.y );
2817  }
2818  }
2819  }
2820  else {
2821  vpERROR_TRACE ( "X not initialized " ) ;
2823  "X not initialized" ) ) ;
2824  }
2825  return ret ;
2826 }
2827 
2847 bool
2850  bool blocking )
2851 {
2852 
2853  bool ret = false;
2854  if ( displayHasBeenInitialized ) {
2855 
2856  Window rootwin, childwin ;
2857  int root_x, root_y, win_x, win_y ;
2858  unsigned int modifier ;
2859 
2860  // Event testing
2861  if(blocking){
2862  XCheckMaskEvent(display , ButtonPressMask, &event);
2863  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2864  XMaskEvent ( display, ButtonPressMask ,&event );
2865  ret = true;
2866  }
2867  else{
2868  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2869  }
2870 
2871  if(ret){
2872  // Get mouse position
2873  if ( XQueryPointer ( display,
2874  window,
2875  &rootwin, &childwin,
2876  &root_x, &root_y,
2877  &win_x, &win_y,
2878  &modifier ) ) {
2879  ip.set_u( (double)event.xbutton.x );
2880  ip.set_v( (double)event.xbutton.y );
2881  switch ( event.xbutton.button ) {
2882  case Button1: button = vpMouseButton::button1; break;
2883  case Button2: button = vpMouseButton::button2; break;
2884  case Button3: button = vpMouseButton::button3; break;
2885  }
2886  }
2887  }
2888  }
2889  else {
2890  vpERROR_TRACE ( "X not initialized " ) ;
2892  "X not initialized" ) ) ;
2893  }
2894  return ret ;
2895 }
2896 
2920 bool
2923  bool blocking )
2924 {
2925 
2926  bool ret = false;
2927  if ( displayHasBeenInitialized ) {
2928  Window rootwin, childwin ;
2929  int root_x, root_y, win_x, win_y ;
2930  unsigned int modifier ;
2931 
2932  // Event testing
2933  if(blocking){
2934  XCheckMaskEvent(display , ButtonPressMask, &event);
2935  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2936  XMaskEvent ( display, ButtonReleaseMask ,&event );
2937  ret = true;
2938  }
2939  else{
2940  ret = XCheckMaskEvent(display , ButtonReleaseMask, &event);
2941  }
2942 
2943  if(ret){
2944  /* Recuperation de la coordonnee du pixel cliqu�. */
2945  if ( XQueryPointer ( display,
2946  window,
2947  &rootwin, &childwin,
2948  &root_x, &root_y,
2949  &win_x, &win_y,
2950  &modifier ) ) {
2951  ip.set_u( (double)event.xbutton.x );
2952  ip.set_v( (double)event.xbutton.y );
2953  switch ( event.xbutton.button ) {
2954  case Button1: button = vpMouseButton::button1; break;
2955  case Button2: button = vpMouseButton::button2; break;
2956  case Button3: button = vpMouseButton::button3; break;
2957  }
2958  }
2959  }
2960  }
2961  else {
2962  vpERROR_TRACE ( "X not initialized " ) ;
2964  "X not initialized" ) ) ;
2965  }
2966  return ret ;
2967 }
2968 
2969 /*
2970  Gets the displayed image (including the overlay plane)
2971  and returns an RGBa image.
2972 
2973  \param I : Image to get.
2974 */
2976 {
2977 
2979  {
2980 
2981 
2982  XImage *xi ;
2983  //xi= XGetImage ( display,window, 0,0, getWidth(), getHeight(),
2984  // AllPlanes, ZPixmap ) ;
2985 
2986  XCopyArea (display,window, pixmap, context,
2987  0,0, getWidth(), getHeight(), 0, 0);
2988 
2989  xi= XGetImage ( display,pixmap, 0,0, getWidth(), getHeight(),
2990  AllPlanes, ZPixmap ) ;
2991 
2992  try
2993  {
2994  I.resize ( getHeight(), getWidth() ) ;
2995  }
2996  catch ( ... )
2997  {
2998  vpERROR_TRACE ( "Error caught" ) ;
2999  throw ;
3000  }
3001 
3002  unsigned char *src_32 = NULL;
3003  src_32 = ( unsigned char* ) xi->data;
3004 
3005 #ifdef BIGENDIAN
3006  // little indian/big indian
3007  for ( unsigned int i = 0; i < I.getWidth() * I.getHeight() ; i++ )
3008  {
3009  I.bitmap[i].A = src_32[i*4] ;
3010  I.bitmap[i].R = src_32[i*4 + 1] ;
3011  I.bitmap[i].G = src_32[i*4 + 2] ;
3012  I.bitmap[i].B = src_32[i*4 + 3] ;
3013  }
3014 #else
3015  for ( unsigned int i = 0; i < I.getWidth() * I.getHeight() ; i++ )
3016  {
3017  I.bitmap[i].B = src_32[i*4] ;
3018  I.bitmap[i].G = src_32[i*4 + 1] ;
3019  I.bitmap[i].R = src_32[i*4 + 2] ;
3020  I.bitmap[i].A = src_32[i*4 + 3] ;
3021  }
3022 #endif
3023 
3024 
3025  XDestroyImage ( xi ) ;
3026 
3027  }
3028  else
3029  {
3030  vpERROR_TRACE ( "X not initialized " ) ;
3032  "X not initialized" ) ) ;
3033  }
3034 }
3035 
3040 {
3041  Display *display_;
3042  int screen_;
3043  unsigned int depth;
3044 
3045  if ( ( display_ = XOpenDisplay ( NULL ) ) == NULL )
3046  {
3047  vpERROR_TRACE ( "Can't connect display on server %s.",
3048  XDisplayName ( NULL ) );
3050  "Can't connect display on server." ) ) ;
3051  }
3052  screen_ = DefaultScreen ( display_ );
3053  depth = (unsigned int)DefaultDepth ( display_, screen_ );
3054 
3055  XCloseDisplay ( display_ );
3056 
3057  return ( depth );
3058 }
3059 
3064 void vpDisplayX::getScreenSize ( unsigned int &w, unsigned int &h )
3065 {
3066  Display *display_;
3067  int screen_;
3068 
3069  if ( ( display_ = XOpenDisplay ( NULL ) ) == NULL )
3070  {
3071  vpERROR_TRACE ( "Can't connect display on server %s.",
3072  XDisplayName ( NULL ) );
3074  "Can't connect display on server." ) ) ;
3075  }
3076  screen_ = DefaultScreen ( display_ );
3077  w = (unsigned int)DisplayWidth ( display_, screen_ );
3078  h = (unsigned int)DisplayHeight ( display_, screen_ );
3079 
3080  XCloseDisplay ( display_ );
3081 }
3102 bool
3104 {
3105 
3106  bool ret = false;
3107 
3108  if ( displayHasBeenInitialized ) {
3109  // Event testing
3110  if(blocking){
3111  XMaskEvent ( display, KeyPressMask ,&event );
3112  ret = true;
3113  }
3114  else{
3115  ret = XCheckMaskEvent(display , KeyPressMask, &event);
3116  }
3117  }
3118  else {
3119  vpERROR_TRACE ( "X not initialized " ) ;
3121  "X not initialized" ) ) ;
3122  }
3123  return ret;
3124 }
3148 bool
3149 vpDisplayX::getKeyboardEvent(char *string, bool blocking)
3150 {
3151 
3152  bool ret = false;
3153  KeySym keysym;
3154 // int count;
3155  XComposeStatus compose_status;
3156  char buffer;
3157 
3158  if ( displayHasBeenInitialized ) {
3159  // Event testing
3160  if(blocking){
3161  XMaskEvent ( display, KeyPressMask ,&event );
3162  /* count = */ XLookupString ((XKeyEvent *)&event, &buffer, 1,
3163  &keysym, &compose_status);
3164  //std::cout <<"count: " << count << " get \"" << buffer << "\"" << std::endl;
3165  sprintf(string, "%c", buffer);
3166  ret = true;
3167  }
3168  else{
3169  ret = XCheckMaskEvent(display , KeyPressMask, &event);
3170  if (ret) {
3171  /* count = */ XLookupString ((XKeyEvent *)&event, &buffer, 1,
3172  &keysym, &compose_status);
3173  sprintf(string, "%c", buffer);
3174  }
3175  }
3176  }
3177  else {
3178  vpERROR_TRACE ( "X not initialized " ) ;
3180  "X not initialized" ) ) ;
3181  }
3182  return ret;
3183 }
3196 bool
3198 {
3199 
3200  bool ret = false;
3201  if ( displayHasBeenInitialized ) {
3202 
3203  Window rootwin, childwin ;
3204  int root_x, root_y, win_x, win_y ;
3205  unsigned int modifier ;
3206  // Event testing
3207  ret = XCheckMaskEvent(display , PointerMotionMask, &event);
3208 
3209  if(ret){
3210  // Get mouse position
3211  if ( XQueryPointer ( display,
3212  window,
3213  &rootwin, &childwin,
3214  &root_x, &root_y,
3215  &win_x, &win_y,
3216  &modifier ) ) {
3217  ip.set_u( (double)event.xbutton.x );
3218  ip.set_v( (double)event.xbutton.y );
3219  }
3220  }
3221  }
3222  else {
3223  vpERROR_TRACE ( "X not initialized " ) ;
3225  "X not initialized" ) ) ;
3226  }
3227  return ret ;
3228 }
3229 
3240 bool
3242 {
3243 
3244  bool ret = false;
3245  if ( displayHasBeenInitialized ) {
3246 
3247  Window rootwin, childwin ;
3248  int root_x, root_y, win_x, win_y ;
3249  unsigned int modifier ;
3250  // Event testing
3251  ret = true;
3252 
3253  if(ret){
3254  // Get mouse position
3255  if ( XQueryPointer ( display,
3256  window,
3257  &rootwin, &childwin,
3258  &root_x, &root_y,
3259  &win_x, &win_y,
3260  &modifier ) ) {
3261  ip.set_u( (double)win_x );
3262  ip.set_v( (double)win_y );
3263  }
3264  }
3265  }
3266  else {
3267  vpERROR_TRACE ( "X not initialized " ) ;
3269  "X not initialized" ) ) ;
3270  }
3271  return ret ;
3272 }
3273 
3274 #endif
3275 
3276 /*
3277  * Local variables:
3278  * c-basic-offset: 2
3279  * End:
3280  */
void closeDisplay()
void clearDisplay(const vpColor &color=vpColor::white)
vpDisplay * display
Definition: vpImage.h:121
#define vpDEBUG_TRACE
Definition: vpDebug.h:482
double getTop() const
Definition: vpRect.h:174
double get_v() const
Definition: vpImagePoint.h:263
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:185
double get_i() const
Definition: vpImagePoint.h:194
unsigned int getWidth() const
Definition: vpImage.h:159
void displayImage(const vpImage< vpRGBa > &I)
#define vpERROR_TRACE
Definition: vpDebug.h:395
unsigned char B
Blue component.
Definition: vpRGBa.h:148
#define vpTRACE
Definition: vpDebug.h:418
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
static const vpColor black
Definition: vpColor.h:161
static const vpColor darkRed
Definition: vpColor.h:168
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
double get_u() const
Definition: vpImagePoint.h:252
static const vpColor lightGray
Definition: vpColor.h:163
double getHeight() const
Definition: vpRect.h:155
void flushDisplay()
static const vpColor darkBlue
Definition: vpColor.h:174
bool displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:180
unsigned char G
Green component.
Definition: vpRGBa.h:147
static const vpColor green
Definition: vpColor.h:170
unsigned int getHeight() const
Definition: vpDisplayX.h:269
static int round(const double x)
Definition: vpMath.h:228
double get_j() const
Definition: vpImagePoint.h:205
static const vpColor lightRed
Definition: vpColor.h:166
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
static const vpColor red
Definition: vpColor.h:167
bool getPointerPosition(vpImagePoint &ip)
static const vpColor orange
Definition: vpColor.h:177
std::string title_
Definition: vpDisplay.h:187
bool getClick(bool blocking=true)
vpColorIdentifier id
Definition: vpColor.h:156
void set_i(const double ii)
Definition: vpImagePoint.h:158
double getWidth() const
Definition: vpRect.h:193
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:176
static const vpColor lightGreen
Definition: vpColor.h:169
void set_u(const double u)
Definition: vpImagePoint.h:216
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:186
void getScreenSize(unsigned int &width, unsigned int &height)
void set_v(const double v)
Definition: vpImagePoint.h:227
unsigned char A
Additionnal component.
Definition: vpRGBa.h:149
bool getKeyboardEvent(bool blocking=true)
void resize(const unsigned int h, const unsigned int w)
set the size of the image
Definition: vpImage.h:532
static const vpColor gray
Definition: vpColor.h:164
void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
void setWindowPosition(int winx, int winy)
virtual ~vpDisplayX()
Definition: vpDisplayX.cpp:177
static const vpColor darkGray
Definition: vpColor.h:165
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)
void set_j(const double jj)
Definition: vpImagePoint.h:169
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:182
unsigned char R
Red component.
Definition: vpRGBa.h:146
unsigned int getWidth() const
Definition: vpDisplayX.h:268
unsigned int getHeight() const
Definition: vpImage.h:150
Defines a rectangle in the plane.
Definition: vpRect.h:85
static const vpColor darkGreen
Definition: vpColor.h:171
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:191
static const vpColor yellow
Definition: vpColor.h:175
static const vpColor lightBlue
Definition: vpColor.h:172
int windowYPosition
display position
Definition: vpDisplay.h:184
static const vpColor purple
Definition: vpColor.h:178
static const vpColor white
Definition: vpColor.h:162
double getLeft() const
Definition: vpRect.h:161
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:173
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)