ViSP  2.8.0
vpDisplayX.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDisplayX.cpp 4174 2013-03-22 10:28:41Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 ) : vpDisplay()
102 {
103  x_color = NULL;
104  init ( I, x, y, title ) ;
105 }
106 
129 vpDisplayX::vpDisplayX ( int x, int y, const char *title ) : vpDisplay()
130 {
131  windowXPosition = x ;
132  windowYPosition = y ;
133 
134  this->x_color = NULL;
135 
136  if (title != NULL)
137  strcpy (this->title, title);
138 
139  ximage_data_init = false;
140 }
141 
162 {
163  x_color = NULL;
164  ximage_data_init = false;
165 }
166 
171 {
172  closeDisplay() ;
173 }
174 
183 void
184 vpDisplayX::init ( vpImage<unsigned char> &I, int x, int y, const char *title )
185 {
186 
187  if (x_color == NULL) {
188  // id_unknown = number of predefined colors
189  x_color= new unsigned long [vpColor::id_unknown];
190  }
191 
192  XSizeHints hints;
193  if (x != -1)
194  windowXPosition = x ;
195  if (y != -1)
196  windowYPosition = y ;
197 
198  if ( title != NULL )
199  strcpy ( this->title, title ) ;
200 
201  // Positionnement de la fenetre dans l'�cran.
202  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
203  {
204  hints.flags = 0;
205  }
206  else
207  {
208  hints.flags = USPosition;
209  hints.x = windowXPosition;
210  hints.y = windowYPosition;
211  }
212 
213  // setup X11 --------------------------------------------------
214  width = I.getWidth();
215  height = I.getHeight();
216  display = XOpenDisplay ( NULL );
217  if ( display == NULL )
218  {
219  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
221  "Can't connect display on server." ) ) ;
222  }
223 
224  screen = DefaultScreen ( display );
225  lut = DefaultColormap ( display, screen );
226  screen_depth = (unsigned int)DefaultDepth ( display, screen );
227 
228  if ( ( window =
229  XCreateSimpleWindow ( display, RootWindow ( display, screen ),
231  BlackPixel ( display, screen ),
232  WhitePixel ( display, screen ) ) ) == 0 )
233  {
234  vpERROR_TRACE ( "Can't create window." );
236  "Can't create window." ) ) ;
237  }
238 
239  //
240  // Create color table for 8 and 16 bits screen
241  //
242  if ( screen_depth == 8 )
243  {
244  lut = XCreateColormap ( display, window,
245  DefaultVisual ( display, screen ), AllocAll ) ;
246  xcolor.flags = DoRed | DoGreen | DoBlue ;
247 
248  for ( unsigned int i = 0 ; i < 256 ; i++ )
249  {
250  xcolor.pixel = i ;
251  xcolor.red = 256 * i;
252  xcolor.green = 256 * i;
253  xcolor.blue = 256 * i;
254  XStoreColor ( display, lut, &xcolor );
255  }
256 
257  XSetWindowColormap ( display, window, lut ) ;
258  XInstallColormap ( display, lut ) ;
259  }
260 
261  else if ( screen_depth == 16 )
262  {
263  for ( unsigned int i = 0; i < 256; i ++ )
264  {
265  xcolor.pad = 0;
266  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
267  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
268  {
269  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
271  "Can't allocate 256 colors." ) ) ;
272  }
273  colortable[i] = xcolor.pixel;
274  }
275 
276  XSetWindowColormap ( display, window, lut ) ;
277  XInstallColormap ( display, lut ) ;
278 
279  }
280 
281  //
282  // Create colors for overlay
283  //
284  switch ( screen_depth )
285  {
286  case 8:
287  // Color BLACK and WHITE are set properly by default.
288 
289  // Color LIGHT GRAY.
290  x_color[vpColor::id_lightGray] = 254;
291  xcolor.pixel = x_color[vpColor::id_lightGray] ;
292  xcolor.red = 256 * 192;
293  xcolor.green = 256 * 192;
294  xcolor.blue = 256 * 192;
295  XStoreColor ( display, lut, &xcolor );
296 
297  // Color GRAY.
298  x_color[vpColor::id_gray] = 253;
299  xcolor.pixel = x_color[vpColor::id_gray] ;
300  xcolor.red = 256 * 128;
301  xcolor.green = 256 * 128;
302  xcolor.blue = 256 * 128;
303  XStoreColor ( display, lut, &xcolor );
304 
305  // Color DARK GRAY.
306  x_color[vpColor::id_darkGray] = 252;
307  xcolor.pixel = x_color[vpColor::id_darkGray] ;
308  xcolor.red = 256 * 64;
309  xcolor.green = 256 * 64;
310  xcolor.blue = 256 * 64;
311  XStoreColor ( display, lut, &xcolor );
312 
313  // Color LIGHT RED.
314  x_color[vpColor::id_lightRed] = 251;
315  xcolor.pixel = x_color[vpColor::id_lightRed] ;
316  xcolor.red = 256 * 255;
317  xcolor.green = 256 * 140;
318  xcolor.blue = 256 * 140;
319  XStoreColor ( display, lut, &xcolor );
320 
321  // Color RED.
322  x_color[vpColor::id_red] = 250;
323  xcolor.pixel = x_color[vpColor::id_red] ;
324  xcolor.red = 256 * 255;
325  xcolor.green = 0;
326  xcolor.blue = 0;
327  XStoreColor ( display, lut, &xcolor );
328 
329  // Color DARK RED.
330  x_color[vpColor::id_darkRed] = 249;
331  xcolor.pixel = x_color[vpColor::id_darkRed] ;
332  xcolor.red = 256 * 128;
333  xcolor.green = 0;
334  xcolor.blue = 0;
335  XStoreColor ( display, lut, &xcolor );
336 
337  // Color LIGHT GREEN.
338  x_color[vpColor::id_lightGreen] = 248;
339  xcolor.pixel = x_color[vpColor::id_lightGreen] ;
340  xcolor.red = 256 * 140;
341  xcolor.green = 256 * 255;
342  xcolor.blue = 256 * 140;
343  XStoreColor ( display, lut, &xcolor );
344 
345  // Color GREEN.
346  x_color[vpColor::id_green] = 247;
347  xcolor.pixel = x_color[vpColor::id_green];
348  xcolor.red = 0;
349  xcolor.green = 256 * 255;
350  xcolor.blue = 0;
351  XStoreColor ( display, lut, &xcolor );
352 
353  // Color DARK GREEN.
354  x_color[vpColor::id_darkGreen] = 246;
355  xcolor.pixel = x_color[vpColor::id_darkGreen] ;
356  xcolor.red = 0;
357  xcolor.green = 256 * 128;
358  xcolor.blue = 0;
359  XStoreColor ( display, lut, &xcolor );
360 
361  // Color LIGHT BLUE.
362  x_color[vpColor::id_lightBlue] = 245;
363  xcolor.pixel = x_color[vpColor::id_lightBlue] ;
364  xcolor.red = 256 * 140;
365  xcolor.green = 256 * 140;
366  xcolor.blue = 256 * 255;
367  XStoreColor ( display, lut, &xcolor );
368 
369  // Color BLUE.
370  x_color[vpColor::id_blue] = 244;
371  xcolor.pixel = x_color[vpColor::id_blue];
372  xcolor.red = 0;
373  xcolor.green = 0;
374  xcolor.blue = 256 * 255;
375  XStoreColor ( display, lut, &xcolor );
376 
377  // Color DARK BLUE.
378  x_color[vpColor::id_darkBlue] = 243;
379  xcolor.pixel = x_color[vpColor::id_darkBlue] ;
380  xcolor.red = 0;
381  xcolor.green = 0;
382  xcolor.blue = 256 * 128;
383  XStoreColor ( display, lut, &xcolor );
384 
385  // Color YELLOW.
386  x_color[vpColor::id_yellow] = 242;
387  xcolor.pixel = x_color[vpColor::id_yellow];
388  xcolor.red = 256 * 255;
389  xcolor.green = 256 * 255;
390  xcolor.blue = 0;
391  XStoreColor ( display, lut, &xcolor );
392 
393  // Color ORANGE.
394  x_color[vpColor::id_orange] = 241;
395  xcolor.pixel = x_color[vpColor::id_orange];
396  xcolor.red = 256 * 255;
397  xcolor.green = 256 * 165;
398  xcolor.blue = 0;
399  XStoreColor ( display, lut, &xcolor );
400 
401  // Color CYAN.
402  x_color[vpColor::id_cyan] = 240;
403  xcolor.pixel = x_color[vpColor::id_cyan];
404  xcolor.red = 0;
405  xcolor.green = 256 * 255;
406  xcolor.blue = 256 * 255;
407  XStoreColor ( display, lut, &xcolor );
408 
409  // Color PURPLE.
410  x_color[vpColor::id_purple] = 239;
411  xcolor.pixel = x_color[vpColor::id_purple];
412  xcolor.red = 256 * 128;
413  xcolor.green = 0;
414  xcolor.blue = 256 * 128;
415  XStoreColor ( display, lut, &xcolor );
416 
417  break;
418 
419  case 16:
420  case 24:
421  {
422  xcolor.flags = DoRed | DoGreen | DoBlue ;
423 
424  // Couleur BLACK.
425  xcolor.pad = 0;
426  xcolor.red = 0;
427  xcolor.green = 0;
428  xcolor.blue = 0;
429  XAllocColor ( display, lut, &xcolor );
430  x_color[vpColor::id_black] = xcolor.pixel;
431 
432  // Couleur WHITE.
433  xcolor.pad = 0;
434  xcolor.red = 256* 255;
435  xcolor.green = 256* 255;
436  xcolor.blue = 256* 255;
437  XAllocColor ( display, lut, &xcolor );
438  x_color[vpColor::id_white] = xcolor.pixel;
439 
440  // Couleur LIGHT GRAY.
441  xcolor.pad = 0;
442  xcolor.red = 256 * 192;
443  xcolor.green = 256 * 192;
444  xcolor.blue = 256 * 192;
445  XAllocColor ( display, lut, &xcolor );
446  x_color[vpColor::id_lightGray] = xcolor.pixel;
447 
448  // Couleur GRAY.
449  xcolor.pad = 0;
450  xcolor.red = 256 * 128;
451  xcolor.green = 256 * 128;
452  xcolor.blue = 256 * 128;
453  XAllocColor ( display, lut, &xcolor );
454  x_color[vpColor::id_gray] = xcolor.pixel;
455 
456  // Couleur DARK GRAY.
457  xcolor.pad = 0;
458  xcolor.red = 256 * 64;
459  xcolor.green = 256 * 64;
460  xcolor.blue = 256 * 64;
461  XAllocColor ( display, lut, &xcolor );
462  x_color[vpColor::id_darkGray] = xcolor.pixel;
463 
464  // Couleur LIGHT RED.
465  xcolor.pad = 0;
466  xcolor.red = 256 * 255;
467  xcolor.green = 256 * 140;
468  xcolor.blue = 256 * 140;
469  XAllocColor ( display, lut, &xcolor );
470  x_color[vpColor::id_lightRed] = xcolor.pixel;
471 
472  // Couleur RED.
473  xcolor.pad = 0;
474  xcolor.red = 256* 255;
475  xcolor.green = 0;
476  xcolor.blue = 0;
477  XAllocColor ( display, lut, &xcolor );
478  x_color[vpColor::id_red] = xcolor.pixel;
479 
480  // Couleur DARK RED.
481  xcolor.pad = 0;
482  xcolor.red = 256* 128;
483  xcolor.green = 0;
484  xcolor.blue = 0;
485  XAllocColor ( display, lut, &xcolor );
486  x_color[vpColor::id_darkRed] = xcolor.pixel;
487 
488  // Couleur LIGHT GREEN.
489  xcolor.pad = 0;
490  xcolor.red = 256 * 140;
491  xcolor.green = 256 * 255;
492  xcolor.blue = 256 * 140;
493  XAllocColor ( display, lut, &xcolor );
494  x_color[vpColor::id_lightGreen] = xcolor.pixel;
495 
496  // Couleur GREEN.
497  xcolor.pad = 0;
498  xcolor.red = 0;
499  xcolor.green = 256*255;
500  xcolor.blue = 0;
501  XAllocColor ( display, lut, &xcolor );
502  x_color[vpColor::id_green] = xcolor.pixel;
503 
504  // Couleur DARK GREEN.
505  xcolor.pad = 0;
506  xcolor.red = 0;
507  xcolor.green = 256* 128;
508  xcolor.blue = 0;
509  XAllocColor ( display, lut, &xcolor );
510  x_color[vpColor::id_darkGreen] = xcolor.pixel;
511 
512  // Couleur LIGHT Blue.
513  xcolor.pad = 0;
514  xcolor.red = 256 * 140;
515  xcolor.green = 256 * 140;
516  xcolor.blue = 256 * 255;
517  XAllocColor ( display, lut, &xcolor );
518  x_color[vpColor::id_lightBlue] = xcolor.pixel;
519 
520  // Couleur BLUE.
521  xcolor.pad = 0;
522  xcolor.red = 0;
523  xcolor.green = 0;
524  xcolor.blue = 256* 255;
525  XAllocColor ( display, lut, &xcolor );
526  x_color[vpColor::id_blue] = xcolor.pixel;
527 
528  // Couleur DARK BLUE.
529  xcolor.pad = 0;
530  xcolor.red = 0;
531  xcolor.green = 0;
532  xcolor.blue = 256* 128;
533  XAllocColor ( display, lut, &xcolor );
534  x_color[vpColor::id_darkBlue] = xcolor.pixel;
535 
536  // Couleur YELLOW.
537  xcolor.pad = 0;
538  xcolor.red = 256 * 255;
539  xcolor.green = 256 * 255;
540  xcolor.blue = 0;
541  XAllocColor ( display, lut, &xcolor );
542  x_color[vpColor::id_yellow] = xcolor.pixel;
543 
544  // Couleur ORANGE.
545  xcolor.pad = 0;
546  xcolor.red = 256 * 255;
547  xcolor.green = 256 * 165;
548  xcolor.blue = 0;
549  XAllocColor ( display, lut, &xcolor );
550  x_color[vpColor::id_orange] = xcolor.pixel;
551 
552  // Couleur CYAN.
553  xcolor.pad = 0;
554  xcolor.red = 0;
555  xcolor.green = 256 * 255;
556  xcolor.blue = 256 * 255;
557  XAllocColor ( display, lut, &xcolor );
558  x_color[vpColor::id_cyan] = xcolor.pixel;
559 
560  // Couleur PURPLE.
561  xcolor.pad = 0;
562  xcolor.red = 256 * 128;
563  xcolor.green = 0;
564  xcolor.blue = 256 * 128;
565  XAllocColor ( display, lut, &xcolor );
566  x_color[vpColor::id_purple] = xcolor.pixel;
567  break;
568  }
569  }
570 
571  XSetStandardProperties ( display, window, this->title, this->title, None, 0, 0, &hints );
572  XMapWindow ( display, window ) ;
573  // Selection des evenements.
574  XSelectInput ( display, window,
575  ExposureMask |
576  ButtonPressMask | ButtonReleaseMask |
577  KeyPressMask | KeyReleaseMask |
578  StructureNotifyMask |
579  PointerMotionMask);
580 
581  // graphic context creation
582  values.plane_mask = AllPlanes;
583  values.fill_style = FillSolid;
584  values.foreground = WhitePixel ( display, screen );
585  values.background = BlackPixel ( display, screen );
586  context = XCreateGC ( display, window,
587  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
588  &values );
589 
590  if ( context == NULL )
591  {
592  vpERROR_TRACE ( "Can't create graphics context." );
594  "Can't create graphics context" ) ) ;
595 
596  }
597 
598  // Pixmap creation.
599  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
600 
601  do
602  XNextEvent ( display, &event );
603  while ( event.xany.type != Expose );
604 
605  {
606  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
607  screen_depth, ZPixmap, 0, NULL,
608  I.getWidth() , I.getHeight(), XBitmapPad ( display ), 0 );
609 
610  Ximage->data = ( char * ) malloc ( I.getWidth() * I.getHeight() * (unsigned int)Ximage->bits_per_pixel / 8 );
611  ximage_data_init = true;
612 
613  }
615  setTitle ( this->title ) ;
616  XSync ( display, 1 );
617 
618  I.display = this ;
619 }
620 
630 void
631 vpDisplayX::init ( vpImage<vpRGBa> &I, int x, int y, const char *title )
632 {
633 
634  XSizeHints hints;
635  if (x != -1)
636  windowXPosition = x ;
637  if (y != -1)
638  windowYPosition = y ;
639 
640  if (x_color == NULL) {
641  // id_unknown = number of predefined colors
642  x_color= new unsigned long [vpColor::id_unknown];
643  }
644 
645  if ( title != NULL )
646  strcpy ( this->title, title ) ;
647 
648  // Positionnement de la fenetre dans l'�cran.
649  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
650  {
651  hints.flags = 0;
652  }
653  else
654  {
655  hints.flags = USPosition;
656  hints.x = windowXPosition;
657  hints.y = windowYPosition;
658  }
659 
660  // setup X11 --------------------------------------------------
661  width = I.getWidth();
662  height = I.getHeight();
663 
664  if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
665  {
666  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
668  "Can't connect display on server." ) ) ;
669  }
670 
671  screen = DefaultScreen ( display );
672  lut = DefaultColormap ( display, screen );
673  screen_depth = (unsigned int)DefaultDepth ( display, screen );
674 
675  vpDEBUG_TRACE ( 1, "Screen depth: %d\n", screen_depth );
676 
677  if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
679  width, height, 1,
680  BlackPixel ( display, screen ),
681  WhitePixel ( display, screen ) ) ) == 0 )
682  {
683  vpERROR_TRACE ( "Can't create window." );
685  "Can't create window." ) ) ;
686  }
687 
688  //
689  // Create color table for 8 and 16 bits screen
690  //
691  if ( screen_depth == 8 )
692  {
693  lut = XCreateColormap ( display, window,
694  DefaultVisual ( display, screen ), AllocAll ) ;
695  xcolor.flags = DoRed | DoGreen | DoBlue ;
696 
697  for ( unsigned int i = 0 ; i < 256 ; i++ )
698  {
699  xcolor.pixel = i ;
700  xcolor.red = 256 * i;
701  xcolor.green = 256 * i;
702  xcolor.blue = 256 * i;
703  XStoreColor ( display, lut, &xcolor );
704  }
705 
706  XSetWindowColormap ( display, window, lut ) ;
707  XInstallColormap ( display, lut ) ;
708  }
709 
710  else if ( screen_depth == 16 )
711  {
712  for ( unsigned int i = 0; i < 256; i ++ )
713  {
714  xcolor.pad = 0;
715  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
716  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
717  {
718  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
720  "Can't allocate 256 colors." ) ) ;
721  }
722  colortable[i] = xcolor.pixel;
723  }
724 
725  XSetWindowColormap ( display, window, lut ) ;
726  XInstallColormap ( display, lut ) ;
727 
728  }
729 
730 
731  //
732  // Create colors for overlay
733  //
734  switch ( screen_depth )
735  {
736 
737  case 8:
738  // Color BLACK and WHITE are set properly.
739 
740  // Color LIGHT GRAY.
741  x_color[vpColor::id_lightGray] = 254;
742  xcolor.pixel = x_color[vpColor::id_lightGray] ;
743  xcolor.red = 256 * 192;
744  xcolor.green = 256 * 192;
745  xcolor.blue = 256 * 192;
746  XStoreColor ( display, lut, &xcolor );
747 
748  // Color GRAY.
749  x_color[vpColor::id_gray] = 253;
750  xcolor.pixel = x_color[vpColor::id_gray] ;
751  xcolor.red = 256 * 128;
752  xcolor.green = 256 * 128;
753  xcolor.blue = 256 * 128;
754  XStoreColor ( display, lut, &xcolor );
755 
756  // Color DARK GRAY.
757  x_color[vpColor::id_darkGray] = 252;
758  xcolor.pixel = x_color[vpColor::id_darkGray] ;
759  xcolor.red = 256 * 64;
760  xcolor.green = 256 * 64;
761  xcolor.blue = 256 * 64;
762  XStoreColor ( display, lut, &xcolor );
763 
764  // Color LIGHT RED.
765  x_color[vpColor::id_lightRed] = 251;
766  xcolor.pixel = x_color[vpColor::id_lightRed] ;
767  xcolor.red = 256 * 255;
768  xcolor.green = 256 * 140;
769  xcolor.blue = 256 * 140;
770  XStoreColor ( display, lut, &xcolor );
771 
772  // Color RED.
773  x_color[vpColor::id_red] = 250;
774  xcolor.pixel = x_color[vpColor::id_red] ;
775  xcolor.red = 256 * 255;
776  xcolor.green = 0;
777  xcolor.blue = 0;
778  XStoreColor ( display, lut, &xcolor );
779 
780  // Color DARK RED.
781  x_color[vpColor::id_darkRed] = 249;
782  xcolor.pixel = x_color[vpColor::id_darkRed] ;
783  xcolor.red = 256 * 128;
784  xcolor.green = 0;
785  xcolor.blue = 0;
786  XStoreColor ( display, lut, &xcolor );
787 
788  // Color LIGHT GREEN.
789  x_color[vpColor::id_lightGreen] = 248;
790  xcolor.pixel = x_color[vpColor::id_lightGreen] ;
791  xcolor.red = 256 * 140;
792  xcolor.green = 256 * 255;
793  xcolor.blue = 256 * 140;
794  XStoreColor ( display, lut, &xcolor );
795 
796  // Color GREEN.
797  x_color[vpColor::id_green] = 247;
798  xcolor.pixel = x_color[vpColor::id_green];
799  xcolor.red = 0;
800  xcolor.green = 256 * 255;
801  xcolor.blue = 0;
802  XStoreColor ( display, lut, &xcolor );
803 
804  // Color DARK GREEN.
805  x_color[vpColor::id_darkGreen] = 246;
806  xcolor.pixel = x_color[vpColor::id_darkGreen] ;
807  xcolor.red = 0;
808  xcolor.green = 256 * 128;
809  xcolor.blue = 0;
810  XStoreColor ( display, lut, &xcolor );
811 
812  // Color LIGHT BLUE.
813  x_color[vpColor::id_lightBlue] = 245;
814  xcolor.pixel = x_color[vpColor::id_lightBlue] ;
815  xcolor.red = 256 * 140;
816  xcolor.green = 256 * 140;
817  xcolor.blue = 256 * 255;
818  XStoreColor ( display, lut, &xcolor );
819 
820  // Color BLUE.
821  x_color[vpColor::id_blue] = 244;
822  xcolor.pixel = x_color[vpColor::id_blue];
823  xcolor.red = 0;
824  xcolor.green = 0;
825  xcolor.blue = 256 * 255;
826  XStoreColor ( display, lut, &xcolor );
827 
828  // Color DARK BLUE.
829  x_color[vpColor::id_darkBlue] = 243;
830  xcolor.pixel = x_color[vpColor::id_darkBlue] ;
831  xcolor.red = 0;
832  xcolor.green = 0;
833  xcolor.blue = 256 * 128;
834  XStoreColor ( display, lut, &xcolor );
835 
836  // Color YELLOW.
837  x_color[vpColor::id_yellow] = 242;
838  xcolor.pixel = x_color[vpColor::id_yellow];
839  xcolor.red = 256 * 255;
840  xcolor.green = 256 * 255;
841  xcolor.blue = 0;
842  XStoreColor ( display, lut, &xcolor );
843 
844  // Color ORANGE.
845  x_color[vpColor::id_orange] = 241;
846  xcolor.pixel = x_color[vpColor::id_orange];
847  xcolor.red = 256 * 255;
848  xcolor.green = 256 * 165;
849  xcolor.blue = 0;
850  XStoreColor ( display, lut, &xcolor );
851 
852  // Color CYAN.
853  x_color[vpColor::id_cyan] = 240;
854  xcolor.pixel = x_color[vpColor::id_cyan];
855  xcolor.red = 0;
856  xcolor.green = 256 * 255;
857  xcolor.blue = 256 * 255;
858  XStoreColor ( display, lut, &xcolor );
859 
860  // Color PURPLE.
861  x_color[vpColor::id_purple] = 239;
862  xcolor.pixel = x_color[vpColor::id_purple];
863  xcolor.red = 256 * 128;
864  xcolor.green = 0;
865  xcolor.blue = 256 * 128;
866  XStoreColor ( display, lut, &xcolor );
867 
868  break;
869 
870  case 16:
871  case 24:
872  {
873  xcolor.flags = DoRed | DoGreen | DoBlue ;
874 
875  // Couleur BLACK.
876  xcolor.pad = 0;
877  xcolor.red = 0;
878  xcolor.green = 0;
879  xcolor.blue = 0;
880  XAllocColor ( display, lut, &xcolor );
881  x_color[vpColor::id_black] = xcolor.pixel;
882 
883  // Couleur WHITE.
884  xcolor.pad = 0;
885  xcolor.red = 256* 255;
886  xcolor.green = 256* 255;
887  xcolor.blue = 256* 255;
888  XAllocColor ( display, lut, &xcolor );
889  x_color[vpColor::id_white] = xcolor.pixel;
890 
891  // Couleur LIGHT GRAY.
892  xcolor.pad = 0;
893  xcolor.red = 256 * 192;
894  xcolor.green = 256 * 192;
895  xcolor.blue = 256 * 192;
896  XAllocColor ( display, lut, &xcolor );
897  x_color[vpColor::id_lightGray] = xcolor.pixel;
898 
899  // Couleur GRAY.
900  xcolor.pad = 0;
901  xcolor.red = 256 * 128;
902  xcolor.green = 256 * 128;
903  xcolor.blue = 256 * 128;
904  XAllocColor ( display, lut, &xcolor );
905  x_color[vpColor::id_gray] = xcolor.pixel;
906 
907  // Couleur DARK GRAY.
908  xcolor.pad = 0;
909  xcolor.red = 256 * 64;
910  xcolor.green = 256 * 64;
911  xcolor.blue = 256 * 64;
912  XAllocColor ( display, lut, &xcolor );
913  x_color[vpColor::id_darkGray] = xcolor.pixel;
914 
915  // Couleur LIGHT RED.
916  xcolor.pad = 0;
917  xcolor.red = 256 * 255;
918  xcolor.green = 256 * 140;
919  xcolor.blue = 256 * 140;
920  XAllocColor ( display, lut, &xcolor );
921  x_color[vpColor::id_lightRed] = xcolor.pixel;
922 
923  // Couleur RED.
924  xcolor.pad = 0;
925  xcolor.red = 256* 255;
926  xcolor.green = 0;
927  xcolor.blue = 0;
928  XAllocColor ( display, lut, &xcolor );
929  x_color[vpColor::id_red] = xcolor.pixel;
930 
931  // Couleur DARK RED.
932  xcolor.pad = 0;
933  xcolor.red = 256* 128;
934  xcolor.green = 0;
935  xcolor.blue = 0;
936  XAllocColor ( display, lut, &xcolor );
937  x_color[vpColor::id_darkRed] = xcolor.pixel;
938 
939  // Couleur LIGHT GREEN.
940  xcolor.pad = 0;
941  xcolor.red = 256 * 140;
942  xcolor.green = 256 * 255;
943  xcolor.blue = 256 * 140;
944  XAllocColor ( display, lut, &xcolor );
945  x_color[vpColor::id_lightGreen] = xcolor.pixel;
946 
947  // Couleur GREEN.
948  xcolor.pad = 0;
949  xcolor.red = 0;
950  xcolor.green = 256*255;
951  xcolor.blue = 0;
952  XAllocColor ( display, lut, &xcolor );
953  x_color[vpColor::id_green] = xcolor.pixel;
954 
955  // Couleur DARK GREEN.
956  xcolor.pad = 0;
957  xcolor.red = 0;
958  xcolor.green = 256* 128;
959  xcolor.blue = 0;
960  XAllocColor ( display, lut, &xcolor );
961  x_color[vpColor::id_darkGreen] = xcolor.pixel;
962 
963  // Couleur LIGHT Blue.
964  xcolor.pad = 0;
965  xcolor.red = 256 * 140;
966  xcolor.green = 256 * 140;
967  xcolor.blue = 256 * 255;
968  XAllocColor ( display, lut, &xcolor );
969  x_color[vpColor::id_lightBlue] = xcolor.pixel;
970 
971  // Couleur BLUE.
972  xcolor.pad = 0;
973  xcolor.red = 0;
974  xcolor.green = 0;
975  xcolor.blue = 256* 255;
976  XAllocColor ( display, lut, &xcolor );
977  x_color[vpColor::id_blue] = xcolor.pixel;
978 
979  // Couleur DARK BLUE.
980  xcolor.pad = 0;
981  xcolor.red = 0;
982  xcolor.green = 0;
983  xcolor.blue = 256* 128;
984  XAllocColor ( display, lut, &xcolor );
985  x_color[vpColor::id_darkBlue] = xcolor.pixel;
986 
987  // Couleur YELLOW.
988  xcolor.pad = 0;
989  xcolor.red = 256 * 255;
990  xcolor.green = 256 * 255;
991  xcolor.blue = 0;
992  XAllocColor ( display, lut, &xcolor );
993  x_color[vpColor::id_yellow] = xcolor.pixel;
994 
995  // Couleur ORANGE.
996  xcolor.pad = 0;
997  xcolor.red = 256 * 255;
998  xcolor.green = 256 * 165;
999  xcolor.blue = 0;
1000  XAllocColor ( display, lut, &xcolor );
1001  x_color[vpColor::id_orange] = xcolor.pixel;
1002 
1003  // Couleur CYAN.
1004  xcolor.pad = 0;
1005  xcolor.red = 0;
1006  xcolor.green = 256 * 255;
1007  xcolor.blue = 256 * 255;
1008  XAllocColor ( display, lut, &xcolor );
1009  x_color[vpColor::id_cyan] = xcolor.pixel;
1010 
1011  // Couleur PURPLE.
1012  xcolor.pad = 0;
1013  xcolor.red = 256 * 128;
1014  xcolor.green = 0;
1015  xcolor.blue = 256 * 128;
1016  XAllocColor ( display, lut, &xcolor );
1017  x_color[vpColor::id_purple] = xcolor.pixel;
1018  break;
1019  }
1020  }
1021 
1022  XSetStandardProperties ( display, window, this->title, this->title, None, 0, 0, &hints );
1023  XMapWindow ( display, window ) ;
1024  // Selection des evenements.
1025  XSelectInput ( display, window,
1026  ExposureMask |
1027  ButtonPressMask | ButtonReleaseMask |
1028  KeyPressMask | KeyReleaseMask |
1029  StructureNotifyMask |
1030  PointerMotionMask);
1031 
1032  // Creation du contexte graphique
1033  values.plane_mask = AllPlanes;
1034  values.fill_style = FillSolid;
1035  values.foreground = WhitePixel ( display, screen );
1036  values.background = BlackPixel ( display, screen );
1037  context = XCreateGC ( display, window,
1038  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1039  &values );
1040 
1041  if ( context == NULL )
1042  {
1043  vpERROR_TRACE ( "Can't create graphics context." );
1045  "Can't create graphics context" ) ) ;
1046  }
1047 
1048  // Pixmap creation.
1049  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1050 
1051  do
1052  XNextEvent ( display, &event );
1053  while ( event.xany.type != Expose );
1054 
1055 
1056  {
1057  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1058  screen_depth, ZPixmap, 0, NULL,
1059  I.getWidth() , I.getHeight(), XBitmapPad ( display ), 0 );
1060 
1061 
1062  Ximage->data = ( char * ) malloc ( I.getWidth() * I.getHeight()
1063  * (unsigned int)Ximage->bits_per_pixel / 8 );
1064  ximage_data_init = true;
1065 
1066  }
1067  displayHasBeenInitialized = true ;
1068 
1069  XSync ( display, true );
1070  setTitle ( this->title ) ;
1071 
1072  I.display = this ;
1073 }
1074 
1075 
1083 void vpDisplayX::init ( unsigned int width, unsigned int height,
1084  int x, int y, const char *title )
1085 {
1086 
1087  /* setup X11 ------------------------------------------------------------- */
1088  this->width = width;
1089  this->height = height;
1090 
1091  XSizeHints hints;
1092 
1093  if (x != -1)
1094  windowXPosition = x ;
1095  if (y != -1)
1096  windowYPosition = y ;
1097  // Positionnement de la fenetre dans l'�cran.
1098  if ( ( windowXPosition < 0 ) || ( windowYPosition < 0 ) )
1099  {
1100  hints.flags = 0;
1101  }
1102  else
1103  {
1104  hints.flags = USPosition;
1105  hints.x = windowXPosition;
1106  hints.y = windowYPosition;
1107  }
1108 
1109  if ( title != NULL )
1110  strcpy ( this->title, title ) ;
1111 
1112  if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
1113  {
1114  vpERROR_TRACE ( "Can't connect display on server %s.\n", XDisplayName ( NULL ) );
1116  "Can't connect display on server." ) ) ;
1117  }
1118 
1119  screen = DefaultScreen ( display );
1120  lut = DefaultColormap ( display, screen );
1121  screen_depth = (unsigned int)DefaultDepth ( display, screen );
1122 
1123  vpTRACE ( "Screen depth: %d\n", screen_depth );
1124 
1125  if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
1127  width, height, 1,
1128  BlackPixel ( display, screen ),
1129  WhitePixel ( display, screen ) ) ) == 0 )
1130  {
1131  vpERROR_TRACE ( "Can't create window." );
1133  "Can't create window." ) ) ;
1134  }
1135 
1136 
1137  //
1138  // Create color table for 8 and 16 bits screen
1139  //
1140  if ( screen_depth == 8 )
1141  {
1142  lut = XCreateColormap ( display, window,
1143  DefaultVisual ( display, screen ), AllocAll ) ;
1144  xcolor.flags = DoRed | DoGreen | DoBlue ;
1145 
1146  for ( unsigned int i = 0 ; i < 256 ; i++ )
1147  {
1148  xcolor.pixel = i ;
1149  xcolor.red = 256 * i;
1150  xcolor.green = 256 * i;
1151  xcolor.blue = 256 * i;
1152  XStoreColor ( display, lut, &xcolor );
1153  }
1154 
1155  XSetWindowColormap ( display, window, lut ) ;
1156  XInstallColormap ( display, lut ) ;
1157  }
1158 
1159  else if ( screen_depth == 16 )
1160  {
1161  for ( unsigned int i = 0; i < 256; i ++ )
1162  {
1163  xcolor.pad = 0;
1164  xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1165  if ( XAllocColor ( display, lut, &xcolor ) == 0 )
1166  {
1167  vpERROR_TRACE ( "Can't allocate 256 colors. Only %d allocated.", i );
1169  "Can't allocate 256 colors." ) ) ;
1170  }
1171  colortable[i] = xcolor.pixel;
1172  }
1173 
1174  XSetWindowColormap ( display, window, lut ) ;
1175  XInstallColormap ( display, lut ) ;
1176 
1177  }
1178 
1179  vpColor pcolor; // predefined colors
1180 
1181  //
1182  // Create colors for overlay
1183  //
1184  switch ( screen_depth )
1185  {
1186 
1187  case 8:
1188  // Color BLACK: default set to 0
1189 
1190  // Color WHITE: default set to 255
1191 
1192  // Color LIGHT GRAY.
1193  pcolor = vpColor::lightGray;
1194  xcolor.pixel = 254 ; // affected to 254
1195  xcolor.red = 256 * pcolor.R;
1196  xcolor.green = 256 * pcolor.G;
1197  xcolor.blue = 256 * pcolor.B;
1198  XStoreColor ( display, lut, &xcolor );
1199 
1200  // Color GRAY.
1201  pcolor = vpColor::gray;
1202  xcolor.pixel = 253 ; // affected to 253
1203  xcolor.red = 256 * pcolor.R;
1204  xcolor.green = 256 * pcolor.G;
1205  xcolor.blue = 256 * pcolor.B;
1206  XStoreColor ( display, lut, &xcolor );
1207 
1208  // Color DARK GRAY.
1209  pcolor = vpColor::darkGray;
1210  xcolor.pixel = 252 ; // affected to 252
1211  xcolor.red = 256 * pcolor.R;
1212  xcolor.green = 256 * pcolor.G;
1213  xcolor.blue = 256 * pcolor.B;
1214  XStoreColor ( display, lut, &xcolor );
1215 
1216  // Color LIGHT RED.
1217  pcolor = vpColor::lightRed;
1218  xcolor.pixel = 251 ; // affected to 251
1219  xcolor.red = 256 * pcolor.R;
1220  xcolor.green = 256 * pcolor.G;
1221  xcolor.blue = 256 * pcolor.B;
1222  XStoreColor ( display, lut, &xcolor );
1223 
1224  // Color RED.
1225  pcolor = vpColor::red;
1226  xcolor.pixel = 250 ; // affected to 250
1227  xcolor.red = 256 * pcolor.R;
1228  xcolor.green = 256 * pcolor.G;
1229  xcolor.blue = 256 * pcolor.B;
1230  XStoreColor ( display, lut, &xcolor );
1231 
1232  // Color DARK RED.
1233  pcolor = vpColor::darkRed;
1234  xcolor.pixel = 249 ; // affected to 249
1235  xcolor.red = 256 * pcolor.R;
1236  xcolor.green = 256 * pcolor.G;
1237  xcolor.blue = 256 * pcolor.B;
1238  XStoreColor ( display, lut, &xcolor );
1239 
1240  // Color LIGHT GREEN.
1241  pcolor = vpColor::lightGreen;
1242  xcolor.pixel = 248 ; // affected to 248
1243  xcolor.red = 256 * pcolor.R;
1244  xcolor.green = 256 * pcolor.G;
1245  xcolor.blue = 256 * pcolor.B;
1246  XStoreColor ( display, lut, &xcolor );
1247 
1248  // Color GREEN.
1249  pcolor = vpColor::green;
1250  xcolor.pixel = 247; // affected to 247
1251  xcolor.red = 256 * pcolor.R;
1252  xcolor.green = 256 * pcolor.G;
1253  xcolor.blue = 256 * pcolor.B;
1254  XStoreColor ( display, lut, &xcolor );
1255 
1256  // Color DARK GREEN.
1257  pcolor = vpColor::darkGreen;
1258  xcolor.pixel = 246 ; // affected to 246
1259  xcolor.red = 256 * pcolor.R;
1260  xcolor.green = 256 * pcolor.G;
1261  xcolor.blue = 256 * pcolor.B;
1262  XStoreColor ( display, lut, &xcolor );
1263 
1264  // Color LIGHT BLUE.
1265  pcolor = vpColor::lightBlue;
1266  xcolor.pixel = 245 ; // affected to 245
1267  xcolor.red = 256 * pcolor.R;
1268  xcolor.green = 256 * pcolor.G;
1269  xcolor.blue = 256 * pcolor.B;
1270  XStoreColor ( display, lut, &xcolor );
1271 
1272  // Color BLUE.
1273  pcolor = vpColor::blue;
1274  xcolor.pixel = 244; // affected to 244
1275  xcolor.red = 256 * pcolor.R;
1276  xcolor.green = 256 * pcolor.G;
1277  xcolor.blue = 256 * pcolor.B;
1278  XStoreColor ( display, lut, &xcolor );
1279 
1280  // Color DARK BLUE.
1281  pcolor = vpColor::darkBlue;
1282  xcolor.pixel = 243 ; // affected to 243
1283  xcolor.red = 256 * pcolor.R;
1284  xcolor.green = 256 * pcolor.G;
1285  xcolor.blue = 256 * pcolor.B;
1286  XStoreColor ( display, lut, &xcolor );
1287 
1288  // Color YELLOW.
1289  pcolor = vpColor::yellow;
1290  xcolor.pixel = 242; // affected to 242
1291  xcolor.red = 256 * pcolor.R;
1292  xcolor.green = 256 * pcolor.G;
1293  xcolor.blue = 256 * pcolor.B;
1294  XStoreColor ( display, lut, &xcolor );
1295 
1296  // Color ORANGE.
1297  pcolor = vpColor::orange;
1298  xcolor.pixel = 241; // affected to 241
1299  xcolor.red = 256 * pcolor.R;
1300  xcolor.green = 256 * pcolor.G;
1301  xcolor.blue = 256 * pcolor.B;
1302  XStoreColor ( display, lut, &xcolor );
1303 
1304  // Color CYAN.
1305  pcolor = vpColor::cyan;
1306  xcolor.pixel = 240; // affected to 240
1307  xcolor.red = 256 * pcolor.R;
1308  xcolor.green = 256 * pcolor.G;
1309  xcolor.blue = 256 * pcolor.B;
1310  XStoreColor ( display, lut, &xcolor );
1311 
1312  // Color PURPLE.
1313  pcolor = vpColor::purple;
1314  xcolor.pixel = 239; // affected to 239
1315  xcolor.red = 256 * pcolor.R;
1316  xcolor.green = 256 * pcolor.G;
1317  xcolor.blue = 256 * pcolor.B;
1318  XStoreColor ( display, lut, &xcolor );
1319 
1320  break;
1321 
1322  case 16:
1323  case 24:
1324  {
1325  xcolor.flags = DoRed | DoGreen | DoBlue ;
1326 
1327  // Couleur BLACK.
1328  pcolor = vpColor::black;
1329  xcolor.pad = 0;
1330  xcolor.red = 256 * pcolor.R;
1331  xcolor.green = 256 * pcolor.G;
1332  xcolor.blue = 256 * pcolor.B;
1333  XAllocColor ( display, lut, &xcolor );
1334  x_color[vpColor::id_black] = xcolor.pixel;
1335 
1336  // Color WHITE.
1337  pcolor = vpColor::white;
1338  xcolor.pad = 0;
1339  xcolor.red = 256 * pcolor.R;
1340  xcolor.green = 256 * pcolor.G;
1341  xcolor.blue = 256 * pcolor.B;
1342  XAllocColor ( display, lut, &xcolor );
1343  x_color[vpColor::id_white] = xcolor.pixel;
1344 
1345  // Color LIGHT GRAY.
1346  pcolor = vpColor::lightGray;
1347  xcolor.pad = 0;
1348  xcolor.red = 256 * pcolor.R;
1349  xcolor.green = 256 * pcolor.G;
1350  xcolor.blue = 256 * pcolor.B;
1351  XAllocColor ( display, lut, &xcolor );
1352  x_color[vpColor::id_lightGray] = xcolor.pixel;
1353 
1354  // Color GRAY.
1355  pcolor = vpColor::gray;
1356  xcolor.pad = 0;
1357  xcolor.red = 256 * pcolor.R;
1358  xcolor.green = 256 * pcolor.G;
1359  xcolor.blue = 256 * pcolor.B;
1360  XAllocColor ( display, lut, &xcolor );
1361  x_color[vpColor::id_gray] = xcolor.pixel;
1362 
1363  // Color DARK GRAY.
1364  pcolor = vpColor::darkGray;
1365  xcolor.pad = 0;
1366  xcolor.red = 256 * pcolor.R;
1367  xcolor.green = 256 * pcolor.G;
1368  xcolor.blue = 256 * pcolor.B;
1369  XAllocColor ( display, lut, &xcolor );
1370  x_color[vpColor::id_darkGray] = xcolor.pixel;
1371 
1372  // Color LIGHT RED.
1373  pcolor = vpColor::lightRed;
1374  xcolor.pad = 0;
1375  xcolor.red = 256 * pcolor.R;
1376  xcolor.green = 256 * pcolor.G;
1377  xcolor.blue = 256 * pcolor.B;
1378  XAllocColor ( display, lut, &xcolor );
1379  x_color[vpColor::id_lightRed] = xcolor.pixel;
1380 
1381  // Color RED.
1382  pcolor = vpColor::red;
1383  xcolor.pad = 0;
1384  xcolor.red = 256 * pcolor.R;
1385  xcolor.green = 256 * pcolor.G;
1386  xcolor.blue = 256 * pcolor.B;
1387  XAllocColor ( display, lut, &xcolor );
1388  x_color[vpColor::id_red] = xcolor.pixel;
1389 
1390  // Color DARK RED.
1391  pcolor = vpColor::darkRed;
1392  xcolor.pad = 0;
1393  xcolor.red = 256 * pcolor.R;
1394  xcolor.green = 256 * pcolor.G;
1395  xcolor.blue = 256 * pcolor.B;
1396  XAllocColor ( display, lut, &xcolor );
1397  x_color[vpColor::id_darkRed] = xcolor.pixel;
1398 
1399  // Color LIGHT GREEN.
1400  pcolor = vpColor::lightGreen;
1401  xcolor.pad = 0;
1402  xcolor.red = 256 * pcolor.R;
1403  xcolor.green = 256 * pcolor.G;
1404  xcolor.blue = 256 * pcolor.B;
1405  XAllocColor ( display, lut, &xcolor );
1406  x_color[vpColor::id_lightGreen] = xcolor.pixel;
1407 
1408  // Color GREEN.
1409  pcolor = vpColor::green;
1410  xcolor.pad = 0;
1411  xcolor.red = 256 * pcolor.R;
1412  xcolor.green = 256 * pcolor.G;
1413  xcolor.blue = 256 * pcolor.B;
1414  XAllocColor ( display, lut, &xcolor );
1415  x_color[vpColor::id_green] = xcolor.pixel;
1416 
1417  // Color DARK GREEN.
1418  pcolor = vpColor::darkGreen;
1419  xcolor.pad = 0;
1420  xcolor.red = 256 * pcolor.R;
1421  xcolor.green = 256 * pcolor.G;
1422  xcolor.blue = 256 * pcolor.B;
1423  XAllocColor ( display, lut, &xcolor );
1424  x_color[vpColor::id_darkGreen] = xcolor.pixel;
1425 
1426  // Color LIGHT BLUE.
1427  pcolor = vpColor::lightBlue;
1428  xcolor.pad = 0;
1429  xcolor.red = 256 * pcolor.R;
1430  xcolor.green = 256 * pcolor.G;
1431  xcolor.blue = 256 * pcolor.B;
1432  XAllocColor ( display, lut, &xcolor );
1433  x_color[vpColor::id_lightBlue] = xcolor.pixel;
1434 
1435  // Color BLUE.
1436  pcolor = vpColor::blue;
1437  xcolor.pad = 0;
1438  xcolor.red = 256 * pcolor.R;
1439  xcolor.green = 256 * pcolor.G;
1440  xcolor.blue = 256 * pcolor.B;
1441  XAllocColor ( display, lut, &xcolor );
1442  x_color[vpColor::id_blue] = xcolor.pixel;
1443 
1444  // Color DARK BLUE.
1445  pcolor = vpColor::darkBlue;
1446  xcolor.pad = 0;
1447  xcolor.red = 256 * pcolor.R;
1448  xcolor.green = 256 * pcolor.G;
1449  xcolor.blue = 256 * pcolor.B;
1450  XAllocColor ( display, lut, &xcolor );
1451  x_color[vpColor::id_darkBlue] = xcolor.pixel;
1452 
1453  // Color YELLOW.
1454  pcolor = vpColor::yellow;
1455  xcolor.pad = 0;
1456  xcolor.red = 256 * pcolor.R;
1457  xcolor.green = 256 * pcolor.G;
1458  xcolor.blue = 256 * pcolor.B;
1459  XAllocColor ( display, lut, &xcolor );
1460  x_color[vpColor::id_yellow] = xcolor.pixel;
1461 
1462  // Color ORANGE.
1463  pcolor = vpColor::orange;
1464  xcolor.pad = 0;
1465  xcolor.red = 256 * pcolor.R;
1466  xcolor.green = 256 * pcolor.G;
1467  xcolor.blue = 256 * pcolor.B;
1468  XAllocColor ( display, lut, &xcolor );
1469  x_color[vpColor::id_orange] = xcolor.pixel;
1470 
1471  // Color CYAN.
1472  pcolor = vpColor::cyan;
1473  xcolor.pad = 0;
1474  xcolor.red = 256 * pcolor.R;
1475  xcolor.green = 256 * pcolor.G;
1476  xcolor.blue = 256 * pcolor.B;
1477  XAllocColor ( display, lut, &xcolor );
1478  x_color[vpColor::id_cyan] = xcolor.pixel;
1479 
1480  // Color PURPLE.
1481  pcolor = vpColor::purple;
1482  xcolor.pad = 0;
1483  xcolor.red = 256 * pcolor.R;
1484  xcolor.green = 256 * pcolor.G;
1485  xcolor.blue = 256 * pcolor.B;
1486  XAllocColor ( display, lut, &xcolor );
1487  x_color[vpColor::id_purple] = xcolor.pixel;
1488  break;
1489  }
1490  }
1491 
1492  XSetStandardProperties ( display, window, this->title, this->title, None, 0, 0, &hints );
1493  XMapWindow ( display, window ) ;
1494  // Selection des evenements.
1495  XSelectInput ( display, window,
1496  ExposureMask |
1497  ButtonPressMask | ButtonReleaseMask |
1498  KeyPressMask | KeyReleaseMask |
1499  StructureNotifyMask |
1500  PointerMotionMask);
1501 
1502  /* Creation du contexte graphique */
1503  values.plane_mask = AllPlanes;
1504  values.fill_style = FillSolid;
1505  values.foreground = WhitePixel ( display, screen );
1506  values.background = BlackPixel ( display, screen );
1507  context = XCreateGC ( display, window,
1508  GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1509  &values );
1510 
1511  if ( context == NULL )
1512  {
1513  vpERROR_TRACE ( "Can't create graphics context." );
1515  "Can't create graphics context" ) ) ;
1516  }
1517 
1518  // Pixmap creation.
1519  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1520 
1521  do
1522  XNextEvent ( display, &event );
1523  while ( event.xany.type != Expose );
1524 
1525  {
1526  Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1527  screen_depth, ZPixmap, 0, NULL,
1528  width, height, XBitmapPad ( display ), 0 );
1529 
1530  Ximage->data = ( char * ) malloc ( width * height
1531  * (unsigned int)Ximage->bits_per_pixel / 8 );
1532  ximage_data_init = true;
1533  }
1534  displayHasBeenInitialized = true ;
1535 
1536  XSync ( display, true );
1537  setTitle ( this->title ) ;
1538 
1539 }
1540 
1555 void vpDisplayX::setFont( const char* font )
1556 {
1558  {
1559  if (font!=NULL)
1560  {
1561  try
1562  {
1563  Font stringfont;
1564  stringfont = XLoadFont (display, font) ; //"-adobe-times-bold-r-normal--18*");
1565  XSetFont (display, context, stringfont);
1566  }
1567  catch(...)
1568  {
1569  vpERROR_TRACE ( "Bad font " ) ;
1571  }
1572  }
1573  }
1574  else
1575  {
1576  vpERROR_TRACE ( "X not initialized " ) ;
1578  "X not initialized" ) ) ;
1579  }
1580 }
1581 
1586 void
1587 vpDisplayX::setTitle ( const char *title )
1588 {
1590  {
1591  XStoreName ( display, window, title );
1592  }
1593  else
1594  {
1595  vpERROR_TRACE ( "X not initialized " ) ;
1597  "X not initialized" ) ) ;
1598  }
1599 }
1600 
1609 void vpDisplayX::setWindowPosition(int winx, int winy)
1610 {
1611  if ( displayHasBeenInitialized ) {
1612  XMoveWindow(display, window, winx, winy);
1613  }
1614  else
1615  {
1616  vpERROR_TRACE ( "X not initialized " ) ;
1618  "X not initialized" ) ) ;
1619  }
1620 }
1621 
1634 {
1635 
1637  {
1638  switch ( screen_depth )
1639  {
1640  case 8:
1641  {
1642  unsigned char *src_8 = NULL;
1643  unsigned char *dst_8 = NULL;
1644  src_8 = ( unsigned char * ) I.bitmap;
1645  dst_8 = ( unsigned char * ) Ximage->data;
1646  // Correction de l'image de facon a liberer les niveaux de gris
1647  // ROUGE, VERT, BLEU, JAUNE
1648  {
1649  unsigned int i = 0;
1650  unsigned int size = width * height;
1651  unsigned char nivGris;
1652  unsigned char nivGrisMax = 255 - vpColor::id_unknown;
1653 
1654  while ( i < size )
1655  {
1656  nivGris = src_8[i] ;
1657  if ( nivGris > nivGrisMax )
1658  dst_8[i] = 255;
1659  else
1660  dst_8[i] = nivGris;
1661  i++ ;
1662  }
1663  }
1664 
1665  // Affichage de l'image dans la Pixmap.
1666  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1667  XSetWindowBackgroundPixmap ( display, window, pixmap );
1668 // XClearWindow ( display, window );
1669 // XSync ( display,1 );
1670  break;
1671  }
1672  case 16:
1673  {
1674  unsigned short *dst_16 = NULL;
1675  dst_16 = ( unsigned short* ) Ximage->data;
1676 
1677  for ( unsigned int i = 0; i < height ; i++ )
1678  {
1679  for ( unsigned int j=0 ; j < width; j++ )
1680  {
1681  * ( dst_16+ ( i*width+j ) ) = ( unsigned short ) colortable[I[i][j]] ;
1682  }
1683  }
1684 
1685  // Affichage de l'image dans la Pixmap.
1686  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1687  XSetWindowBackgroundPixmap ( display, window, pixmap );
1688 // XClearWindow ( display, window );
1689 // XSync ( display,1 );
1690  break;
1691  }
1692 
1693  case 24:
1694  default:
1695  {
1696  unsigned char *dst_32 = NULL;
1697  unsigned int size = width * height ;
1698  dst_32 = ( unsigned char* ) Ximage->data;
1699  unsigned char *bitmap = I.bitmap ;
1700  unsigned char *n = I.bitmap + size;
1701  //for (unsigned int i = 0; i < size; i++) // suppression de l'iterateur i
1702  while ( bitmap < n )
1703  {
1704  unsigned char val = * ( bitmap++ );
1705  * ( dst_32 ++ ) = val; // Composante Rouge.
1706  * ( dst_32 ++ ) = val; // Composante Verte.
1707  * ( dst_32 ++ ) = val; // Composante Bleue.
1708  * ( dst_32 ++ ) = val;
1709  }
1710 
1711  // Affichage de l'image dans la Pixmap.
1712  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1713  XSetWindowBackgroundPixmap ( display, window, pixmap );
1714 // XClearWindow ( display, window );
1715 // XSync ( display,1 );
1716  break;
1717  }
1718  }
1719  }
1720  else
1721  {
1722  vpERROR_TRACE ( "X not initialized " ) ;
1724  "X not initialized" ) ) ;
1725  }
1726 }
1739 {
1740 
1742  {
1743 
1744  switch ( screen_depth )
1745  {
1746  case 24:
1747  case 32:
1748  {
1749  /*
1750  * 32-bit source, 24/32-bit destination
1751  */
1752 
1753  unsigned char *dst_32 = NULL;
1754  dst_32 = ( unsigned char* ) Ximage->data;
1755  vpRGBa* bitmap = I.bitmap;
1756  unsigned int sizeI = I.getWidth() * I.getHeight();
1757 #ifdef BIGENDIAN
1758  // little indian/big indian
1759  for ( unsigned int i = 0; i < sizeI ; i++ )
1760  {
1761  *(dst_32++) = bitmap->A;
1762  *(dst_32++) = bitmap->R;
1763  *(dst_32++) = bitmap->G;
1764  *(dst_32++) = bitmap->B;
1765  bitmap++;
1766  }
1767 #else
1768  for ( unsigned int i = 0; i < sizeI; i++ )
1769  {
1770  *(dst_32++) = bitmap->B;
1771  *(dst_32++) = bitmap->G;
1772  *(dst_32++) = bitmap->R;
1773  *(dst_32++) = bitmap->A;
1774  bitmap++;
1775  }
1776 #endif
1777  // Affichage de l'image dans la Pixmap.
1778  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1779  XSetWindowBackgroundPixmap ( display, window, pixmap );
1780 // XClearWindow ( display, window );
1781 // XSync ( display,1 );
1782  break;
1783 
1784  }
1785  default:
1786  vpERROR_TRACE ( "Unsupported depth (%d bpp) for color display",
1787  screen_depth ) ;
1789  "Unsupported depth for color display" ) ) ;
1790  }
1791  }
1792  else
1793  {
1794  vpERROR_TRACE ( "X not initialized " ) ;
1796  "X not initialized" ) ) ;
1797  }
1798 }
1799 
1811 void vpDisplayX::displayImage ( const unsigned char *I )
1812 {
1813  unsigned char *dst_32 = NULL;
1814 
1816  {
1817 
1818  dst_32 = ( unsigned char* ) Ximage->data;
1819 
1820  for ( unsigned int i = 0; i < width * height; i++ )
1821  {
1822  * ( dst_32 ++ ) = *I; // red component.
1823  * ( dst_32 ++ ) = *I; // green component.
1824  * ( dst_32 ++ ) = *I; // blue component.
1825  * ( dst_32 ++ ) = *I; // luminance component.
1826  I++;
1827  }
1828 
1829  // Affichage de l'image dans la Pixmap.
1830  XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0, width, height );
1831  XSetWindowBackgroundPixmap ( display, window, pixmap );
1832 // XClearWindow ( display, window );
1833 // XSync ( display,1 );
1834  }
1835  else
1836  {
1837  vpERROR_TRACE ( "X not initialized " ) ;
1839  "X not initialized" ) ) ;
1840  }
1841 }
1842 
1843 
1861 void vpDisplayX::displayImageROI ( const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height )
1862 {
1864  {
1865  switch ( screen_depth )
1866  {
1867  case 8:
1868  {
1869  unsigned char *src_8 = NULL;
1870  unsigned char *dst_8 = NULL;
1871  src_8 = ( unsigned char * ) I.bitmap;
1872  dst_8 = ( unsigned char * ) Ximage->data;
1873  // Correction de l'image de facon a liberer les niveaux de gris
1874  // ROUGE, VERT, BLEU, JAUNE
1875  {
1876  //int size = width * height;
1877  unsigned char nivGris;
1878  unsigned char nivGrisMax = 255 - vpColor::id_unknown;
1879 
1880  //unsigned int iwidth = I.getWidth();
1881  unsigned int iwidth = I.getWidth();
1882 
1883  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1884  dst_8 = dst_8 + (int)(iP.get_i()*this->height+ iP.get_j());
1885 
1886  unsigned int i = 0;
1887  while (i < height)
1888  {
1889  unsigned int j = 0;
1890  while (j < width)
1891  {
1892  nivGris = *(src_8+j);
1893  if ( nivGris > nivGrisMax )
1894  *(dst_8+j) = 255;
1895  else
1896  *(dst_8+j) = nivGris;
1897  j++;
1898  }
1899  src_8 = src_8 + iwidth;
1900  dst_8 = dst_8 + this->height;
1901  i++;
1902  }
1903  }
1904 
1905  // Affichage de l'image dans la Pixmap.
1906  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
1907  XSetWindowBackgroundPixmap ( display, window, pixmap );
1908 // XClearWindow ( display, window );
1909 // XSync ( display,1 );
1910  break;
1911  }
1912  case 16:
1913  {
1914  unsigned short *dst_16 = NULL;
1915  dst_16 = ( unsigned short* ) Ximage->data;
1916  unsigned char *src_8 = NULL;
1917  src_8 = ( unsigned char * ) I.bitmap;
1918 
1919  unsigned int iwidth = I.getWidth();
1920 
1921  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1922  dst_16 = dst_16 + (int)(iP.get_i()*this->height+ iP.get_j());
1923 
1924  unsigned int i = 0;
1925  while (i < height)
1926  {
1927  unsigned int j = 0;
1928  while (j < width)
1929  {
1930  *(dst_16+j) = ( unsigned short ) colortable[*(src_8+j)];
1931  j++;
1932  }
1933  src_8 = src_8 + iwidth;
1934  dst_16 = dst_16 + this->height;
1935  i++;
1936  }
1937 
1938  // Affichage de l'image dans la Pixmap.
1939  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
1940  XSetWindowBackgroundPixmap ( display, window, pixmap );
1941 // XClearWindow ( display, window );
1942 // XSync ( display,1 );
1943  break;
1944  }
1945 
1946  case 24:
1947  default:
1948  {
1949  unsigned char *dst_32 = NULL;
1950  //unsigned int size = width * height ;
1951  dst_32 = ( unsigned char* ) Ximage->data;
1952  unsigned char *src_8 = I.bitmap ;
1953  //unsigned char *n = I.bitmap + size;
1954 
1955  unsigned int iwidth = I.getWidth();
1956 
1957  src_8 = src_8 + (int)(iP.get_i()*iwidth+ iP.get_j());
1958  dst_32 = dst_32 + (int)(iP.get_i()*4*this->width+ iP.get_j()*4);
1959 
1960  unsigned int i = 0;
1961  while (i < height)
1962  {
1963  unsigned int j = 0;
1964  while (j < width)
1965  {
1966  unsigned char val = *(src_8+j);
1967  *(dst_32+4*j) = val;
1968  *(dst_32+4*j+1) = val;
1969  *(dst_32+4*j+2) = val;
1970  *(dst_32+4*j+3) = val;
1971  j++;
1972  }
1973  src_8 = src_8 + iwidth;
1974  dst_32 = dst_32 + 4*this->width;
1975  i++;
1976  }
1977 
1978  // Affichage de l'image dans la Pixmap.
1979  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
1980  XSetWindowBackgroundPixmap ( display, window, pixmap );
1981 // XClearWindow ( display, window );
1982 // XSync ( display,1 );
1983  break;
1984  }
1985  }
1986  }
1987  else
1988  {
1989  vpERROR_TRACE ( "X not initialized " ) ;
1991  "X not initialized" ) ) ;
1992  }
1993 }
1994 
1995 
2013 void vpDisplayX::displayImageROI ( const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height )
2014 {
2015 
2017  {
2018 
2019  switch ( screen_depth )
2020  {
2021  case 24:
2022  case 32:
2023  {
2024  /*
2025  * 32-bit source, 24/32-bit destination
2026  */
2027 
2028  unsigned char *dst_32 = NULL;
2029  dst_32 = ( unsigned char* ) Ximage->data;
2030  vpRGBa* src_32 = I.bitmap;
2031  //unsigned int sizeI = I.getWidth() * I.getHeight();
2032 
2033  unsigned int iwidth = I.getWidth();
2034 
2035  src_32 = src_32 + (int)(iP.get_i()*iwidth+ iP.get_j());
2036  dst_32 = dst_32 + (int)(iP.get_i()*4*this->width+ iP.get_j()*4);
2037 
2038  unsigned int i = 0;
2039  while (i < height)
2040  {
2041  unsigned int j = 0;
2042  while (j < width)
2043  {
2044 #ifdef BIGENDIAN
2045  *(dst_32+4*j) = (src_32+j)->A;
2046  *(dst_32+4*j+1) = (src_32+j)->R;
2047  *(dst_32+4*j+2) = (src_32+j)->G;
2048  *(dst_32+4*j+3) = (src_32+j)->B;
2049 #else
2050  *(dst_32+4*j) = (src_32+j)->B;
2051  *(dst_32+4*j+1) = (src_32+j)->G;
2052  *(dst_32+4*j+2) = (src_32+j)->R;
2053  *(dst_32+4*j+3) = (src_32+j)->A;
2054 #endif
2055  j++;
2056  }
2057  src_32 = src_32 + iwidth;
2058  dst_32 = dst_32 + 4*this->width;
2059  i++;
2060  }
2061 
2062  // Affichage de l'image dans la Pixmap.
2063  XPutImage ( display, pixmap, context, Ximage, iP.get_u(), iP.get_v(), iP.get_u(), iP.get_v(), width, height );
2064  XSetWindowBackgroundPixmap ( display, window, pixmap );
2065 // XClearWindow ( display, window );
2066 // XSync ( display,1 );
2067  break;
2068 
2069  }
2070  default:
2071  vpERROR_TRACE ( "Unsupported depth (%d bpp) for color display",
2072  screen_depth ) ;
2074  "Unsupported depth for color display" ) ) ;
2075  }
2076  }
2077  else
2078  {
2079  vpERROR_TRACE ( "X not initialized " ) ;
2081  "X not initialized" ) ) ;
2082  }
2083 }
2084 
2093 {
2095  {
2096  if ( ximage_data_init == true )
2097  free ( Ximage->data );
2098 
2099  Ximage->data = NULL;
2100  XDestroyImage ( Ximage );
2101 
2102  XFreePixmap ( display, pixmap );
2103 
2104  XFreeGC ( display, context );
2105  XDestroyWindow ( display, window );
2106  XCloseDisplay ( display );
2107 
2108  displayHasBeenInitialized = false;
2109 
2110  if (x_color != NULL) {
2111  delete [] x_color;
2112  x_color = NULL;
2113  }
2114  }
2115 }
2116 
2117 
2124 {
2126  {
2127  XClearWindow ( display, window );
2128  //XClearArea ( display, window,0,0,100,100,0 );
2129  XFlush ( display );
2130  }
2131  else
2132  {
2133  vpERROR_TRACE ( "X not initialized " ) ;
2135  "X not initialized" ) ) ;
2136  }
2137 }
2138 
2147 void vpDisplayX::flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
2148 {
2150  {
2151  //XClearWindow ( display, window );
2152  XClearArea ( display, window,iP.get_u(),iP.get_v(),width,height,0 );
2153  XFlush ( display );
2154  }
2155  else
2156  {
2157  vpERROR_TRACE ( "X not initialized " ) ;
2159  "X not initialized" ) ) ;
2160  }
2161 }
2162 
2163 
2168 void vpDisplayX::clearDisplay ( const vpColor &color )
2169 {
2171  {
2172 
2173  if (color.id < vpColor::id_unknown)
2174  XSetWindowBackground ( display, window, x_color[color.id] );
2175  else {
2176  xcolor.pad = 0;
2177  xcolor.red = 256 * color.R;
2178  xcolor.green = 256 * color.G;
2179  xcolor.blue = 256 * color.B;
2180  XAllocColor ( display, lut, &xcolor );
2181  XSetForeground ( display, context, xcolor.pixel );
2182  }
2183 
2184  XClearWindow ( display, window );
2185 
2186  XFreePixmap ( display, pixmap );
2187  // Pixmap creation.
2188  pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
2189  }
2190  else
2191  {
2192  vpERROR_TRACE ( "X not initialized " ) ;
2194  "X not initialized" ) ) ;
2195  }
2196 }
2197 
2206  const vpImagePoint &ip2,
2207  const vpColor &color,
2208  unsigned int w, unsigned int h,
2209  unsigned int thickness)
2210 {
2212  {
2213  try
2214  {
2215  double a = ip2.get_i() - ip1.get_i() ;
2216  double b = ip2.get_j() - ip1.get_j() ;
2217  double lg = sqrt ( vpMath::sqr ( a ) + vpMath::sqr ( b ) ) ;
2218 
2219  //if ( ( a==0 ) && ( b==0 ) )
2220  if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
2221  {
2222  // DisplayCrossLarge(i1,j1,3,col) ;
2223  }
2224  else
2225  {
2226  a /= lg ;
2227  b /= lg ;
2228 
2229  vpImagePoint ip3;
2230  ip3.set_i(ip2.get_i() - w*a);
2231  ip3.set_j(ip2.get_j() - w*b);
2232 
2233  vpImagePoint ip4;
2234  ip4.set_i( ip3.get_i() - b*h );
2235  ip4.set_j( ip3.get_j() + a*h );
2236 
2237  displayLine ( ip2, ip4, color, thickness ) ;
2238 
2239  ip4.set_i( ip3.get_i() + b*h );
2240  ip4.set_j( ip3.get_j() - a*h );
2241 
2242  displayLine ( ip2, ip4, color, thickness ) ;
2243  displayLine ( ip1, ip2, color, thickness ) ;
2244  }
2245  }
2246  catch ( ... )
2247  {
2248  vpERROR_TRACE ( "Error caught" ) ;
2249  throw ;
2250  }
2251  }
2252  else
2253  {
2254  vpERROR_TRACE ( "X not initialized " ) ;
2256  "X not initialized" ) ) ;
2257  }
2258 }
2259 
2272  const char *text,
2273  const vpColor &color )
2274 {
2276  {
2277  if (color.id < vpColor::id_unknown)
2278  XSetForeground ( display, context, x_color[color.id] );
2279  else {
2280  xcolor.pad = 0;
2281  xcolor.red = 256 * color.R;
2282  xcolor.green = 256 * color.G;
2283  xcolor.blue = 256 * color.B;
2284  XAllocColor ( display, lut, &xcolor );
2285  XSetForeground ( display, context, xcolor.pixel );
2286  }
2287  XDrawString ( display, pixmap, context,
2288  (int)ip.get_u(), (int)ip.get_v(),
2289  text, (int)strlen ( text ) );
2290  }
2291  else
2292  {
2293  vpERROR_TRACE ( "X not initialized " ) ;
2295  "X not initialized" ) ) ;
2296  }
2297 }
2298 
2309  unsigned int radius,
2310  const vpColor &color,
2311  bool fill,
2312  unsigned int thickness )
2313 {
2315  {
2316  if ( thickness == 1 ) thickness = 0;
2317  if (color.id < vpColor::id_unknown)
2318  XSetForeground ( display, context, x_color[color.id] );
2319  else {
2320  xcolor.pad = 0;
2321  xcolor.red = 256 * color.R;
2322  xcolor.green = 256 * color.G;
2323  xcolor.blue = 256 * color.B;
2324  XAllocColor ( display, lut, &xcolor );
2325  XSetForeground ( display, context, xcolor.pixel );
2326  }
2327 
2328  XSetLineAttributes ( display, context, thickness,
2329  LineSolid, CapButt, JoinBevel );
2330 
2331  if ( fill == false )
2332  {
2333  XDrawArc ( display, pixmap, context,
2334  vpMath::round( center.get_u()-radius ),
2335  vpMath::round( center.get_v()-radius ),
2336  radius*2, radius*2, 0, 23040 ); /* 23040 = 360*64 */
2337  }
2338  else
2339  {
2340  XFillArc ( display, pixmap, context,
2341  vpMath::round( center.get_u()-radius ),
2342  vpMath::round( center.get_v()-radius ),
2343  radius*2, radius*2, 0, 23040 ); /* 23040 = 360*64 */
2344  }
2345  }
2346  else
2347  {
2348  vpERROR_TRACE ( "X not initialized " ) ;
2350  "X not initialized" ) ) ;
2351  }
2352 }
2353 
2362  unsigned int size,
2363  const vpColor &color,
2364  unsigned int thickness)
2365 {
2367  {
2368  try
2369  {
2370  double i = ip.get_i();
2371  double j = ip.get_j();
2372  vpImagePoint ip1, ip2;
2373 
2374  ip1.set_i( i-size/2 );
2375  ip1.set_j( j );
2376  ip2.set_i( i+size/2 );
2377  ip2.set_j( j );
2378  displayLine ( ip1, ip2, color, thickness ) ;
2379 
2380  ip1.set_i( i );
2381  ip1.set_j( j-size/2 );
2382  ip2.set_i( i );
2383  ip2.set_j( j+size/2 );
2384 
2385  displayLine ( ip1, ip2, color, thickness ) ;
2386  }
2387  catch ( ... )
2388  {
2389  vpERROR_TRACE ( "Error caught" ) ;
2390  throw ;
2391  }
2392  }
2393 
2394  else
2395  {
2396  vpERROR_TRACE ( "X not initialized " ) ;
2398  "X not initialized" ) ) ;
2399  }
2400 
2401 }
2409  const vpImagePoint &ip2,
2410  const vpColor &color,
2411  unsigned int thickness )
2412 {
2413 
2415  {
2416  if ( thickness == 1 ) thickness = 0;
2417 
2418  if (color.id < vpColor::id_unknown)
2419  XSetForeground ( display, context, x_color[color.id] );
2420  else {
2421  xcolor.pad = 0;
2422  xcolor.red = 256 * color.R;
2423  xcolor.green = 256 * color.G;
2424  xcolor.blue = 256 * color.B;
2425  XAllocColor ( display, lut, &xcolor );
2426  XSetForeground ( display, context, xcolor.pixel );
2427  }
2428 
2429  XSetLineAttributes ( display, context, thickness,
2430  LineOnOffDash, CapButt, JoinBevel );
2431 
2432  XDrawLine ( display, pixmap, context,
2433  vpMath::round( ip1.get_u() ),
2434  vpMath::round( ip1.get_v() ),
2435  vpMath::round( ip2.get_u() ),
2436  vpMath::round( ip2.get_v() ) );
2437  }
2438  else
2439  {
2440  vpERROR_TRACE ( "X not initialized " ) ;
2442  "X not initialized" ) ) ;
2443  }
2444 }
2445 
2453  const vpImagePoint &ip2,
2454  const vpColor &color,
2455  unsigned int thickness )
2456 {
2458  {
2459  if ( thickness == 1 ) thickness = 0;
2460 
2461  if (color.id < vpColor::id_unknown)
2462  XSetForeground ( display, context, x_color[color.id] );
2463  else {
2464  xcolor.pad = 0;
2465  xcolor.red = 256 * color.R;
2466  xcolor.green = 256 * color.G;
2467  xcolor.blue = 256 * color.B;
2468  XAllocColor ( display, lut, &xcolor );
2469  XSetForeground ( display, context, xcolor.pixel );
2470  }
2471 
2472  XSetLineAttributes ( display, context, thickness,
2473  LineSolid, CapButt, JoinBevel );
2474 
2475  XDrawLine ( display, pixmap, context,
2476  vpMath::round( ip1.get_u() ),
2477  vpMath::round( ip1.get_v() ),
2478  vpMath::round( ip2.get_u() ),
2479  vpMath::round( ip2.get_v() ) );
2480  }
2481  else
2482  {
2483  vpERROR_TRACE ( "X not initialized " ) ;
2485  "X not initialized" ) ) ;
2486  }
2487 }
2488 
2495  const vpColor &color )
2496 {
2498  {
2499  if (color.id < vpColor::id_unknown)
2500  XSetForeground ( display, context, x_color[color.id] );
2501  else {
2502  xcolor.pad = 0;
2503  xcolor.red = 256 * color.R;
2504  xcolor.green = 256 * color.G;
2505  xcolor.blue = 256 * color.B;
2506  XAllocColor ( display, lut, &xcolor );
2507  XSetForeground ( display, context, xcolor.pixel );
2508  }
2509 
2510  XDrawPoint ( display, pixmap, context,
2511  vpMath::round( ip.get_u() ),
2512  vpMath::round( ip.get_v() ) );
2513  }
2514  else
2515  {
2516  vpERROR_TRACE ( "X not initialized " ) ;
2518  "X not initialized" ) ) ;
2519  }
2520 }
2521 
2535 void
2537  unsigned int width, unsigned int height,
2538  const vpColor &color, bool fill,
2539  unsigned int thickness )
2540 {
2542  {
2543  if ( thickness == 1 ) thickness = 0;
2544  if (color.id < vpColor::id_unknown)
2545  XSetForeground ( display, context, x_color[color.id] );
2546  else {
2547  xcolor.pad = 0;
2548  xcolor.red = 256 * color.R;
2549  xcolor.green = 256 * color.G;
2550  xcolor.blue = 256 * color.B;
2551  XAllocColor ( display, lut, &xcolor );
2552  XSetForeground ( display, context, xcolor.pixel );
2553  }
2554  XSetLineAttributes ( display, context, thickness,
2555  LineSolid, CapButt, JoinBevel );
2556  if ( fill == false )
2557  {
2558  XDrawRectangle ( display, pixmap, context,
2559  vpMath::round( topLeft.get_u() ),
2560  vpMath::round( topLeft.get_v() ),
2561  width-1, height-1 );
2562  }
2563  else
2564  {
2565  XFillRectangle ( display, pixmap, context,
2566  vpMath::round( topLeft.get_u() ),
2567  vpMath::round( topLeft.get_v() ),
2568  width, height );
2569  }
2570  }
2571  else
2572  {
2573  vpERROR_TRACE ( "X not initialized " ) ;
2575  "X not initialized" ) ) ;
2576  }
2577 }
2578 
2591 void
2593  const vpImagePoint &bottomRight,
2594  const vpColor &color, bool fill,
2595  unsigned int thickness )
2596 {
2598  {
2599  if ( thickness == 1 ) thickness = 0;
2600  if (color.id < vpColor::id_unknown)
2601  XSetForeground ( display, context, x_color[color.id] );
2602  else {
2603  xcolor.pad = 0;
2604  xcolor.red = 256 * color.R;
2605  xcolor.green = 256 * color.G;
2606  xcolor.blue = 256 * color.B;
2607  XAllocColor ( display, lut, &xcolor );
2608  XSetForeground ( display, context, xcolor.pixel );
2609  }
2610 
2611  XSetLineAttributes ( display, context, thickness,
2612  LineSolid, CapButt, JoinBevel );
2613 
2614  unsigned int width = (unsigned int)vpMath::round( std::fabs(bottomRight.get_u() - topLeft.get_u()) );
2615  unsigned int height = (unsigned int)vpMath::round( std::fabs(bottomRight.get_v() - topLeft.get_v()) );
2616  if ( fill == false )
2617  {
2618 
2619  XDrawRectangle ( display, pixmap, context,
2620  vpMath::round( topLeft.get_u() < bottomRight.get_u() ? topLeft.get_u() : bottomRight.get_u() ),
2621  vpMath::round( topLeft.get_v() < bottomRight.get_v() ? topLeft.get_v() : bottomRight.get_v() ),
2622  width > 0 ? width-1 : 1, height > 0 ? height : 1 );
2623  }
2624  else
2625  {
2626  XFillRectangle ( display, pixmap, context,
2627  vpMath::round( topLeft.get_u() < bottomRight.get_u() ? topLeft.get_u() : bottomRight.get_u() ),
2628  vpMath::round( topLeft.get_v() < bottomRight.get_v() ? topLeft.get_v() : bottomRight.get_v() ),
2629  width, height );
2630  }
2631  }
2632  else
2633  {
2634  vpERROR_TRACE ( "X not initialized " ) ;
2636  "X not initialized" ) ) ;
2637  }
2638 }
2639 
2652 void
2654  const vpColor &color, bool fill,
2655  unsigned int thickness )
2656 {
2658  {
2659  if ( thickness == 1 ) thickness = 0;
2660  if (color.id < vpColor::id_unknown)
2661  XSetForeground ( display, context, x_color[color.id] );
2662  else {
2663  xcolor.pad = 0;
2664  xcolor.red = 256 * color.R;
2665  xcolor.green = 256 * color.G;
2666  xcolor.blue = 256 * color.B;
2667  XAllocColor ( display, lut, &xcolor );
2668  XSetForeground ( display, context, xcolor.pixel );
2669  }
2670 
2671  XSetLineAttributes ( display, context, thickness,
2672  LineSolid, CapButt, JoinBevel );
2673 
2674  if ( fill == false )
2675  {
2676  XDrawRectangle ( display, pixmap, context,
2677  vpMath::round( rectangle.getLeft() ),
2678  vpMath::round( rectangle.getTop() ),
2679  (unsigned int)vpMath::round( rectangle.getWidth()-1 ),
2680  (unsigned int)vpMath::round( rectangle.getHeight()-1 ) );
2681  }
2682  else
2683  {
2684  XFillRectangle ( display, pixmap, context,
2685  vpMath::round( rectangle.getLeft() ),
2686  vpMath::round( rectangle.getTop() ),
2687  (unsigned int)vpMath::round( rectangle.getWidth() ),
2688  (unsigned int)vpMath::round( rectangle.getHeight() ) );
2689  }
2690 
2691  }
2692  else
2693  {
2694  vpERROR_TRACE ( "X not initialized " ) ;
2696  "X not initialized" ) ) ;
2697  }
2698 }
2699 
2716 bool
2717 vpDisplayX::getClick(bool blocking)
2718 {
2719 
2720  bool ret = false;
2721 
2722  if ( displayHasBeenInitialized ) {
2723  Window rootwin, childwin ;
2724  int root_x, root_y, win_x, win_y ;
2725  unsigned int modifier ;
2726 
2727  // Event testing
2728  if(blocking){
2729  XCheckMaskEvent(display , ButtonPressMask, &event);
2730  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2731  XMaskEvent ( display, ButtonPressMask ,&event );
2732  ret = true;
2733  }
2734  else{
2735  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2736  }
2737 
2738  if(ret){
2739  /* Recuperation de la coordonnee du pixel cliqu�. */
2740  if ( XQueryPointer ( display,
2741  window,
2742  &rootwin, &childwin,
2743  &root_x, &root_y,
2744  &win_x, &win_y,
2745  &modifier ) ) {}
2746  }
2747  }
2748  else {
2749  vpERROR_TRACE ( "X not initialized " ) ;
2751  "X not initialized" ) ) ;
2752  }
2753  return ret;
2754 }
2755 
2772 bool
2773 vpDisplayX::getClick ( vpImagePoint &ip, bool blocking )
2774 {
2775 
2776  bool ret = false;
2777  if ( displayHasBeenInitialized ) {
2778 
2779  Window rootwin, childwin ;
2780  int root_x, root_y, win_x, win_y ;
2781  unsigned int modifier ;
2782  // Event testing
2783  if(blocking){
2784  XCheckMaskEvent(display , ButtonPressMask, &event);
2785  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2786  XMaskEvent ( display, ButtonPressMask ,&event );
2787  ret = true;
2788  }
2789  else{
2790  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2791  }
2792 
2793  if(ret){
2794  // Get mouse position
2795  if ( XQueryPointer ( display,
2796  window,
2797  &rootwin, &childwin,
2798  &root_x, &root_y,
2799  &win_x, &win_y,
2800  &modifier ) ) {
2801  ip.set_u( (double)event.xbutton.x );
2802  ip.set_v( (double)event.xbutton.y );
2803  }
2804  }
2805  }
2806  else {
2807  vpERROR_TRACE ( "X not initialized " ) ;
2809  "X not initialized" ) ) ;
2810  }
2811  return ret ;
2812 }
2813 
2833 bool
2836  bool blocking )
2837 {
2838 
2839  bool ret = false;
2840  if ( displayHasBeenInitialized ) {
2841 
2842  Window rootwin, childwin ;
2843  int root_x, root_y, win_x, win_y ;
2844  unsigned int modifier ;
2845 
2846  // Event testing
2847  if(blocking){
2848  XCheckMaskEvent(display , ButtonPressMask, &event);
2849  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2850  XMaskEvent ( display, ButtonPressMask ,&event );
2851  ret = true;
2852  }
2853  else{
2854  ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2855  }
2856 
2857  if(ret){
2858  // Get mouse position
2859  if ( XQueryPointer ( display,
2860  window,
2861  &rootwin, &childwin,
2862  &root_x, &root_y,
2863  &win_x, &win_y,
2864  &modifier ) ) {
2865  ip.set_u( (double)event.xbutton.x );
2866  ip.set_v( (double)event.xbutton.y );
2867  switch ( event.xbutton.button ) {
2868  case Button1: button = vpMouseButton::button1; break;
2869  case Button2: button = vpMouseButton::button2; break;
2870  case Button3: button = vpMouseButton::button3; break;
2871  }
2872  }
2873  }
2874  }
2875  else {
2876  vpERROR_TRACE ( "X not initialized " ) ;
2878  "X not initialized" ) ) ;
2879  }
2880  return ret ;
2881 }
2882 
2906 bool
2909  bool blocking )
2910 {
2911 
2912  bool ret = false;
2913  if ( displayHasBeenInitialized ) {
2914  Window rootwin, childwin ;
2915  int root_x, root_y, win_x, win_y ;
2916  unsigned int modifier ;
2917 
2918  // Event testing
2919  if(blocking){
2920  XCheckMaskEvent(display , ButtonPressMask, &event);
2921  XCheckMaskEvent(display , ButtonReleaseMask, &event);
2922  XMaskEvent ( display, ButtonReleaseMask ,&event );
2923  ret = true;
2924  }
2925  else{
2926  ret = XCheckMaskEvent(display , ButtonReleaseMask, &event);
2927  }
2928 
2929  if(ret){
2930  /* Recuperation de la coordonnee du pixel cliqu�. */
2931  if ( XQueryPointer ( display,
2932  window,
2933  &rootwin, &childwin,
2934  &root_x, &root_y,
2935  &win_x, &win_y,
2936  &modifier ) ) {
2937  ip.set_u( (double)event.xbutton.x );
2938  ip.set_v( (double)event.xbutton.y );
2939  switch ( event.xbutton.button ) {
2940  case Button1: button = vpMouseButton::button1; break;
2941  case Button2: button = vpMouseButton::button2; break;
2942  case Button3: button = vpMouseButton::button3; break;
2943  }
2944  }
2945  }
2946  }
2947  else {
2948  vpERROR_TRACE ( "X not initialized " ) ;
2950  "X not initialized" ) ) ;
2951  }
2952  return ret ;
2953 }
2954 
2955 /*
2956  Gets the displayed image (including the overlay plane)
2957  and returns an RGBa image.
2958 
2959  \param I : Image to get.
2960 */
2962 {
2963 
2965  {
2966 
2967 
2968  XImage *xi ;
2969  //xi= XGetImage ( display,window, 0,0, getWidth(), getHeight(),
2970  // AllPlanes, ZPixmap ) ;
2971 
2972  XCopyArea (display,window, pixmap, context,
2973  0,0, getWidth(), getHeight(), 0, 0);
2974 
2975  xi= XGetImage ( display,pixmap, 0,0, getWidth(), getHeight(),
2976  AllPlanes, ZPixmap ) ;
2977 
2978  try
2979  {
2980  I.resize ( getHeight(), getWidth() ) ;
2981  }
2982  catch ( ... )
2983  {
2984  vpERROR_TRACE ( "Error caught" ) ;
2985  throw ;
2986  }
2987 
2988  unsigned char *src_32 = NULL;
2989  src_32 = ( unsigned char* ) xi->data;
2990 
2991 #ifdef BIGENDIAN
2992  // little indian/big indian
2993  for ( unsigned int i = 0; i < I.getWidth() * I.getHeight() ; i++ )
2994  {
2995  I.bitmap[i].A = src_32[i*4] ;
2996  I.bitmap[i].R = src_32[i*4 + 1] ;
2997  I.bitmap[i].G = src_32[i*4 + 2] ;
2998  I.bitmap[i].B = src_32[i*4 + 3] ;
2999  }
3000 #else
3001  for ( unsigned int i = 0; i < I.getWidth() * I.getHeight() ; i++ )
3002  {
3003  I.bitmap[i].B = src_32[i*4] ;
3004  I.bitmap[i].G = src_32[i*4 + 1] ;
3005  I.bitmap[i].R = src_32[i*4 + 2] ;
3006  I.bitmap[i].A = src_32[i*4 + 3] ;
3007  }
3008 #endif
3009 
3010 
3011  XDestroyImage ( xi ) ;
3012 
3013  }
3014  else
3015  {
3016  vpERROR_TRACE ( "X not initialized " ) ;
3018  "X not initialized" ) ) ;
3019  }
3020 }
3021 
3026 {
3027  Display *_display;
3028  int screen;
3029  unsigned int depth;
3030 
3031  if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3032  {
3033  vpERROR_TRACE ( "Can't connect display on server %s.",
3034  XDisplayName ( NULL ) );
3036  "Can't connect display on server." ) ) ;
3037  }
3038  screen = DefaultScreen ( _display );
3039  depth = (unsigned int)DefaultDepth ( _display, screen );
3040 
3041  XCloseDisplay ( _display );
3042 
3043  return ( depth );
3044 }
3045 
3050 void vpDisplayX::getScreenSize ( unsigned int &width, unsigned int &height )
3051 {
3052  Display *_display;
3053  int screen;
3054 
3055  if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3056  {
3057  vpERROR_TRACE ( "Can't connect display on server %s.",
3058  XDisplayName ( NULL ) );
3060  "Can't connect display on server." ) ) ;
3061  }
3062  screen = DefaultScreen ( _display );
3063  width = (unsigned int)DisplayWidth ( _display, screen );
3064  height = (unsigned int)DisplayHeight ( _display, screen );
3065 
3066  XCloseDisplay ( _display );
3067 }
3088 bool
3090 {
3091 
3092  bool ret = false;
3093 
3094  if ( displayHasBeenInitialized ) {
3095  // Event testing
3096  if(blocking){
3097  XMaskEvent ( display, KeyPressMask ,&event );
3098  ret = true;
3099  }
3100  else{
3101  ret = XCheckMaskEvent(display , KeyPressMask, &event);
3102  }
3103  }
3104  else {
3105  vpERROR_TRACE ( "X not initialized " ) ;
3107  "X not initialized" ) ) ;
3108  }
3109  return ret;
3110 }
3134 bool
3135 vpDisplayX::getKeyboardEvent(char *string, bool blocking)
3136 {
3137 
3138  bool ret = false;
3139  KeySym keysym;
3140 // int count;
3141  XComposeStatus compose_status;
3142  char buffer;
3143 
3144  if ( displayHasBeenInitialized ) {
3145  // Event testing
3146  if(blocking){
3147  XMaskEvent ( display, KeyPressMask ,&event );
3148  /* count = */ XLookupString ((XKeyEvent *)&event, &buffer, 1,
3149  &keysym, &compose_status);
3150  //std::cout <<"count: " << count << " get \"" << buffer << "\"" << std::endl;
3151  sprintf(string, "%c", buffer);
3152  ret = true;
3153  }
3154  else{
3155  ret = XCheckMaskEvent(display , KeyPressMask, &event);
3156  if (ret) {
3157  /* count = */ XLookupString ((XKeyEvent *)&event, &buffer, 1,
3158  &keysym, &compose_status);
3159  sprintf(string, "%c", buffer);
3160  }
3161  }
3162  }
3163  else {
3164  vpERROR_TRACE ( "X not initialized " ) ;
3166  "X not initialized" ) ) ;
3167  }
3168  return ret;
3169 }
3182 bool
3184 {
3185 
3186  bool ret = false;
3187  if ( displayHasBeenInitialized ) {
3188 
3189  Window rootwin, childwin ;
3190  int root_x, root_y, win_x, win_y ;
3191  unsigned int modifier ;
3192  // Event testing
3193  ret = XCheckMaskEvent(display , PointerMotionMask, &event);
3194 
3195  if(ret){
3196  // Get mouse position
3197  if ( XQueryPointer ( display,
3198  window,
3199  &rootwin, &childwin,
3200  &root_x, &root_y,
3201  &win_x, &win_y,
3202  &modifier ) ) {
3203  ip.set_u( (double)event.xbutton.x );
3204  ip.set_v( (double)event.xbutton.y );
3205  }
3206  }
3207  }
3208  else {
3209  vpERROR_TRACE ( "X not initialized " ) ;
3211  "X not initialized" ) ) ;
3212  }
3213  return ret ;
3214 }
3215 
3226 bool
3228 {
3229 
3230  bool ret = false;
3231  if ( displayHasBeenInitialized ) {
3232 
3233  Window rootwin, childwin ;
3234  int root_x, root_y, win_x, win_y ;
3235  unsigned int modifier ;
3236  // Event testing
3237  ret = true;
3238 
3239  if(ret){
3240  // Get mouse position
3241  if ( XQueryPointer ( display,
3242  window,
3243  &rootwin, &childwin,
3244  &root_x, &root_y,
3245  &win_x, &win_y,
3246  &modifier ) ) {
3247  ip.set_u( (double)win_x );
3248  ip.set_v( (double)win_y );
3249  }
3250  }
3251  }
3252  else {
3253  vpERROR_TRACE ( "X not initialized " ) ;
3255  "X not initialized" ) ) ;
3256  }
3257  return ret ;
3258 }
3259 
3260 #endif
3261 
3262 /*
3263  * Local variables:
3264  * c-basic-offset: 2
3265  * End:
3266  */
void closeDisplay()
void set_j(const double j)
Definition: vpImagePoint.h:156
void clearDisplay(const vpColor &color=vpColor::white)
vpDisplay * display
Definition: vpImage.h:121
#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:175
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:187
double get_i() const
Definition: vpImagePoint.h:181
unsigned int getWidth() const
Definition: vpImage.h:159
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: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:239
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:535
void set_i(const double i)
Definition: vpImagePoint.h:145
static const vpColor lightGray
Definition: vpColor.h:163
double getHeight() const
Definition: vpRect.h:150
void flushDisplay()
static const vpColor darkBlue
Definition: vpColor.h:174
bool displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:179
unsigned char G
Green component.
Definition: vpRGBa.h:154
static const vpColor green
Definition: vpColor.h:170
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: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
bool getClick(bool blocking=true)
vpColorIdentifier id
Definition: vpColor.h:156
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:176
static const vpColor lightGreen
Definition: vpColor.h:169
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:188
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: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:170
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)
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:181
unsigned char R
Red component.
Definition: vpRGBa.h:153
unsigned int getWidth() const
Definition: vpDisplayX.h:269
unsigned int getHeight() const
Definition: vpImage.h:150
Defines a rectangle in the plane.
Definition: vpRect.h:82
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:184
static const vpColor yellow
Definition: vpColor.h:175
static const vpColor lightBlue
Definition: vpColor.h:172
int windowYPosition
display position
Definition: vpDisplay.h:183
static const vpColor purple
Definition: vpColor.h:178
static const vpColor white
Definition: vpColor.h:162
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:173
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)