ViSP  2.10.0
vpDisplay.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDisplay.cpp 5008 2014-11-25 17:59:43Z 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  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 #include <limits>
44 
45 #include <visp/vpDisplay.h>
46 #include <visp/vpDisplayException.h>
47 #include <visp/vpImageConvert.h>
48 
49 #include <visp/vpPoint.h>
50 #include <visp/vpMeterPixelConversion.h>
51 #include <visp/vpMath.h>
52 
53 
63  : displayHasBeenInitialized(false), windowXPosition(0), windowYPosition(0), width(0), height(0), title_() {}
64 
69  : displayHasBeenInitialized(false), windowXPosition(0), windowYPosition(0), width(0), height(0), title_()
70 {
74 
75  width = d.width;
76  height = d.height;
77 }
78 
83 {
85 }
86 
100 void
102  const char *fontname )
103 {
104 
105  try
106  {
107  if ( I.display != NULL )
108  {
109  ( I.display )->setFont ( fontname ) ;
110  }
111  }
112  catch ( ... )
113  {
114  vpERROR_TRACE ( "Error caught" ) ;
115  throw ;
116  }
117 }
125 void
127  const char *windowtitle )
128 {
129 
130  try
131  {
132  if ( I.display != NULL )
133  {
134  ( I.display )->setTitle ( windowtitle ) ;
135  }
136  }
137  catch ( ... )
138  {
139  vpERROR_TRACE ( "Error caught" ) ;
140  throw ;
141  }
142 }
143 
153 void
155  int winx, int winy )
156 {
157 
158  try
159  {
160  if ( I.display != NULL )
161  {
162  ( I.display )->setWindowPosition ( winx, winy ) ;
163  }
164  }
165  catch ( ... )
166  {
167  vpERROR_TRACE ( "Error caught" ) ;
168  throw ;
169  }
170 }
171 
181 void
183 {
184  try
185  {
186  if ( I.display != NULL )
187  {
188  ( I.display )->clearDisplay ( color ) ;
189  }
190  }
191  catch ( ... )
192  {
193  vpERROR_TRACE ( "Error caught" ) ;
194  throw ;
195  }
196 }
197 
209 void
211 {
212 
213  try
214  {
215  if ( I.display != NULL )
216  {
217  ( I.display )->displayImage ( I ) ;
218  }
219  }
220  catch ( ... )
221  {
222  vpERROR_TRACE ( "Error caught" ) ;
223  throw ;
224  }
225 }
226 
227 
228 void
230 {
231  vpImagePoint topLeft;
232  double top = floor(roi.getTop());
233  double left = floor(roi.getLeft());
234  double roiheight = floor(roi.getHeight());
235  double roiwidth = floor(roi.getWidth());
236  double iheight = (double)(I.getHeight());
237  double iwidth = (double)(I.getWidth());
238 
239  if (top < 0 || top > iheight || left < 0 || left > iwidth || top+roiheight > iheight || left+roiwidth > iwidth)
240  {
241  vpERROR_TRACE ( "Region of interest outside of the image" ) ;
242  throw ( vpException ( vpException::dimensionError,"Region of interest outside of the image" ) ) ;
243  }
244 
245  try
246  {
247  if ( I.display != NULL )
248  {
249  ( I.display )->displayImageROI ( I , vpImagePoint(top,left), (unsigned int)roiwidth,(unsigned int)roiheight ) ;
250  }
251  }
252  catch ( ... )
253  {
254  vpERROR_TRACE ( "Error caught" ) ;
255  throw ;
256  }
257 }
258 
259 
260 
327 void
329  vpImage<vpRGBa> &Idest )
330 {
331 
332  try
333  {
334  if ( Isrc.display != NULL )
335  {
336  ( Isrc.display )->getImage ( Idest ) ;
337  }
338  else
339  {
340  vpImageConvert::convert(Isrc, Idest);
341 // vpERROR_TRACE ( "Display not initialized" ) ;
342 // throw ( vpDisplayException ( vpDisplayException::notInitializedError,
343 // "Display not initialized" ) ) ;
344  }
345  }
346  catch ( ... )
347  {
348  vpERROR_TRACE ( "Error caught" ) ;
349  throw ;
350  }
351 }
352 
353 
374 void
376  const vpHomogeneousMatrix &cMo,
377  const vpCameraParameters &cam,
378  double size,
379  const vpColor &color, unsigned int thickness)
380 {
381  // used by display
382  vpPoint o; o.setWorldCoordinates ( 0.0,0.0,0.0 ) ;
383  vpPoint x; x.setWorldCoordinates ( size,0.0,0.0 ) ;
384  vpPoint y; y.setWorldCoordinates ( 0.0,size,0.0 ) ;
385  vpPoint z; z.setWorldCoordinates ( 0.0,0.0,size ) ;
386 
387  o.track ( cMo ) ;
388  x.track ( cMo ) ;
389  y.track ( cMo ) ;
390  z.track ( cMo ) ;
391 
392  vpImagePoint ipo, ip1;
393 
394  if ( color == vpColor::none )
395  {
396  vpMeterPixelConversion::convertPoint ( cam, o.p[0], o.p[1], ipo) ;
397 
398  vpMeterPixelConversion::convertPoint ( cam, x.p[0], x.p[1], ip1) ;
399  vpDisplay::displayArrow ( I, ipo, ip1, vpColor::red, 4*thickness, 2*thickness, thickness) ;
400 
401  vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
402  vpDisplay::displayArrow ( I, ipo, ip1, vpColor::green, 4*thickness, 2*thickness, thickness) ;
403 
404  vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
405  vpDisplay::displayArrow ( I,ipo, ip1, vpColor::blue, 4*thickness, 2*thickness, thickness) ;
406  }
407  else
408  {
409  vpMeterPixelConversion::convertPoint ( cam, o.p[0], o.p[1], ipo) ;
410 
411  vpMeterPixelConversion::convertPoint ( cam, x.p[0], x.p[1], ip1) ;
412  vpDisplay::displayArrow ( I, ipo, ip1, color, 4*thickness, 2*thickness, thickness) ;
413 
414  vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
415  vpDisplay::displayArrow ( I, ipo, ip1, color, 4*thickness, 2*thickness, thickness) ;
416 
417  vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
418  vpDisplay::displayArrow ( I,ipo, ip1, color, 4*thickness, 2*thickness, thickness) ;
419 
420  }
421 }
422 
423 
444 void
446  const vpHomogeneousMatrix &cMo,
447  const vpCameraParameters &cam,
448  double size, const vpColor &color,
449  unsigned int thickness )
450 {
451  // used by display
452  vpPoint o; o.setWorldCoordinates ( 0.0,0.0,0.0 ) ;
453  vpPoint x; x.setWorldCoordinates ( size,0.0,0.0 ) ;
454  vpPoint y; y.setWorldCoordinates ( 0.0,size,0.0 ) ;
455  vpPoint z; z.setWorldCoordinates ( 0.0,0.0,size ) ;
456 
457  o.track ( cMo ) ;
458  x.track ( cMo ) ;
459  y.track ( cMo ) ;
460  z.track ( cMo ) ;
461 
462  vpImagePoint ipo, ip1;
463  if ( color == vpColor::none )
464  {
465  vpMeterPixelConversion::convertPoint ( cam, o.p[0], o.p[1], ipo) ;
466 
467  vpMeterPixelConversion::convertPoint ( cam, x.p[0], x.p[1], ip1) ;
468  vpDisplay::displayArrow ( I, ipo, ip1, vpColor::red, 4, 2, thickness) ;
469 
470  vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
471  vpDisplay::displayArrow ( I, ipo, ip1, vpColor::green, 4, 2, thickness) ;
472 
473  vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
474  vpDisplay::displayArrow ( I,ipo, ip1, vpColor::blue, 4, 2, thickness) ;
475  }
476  else
477  {
478  vpMeterPixelConversion::convertPoint ( cam, o.p[0], o.p[1], ipo) ;
479 
480  vpMeterPixelConversion::convertPoint ( cam, x.p[0], x.p[1], ip1) ;
481  vpDisplay::displayArrow ( I, ipo, ip1, color, 4*thickness, 2*thickness, thickness) ;
482 
483  vpMeterPixelConversion::convertPoint ( cam, y.p[0], y.p[1], ip1) ;
484  vpDisplay::displayArrow ( I, ipo, ip1, color, 4*thickness, 2*thickness, thickness) ;
485 
486  vpMeterPixelConversion::convertPoint ( cam, z.p[0], z.p[1], ip1) ;
487  vpDisplay::displayArrow ( I,ipo, ip1, color, 4*thickness, 2*thickness, thickness) ;
488 
489  }
490 }
491 
512 void
514  const vpHomogeneousMatrix &cMo,
515  const vpCameraParameters &cam,
516  double size, const vpColor &color,
517  unsigned int thickness)
518 {
519  // used by display
520  double halfSize = size/2.0;
521  vpPoint pt[5];
522  pt[0].setWorldCoordinates ( -halfSize,-halfSize,0.0 );
523  pt[1].setWorldCoordinates ( halfSize,-halfSize,0.0 );
524  pt[2].setWorldCoordinates ( halfSize,halfSize,0.0 );
525  pt[3].setWorldCoordinates ( -halfSize,halfSize,0.0 );
526  pt[4].setWorldCoordinates ( 0.0,0.0,-size );
527 
528  for (int i = 0; i < 5; i++)
529  pt[i].track ( cMo ) ;
530 
531  vpImagePoint ip, ip_1, ip0;
532  vpMeterPixelConversion::convertPoint ( cam, pt[4].p[0], pt[4].p[1], ip0);
533 
534  for (int i = 0; i < 4; i++)
535  {
536  vpMeterPixelConversion::convertPoint ( cam, pt[i].p[0], pt[i].p[1], ip_1);
537  vpMeterPixelConversion::convertPoint ( cam, pt[(i+1)%4].p[0], pt[(i+1)%4].p[1], ip);
538  vpDisplay::displayLine ( I, ip_1, ip, color, thickness);
539  vpDisplay::displayLine ( I, ip0, ip_1, color, thickness);
540  }
541 }
542 
543 
564 void
566  const vpHomogeneousMatrix &cMo,
567  const vpCameraParameters &cam,
568  double size, const vpColor &color,
569  unsigned int thickness)
570 {
571  // used by display
572  double halfSize = size/2.0;
573  vpPoint pt[5];
574  pt[0].setWorldCoordinates ( -halfSize,-halfSize,0.0 );
575  pt[1].setWorldCoordinates ( halfSize,-halfSize,0.0 );
576  pt[2].setWorldCoordinates ( halfSize,halfSize,0.0 );
577  pt[3].setWorldCoordinates ( -halfSize,halfSize,0.0 );
578  pt[4].setWorldCoordinates ( 0.0,0.0,-size );
579 
580  for (int i = 0; i < 5; i++)
581  pt[i].track ( cMo ) ;
582 
583  vpImagePoint ip, ip_1, ip0;
584  vpMeterPixelConversion::convertPoint ( cam, pt[4].p[0], pt[4].p[1], ip0);
585 
586  for (int i = 0; i < 4; i++)
587  {
588  vpMeterPixelConversion::convertPoint ( cam, pt[i].p[0], pt[i].p[1], ip_1);
589  vpMeterPixelConversion::convertPoint ( cam, pt[(i+1)%4].p[0], pt[(i+1)%4].p[1], ip);
590  vpDisplay::displayLine ( I, ip_1, ip, color, thickness);
591  vpDisplay::displayLine ( I, ip0, ip_1, color, thickness);
592  }
593 }
594 
603 void
605  const vpImagePoint &ip1, const vpImagePoint &ip2,
606  const vpColor &color,
607  unsigned int w,unsigned int h,
608  unsigned int thickness )
609 {
610  try
611  {
612  if ( I.display != NULL )
613  {
614  ( I.display )->displayArrow ( ip1, ip2, color, w, h, thickness ) ;
615  }
616  }
617  catch ( ... )
618  {
619  vpERROR_TRACE ( "Error caught" ) ;
620  throw ;
621  }
622 }
623 
633 void
635  const vpImagePoint &ip1, const vpImagePoint &ip2,
636  const vpColor &color,
637  unsigned int w,unsigned int h,
638  unsigned int thickness )
639 {
640  try
641  {
642  if ( I.display != NULL )
643  {
644  ( I.display )->displayArrow ( ip1, ip2, color, w, h, thickness ) ;
645  }
646  }
647  catch ( ... )
648  {
649  vpERROR_TRACE ( "Error caught" ) ;
650  throw ;
651  }
652 }
653 
664 void
666  int i1, int j1, int i2, int j2,
667  const vpColor &color,
668  unsigned int w, unsigned int h,
669  unsigned int thickness)
670 {
671  try
672  {
673  if ( I.display != NULL )
674  {
675  vpImagePoint ip1, ip2;
676  ip1.set_i(i1);
677  ip1.set_j(j1);
678  ip2.set_i(i2);
679  ip2.set_j(j2);
680  ( I.display )->displayArrow ( ip1, ip2, color, w, h, thickness ) ;
681  }
682  }
683  catch ( ... )
684  {
685  vpERROR_TRACE ( "Error caught" ) ;
686  throw ;
687  }
688 }
689 
702 void
704  int i1, int j1, int i2, int j2,
705  const vpColor &color,
706  unsigned int w, unsigned int h,
707  unsigned int thickness)
708 {
709  try
710  {
711  if ( I.display != NULL )
712  {
713  vpImagePoint ip1, ip2;
714  ip1.set_i(i1);
715  ip1.set_j(j1);
716  ip2.set_i(i2);
717  ip2.set_j(j2);
718 
719  ( I.display )->displayArrow ( ip1, ip2, color, w, h, thickness ) ;
720  }
721  }
722  catch ( ... )
723  {
724  vpERROR_TRACE ( "Error caught" ) ;
725  throw ;
726  }
727 }
728 
744 void
746  const vpImagePoint &ip, const char *string,
747  const vpColor &color )
748 {
749  try
750  {
751  if ( I.display != NULL )
752  {
753  ( I.display )->displayCharString ( ip, string, color ) ;
754  }
755  }
756  catch ( ... )
757  {
758  vpERROR_TRACE ( "Error caught" ) ;
759  throw ;
760  }
761 }
762 
778 void
780  const vpImagePoint &ip, const char *string,
781  const vpColor &color )
782 {
783  try
784  {
785  if ( I.display != NULL )
786  {
787  ( I.display )->displayCharString ( ip, string, color ) ;
788  }
789  }
790  catch ( ... )
791  {
792  vpERROR_TRACE ( "Error caught" ) ;
793  throw ;
794  }
795 }
796 
812 void
814  int i, int j, const char *string,
815  const vpColor &color)
816 {
817  try
818  {
819  if ( I.display != NULL )
820  {
821  vpImagePoint ip;
822  ip.set_i( i );
823  ip.set_j( j );
824 
825  ( I.display )->displayCharString ( ip, string, color ) ;
826  }
827  }
828  catch ( ... )
829  {
830  vpERROR_TRACE ( "Error caught" ) ;
831  throw ;
832  }
833 }
834 
850 void
852  int i, int j, const char *string,
853  const vpColor &color)
854 {
855  try
856  {
857  if ( I.display != NULL )
858  {
859  vpImagePoint ip;
860  ip.set_i( i );
861  ip.set_j( j );
862  ( I.display )->displayCharString ( ip, string, color ) ;
863  }
864  }
865  catch ( ... )
866  {
867  vpERROR_TRACE ( "Error caught" ) ;
868  throw ;
869  }
870 }
871 
886 void
888  const vpImagePoint &ip, const std::string &s,
889  const vpColor &color )
890 {
891  try
892  {
893  if ( I.display != NULL )
894  {
895  ( I.display )->displayCharString ( ip, s.c_str(), color ) ;
896  }
897  }
898  catch ( ... )
899  {
900  vpERROR_TRACE ( "Error caught" ) ;
901  throw ;
902  }
903 }
904 
919 void
921  const vpImagePoint &ip, const std::string &s,
922  const vpColor &color )
923 {
924  try
925  {
926  if ( I.display != NULL )
927  {
928  ( I.display )->displayCharString ( ip, s.c_str(), color ) ;
929  }
930  }
931  catch ( ... )
932  {
933  vpERROR_TRACE ( "Error caught" ) ;
934  throw ;
935  }
936 }
937 
952 void
954  int i, int j, const std::string &s,
955  const vpColor &color)
956 {
957  try
958  {
959  if ( I.display != NULL )
960  {
961  vpImagePoint ip;
962  ip.set_i( i );
963  ip.set_j( j );
964 
965  ( I.display )->displayCharString ( ip, s.c_str(), color ) ;
966  }
967  }
968  catch ( ... )
969  {
970  vpERROR_TRACE ( "Error caught" ) ;
971  throw ;
972  }
973 }
974 
989 void
991  int i, int j, const std::string &s,
992  const vpColor &color)
993 {
994  try
995  {
996  if ( I.display != NULL )
997  {
998  vpImagePoint ip;
999  ip.set_i( i );
1000  ip.set_j( j );
1001  ( I.display )->displayCharString ( ip, s.c_str(), color ) ;
1002  }
1003  }
1004  catch ( ... )
1005  {
1006  vpERROR_TRACE ( "Error caught" ) ;
1007  throw ;
1008  }
1009 }
1010 
1021 void
1023  const vpImagePoint &center, unsigned int radius,
1024  const vpColor &color,
1025  bool fill,
1026  unsigned int thickness)
1027 {
1028  try
1029  {
1030  if ( I.display != NULL )
1031  {
1032  ( I.display )->displayCircle ( center, radius, color, fill, thickness ) ;
1033  }
1034  }
1035  catch ( ... )
1036  {
1037  vpERROR_TRACE ( "Error caught" ) ;
1038  throw ;
1039  }
1040 }
1051 void
1053  const vpImagePoint &center, unsigned int radius,
1054  const vpColor &color,
1055  bool fill,
1056  unsigned int thickness )
1057 {
1058  try
1059  {
1060  if ( I.display != NULL )
1061  {
1062  ( I.display )->displayCircle ( center, radius, color, fill, thickness ) ;
1063  }
1064  }
1065  catch ( ... )
1066  {
1067  vpERROR_TRACE ( "Error caught" ) ;
1068  throw ;
1069  }
1070 }
1083 void
1085  int i, int j, unsigned int radius,
1086  const vpColor &color,
1087  bool fill,
1088  unsigned int thickness)
1089 {
1090  try
1091  {
1092  if ( I.display != NULL )
1093  {
1094  vpImagePoint ip;
1095  ip.set_i( i );
1096  ip.set_j( j );
1097 
1098  ( I.display )->displayCircle ( ip, radius, color, fill, thickness ) ;
1099  }
1100  }
1101  catch ( ... )
1102  {
1103  vpERROR_TRACE ( "Error caught" ) ;
1104  throw ;
1105  }
1106 }
1107 
1108 
1121 void
1123  int i, int j, unsigned int radius,
1124  const vpColor &color,
1125  bool fill,
1126  unsigned int thickness)
1127 {
1128  try
1129  {
1130  if ( I.display != NULL )
1131  {
1132  vpImagePoint ip;
1133  ip.set_i( i );
1134  ip.set_j( j );
1135  ( I.display )->displayCircle ( ip, radius, color, fill, thickness ) ;
1136  }
1137  }
1138  catch ( ... )
1139  {
1140  vpERROR_TRACE ( "Error caught" ) ;
1141  throw ;
1142  }
1143 }
1144 
1154  const vpImagePoint &ip, unsigned int size,
1155  const vpColor &color,
1156  unsigned int thickness )
1157 {
1158  try
1159  {
1160  if ( I.display != NULL )
1161  {
1162  ( I.display )->displayCross ( ip, size, color, thickness ) ;
1163  }
1164  }
1165  catch ( ... )
1166  {
1167  vpERROR_TRACE ( "Error caught" ) ;
1168  throw ;
1169  }
1170 }
1171 
1181  const vpImagePoint &ip, unsigned int size,
1182  const vpColor &color,
1183  unsigned int thickness )
1184 {
1185  try
1186  {
1187  if ( I.display != NULL )
1188  {
1189  ( I.display )->displayCross ( ip, size, color, thickness ) ;
1190  }
1191  }
1192  catch ( ... )
1193  {
1194  vpERROR_TRACE ( "Error caught" ) ;
1195  throw ;
1196  }
1197 }
1207  int i, int j,
1208  unsigned int size, const vpColor &color,
1209  unsigned int thickness )
1210 {
1211  try
1212  {
1213  if ( I.display != NULL )
1214  {
1215  vpImagePoint ip;
1216  ip.set_i( i );
1217  ip.set_j( j );
1218 
1219  ( I.display )->displayCross ( ip, size, color, thickness ) ;
1220  }
1221  }
1222  catch ( ... )
1223  {
1224  vpERROR_TRACE ( "Error caught" ) ;
1225  throw ;
1226  }
1227 }
1228 
1238  int i, int j,
1239  unsigned int size, const vpColor &color,
1240  unsigned int thickness )
1241 {
1242  try
1243  {
1244  if ( I.display != NULL )
1245  {
1246  vpImagePoint ip;
1247  ip.set_i( i );
1248  ip.set_j( j );
1249  ( I.display )->displayCross ( ip, size, color, thickness ) ;
1250  }
1251  }
1252  catch ( ... )
1253  {
1254  vpERROR_TRACE ( "Error caught" ) ;
1255  throw ;
1256  }
1257 }
1258 
1267  const vpImagePoint &ip1,
1268  const vpImagePoint &ip2,
1269  const vpColor &color,
1270  unsigned int thickness )
1271 {
1272  try
1273  {
1274  if ( I.display != NULL )
1275  {
1276  ( I.display )->displayDotLine ( ip1, ip2, color, thickness );
1277  }
1278  }
1279  catch ( ... )
1280  {
1281  vpERROR_TRACE ( "Error caught" ) ;
1282  throw ;
1283  }
1284 }
1285 
1294  const vpImagePoint &ip1,
1295  const vpImagePoint &ip2,
1296  const vpColor &color,
1297  unsigned int thickness )
1298 {
1299  try
1300  {
1301  if ( I.display != NULL )
1302  {
1303  ( I.display )->displayDotLine ( ip1, ip2, color, thickness );
1304  }
1305  }
1306  catch ( ... )
1307  {
1308  vpERROR_TRACE ( "Error caught" ) ;
1309  throw ;
1310  }
1311 }
1322  int i1, int j1, int i2, int j2,
1323  const vpColor &color,
1324  unsigned int thickness )
1325 {
1326  try
1327  {
1328  if ( I.display != NULL )
1329  {
1330  vpImagePoint ip1, ip2;
1331  ip1.set_i( i1 );
1332  ip1.set_j( j1 );
1333  ip2.set_i( i2 );
1334  ip2.set_j( j2 );
1335  ( I.display )->displayDotLine ( ip1, ip2, color, thickness );
1336  }
1337  }
1338  catch ( ... )
1339  {
1340  vpERROR_TRACE ( "Error caught" ) ;
1341  throw ;
1342  }
1343 }
1344 
1354  int i1, int j1,
1355  int i2, int j2,
1356  const vpColor &color,
1357  unsigned int thickness )
1358 {
1359  try
1360  {
1361  if ( I.display != NULL )
1362  {
1363  vpImagePoint ip1, ip2;
1364  ip1.set_i( i1 );
1365  ip1.set_j( j1 );
1366  ip2.set_i( i2 );
1367  ip2.set_j( j2 );
1368  ( I.display )->displayDotLine ( ip1, ip2, color, thickness );
1369  }
1370  }
1371  catch ( ... )
1372  {
1373  vpERROR_TRACE ( "Error caught" ) ;
1374  throw ;
1375  }
1376 }
1377 
1386  const vpImagePoint &ip1,
1387  const vpImagePoint &ip2,
1388  const vpColor &color,
1389  unsigned int thickness )
1390 {
1391 
1392  try
1393  {
1394  if ( I.display != NULL )
1395  {
1396  ( I.display )->displayLine ( ip1, ip2, color, thickness );
1397  }
1398  }
1399  catch ( ... )
1400  {
1401  vpERROR_TRACE ( "Error caught" ) ;
1402  throw ;
1403  }
1404 }
1405 
1416  int i1, int j1, int i2, int j2,
1417  const vpColor &color,
1418  unsigned int thickness )
1419 {
1420 
1421  try
1422  {
1423  if ( I.display != NULL )
1424  {
1425  vpImagePoint ip1, ip2;
1426  ip1.set_i( i1 );
1427  ip1.set_j( j1 );
1428  ip2.set_i( i2 );
1429  ip2.set_j( j2 );
1430  ( I.display )->displayLine ( ip1, ip2, color, thickness );
1431  }
1432  }
1433  catch ( ... )
1434  {
1435  vpERROR_TRACE ( "Error caught" ) ;
1436  throw ;
1437  }
1438 }
1439 
1440 
1451  int i1, int j1,
1452  int i2, int j2,
1453  const vpColor &color,
1454  unsigned int thickness )
1455 {
1456 
1457  try
1458  {
1459  if ( I.display != NULL )
1460  {
1461  vpImagePoint ip1, ip2;
1462  ip1.set_i( i1 );
1463  ip1.set_j( j1 );
1464  ip2.set_i( i2 );
1465  ip2.set_j( j2 );
1466  ( I.display )->displayLine ( ip1, ip2, color, thickness );
1467  }
1468  }
1469  catch ( ... )
1470  {
1471  vpERROR_TRACE ( "Error caught" ) ;
1472  throw ;
1473  }
1474 }
1475 
1484  const vpImagePoint &ip1,
1485  const vpImagePoint &ip2,
1486  const vpColor &color,
1487  unsigned int thickness )
1488 {
1489 
1490  try
1491  {
1492  if ( I.display != NULL )
1493  {
1494  ( I.display )->displayLine ( ip1, ip2, color, thickness );
1495  }
1496  }
1497  catch ( ... )
1498  {
1499  vpERROR_TRACE ( "Error caught" ) ;
1500  throw ;
1501  }
1502 }
1503 
1512  const vpImagePoint &ip,
1513  const vpColor &color,
1514  unsigned int thickness )
1515 {
1516  try
1517  {
1518  if ( I.display != NULL )
1519  {
1520  if (thickness == 1)
1521  ( I.display )->displayPoint ( ip, color ) ;
1522  else {
1523  vpRect rect(0, 0, thickness, thickness);
1524  rect.moveCenter(ip);
1525  ( I.display )->displayRectangle ( rect, color, true ) ;
1526  }
1527  }
1528  }
1529  catch ( ... )
1530  {
1531  vpERROR_TRACE ( "Error caught" ) ;
1532  throw ;
1533  }
1534 }
1543  const vpImagePoint &ip,
1544  const vpColor &color,
1545  unsigned int thickness )
1546 {
1547  try
1548  {
1549  if ( I.display != NULL )
1550  {
1551  if (thickness == 1)
1552  ( I.display )->displayPoint ( ip, color ) ;
1553  else {
1554  vpRect rect(0, 0, thickness, thickness);
1555  rect.moveCenter(ip);
1556  ( I.display )->displayRectangle ( rect, color, true ) ;
1557  }
1558  }
1559  }
1560  catch ( ... )
1561  {
1562  vpERROR_TRACE ( "Error caught" ) ;
1563  throw ;
1564  }
1565 }
1566 
1575  int i, int j,
1576  const vpColor &color,
1577  unsigned int thickness )
1578 {
1579  try
1580  {
1581  if ( I.display != NULL )
1582  {
1583  vpImagePoint ip;
1584  ip.set_i( i );
1585  ip.set_j( j );
1586  if (thickness == 1)
1587  ( I.display )->displayPoint ( ip, color ) ;
1588  else {
1589  vpRect rect(0, 0, thickness, thickness);
1590  rect.moveCenter(ip);
1591  ( I.display )->displayRectangle ( rect, color, true ) ;
1592  }
1593  }
1594  }
1595  catch ( ... )
1596  {
1597  vpERROR_TRACE ( "Error caught" ) ;
1598  throw ;
1599  }
1600 }
1601 
1602 
1612  int i, int j,
1613  const vpColor &color,
1614  unsigned int thickness )
1615 {
1616  try
1617  {
1618  if ( I.display != NULL )
1619  {
1620  vpImagePoint ip;
1621  ip.set_i( i );
1622  ip.set_j( j );
1623  if (thickness == 1)
1624  ( I.display )->displayPoint ( ip, color ) ;
1625  else {
1626  vpRect rect(0, 0, thickness, thickness);
1627  rect.moveCenter(ip);
1628  ( I.display )->displayRectangle ( rect, color, true ) ;
1629  }
1630  }
1631  }
1632  catch ( ... )
1633  {
1634  vpERROR_TRACE ( "Error caught" ) ;
1635  throw ;
1636  }
1637 }
1638 
1647 void
1649  const std::vector<vpImagePoint> &vip,
1650  const vpColor &color,
1651  unsigned int thickness)
1652 {
1653  try
1654  {
1655  if ( I.display != NULL )
1656  {
1657  for (unsigned int i=0; i< vip.size(); i++)
1658  ( I.display )->displayLine ( vip[i], vip[(i+1)%vip.size()], color, thickness );
1659  }
1660  }
1661  catch ( ... )
1662  {
1663  vpERROR_TRACE ( "Error caught" ) ;
1664  throw ;
1665  }
1666 }
1667 
1676 void
1678  const std::vector<vpImagePoint> &vip,
1679  const vpColor &color,
1680  unsigned int thickness)
1681 {
1682  try
1683  {
1684  if ( I.display != NULL )
1685  {
1686  for (unsigned int i=0; i< vip.size(); i++)
1687  ( I.display )->displayLine ( vip[i], vip[(i+1)%vip.size()], color, thickness );
1688  }
1689  }
1690  catch ( ... )
1691  {
1692  vpERROR_TRACE ( "Error caught" ) ;
1693  throw ;
1694  }
1695 }
1696 
1711 void
1713  const vpImagePoint &topLeft,
1714  unsigned int width, unsigned int height,
1715  const vpColor &color, bool fill,
1716  unsigned int thickness)
1717 {
1718  try
1719  {
1720  if ( I.display != NULL )
1721  {
1722  ( I.display )->displayRectangle ( topLeft, width, height, color,
1723  fill, thickness ) ;
1724  }
1725  }
1726  catch ( ... )
1727  {
1728  vpERROR_TRACE ( "Error caught" ) ;
1729  throw ;
1730  }
1731 }
1732 
1733 
1748 void
1750  const vpImagePoint &topLeft,
1751  const vpImagePoint &bottomRight,
1752  const vpColor &color, bool fill,
1753  unsigned int thickness)
1754 {
1755  try
1756  {
1757  if ( I.display != NULL )
1758  {
1759  ( I.display )->displayRectangle ( topLeft, bottomRight, color,
1760  fill, thickness ) ;
1761  }
1762  }
1763  catch ( ... )
1764  {
1765  vpERROR_TRACE ( "Error caught" ) ;
1766  throw ;
1767  }
1768 }
1783 void
1785  const vpRect &rectangle,
1786  const vpColor &color, bool fill,
1787  unsigned int thickness )
1788 {
1789  try
1790  {
1791  if ( I.display != NULL )
1792  {
1793  ( I.display )->displayRectangle ( rectangle, color, fill, thickness ) ;
1794  }
1795  }
1796  catch ( ... )
1797  {
1798  vpERROR_TRACE ( "Error caught" ) ;
1799  throw ;
1800  }
1801 }
1802 
1803 
1819 void
1821  const vpImagePoint &center,
1822  float angle,
1823  unsigned int width, unsigned int height,
1824  const vpColor &color,
1825  unsigned int thickness)
1826 {
1827  try
1828  {
1829  if (I.display != NULL)
1830  {
1831  double i = center.get_i();
1832  double j = center.get_j();
1833 
1834  //A, B, C, D, corners of the rectangle clockwise
1835  vpImagePoint ipa, ipb, ipc, ipd;
1836  double cosinus = cos(angle);
1837  double sinus = sin(angle);
1838  ipa.set_u(j + 0.5*width*cosinus + 0.5*height*sinus);
1839  ipa.set_v(i + 0.5*width*sinus - 0.5*height*cosinus);
1840  ipb.set_u(j + 0.5*width*cosinus - 0.5*height*sinus);
1841  ipb.set_v(i + 0.5*width*sinus + 0.5*height*cosinus);
1842  ipc.set_u(j - 0.5*width*cosinus - 0.5*height*sinus);
1843  ipc.set_v(i - 0.5*width*sinus + 0.5*height*cosinus);
1844  ipd.set_u(j - 0.5*width*cosinus + 0.5*height*sinus);
1845  ipd.set_v(i - 0.5*width*sinus - 0.5*height*cosinus);
1846 
1847  ( I.display )->displayLine(I, ipa, ipb, color, thickness);
1848  ( I.display )->displayLine(I, ipa, ipd, color, thickness);
1849  ( I.display )->displayLine(I, ipc, ipb, color, thickness);
1850  ( I.display )->displayLine(I, ipc, ipd, color, thickness);
1851  }
1852  }
1853  catch(...)
1854  {
1855  vpERROR_TRACE("Error caught in displayRectangle") ;
1856  throw ;
1857  }
1858 }
1859 
1874 void
1876  const vpImagePoint &topLeft,
1877  unsigned int width, unsigned int height,
1878  const vpColor &color, bool fill,
1879  unsigned int thickness)
1880 {
1881  try
1882  {
1883  if ( I.display != NULL )
1884  {
1885  ( I.display )->displayRectangle ( topLeft, width, height, color,
1886  fill, thickness ) ;
1887  }
1888  }
1889  catch ( ... )
1890  {
1891  vpERROR_TRACE ( "Error caught" ) ;
1892  throw ;
1893  }
1894 }
1909 void
1911  const vpImagePoint &topLeft,
1912  const vpImagePoint &bottomRight,
1913  const vpColor &color, bool fill,
1914  unsigned int thickness)
1915 {
1916  try
1917  {
1918  if ( I.display != NULL )
1919  {
1920  ( I.display )->displayRectangle ( topLeft, bottomRight, color,
1921  fill, thickness ) ;
1922  }
1923  }
1924  catch ( ... )
1925  {
1926  vpERROR_TRACE ( "Error caught" ) ;
1927  throw ;
1928  }
1929 }
1944 void
1946  const vpRect &rectangle,
1947  const vpColor &color, bool fill,
1948  unsigned int thickness )
1949 {
1950  try
1951  {
1952  if ( I.display != NULL )
1953  {
1954  ( I.display )->displayRectangle ( rectangle, color, fill, thickness ) ;
1955  }
1956  }
1957  catch ( ... )
1958  {
1959  vpERROR_TRACE ( "Error caught" ) ;
1960  throw ;
1961  }
1962 }
1963 
1964 
1980 void
1982  const vpImagePoint &center,
1983  float angle,
1984  unsigned int width, unsigned int height,
1985  const vpColor &color,
1986  unsigned int thickness)
1987 {
1988  try
1989  {
1990  if (I.display != NULL)
1991  {
1992  double i = center.get_i();
1993  double j = center.get_j();
1994 
1995  //A, B, C, D, corners of the rectangle clockwise
1996  vpImagePoint ipa, ipb, ipc, ipd;
1997  double cosinus = cos(angle);
1998  double sinus = sin(angle);
1999  ipa.set_u(j + 0.5*width*cosinus + 0.5*height*sinus);
2000  ipa.set_v(i + 0.5*width*sinus - 0.5*height*cosinus);
2001  ipb.set_u(j + 0.5*width*cosinus - 0.5*height*sinus);
2002  ipb.set_v(i + 0.5*width*sinus + 0.5*height*cosinus);
2003  ipc.set_u(j - 0.5*width*cosinus - 0.5*height*sinus);
2004  ipc.set_v(i - 0.5*width*sinus + 0.5*height*cosinus);
2005  ipd.set_u(j - 0.5*width*cosinus + 0.5*height*sinus);
2006  ipd.set_v(i - 0.5*width*sinus - 0.5*height*cosinus);
2007 
2008  ( I.display )->displayLine(I, ipa, ipb, color, thickness);
2009  ( I.display )->displayLine(I, ipa, ipd, color, thickness);
2010  ( I.display )->displayLine(I, ipc, ipb, color, thickness);
2011  ( I.display )->displayLine(I, ipc, ipd, color, thickness);
2012  }
2013  }
2014  catch(...)
2015  {
2016  vpERROR_TRACE("Error caught in displayRectangle") ;
2017  throw ;
2018  }
2019 }
2020 
2037 void
2039  int i, int j,
2040  unsigned int width, unsigned int height,
2041  const vpColor &color, bool fill,
2042  unsigned int thickness)
2043 {
2044  try
2045  {
2046  if ( I.display != NULL )
2047  {
2048  vpImagePoint topLeft;
2049  topLeft.set_i( i );
2050  topLeft.set_j( j );
2051 
2052  ( I.display )->displayRectangle ( topLeft, width, height,
2053  color, fill, thickness ) ;
2054  }
2055  }
2056  catch ( ... )
2057  {
2058  vpERROR_TRACE ( "Error caught" ) ;
2059  throw ;
2060  }
2061 }
2077 void
2079  unsigned int i, unsigned int j, float angle,
2080  unsigned int width, unsigned int height,
2081  const vpColor &color,unsigned int thickness)
2082 {
2083  try
2084  {
2085  if (I.display != NULL)
2086  {
2087  //A, B, C, D, corners of the rectangle clockwise
2088  vpImagePoint ipa, ipb, ipc, ipd;
2089  float cosinus = cos(angle);
2090  float sinus = sin(angle);
2091  ipa.set_u(j + 0.5*width*cosinus + 0.5*height*sinus);
2092  ipa.set_v(i + 0.5*width*sinus - 0.5*height*cosinus);
2093  ipb.set_u(j + 0.5*width*cosinus - 0.5*height*sinus);
2094  ipb.set_v(i + 0.5*width*sinus + 0.5*height*cosinus);
2095  ipc.set_u(j - 0.5*width*cosinus - 0.5*height*sinus);
2096  ipc.set_v(i - 0.5*width*sinus + 0.5*height*cosinus);
2097  ipd.set_u(j - 0.5*width*cosinus + 0.5*height*sinus);
2098  ipd.set_v(i - 0.5*width*sinus - 0.5*height*cosinus);
2099 
2100  ( I.display )->displayLine(I, ipa, ipb, color, thickness);
2101  ( I.display )->displayLine(I, ipa, ipd, color, thickness);
2102  ( I.display )->displayLine(I, ipc, ipb, color, thickness);
2103  ( I.display )->displayLine(I, ipc, ipd, color, thickness);
2104  }
2105  }
2106  catch(...)
2107  {
2108  vpERROR_TRACE("Error caught in displayRectangle") ;
2109  throw ;
2110  }
2111 }
2112 
2129 void
2131  int i, int j,
2132  unsigned int width, unsigned int height,
2133  const vpColor &color, bool fill,
2134  unsigned int thickness)
2135 {
2136  try
2137  {
2138  if ( I.display != NULL )
2139  {
2140  vpImagePoint topLeft;
2141  topLeft.set_i( i );
2142  topLeft.set_j( j );
2143 
2144  ( I.display )->displayRectangle ( topLeft, width, height,
2145  color, fill, thickness ) ;
2146  }
2147  }
2148  catch ( ... )
2149  {
2150  vpERROR_TRACE ( "Error caught" ) ;
2151  throw ;
2152  }
2153 }
2168 void
2170  unsigned int i, unsigned int j, float angle,
2171  unsigned int width, unsigned int height,
2172  const vpColor &color, unsigned int thickness)
2173 {
2174  try
2175  {
2176  if (I.display != NULL)
2177  {
2178  //A, B, C, D, corners of the rectangle clockwise
2179  vpImagePoint ipa, ipb, ipc, ipd;
2180  float cosinus = cos(angle);
2181  float sinus = sin(angle);
2182  ipa.set_u(j + 0.5*width*cosinus + 0.5*height*sinus);
2183  ipa.set_v(i + 0.5*width*sinus - 0.5*height*cosinus);
2184  ipb.set_u(j + 0.5*width*cosinus - 0.5*height*sinus);
2185  ipb.set_v(i + 0.5*width*sinus + 0.5*height*cosinus);
2186  ipc.set_u(j - 0.5*width*cosinus - 0.5*height*sinus);
2187  ipc.set_v(i - 0.5*width*sinus + 0.5*height*cosinus);
2188  ipd.set_u(j - 0.5*width*cosinus + 0.5*height*sinus);
2189  ipd.set_v(i - 0.5*width*sinus - 0.5*height*cosinus);
2190 
2191  ( I.display )->displayLine(I, ipa, ipb, color, thickness);
2192  ( I.display )->displayLine(I, ipa, ipd, color, thickness);
2193  ( I.display )->displayLine(I, ipc, ipb, color, thickness);
2194  ( I.display )->displayLine(I, ipc, ipd, color, thickness);
2195  }
2196  }
2197  catch(...)
2198  {
2199  vpERROR_TRACE("Error caught in displayRectangle") ;
2200  throw ;
2201  }
2202 }
2203 
2233 {
2234 
2235  try
2236  {
2237  if ( I.display != NULL )
2238  {
2239  ( I.display )->flushDisplay() ;
2240  }
2241  }
2242  catch ( ... )
2243  {
2244  vpERROR_TRACE ( "Error caught" ) ;
2245  throw ;
2246  }
2247 }
2248 
2250 {
2251 
2252  try
2253  {
2254  if ( I.display != NULL )
2255  {
2256  ( I.display )->flushDisplayROI(roi.getTopLeft(),(unsigned int)roi.getWidth(),(unsigned int)roi.getHeight()) ;
2257  }
2258  }
2259  catch ( ... )
2260  {
2261  vpERROR_TRACE ( "Error caught" ) ;
2262  throw ;
2263  }
2264 }
2265 
2270 {
2271 
2272  try
2273  {
2274  if ( I.display != NULL )
2275  {
2276  ( I.display )->closeDisplay() ;
2277  I.display = NULL;
2278  }
2279  }
2280  catch ( ... )
2281  {
2282  vpERROR_TRACE ( "Error caught" ) ;
2283  throw ;
2284  }
2285 }
2286 
2287 
2295 void
2296 vpDisplay::setTitle ( const vpImage<vpRGBa> &I, const char *windowtitle )
2297 {
2298 
2299  try
2300  {
2301  if ( I.display != NULL )
2302  {
2303  ( I.display )->setTitle ( windowtitle ) ;
2304  }
2305  }
2306  catch ( ... )
2307  {
2308  vpERROR_TRACE ( "Error caught" ) ;
2309  throw ;
2310  }
2311 }
2312 
2322 void
2323 vpDisplay::setWindowPosition ( const vpImage<vpRGBa> &I, int winx, int winy )
2324 {
2325 
2326  try
2327  {
2328  if ( I.display != NULL )
2329  {
2330  ( I.display )->setWindowPosition ( winx, winy ) ;
2331  }
2332  }
2333  catch ( ... )
2334  {
2335  vpERROR_TRACE ( "Error caught" ) ;
2336  throw ;
2337  }
2338 }
2339 
2353 void
2354 vpDisplay::setFont ( const vpImage<vpRGBa> &I, const char *fontname )
2355 {
2356 
2357  try
2358  {
2359  if ( I.display != NULL )
2360  {
2361  ( I.display )->setFont ( fontname ) ;
2362  }
2363  }
2364  catch ( ... )
2365  {
2366  vpERROR_TRACE ( "Error caught" ) ;
2367  throw ;
2368  }
2369 }
2370 
2380 void
2382 {
2383  try
2384  {
2385  if ( I.display != NULL )
2386  {
2387  ( I.display )->clearDisplay ( color ) ;
2388  }
2389  }
2390  catch ( ... )
2391  {
2392  vpERROR_TRACE ( "Error caught" ) ;
2393  throw ;
2394  }
2395 }
2396 
2408 void
2410 {
2411 
2412  try
2413  {
2414  if ( I.display != NULL )
2415  {
2416  ( I.display )->displayImage ( I ) ;
2417  }
2418  }
2419  catch ( ... )
2420  {
2421  vpERROR_TRACE ( "Error caught" ) ;
2422  throw ;
2423  }
2424 }
2425 
2426 void
2428 {
2429  vpImagePoint topLeft;
2430  double top = floor(roi.getTop());
2431  double left = floor(roi.getLeft());
2432  double roiheight = floor(roi.getHeight());
2433  double roiwidth = floor(roi.getWidth());
2434  double iheight = (double)(I.getHeight());
2435  double iwidth = (double)(I.getWidth());
2436 
2437  if (top < 0 || top >= iheight || left < 0 || left >= iwidth || top+roiheight >= iheight || left+roiwidth >= iwidth)
2438  {
2439  vpERROR_TRACE ( "Region of interest outside of the image" ) ;
2441  "Region of interest outside of the image" ) ) ;
2442  }
2443 
2444  try
2445  {
2446  if ( I.display != NULL )
2447  {
2448  ( I.display )->displayImageROI ( I , vpImagePoint(top,left), (unsigned int)roiwidth,(unsigned int)roiheight ) ;
2449  }
2450  }
2451  catch ( ... )
2452  {
2453  vpERROR_TRACE ( "Error caught" ) ;
2454  throw ;
2455  }
2456 }
2457 
2458 
2525 void
2527 {
2528 
2529  try
2530  {
2531  if ( Isrc.display != NULL )
2532  {
2533  ( Isrc.display )->getImage ( Idest ) ;
2534  }
2535  else {
2536  Idest = Isrc;
2537  }
2538  }
2539  catch ( ... )
2540  {
2541  vpERROR_TRACE ( "Error caught" ) ;
2542  throw ;
2543  }
2544 }
2545 
2576 {
2577 
2578  try
2579  {
2580  if ( I.display != NULL )
2581  {
2582  ( I.display )->flushDisplay() ;
2583  }
2584  }
2585  catch ( ... )
2586  {
2587  vpERROR_TRACE ( "Error caught" ) ;
2588  throw ;
2589  }
2590 }
2591 
2592 void vpDisplay::flushROI ( const vpImage<vpRGBa> &I, const vpRect &roi )
2593 {
2594 
2595  try
2596  {
2597  if ( I.display != NULL )
2598  {
2599  ( I.display )->flushDisplayROI(roi.getTopLeft(),(unsigned int)roi.getWidth(),(unsigned int)roi.getHeight()) ;
2600  }
2601  }
2602  catch ( ... )
2603  {
2604  vpERROR_TRACE ( "Error caught" ) ;
2605  throw ;
2606  }
2607 }
2608 
2613 {
2614 
2615  try
2616  {
2617  if ( I.display != NULL )
2618  {
2619  ( I.display )->closeDisplay() ;
2620  I.display = NULL;
2621  }
2622  }
2623  catch ( ... )
2624  {
2625  vpERROR_TRACE ( "Error caught" ) ;
2626  throw ;
2627  }
2628 }
2629 
2647 bool vpDisplay::getClick ( const vpImage<unsigned char> &I, bool blocking )
2648 {
2649  try
2650  {
2651  if ( I.display != NULL )
2652  {
2653  return ( I.display )->getClick(blocking) ;
2654  }
2655  }
2656  catch ( ... )
2657  {
2658  vpERROR_TRACE ( "Error caught" ) ;
2659  throw ;
2660  }
2661  return false ;
2662 }
2663 
2685  vpImagePoint &ip, bool blocking )
2686 {
2687  try
2688  {
2689  if ( I.display != NULL )
2690  {
2691  return ( I.display )->getClick ( ip, blocking ) ;
2692  }
2693  }
2694  catch ( ... )
2695  {
2696  vpERROR_TRACE ( "Error caught" ) ;
2697  throw ;
2698  }
2699  return false ;
2700 }
2701 
2724  vpImagePoint &ip,
2726  bool blocking)
2727 {
2728  try
2729  {
2730  if ( I.display != NULL )
2731  {
2732  return ( I.display )->getClick ( ip, button, blocking ) ;
2733  }
2734  }
2735  catch ( ... )
2736  {
2737  vpERROR_TRACE ( "Error caught" ) ;
2738  throw ;
2739  }
2740  return false ;
2741 }
2742 
2762  bool blocking)
2763 {
2764  vpImagePoint ip;
2765  return vpDisplay::getClick(I, ip, button, blocking);
2766 }
2767 
2787  bool blocking)
2788 {
2789  vpImagePoint ip;
2790  return vpDisplay::getClick(I, ip, button, blocking);
2791 }
2792 
2814 bool
2816  vpImagePoint &ip,
2818  bool blocking )
2819 {
2820  try
2821  {
2822  if ( I.display != NULL )
2823  {
2824  return ( I.display )->getClickUp ( ip, button, blocking ) ;
2825  }
2826  }
2827  catch ( ... )
2828  {
2829  vpERROR_TRACE ( "Error caught" ) ;
2830  throw ;
2831  }
2832  return false ;
2833 }
2834 
2854  bool blocking)
2855 {
2856  vpImagePoint ip;
2857  return vpDisplay::getClickUp(I, ip, button, blocking);
2858 }
2859 
2879  bool blocking)
2880 {
2881  vpImagePoint ip;
2882  return vpDisplay::getClickUp(I, ip, button, blocking);
2883 }
2884 
2970 bool
2972 {
2973  try
2974  {
2975  if ( I.display != NULL )
2976  {
2977  return ( I.display )->getKeyboardEvent ( blocking ) ;
2978  }
2979  }
2980  catch ( ... )
2981  {
2982  vpERROR_TRACE ( "Error caught" ) ;
2983  throw ;
2984  }
2985  return false ;
2986 }
2987 
3077 bool
3079  char *string, bool blocking)
3080 {
3081  try
3082  {
3083  if ( I.display != NULL )
3084  {
3085  return ( I.display )->getKeyboardEvent ( string, blocking ) ;
3086  }
3087  }
3088  catch ( ... )
3089  {
3090  vpERROR_TRACE ( "Error caught" ) ;
3091  throw ;
3092  }
3093  return false ;
3094 }
3105 bool
3107  vpImagePoint &ip)
3108 {
3109  try
3110  {
3111  if ( I.display != NULL )
3112  {
3113  return ( I.display )->getPointerMotionEvent ( ip ) ;
3114  }
3115  }
3116  catch ( ... )
3117  {
3118  vpERROR_TRACE ( "Error caught" ) ;
3119  throw ;
3120  }
3121  return false;
3122 }
3123 
3134 bool
3136  vpImagePoint &ip)
3137 {
3138  try
3139  {
3140  if ( I.display != NULL )
3141  {
3142  return ( I.display )->getPointerPosition ( ip ) ;
3143  }
3144  }
3145  catch ( ... )
3146  {
3147  vpERROR_TRACE ( "Error caught" ) ;
3148  throw ;
3149  }
3150  return false;
3151 }
3152 
3166 bool vpDisplay::getClick ( const vpImage<vpRGBa> &I, bool blocking )
3167 {
3168  try
3169  {
3170  if ( I.display != NULL )
3171  {
3172  return ( I.display )->getClick(blocking) ;
3173  }
3174  }
3175  catch ( ... )
3176  {
3177  vpERROR_TRACE ( "Error caught" ) ;
3178  throw ;
3179  }
3180  return false;
3181 }
3182 
3183 
3203  vpImagePoint &ip, bool blocking )
3204 {
3205  try
3206  {
3207  if ( I.display != NULL )
3208  {
3209  return ( I.display )->getClick ( ip, blocking ) ;
3210  }
3211  }
3212  catch ( ... )
3213  {
3214  vpERROR_TRACE ( "Error caught" ) ;
3215  throw ;
3216  }
3217  return false ;
3218 }
3219 
3241  vpImagePoint &ip,
3243  bool blocking )
3244 {
3245  try
3246  {
3247  if ( I.display != NULL )
3248  {
3249  return ( I.display )->getClick ( ip, button, blocking ) ;
3250  }
3251  }
3252  catch ( ... )
3253  {
3254  vpERROR_TRACE ( "Error caught" ) ;
3255  throw ;
3256  }
3257  return false ;
3258 }
3259 
3280 bool
3282  vpImagePoint &ip,
3284  bool blocking )
3285 {
3286  try
3287  {
3288  if ( I.display != NULL )
3289  {
3290  return ( I.display )->getClickUp ( ip, button, blocking ) ;
3291  }
3292  }
3293  catch ( ... )
3294  {
3295  vpERROR_TRACE ( "Error caught" ) ;
3296  throw ;
3297  }
3298  return false ;
3299 }
3300 
3385 bool
3387 {
3388  try
3389  {
3390  if ( I.display != NULL )
3391  {
3392  return ( I.display )->getKeyboardEvent ( blocking ) ;
3393  }
3394  }
3395  catch ( ... )
3396  {
3397  vpERROR_TRACE ( "Error caught" ) ;
3398  throw ;
3399  }
3400  return false ;
3401 }
3402 
3490 bool
3492  char *string, bool blocking)
3493 {
3494  try
3495  {
3496  if ( I.display != NULL )
3497  {
3498  return ( I.display )->getKeyboardEvent ( string, blocking ) ;
3499  }
3500  }
3501  catch ( ... )
3502  {
3503  vpERROR_TRACE ( "Error caught" ) ;
3504  throw ;
3505  }
3506  return false ;
3507 }
3518 bool
3520 {
3521  try
3522  {
3523  if ( I.display != NULL )
3524  {
3525  return ( I.display )->getPointerMotionEvent ( ip ) ;
3526  }
3527  }
3528  catch ( ... )
3529  {
3530  vpERROR_TRACE ( "Error caught" ) ;
3531  throw ;
3532  }
3533  return false;
3534 }
3535 
3545 bool
3547 {
3548  try
3549  {
3550  if ( I.display != NULL )
3551  {
3552  return ( I.display )->getPointerPosition ( ip ) ;
3553  }
3554  }
3555  catch ( ... )
3556  {
3557  vpERROR_TRACE ( "Error caught" ) ;
3558  throw ;
3559  }
3560  return false;
3561 }
3562 
3609  const vpImagePoint &center,
3610  const double &coef1, const double &coef2, const double &coef3,
3611  bool use_centered_moments,
3612  const vpColor &color,
3613  unsigned int thickness)
3614 {
3615  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., vpMath::rad(360), use_centered_moments, color, thickness);
3616 }
3617 
3668  const vpImagePoint &center,
3669  const double &coef1, const double &coef2, const double &coef3,
3670  const double &theta1, const double &theta2, bool use_centered_moments,
3671  const vpColor &color,
3672  unsigned int thickness)
3673 {
3674  try
3675  {
3676  if ( I.display != NULL )
3677  {
3678  double j1, i1;
3679  vpImagePoint iP11;
3680  double j2, i2;
3681  vpImagePoint iP22;
3682  j1 = j2 = i1 = i2 = 0 ;
3683  double a=0., b=0., e=0.;
3684 
3685  double mu20_p = coef1;
3686  double mu11_p = coef2;
3687  double mu02_p = coef3;
3688 
3689  if (use_centered_moments) {
3690  if (std::fabs(mu11_p) > std::numeric_limits<double>::epsilon()) {
3691 
3692  double val_p = sqrt(vpMath::sqr(mu20_p-mu02_p) + 4*vpMath::sqr(mu11_p));
3693  a = sqrt((mu20_p + mu02_p + val_p)/2);
3694  b = sqrt((mu20_p + mu02_p - val_p)/2);
3695 
3696  e = (mu02_p - mu20_p + val_p)/(2*mu11_p);
3697  e = atan(e);
3698  }
3699  else {
3700  a = sqrt(mu20_p);
3701  b = sqrt(mu02_p);
3702  e = 0.;
3703  }
3704  }
3705  else {
3706  a = coef1;
3707  b = coef2;
3708  e = coef3;
3709  }
3710 
3711  // Approximation of the circumference of an ellipse:
3712  // [Ramanujan, S., "Modular Equations and Approximations to ,"
3713  // Quart. J. Pure. Appl. Math., vol. 45 (1913-1914), pp. 350-372]
3714  double t = (a-b)/(a+b);
3715  double circumference = M_PI*(a+b)*(1 + 3*vpMath::sqr(t)/(10 + sqrt(4 - 3*vpMath::sqr(t))));
3716 
3717  int nbpoints = (int)(floor(circumference/5));
3718  if (nbpoints < 10)
3719  nbpoints = 10;
3720  double incr = 2*M_PI / nbpoints ; // angle increment
3721 
3722  double smallalpha = theta1;
3723  double highalpha = theta2;
3724  double ce = cos(e);
3725  double se = sin(e);
3726 
3727  double k = smallalpha ;
3728  j1 = a *cos(k) ; // equation of an ellipse
3729  i1 = b *sin(k) ; // equation of an ellipse
3730 
3731  // (i1,j1) are the coordinates on the origin centered ellipse ;
3732  // a rotation by "e" and a translation by (xci,jc) are done
3733  // to get the coordinates of the point on the shifted ellipse
3734  iP11.set_j ( center.get_j() + ce *j1 - se *i1 );
3735  iP11.set_i ( center.get_i() + se *j1 + ce *i1 );
3736 
3737  while (k+incr<highalpha+incr)
3738  {
3739  j2 = a *cos(k+incr) ; // equation of an ellipse
3740  i2 = b *sin(k+incr) ; // equation of an ellipse
3741 
3742  // to get the coordinates of the point on the shifted ellipse
3743  iP22.set_j ( center.get_j() + ce *j2 - se *i2 );
3744  iP22.set_i ( center.get_i() + se *j2 + ce *i2 );
3745 
3746  ( I.display )->displayLine(iP11, iP22, color, thickness) ;
3747 
3748  i1 = i2;
3749  j1 = j2;
3750  iP11 = iP22;
3751 
3752  k += incr ;
3753  }
3754  }
3755  }
3756  catch ( vpException &e )
3757  {
3758  throw(e) ;
3759  }
3760 }
3761 
3808  const vpImagePoint &center,
3809  const double &coef1, const double &coef2, const double &coef3,
3810  bool use_centered_moments,
3811  const vpColor &color,
3812  unsigned int thickness)
3813 {
3814  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., vpMath::rad(360), use_centered_moments, color, thickness);
3815 }
3816 
3867  const vpImagePoint &center,
3868  const double &coef1, const double &coef2, const double &coef3,
3869  const double &theta1, const double &theta2, bool use_centered_moments,
3870  const vpColor &color,
3871  unsigned int thickness)
3872 {
3873  try
3874  {
3875  if ( I.display != NULL )
3876  {
3877  double j1, i1;
3878  vpImagePoint iP11;
3879  double j2, i2;
3880  vpImagePoint iP22;
3881  j1 = j2 = i1 = i2 = 0 ;
3882  double a=0., b=0., e=0.;
3883 
3884  double mu20_p = coef1;
3885  double mu11_p = coef2;
3886  double mu02_p = coef3;
3887 
3888  if (use_centered_moments) {
3889  if (std::fabs(mu11_p) > std::numeric_limits<double>::epsilon()) {
3890 
3891  double val_p = sqrt(vpMath::sqr(mu20_p-mu02_p) + 4*vpMath::sqr(mu11_p));
3892  a = sqrt((mu20_p + mu02_p + val_p)/2);
3893  b = sqrt((mu20_p + mu02_p - val_p)/2);
3894 
3895  e = (mu02_p - mu20_p + val_p)/(2*mu11_p);
3896  e = atan(e);
3897  }
3898  else {
3899  a = sqrt(mu20_p);
3900  b = sqrt(mu02_p);
3901  e = 0.;
3902  }
3903  }
3904  else {
3905  a = coef1;
3906  b = coef2;
3907  e = coef3;
3908  }
3909 
3910  // Approximation of the circumference of an ellipse:
3911  // [Ramanujan, S., "Modular Equations and Approximations to ,"
3912  // Quart. J. Pure. Appl. Math., vol. 45 (1913-1914), pp. 350-372]
3913  double t = (a-b)/(a+b);
3914  double circumference = M_PI*(a+b)*(1 + 3*vpMath::sqr(t)/(10 + sqrt(4 - 3*vpMath::sqr(t))));
3915 
3916  int nbpoints = (int)(floor(circumference/5));
3917  if (nbpoints < 10)
3918  nbpoints = 10;
3919  double incr = 2*M_PI / nbpoints ; // angle increment
3920 
3921  double smallalpha = theta1;
3922  double highalpha = theta2;
3923  double ce = cos(e);
3924  double se = sin(e);
3925 
3926  double k = smallalpha ;
3927  j1 = a *cos(k) ; // equation of an ellipse
3928  i1 = b *sin(k) ; // equation of an ellipse
3929 
3930  // (i1,j1) are the coordinates on the origin centered ellipse ;
3931  // a rotation by "e" and a translation by (xci,jc) are done
3932  // to get the coordinates of the point on the shifted ellipse
3933  iP11.set_j ( center.get_j() + ce *j1 - se *i1 );
3934  iP11.set_i ( center.get_i() + se *j1 + ce *i1 );
3935 
3936  while (k+incr<highalpha+incr)
3937  {
3938  j2 = a *cos(k+incr) ; // equation of an ellipse
3939  i2 = b *sin(k+incr) ; // equation of an ellipse
3940 
3941  // to get the coordinates of the point on the shifted ellipse
3942  iP22.set_j ( center.get_j() + ce *j2 - se *i2 );
3943  iP22.set_i ( center.get_i() + se *j2 + ce *i2 );
3944 
3945  ( I.display )->displayLine(iP11, iP22, color, thickness) ;
3946 
3947  i1 = i2;
3948  j1 = j2;
3949  iP11 = iP22;
3950 
3951  k += incr ;
3952  }
3953  }
3954  }
3955  catch ( vpException &e )
3956  {
3957  throw(e) ;
3958  }
3959 }
3960 
static void displayCamera(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness)
Definition: vpDisplay.cpp:513
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
vpDisplay * display
Definition: vpImage.h:121
static void displayEllipse(const vpImage< unsigned char > &I, const vpImagePoint &center, const double &coef1, const double &coef2, const double &coef3, bool use_centered_moments, const vpColor &color, unsigned int thickness=1)
Definition: vpDisplay.cpp:3608
double getTop() const
Definition: vpRect.h:180
virtual void displayImage(const vpImage< unsigned char > &I)=0
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:174
virtual 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)=0
unsigned int width
Definition: vpDisplay.h:183
static void close(vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2269
double get_i() const
Definition: vpImagePoint.h:195
unsigned int getWidth() const
Definition: vpImage.h:161
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpERROR_TRACE
Definition: vpDebug.h:395
static void displayPolygon(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, const vpColor &color, unsigned int thickness=1)
Definition: vpDisplay.cpp:1648
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
virtual void clearDisplay(const vpColor &color=vpColor::white)=0
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition: vpDisplay.cpp:887
static const vpColor none
Definition: vpColor.h:179
virtual bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)=0
error that can be emited by ViSP classes.
Definition: vpException.h:76
void track(const vpHomogeneousMatrix &cMo)
double getHeight() const
Definition: vpRect.h:155
virtual bool getPointerMotionEvent(vpImagePoint &ip)=0
bool displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:178
static const vpColor green
Definition: vpColor.h:170
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
double get_j() const
Definition: vpImagePoint.h:206
vpImagePoint getTopLeft() const
Definition: vpRect.h:186
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a point.
Definition: vpPoint.h:65
virtual void flushDisplay()=0
void set_i(const double ii)
Definition: vpImagePoint.h:159
double getWidth() const
Definition: vpRect.h:199
virtual bool getPointerPosition(vpImagePoint &ip)=0
virtual bool getKeyboardEvent(bool blocking=true)=0
void set_u(const double u)
Definition: vpImagePoint.h:217
virtual void setWindowPosition(int winx, int winy)=0
static double sqr(double x)
Definition: vpMath.h:106
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
unsigned int height
Definition: vpDisplay.h:184
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void set_v(const double v)
Definition: vpImagePoint.h:228
Generic class defining intrinsic camera parameters.
virtual void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)=0
virtual void setTitle(const char *title)=0
void moveCenter(double x, double y)
Definition: vpRect.h:310
virtual void setFont(const char *font)=0
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1)
Definition: vpDisplay.cpp:375
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
virtual ~vpDisplay()
Definition: vpDisplay.cpp:82
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:328
static double rad(double deg)
Definition: vpMath.h:100
virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
void set_j(const double jj)
Definition: vpImagePoint.h:170
virtual void closeDisplay()=0
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
int windowXPosition
display position
Definition: vpDisplay.h:180
static void setBackground(const vpImage< unsigned char > &I, const vpColor &color)
Definition: vpDisplay.cpp:182
unsigned int getHeight() const
Definition: vpImage.h:152
Defines a rectangle in the plane.
Definition: vpRect.h:85
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition: vpDisplay.cpp:2249
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition: vpDisplay.cpp:229
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
virtual void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)=0
int windowYPosition
display position
Definition: vpDisplay.h:182
double getLeft() const
Definition: vpRect.h:161
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0
vpColVector p
Definition: vpTracker.h:78
static const vpColor blue
Definition: vpColor.h:173
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
Definition: vpPoint.cpp:74