ViSP  2.6.2
vpPlotGraph.cpp
1 /****************************************************************************
2  *
3  * $Id: vpPlotGraph.cpp 3682 2012-04-11 14:28:29Z fnovotny $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Define a graph for the vpPlot class.
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 #define FLUSH_ON_PLOT
42 
43 #include <visp/vpConfig.h>
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 
46 
47 
48 
49 #include <visp/vpPlotGraph.h>
50 #include <visp/vpMath.h>
51 #include <visp/vpMeterPixelConversion.h>
52 #include <visp/vpPixelMeterConversion.h>
53 #include <visp/vpPose.h>
54 
55 #include <visp/vpDisplayOpenCV.h>
56 #include <visp/vpDisplayX.h>
57 #include <visp/vpDisplayGDI.h>
58 #include <cmath> // std::fabs
59 #include <visp/vpMath.h>
60 #include <limits> // numeric_limits
61 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
62 
63 vpPlotGraph::vpPlotGraph()
64 {
65  curveList = NULL;
66 
67  gridColor.setColor(200,200,200);
68 
69  nbDivisionx = 10;
70  nbDivisiony = 10;
71  nbDivisionz = 10;
72 
73  xmax = 10;
74  xmin = 0;
75  ymax = 10;
76  ymin = -10;
77  zmax = 10;
78  zmin = -10;
79  xdelt = 1;
80  ydelt = 1;
81  zdelt = 1;
82  gridx = true;
83  gridy = true;
84  scaleInitialized = false;
85  firstPoint = true;
86 
87  dispUnit = false;
88  dispTitle = false;
89  dispLegend = false;
90 
91  blockedr = false;
92  blockedz = false;
93  blocked = false;
94 
95  epsi = 5;
96  epsj = 6;
97 
98  old_iPr = vpImagePoint(-1,-1);
99  old_iPz = vpImagePoint(-1,-1);
100 }
101 
102 vpPlotGraph::~vpPlotGraph()
103 {
104  if (curveList != NULL)
105  {
106  delete[] curveList;
107  curveList = NULL;
108  }
109 }
110 
111 void
112 vpPlotGraph::initGraph (unsigned int nbCurve)
113 {
114  curveList = new vpPlotCurve[nbCurve];
115  curveNbr = nbCurve;
116 
118 
119  for (unsigned int i = 0; i < curveNbr; i++)
120  {
121  (curveList+i)->color = colors[i%6];
122  (curveList+i)->curveStyle = line;
123  (curveList+i)->pointListx.clear();
124  (curveList+i)->pointListy.clear();
125  strcpy((curveList+i)->legend,"");
126  }
127 }
128 
129 void
130 vpPlotGraph::initSize (vpImagePoint topLeft, unsigned int width, unsigned int height, unsigned int margei, unsigned int margej)
131 {
132  this->topLeft = topLeft;
133  this->width = width;
134  this->height = height;
135  graphZone.setTopLeft(topLeft);
136  graphZone.setWidth(width);
137  graphZone.setHeight(height);
138 
139  this->dTopLeft = vpImagePoint(topLeft.get_i()+margei,topLeft.get_j()+margej);
140  this->dWidth = width-margej-10;
141  this->dHeight = height-2*margei;
142  dGraphZone.setTopLeft(dTopLeft);
143  dGraphZone.setWidth(dWidth+1);
144  dGraphZone.setHeight(dHeight+1);
145 
146  this->dTopLeft3D = vpImagePoint(topLeft.get_i()+margei,topLeft.get_j()+10);
147  dGraphZone3D.setTopLeft(dTopLeft3D);
148  dGraphZone3D.setWidth(dWidth+1);
149  dGraphZone3D.setHeight(dHeight+1);
150 
151  if (this->dWidth > this->dHeight)
152  {
153  w_ysize = 1.0;
154  w_xsize = this->dWidth/this->dHeight;
155  w_zsize = w_xsize;
156 
157  w_yval = w_ysize/2.0;
158  w_xval = w_xsize/2.0;
159  w_zval = w_zsize/2.0;
160  }
161  else if (this->dWidth == this->dHeight)
162  {
163  w_ysize = 1.0;
164  w_xsize = 1.0;
165  w_zsize = 1.0;
166 
167  w_yval = 0.5;
168  w_xval = 0.5;
169  w_zval = 0.5;
170  }
171  else if (this->dWidth < this->dHeight)
172  {
173  w_xsize = 1.0;
174  w_ysize = this->dHeight/this->dWidth;
175  w_zsize = w_ysize;
176 
177  w_yval = w_ysize/2.0;
178  w_xval = w_xsize/2.0;
179  w_zval = w_zsize/2.0;
180  }
181 
182  cam.initPersProjWithoutDistortion(1000,1000,this->dWidth/2.0,this->dHeight/2.0);
183 
184  findPose();
185 
186  cMf.buildFrom(0,0,cMo[2][3],0,0,0);
187 }
188 
189 
190 void
191 vpPlotGraph::findPose()
192 {
193  vpPoint point[4];
194  point[0].setWorldCoordinates(-w_xval,-w_yval,-w_zval);
195  point[1].setWorldCoordinates(w_xval,-w_yval,-w_zval);
196  point[2].setWorldCoordinates(w_xval,w_yval,-w_zval);
197  point[3].setWorldCoordinates(-w_xval,w_yval,-w_zval);
198 
199  vpImagePoint iP[4];
200  iP[0].set_ij(0,0);
201  iP[1].set_ij(0,dWidth-1);
202  iP[2].set_ij(dHeight-1,dWidth-1);
203  iP[3].set_ij(dHeight-1,0);
204 
205  double x=0, y=0;
206  vpPose pose;
207  pose.clearPoint();
208 
209  for (unsigned int i=0 ; i < 4 ; i++)
210  {
211  vpPixelMeterConversion::convertPoint(cam, iP[i], x, y);
212  point[i].set_x(x);
213  point[i].set_y(y);
214  pose.addPoint(point[i]);
215  }
216 
217  pose.computePose(vpPose::LAGRANGE, cMo) ;
218  pose.computePose(vpPose::VIRTUAL_VS, cMo);
219 }
220 
221 void
222 vpPlotGraph::computeGraphParameters()
223 {
224  zoomx = dWidth/(xmax-xmin);
225  zoomy = dHeight/(ymax-ymin);
226  xorg = dTopLeft.get_j() - (xmin*zoomx);
227  yorg = dTopLeft.get_i() + (ymax*zoomy);
228 }
229 
230 void
231 vpPlotGraph::setCurveColor(const unsigned int curveNum, const vpColor color)
232 {
233  (curveList+curveNum)->color = color;
234 }
235 
236 void
237 vpPlotGraph::setTitle (const char *title)
238 {
239  strcpy(this->title, title);
240  dispTitle = true;
241 }
242 
243 void
244 vpPlotGraph::setUnitX (const char *unitx)
245 {
246  strcpy(this->unitx, unitx);
247  dispUnit = true;
248 }
249 
250 void
251 vpPlotGraph::setUnitY (const char *unity)
252 {
253  strcpy(this->unity, unity);
254  dispUnit = true;
255 }
256 
257 void
258 vpPlotGraph::setUnitZ (const char *unitz)
259 {
260  strcpy(this->unitz, unitz);
261  dispUnit = true;
262 }
263 
264 void
265 vpPlotGraph::setLegend (const unsigned int curveNum, const char *legend)
266 {
267  strcpy((curveList+curveNum)->legend,legend);
268  dispLegend = true;
269 }
270 
271 void
272 vpPlotGraph::setCurveThickness(const unsigned int curveNum, const unsigned int thickness)
273 {
274  (curveList+curveNum)->thickness = thickness;
275 }
276 
277 int
278 laFonctionSansNom (const double delta)
279 {
280  double d = delta;
281  int power = 0;
282  if (d < 1)
283  {
284  while (d < 1)
285  {
286  d = d * 10;
287  power++;
288  }
289  power--;
290  return power;
291  }
292 
293  if (d >= 10)
294  {
295  while (d > 10)
296  {
297  d = d / 10;
298  power--;
299  }
300  power--;
301  return power;
302  }
303 
304  return 0;
305 }
306 
307 void
308 vpPlotGraph::displayGrid (vpImage<unsigned char> &I)
309 {
310  computeGraphParameters();
311 
312  xdelt = (xmax-xmin)/nbDivisionx;
313  ydelt = (ymax-ymin)/nbDivisiony;
314 
315  double t;
316  char valeur[20];
317  int power;
318 
319  power = laFonctionSansNom(xdelt);
320  for(t=xmin;t<=xmax;t=t+xdelt)
321  {
322  double x = xorg+(zoomx*t);
323  if(gridy)
324  vpDisplay::displayDotLine(I,vpImagePoint(dTopLeft.get_i(),x), vpImagePoint(dTopLeft.get_i()+dHeight,x), gridColor);
325  else
327 
328  if (t+xdelt <= xmax+1e-10)
329  {
330  double ttemp;
331  if (power!=0)
332  ttemp = t*pow(10.0,power);
333  else ttemp = t;
334  sprintf(valeur, "%.2f", ttemp);
335 #if defined VISP_HAVE_X11
336  vpDisplay::displayCharString(I,vpImagePoint(yorg + 3*epsi,x),valeur, vpColor::black);
337 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV)
338  vpDisplay::displayCharString(I,vpImagePoint(yorg + epsi,x),valeur, vpColor::black);
339 #endif
340  }
341  }
342  if (power != 0)
343  {
344  sprintf(valeur, "x10e%d", -power);
345 #if defined VISP_HAVE_X11
346  vpDisplay::displayCharString(I,vpImagePoint(yorg+4*epsi,dTopLeft.get_j()+dWidth-6*epsj),valeur, vpColor::black);
347 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV)
348  vpDisplay::displayCharString(I,vpImagePoint(yorg+4*epsi,dTopLeft.get_j()+dWidth-10*epsj),valeur, vpColor::black);
349 #endif
350  }
351 
352  power = laFonctionSansNom(ydelt);
353  for(t=ymin;t<=ymax;t=t+ydelt)
354  {
355  double y = yorg-(zoomy*t);
356  if(gridx)
357  vpDisplay::displayDotLine(I,vpImagePoint(y,dTopLeft.get_j()), vpImagePoint(y,dTopLeft.get_j()+dWidth), gridColor);
358  else
360 
361  double ttemp;
362  if (power!=0)
363  ttemp = t*pow(10.0,power);
364  else ttemp = t;
365 
366  sprintf(valeur, "%.2f", ttemp);
367 #if defined VISP_HAVE_X11
368  vpDisplay::displayCharString(I,vpImagePoint(y+epsi,topLeft.get_j()+epsj),valeur, vpColor::black);
369 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV)
370  vpDisplay::displayCharString(I,vpImagePoint(y-epsi,topLeft.get_j()+epsj),valeur, vpColor::black);
371 #endif
372  }
373  if (power != 0)
374  {
375  sprintf(valeur, "x10e%d", -power);
376 #if defined VISP_HAVE_X11
377  vpDisplay::displayCharString(I,vpImagePoint(dTopLeft.get_i()-3*epsi,dTopLeft.get_j()-6*epsj),valeur, vpColor::black);
378 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV)
379  vpDisplay::displayCharString(I,vpImagePoint(dTopLeft.get_i()-3*epsi,dTopLeft.get_j()-6*epsj),valeur, vpColor::black);
380 #endif
381  }
382 
383 //Ligne horizontal
384  vpDisplay::displayArrow(I,vpImagePoint(yorg,dTopLeft.get_j()), vpImagePoint(yorg,dTopLeft.get_j()+dWidth), vpColor::black);
385 //Ligne vertical
386  vpDisplay::displayArrow(I, vpImagePoint(dTopLeft.get_i()+dHeight,xorg), vpImagePoint(dTopLeft.get_i(),xorg), vpColor::black);
387 
388  if (dispUnit)
389  displayUnit(I);
390  if (dispTitle)
391  displayTitle(I);
392  if (dispLegend)
393  displayLegend(I);
394 
395  //vpDisplay::flushROI(I,graphZone);
396 }
397 
398 void
399 vpPlotGraph::displayUnit (vpImage<unsigned char> &
400 #if defined(VISP_HAVE_X11) || defined (VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
401  I
402 #endif
403  )
404 {
405  unsigned int offsetx = vpMath::minimum<unsigned int>((unsigned int)strlen(unitx), dWidth);
406 
407 #if defined VISP_HAVE_X11
408  vpDisplay::displayCharString(I,vpImagePoint(yorg-2*epsi,dTopLeft.get_j()+dWidth-offsetx*epsj),unitx, vpColor::black);
409  vpDisplay::displayCharString(I,vpImagePoint(dTopLeft.get_i(),dTopLeft.get_j()+epsj),unity, vpColor::black);
410 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV)
411  vpDisplay::displayCharString(I,vpImagePoint(yorg-5*epsi,dTopLeft.get_j()+dWidth-offsetx*epsj),unitx, vpColor::black);
412  vpDisplay::displayCharString(I,vpImagePoint(dTopLeft.get_i(),dTopLeft.get_j()+epsj),unity, vpColor::black);
413 #endif
414 }
415 
416 void
417 vpPlotGraph::displayTitle (vpImage<unsigned char> &I)
418 {
419  double size = (double)strlen(title);
420  size = size/2.0;
422  vpImagePoint(dTopLeft.get_i()-3*epsi,
423  dTopLeft.get_j()+dWidth/2.0-4*size),
424  title,
426 }
427 
428 void
429 vpPlotGraph::displayLegend (vpImage<unsigned char> &I)
430 {
431  unsigned int offsetj = 0;
432  for (unsigned int i = 0; i < curveNbr; i++) {
433  unsigned int offset = epsj * strlen((curveList+i)->legend);
434  offsetj = vpMath::maximum(offset, offsetj);
435  }
436  if (offsetj > dWidth) offsetj = dWidth;
437 
438  for (unsigned int i = 0; i < curveNbr; i++) {
440  vpImagePoint(dTopLeft.get_i()+i*5*epsi,
441  dTopLeft.get_j()+dWidth-offsetj),
442  (curveList+i)->legend,
443  (curveList+i)->color);
444  }
445 }
446 
447 void
448 vpPlotGraph::rescalex(unsigned int side, double extremity)
449 {
450  switch (side)
451  {
452  case 0:
453  xmin = (3*extremity-xmax)/2;
454  break;
455  case 1:
456  xmax = (3*extremity-xmin)/2;
457  break;
458  }
459 
460  xdelt = (xmax-xmin)/(double)nbDivisionx;
461 }
462 
463 void
464 vpPlotGraph::rescaley(unsigned int side, double extremity)
465 {
466  switch (side)
467  {
468  case 0:
469  ymin = (3*extremity-ymax)/2;
470  break;
471  case 1:
472  ymax = (3*extremity-ymin)/2;
473  break;
474  }
475 
476  ydelt = (ymax-ymin)/(double)nbDivisiony;
477 }
478 
479 void
480 vpPlotGraph::initScale(vpImage<unsigned char> &I, const double xmin, const double xmax, const int nbDivx, const double ymin, const double ymax, const int nbDivy, const bool gx, const bool gy)
481 {
482  this->xmin = xmin;
483  this->xmax = xmax;
484  this->ymin = ymin;
485  this->ymax = ymax;
486  this->gridx = gx;
487  this->gridy = gy;
488  this->nbDivisionx = nbDivx;
489  this->nbDivisiony = nbDivy;
490  computeGraphParameters();
491  clearGraphZone(I);
492  displayGrid(I);
493  vpDisplay::flushROI(I,graphZone);
494  scaleInitialized = true;
495 }
496 
497 
498 void
499 vpPlotGraph::initScale(vpImage<unsigned char> &I, const double xmin, const double xmax, const int nbDivx, const double ymin, const double ymax, const int nbDivy, const double zmin, const double zmax, const int nbDivz, const bool gx, const bool gy)
500 {
501  this->xmin = xmin;
502  this->xmax = xmax;
503  this->ymin = ymin;
504  this->ymax = ymax;
505  this->zmin = zmin;
506  this->zmax = zmax;
507  this->gridx = gx;
508  this->gridy = gy;
509  this->nbDivisionx = nbDivx;
510  this->nbDivisiony = nbDivy;
511  this->nbDivisionz = nbDivz;
512  computeGraphParameters();
513  clearGraphZone(I);
514  displayGrid(I);
515  vpDisplay::flushROI(I,graphZone);
516  scaleInitialized = true;
517 }
518 
519 void
520 vpPlotGraph::plot (vpImage<unsigned char> &I, const unsigned int curveNb, const double x, const double y)
521 {
522  if (!scaleInitialized)
523  {
524  if (x < 0)
525  {
526  xmax = 0;
527  rescalex(0,x);
528  }
529  if (x > 0)
530  {
531  xmin = 0;
532  rescalex(1,x);
533  }
534  if (y < 0)
535  {
536  ymax = 0;
537  rescaley(0,y);
538  }
539  if (y > 0)
540  {
541  ymin = 0;
542  rescaley(1,y);
543  }
544  scaleInitialized = true;
545  computeGraphParameters();
546  clearGraphZone(I);
547  displayGrid(I);
548  //if (y == 0)
549  if (std::fabs(y) <= std::numeric_limits<double>::epsilon())
550  scaleInitialized = false;
551  }
552 
553  if (firstPoint)
554  {
555 // clearGraphZone(I);
556 // displayGrid(I);
557 // vpDisplay::flushROI(I,graphZone);
558  replot(I);
559  firstPoint = false;
560  }
561 
562  double i = yorg-(zoomy*y);
563  double j = xorg+(zoomx*x);
564 
565  vpImagePoint iP(i,j);
566 
567  if (!iP.inRectangle(dGraphZone))
568  {
569  if (x > xmax) rescalex(1,x);
570  else if(x < xmin) rescalex(0,x);
571 
572  if (y > ymax) rescaley(1,y);
573  else if(y < ymin) rescaley(0,y);
574 
575  computeGraphParameters();
576 
577  replot(I);
578  i = yorg-(zoomy*y);
579  j = xorg+(zoomx*x);
580 
581  iP.set_ij(i,j);
582  }
583 
584  (curveList+curveNb)->plotPoint(I, iP, x, y);
585 #if (!defined VISP_HAVE_X11 && defined FLUSH_ON_PLOT)
586  vpDisplay::flushROI(I,graphZone);
587  //vpDisplay::flush(I);
588 #endif
589 }
590 
591 void
592 vpPlotGraph::replot (vpImage<unsigned char> &I)
593 {
594  clearGraphZone(I);
595  displayGrid(I);
596  for (unsigned int i = 0; i < curveNbr; i++)
597  (curveList+i)->plotList(I,xorg,yorg,zoomx,zoomy);
598  vpDisplay::flushROI(I,graphZone);
599 }
600 
601 void
602 vpPlotGraph::clearGraphZone(vpImage<unsigned char> &I)
603 {
604  vpDisplay::displayROI(I,graphZone);
605 }
606 
607 bool
608 vpPlotGraph::getPixelValue(vpImage<unsigned char> &I, vpImagePoint &iP)
609 {
610  if (iP.inRectangle(dGraphZone))
611  {
612  double x = (iP.get_j()-xorg)/zoomx;
613  double y = (yorg-iP.get_i())/zoomy;
614 
615  vpDisplay::displayROI(I,vpRect(vpImagePoint(topLeft.get_i()+height-20,topLeft.get_j()),width-1,19));
616  char valeur[200];
617  sprintf(valeur, " x: %f", x);
618  vpDisplay::displayCharString(I,vpImagePoint(topLeft.get_i()+height-2,topLeft.get_j()+5*epsj),valeur, vpColor::black);
619  sprintf(valeur, " y: %f", y);
620  vpDisplay::displayCharString(I,vpImagePoint(topLeft.get_i()+height-2,topLeft.get_j()+width/2.0),valeur, vpColor::black);
621 // vpDisplay::flush(I);
622  vpDisplay::flushROI(I,vpRect(vpImagePoint(topLeft.get_i()+height-20,topLeft.get_j()),width-1,19));
623  return true;
624  }
625  return false;
626 }
627 
628 void
629 vpPlotGraph::resetPointList(const unsigned int curveNum)
630 {
631  (curveList+curveNum)->pointListx.clear();
632  (curveList+curveNum)->pointListy.clear();
633  (curveList+curveNum)->pointListz.clear();
634  (curveList+curveNum)->nbPoint = 0;
635  firstPoint = true;
636 }
637 
638 
639 /************************************************************************************************/
640 
641 bool
642 vpPlotGraph::check3Dline(vpImagePoint &iP1, vpImagePoint &iP2)
643 {
644  bool iP1In = iP1.inRectangle(dGraphZone3D);
645  bool iP2In = iP2.inRectangle(dGraphZone3D);
646 
647  if (!iP1In || !iP2In)
648  {
649  double dTopLeft_i = dTopLeft3D.get_i();
650  double dTopLeft_j = dTopLeft3D.get_j();
651  double dBottomRight_i = dTopLeft_i+dHeight;
652  double dBottomRight_j = dTopLeft_j+dWidth;
653 
654  //Cas vertical
655  if (vpImagePoint::distance(iP1,iP2) < 9)
656  return false;
657  if (fabs(iP2.get_j()-iP1.get_j()) <=2)
658  {
659  if (!iP1In && !iP2In)
660  {
661  if (iP1.get_i() < dTopLeft_i && iP2.get_i() < dTopLeft_i)
662  return false;
663  if (iP1.get_i() > dBottomRight_i && iP2.get_i() > dBottomRight_i)
664  return false;
665  if (iP1.get_j() < dTopLeft_j || iP1.get_j() > dBottomRight_j)
666  return false;
667  if (iP1.get_i() < dTopLeft_i) iP1.set_i(dTopLeft_i);
668  else iP1.set_i(dBottomRight_i);
669  if (iP2.get_i() < dTopLeft_i) iP2.set_i(dTopLeft_i);
670  else iP2.set_i(dBottomRight_i);
671  }
672  else if (!iP1In)
673  {
674  if (iP1.get_j() < dTopLeft_j) iP1.set_j(dTopLeft_j);
675  if (iP1.get_j() > dBottomRight_j) iP1.set_j(dBottomRight_j);
676  if (iP1.get_i() < dTopLeft_i) iP1.set_i(dTopLeft_i);
677  if (iP1.get_i() > dBottomRight_i) iP1.set_i(dBottomRight_i);
678  return true;
679  }
680  else if (!iP2In)
681  {
682  if (iP2.get_j() < dTopLeft_j) iP2.set_j(dTopLeft_j);
683  if (iP2.get_j() > dBottomRight_j) iP2.set_j(dBottomRight_j);
684  if (iP2.get_i() < dTopLeft_i) iP2.set_i(dTopLeft_i);
685  if (iP2.get_i() > dBottomRight_i) iP2.set_i(dBottomRight_i);
686  return true;
687  }
688  }
689  //cas horizontal
690  else if (fabs(iP2.get_i()-iP1.get_i()) <= 2)
691  {
692  if (!iP1In && !iP2In)
693  {
694  if (iP1.get_j() < dTopLeft_j && iP2.get_j() < dTopLeft_j)
695  return false;
696  if (iP1.get_j() > dBottomRight_j && iP2.get_j() > dBottomRight_j)
697  return false;
698  if (iP1.get_i() < dTopLeft_i || iP1.get_i() > dBottomRight_i)
699  return false;
700  if (iP1.get_j() < dTopLeft_j) iP1.set_j(dTopLeft_j);
701  else iP1.set_j(dBottomRight_j);
702  if (iP2.get_j() < dTopLeft_j) iP2.set_j(dTopLeft_j);
703  else iP2.set_j(dBottomRight_j);
704  }
705  else if (!iP1In)
706  {
707  if (iP1.get_j() < dTopLeft_j) iP1.set_j(dTopLeft_j);
708  if (iP1.get_j() > dBottomRight_j) iP1.set_j(dBottomRight_j);
709  if (iP1.get_i() < dTopLeft_i) iP1.set_i(dTopLeft_i);
710  if (iP1.get_i() > dBottomRight_i) iP1.set_i(dBottomRight_i);
711  return true;
712  }
713  else if (!iP2In)
714  {
715  if (iP2.get_j() < dTopLeft_j) iP2.set_j(dTopLeft_j);
716  if (iP2.get_j() > dBottomRight_j) iP2.set_j(dBottomRight_j);
717  if (iP2.get_i() < dTopLeft_i) iP2.set_i(dTopLeft_i);
718  if (iP2.get_i() > dBottomRight_i) iP2.set_i(dBottomRight_i);
719  return true;
720  }
721  }
722 
723  double a = (iP2.get_i()-iP1.get_i())/(iP2.get_j()-iP1.get_j());
724  double b = iP1.get_i()-a*iP1.get_j();
725 
726  //test horizontal
727  double jtop = (dTopLeft_i-b)/a;
728  double jlow = (dBottomRight_i-b)/a;
729  //test vertical
730  double ileft = dTopLeft_j*a+b;
731  double iright = (dBottomRight_j)*a+b;
732 
733  vpImagePoint iP[2];
734  int n = 0;
735 
736  if(jtop >= dTopLeft_j && jtop <= dBottomRight_j)
737  {
738  iP[n].set_ij(dTopLeft_i,jtop);
739  n++;
740  }
741  if(jlow >= dTopLeft_j && jlow <= dBottomRight_j)
742  {
743  iP[n].set_ij(dBottomRight_i,jlow);
744  n++;
745  }
746  if(ileft >= dTopLeft_i && ileft <= dBottomRight_i && n <2)
747  {
748  iP[n].set_ij(ileft,dTopLeft_j);
749  n++;
750  }
751  if(iright >= dTopLeft_i && iright <= dBottomRight_i && n <2)
752  {
753  iP[n].set_ij(iright,dBottomRight_j);
754  n++;
755  }
756 
757  if (n < 2)
758  return false;
759 
760  if (!iP1In && !iP2In)
761  {
762  if (fabs(a) < 1)
763  {
764  if (vpMath::sign(iP1.get_j()-iP[0].get_j()) == vpMath::sign(iP2.get_j()-iP[0].get_j()))
765  return false;
766  int sign = vpMath::sign(iP1.get_j() - iP2.get_j());
767  if (sign == vpMath::sign(iP[0].get_j()-iP[1].get_j()))
768  {
769  iP1 = iP[0]; iP2 = iP[1];
770  }
771  else
772  {
773  iP1 = iP[1]; iP2 = iP[0];
774  }
775  }
776  else
777  {
778  if (vpMath::sign(iP1.get_i()-iP[0].get_i()) == vpMath::sign(iP2.get_i()-iP[0].get_i()))
779  return false;
780  int sign = vpMath::sign(iP1.get_i() - iP2.get_i());
781  if (sign == vpMath::sign(iP[0].get_i()-iP[1].get_i()))
782  {
783  iP1 = iP[0];iP2 = iP[1];
784  }
785  else
786  {
787  iP1 = iP[1];iP2 = iP[0];
788  }
789  }
790  }
791  else if (!iP1In)
792  {
793  vpImagePoint iPtemp = iP1;
794  if (fabs(a) < 1)
795  {
796  int sign = vpMath::sign(iP1.get_j() - iP2.get_j());
797  if (fabs(iP[0].get_j()-iP2.get_j()) > 5)
798  {
799  if (sign == vpMath::sign(iP[0].get_j()-iP2.get_j())) iP1 = iP[0];
800  else iP1 = iP[1];
801  }
802  else
803  {
804  if (sign == vpMath::sign(iP[1].get_j()-iP2.get_j())) iP1 = iP[1];
805  else iP1 = iP[0];
806  }
807  }
808  else
809  {
810  int sign = vpMath::sign(iP1.get_i() - iP2.get_i());
811  if (fabs(iP[0].get_i()-iP2.get_i()) > 5)
812  {
813  if (sign == vpMath::sign(iP[0].get_i()-iP2.get_i())) iP1 = iP[0];
814  else iP1 = iP[1];
815  }
816  else
817  {
818  if (sign == vpMath::sign(iP[1].get_i()-iP2.get_i())) iP1 = iP[1];
819  else iP1 = iP[0];
820  }
821  }
822  if (vpImagePoint::distance(iP1,iP2) < 9)
823  {
824  iP1 = iPtemp;
825  return false;
826  }
827  }
828  else if (!iP2In)
829  {
830  vpImagePoint iPtemp = iP2;
831  if (fabs(a) < 1)
832  {
833  int sign = vpMath::sign(iP2.get_j() - iP1.get_j());
834  if (fabs(iP[0].get_j()-iP1.get_j()) > 5)
835  {
836  if (sign == vpMath::sign(iP[0].get_j()-iP1.get_j())) iP2 = iP[0];
837  else iP2 = iP[1];
838  }
839  else
840  {
841  if (sign == vpMath::sign(iP[1].get_j()-iP1.get_j())) iP2 = iP[1];
842  else iP2 = iP[0];
843  }
844  }
845  else
846  {
847  int sign = vpMath::sign(iP2.get_i() - iP1.get_i());
848  if (fabs(iP[0].get_i()-iP1.get_i()) > 5)
849  {
850  if (sign == vpMath::sign(iP[0].get_i()-iP1.get_i())) iP2 = iP[0];
851  else iP2 = iP[1];
852  }
853  else
854  {
855  if (sign == vpMath::sign(iP[1].get_i()-iP1.get_i())) iP2 = iP[1];
856  else iP2 = iP[0];
857  }
858  }
859  if (vpImagePoint::distance(iP1,iP2) < 9)
860  {
861  iP2 = iPtemp;
862  return false;
863  }
864  }
865  }
866  return true;
867 }
868 
869 bool
870 vpPlotGraph::check3Dpoint(vpImagePoint &iP)
871 {
872  if (!iP.inRectangle(dGraphZone3D))
873  {
874  if (iP.get_i() < dTopLeft3D.get_i())
875  iP.set_i(dTopLeft3D.get_i());
876  else if (iP.get_i() > dTopLeft3D.get_i()+dHeight)
877  iP.set_i(dTopLeft3D.get_i()+dHeight-1);
878  if (iP.get_j() <dTopLeft3D.get_j())
879  iP.set_j(dTopLeft3D.get_j());
880  else if (iP.get_j() > dTopLeft3D.get_j()+dWidth)
881  iP.set_i(dTopLeft3D.get_j()+dWidth-1);
882  return false;
883  }
884  return true;
885 }
886 
887 void
888 vpPlotGraph::computeGraphParameters3D()
889 {
890  zoomx_3D = w_xsize/(xmax-xmin);
891  zoomy_3D = w_ysize/(ymax-ymin);
892  zoomz_3D = w_zsize/(zmax-zmin);
893  ptXorg = w_xval - zoomx_3D*xmax;
894  ptYorg = w_yval + zoomy_3D*ymin;
895  ptZorg = w_zval - zoomz_3D*zmax;
896 }
897 
898 void getGrid3DPoint(const double pente, vpImagePoint &iPunit, vpImagePoint &ip1, vpImagePoint &ip2, vpImagePoint &ip3)
899 {
900  if (pente <= 1)
901  {
902  ip1 = iPunit-vpImagePoint(3,0);
903  ip2 = iPunit+vpImagePoint(3,0);
904  ip3 = iPunit-vpImagePoint(6,6);
905  }
906  else
907  {
908  ip1 = iPunit-vpImagePoint(0,3);
909  ip2 = iPunit+vpImagePoint(0,3);
910  ip3 = iPunit+vpImagePoint(6,6);
911  }
912 }
913 
914 void
915 vpPlotGraph::displayGrid3D (vpImage<unsigned char> &I)
916 {
917  computeGraphParameters3D();
918 
919  xdelt = (xmax-xmin)/nbDivisionx;
920  ydelt = (ymax-ymin)/nbDivisiony;
921  zdelt = (zmax-zmin)/nbDivisionz;
922 
923  vpPoint pt[6];
924  pt[0].setWorldCoordinates(-w_xval,ptYorg,ptZorg);
925  pt[1].setWorldCoordinates(w_xval,ptYorg,ptZorg);
926  pt[2].setWorldCoordinates(ptXorg,-w_yval,ptZorg);
927  pt[3].setWorldCoordinates(ptXorg,w_yval,ptZorg);
928  pt[4].setWorldCoordinates(ptXorg,ptYorg,-w_zval);
929  pt[5].setWorldCoordinates(ptXorg,ptYorg,w_zval);
930 
931  vpImagePoint iP[6];
932  for (unsigned int i = 0; i < 6; i++)
933  {
934  pt[i].track(cMo);
935  double u=0.0,v=0.0;
936  vpMeterPixelConversion::convertPoint(cam,pt[i].get_x(),pt[i].get_y(),u,v);
937  iP[i].set_uv(u,v);
938  iP[i] = iP[i] + dTopLeft3D;
939  }
940 
941  int power;
942  double t;
943  char valeur[20];
944  vpPoint ptunit;
945  vpImagePoint iPunit;
946  double pente;
947  vpImagePoint ip1;
948  vpImagePoint ip2;
949  vpImagePoint ip3;
950  vpImagePoint ip4;
951 
952  power = laFonctionSansNom(xdelt);
953  ptunit.setWorldCoordinates(-w_xval,ptYorg,ptZorg);
954  //if (iP[0].get_j()-iP[1].get_j() != 0)
955  if (std::fabs(iP[0].get_j()-iP[1].get_j()) >
956  vpMath::maximum(std::fabs(iP[0].get_j()), std::fabs(iP[1].get_j()))* std::numeric_limits<double>::epsilon())
957  pente = fabs((iP[0].get_i()-iP[1].get_i())/(iP[0].get_j()-iP[1].get_j()));
958  else pente = 2;
959 
960  unsigned int count = 1;
961  for(t=xmin;t<=xmax;t=t+xdelt)
962  {
963  double x = ptXorg+(zoomx_3D*t);
964  ptunit.set_oX(x);
965  ptunit.track(cMo);
966  double u=0.0, v=0.0;
967  vpMeterPixelConversion::convertPoint(cam,ptunit.get_x(),ptunit.get_y(),u,v);
968  iPunit.set_uv(u,v);
969  iPunit = iPunit + dTopLeft3D;
970 
971  getGrid3DPoint(pente,iPunit,ip1,ip2,ip3);
972 
973  if(check3Dline(ip1,ip2))
974  {
976  if (count%2 == 1)
977  {
978  double ttemp;
979  if (power!=0)
980  ttemp = t*pow(10.0,power);
981  else ttemp = t;
982  sprintf(valeur, "%.1f", ttemp);
984  }
985  }
986  count++;
987  }
988  if (power != 0)
989  {
990  ip4 = iP[1] -vpImagePoint(-15,10);
991  sprintf(valeur, "x10e%d", -power);
992  if(check3Dpoint(ip4))
994  }
995 
996  power = laFonctionSansNom(ydelt);
997  ptunit.setWorldCoordinates(ptXorg,-w_yval,ptZorg);
998  //if (iP[2].get_j()-iP[3].get_j() != 0)
999  if (std::fabs(iP[2].get_j()-iP[3].get_j()) >
1000  vpMath::maximum(std::fabs(iP[2].get_j()), std::fabs(iP[3].get_j()))* std::numeric_limits<double>::epsilon())
1001  pente = fabs((iP[2].get_i()-iP[3].get_i())/(iP[2].get_j()-iP[3].get_j()));
1002  else pente = 2;
1003  count = 0;
1004  for(t=ymin;t<=ymax;t=t+ydelt)
1005  {
1006  double y = ptYorg-(zoomy_3D*t);
1007  ptunit.set_oY(y);
1008  ptunit.track(cMo);
1009  double u=0.0, v=0.0;
1010  vpMeterPixelConversion::convertPoint(cam,ptunit.get_x(),ptunit.get_y(),u,v);
1011  iPunit.set_uv(u,v);
1012  iPunit = iPunit + dTopLeft3D;
1013 
1014  getGrid3DPoint(pente,iPunit,ip1,ip2,ip3);
1015 
1016  if(check3Dline(ip1,ip2))
1017  {
1019  if (count%2 == 1)
1020  {
1021  double ttemp;
1022  if (power!=0)
1023  ttemp = t*pow(10.0,power);
1024  else ttemp = t;
1025  sprintf(valeur, "%.1f", ttemp);
1027  }
1028  }
1029  count++;
1030  }
1031  if (power != 0)
1032  {
1033  ip4 = iP[2] -vpImagePoint(-15,10);
1034  sprintf(valeur, "x10e%d", -power);
1035  if(check3Dpoint(ip4))
1037  }
1038 
1039  power = laFonctionSansNom(zdelt);
1040  ptunit.setWorldCoordinates(ptXorg,ptYorg,-w_zval);
1041  //if (iP[4].get_j()-iP[5].get_j() != 0)
1042  if (std::fabs(iP[4].get_j()-iP[5].get_j()) >
1043  vpMath::maximum(std::fabs(iP[4].get_j()), std::fabs(iP[5].get_j()))* std::numeric_limits<double>::epsilon())
1044  pente = fabs((iP[4].get_i()-iP[5].get_i())/(iP[4].get_j()-iP[5].get_j()));
1045  else pente = 2;
1046  count = 0;
1047  for(t=zmin;t<=zmax;t=t+zdelt)
1048  {
1049  double z = ptZorg+(zoomz_3D*t);
1050  ptunit.set_oZ(z);
1051  ptunit.track(cMo);
1052  double u=0.0, v=0.0;
1053  vpMeterPixelConversion::convertPoint(cam,ptunit.get_x(),ptunit.get_y(),u,v);
1054  iPunit.set_uv(u,v);
1055  iPunit = iPunit + dTopLeft3D;
1056 
1057  getGrid3DPoint(pente,iPunit,ip1,ip2,ip3);
1058 
1059  if(check3Dline(ip1,ip2))
1060  {
1062  if (count%2 == 1)
1063  {
1064  double ttemp;
1065  if (power!=0)
1066  ttemp = t*pow(10.0,power);
1067  else ttemp = t;
1068  sprintf(valeur, "%.1f", ttemp);
1070  }
1071  }
1072  count++;
1073  }
1074  if (power != 0)
1075  {
1076  ip4 = iP[5] -vpImagePoint(-15,10);
1077  sprintf(valeur, "x10e%d", -power);
1078  if(check3Dpoint(ip4))
1080  }
1081 
1082 
1083 //Ligne horizontal
1084  if (check3Dline(iP[0],iP[1]))
1085  {
1086  vpDisplay::displayArrow(I,iP[0],iP[1], vpColor::black);
1087  if (dispUnit)
1088  {
1089  vpImagePoint iPunit(iP[1].get_i(),iP[1].get_j()-10*epsj);
1090  check3Dpoint (iPunit);
1092  }
1093  }
1094  if (check3Dline(iP[3],iP[2]))
1095  {
1096  vpDisplay::displayArrow(I,iP[3],iP[2], vpColor::black);
1097  if (dispUnit)
1098  {
1099  vpImagePoint iPunit(iP[2].get_i(),iP[2].get_j()-10*epsj);
1100  check3Dpoint (iPunit);
1102  }
1103  }
1104  if (check3Dline(iP[4],iP[5]))
1105  {
1106  vpDisplay::displayArrow(I,iP[4],iP[5], vpColor::black);
1107  if (dispUnit)
1108  {
1109  vpImagePoint iPunit(iP[5].get_i(),iP[5].get_j()-10*epsj);
1110  check3Dpoint (iPunit);
1112  }
1113  }
1114 
1115  if (dispTitle)
1116  displayTitle(I);
1117  if (dispLegend)
1118  displayLegend(I);
1119 }
1120 
1121 void
1122 vpPlotGraph::plot (vpImage<unsigned char> &I, const unsigned int curveNb, const double x, const double y, const double z)
1123 {
1124  if (!scaleInitialized)
1125  {
1126  if (x < 0)
1127  {
1128  xmax = 0;
1129  rescalex(0,x);
1130  }
1131  if (x > 0)
1132  {
1133  xmin = 0;
1134  rescalex(1,x);
1135  }
1136  if (y < 0)
1137  {
1138  ymax = 0;
1139  rescaley(0,y);
1140  }
1141  if (y > 0)
1142  {
1143  ymin = 0;
1144  rescaley(1,y);
1145  }
1146  if (z < 0)
1147  {
1148  zmax = 0;
1149  rescalez(0,z);
1150  }
1151  if (z > 0)
1152  {
1153  zmin = 0;
1154  rescalez(1,z);
1155  }
1156  scaleInitialized = true;
1157  computeGraphParameters3D();
1158  clearGraphZone(I);
1159  displayGrid3D(I);
1160  //if (std::fabs(y) == 0 || z == 0)
1161  if (std::fabs(y) <= std::numeric_limits<double>::epsilon() || std::fabs(z) <= std::numeric_limits<double>::epsilon())
1162  scaleInitialized = false;
1163  }
1164 
1165  if (firstPoint)
1166  {
1167  clearGraphZone(I);
1168  displayGrid3D(I);
1169  vpDisplay::flushROI(I,graphZone);
1170  firstPoint = false;
1171  }
1172 
1173  bool changed = false;
1174  if (x > xmax) {rescalex(1,x); changed = true;}
1175  else if(x < xmin) {rescalex(0,x);changed = true;}
1176 
1177  if (y > ymax) {rescaley(1,y);changed = true;}
1178  else if(y < ymin) {rescaley(0,y);changed = true;}
1179 
1180  if (z > zmax) {rescalez(1,z);changed = true;}
1181  else if(z < zmin) {rescalez(0,z);changed = true;}
1182 
1183  if (changed || move(I))
1184  {
1185  computeGraphParameters3D();
1186  replot3D(I);
1187  }
1188 
1189  vpPoint pointPlot;
1190  pointPlot.setWorldCoordinates(ptXorg+(zoomx_3D*x),ptYorg-(zoomy_3D*y),ptZorg+(zoomz_3D*z));
1191  pointPlot.track(cMo);
1192  double u=0.0, v=0.0;
1193  vpMeterPixelConversion::convertPoint(cam,pointPlot.get_x(),pointPlot.get_y(),u,v);
1194  vpImagePoint iP;
1195  iP.set_uv(u,v);
1196  iP = iP + dTopLeft3D;
1197 
1198  (curveList+curveNb)->pointListx.end();
1199  (curveList+curveNb)->pointListy.end();
1200  (curveList+curveNb)->pointListz.end();
1201  if((curveList+curveNb)->nbPoint)
1202  {
1203  if (check3Dline((curveList+curveNb)->lastPoint,iP))
1204  vpDisplay::displayLine(I,(curveList+curveNb)->lastPoint, iP, (curveList+curveNb)->color, (curveList+curveNb)->thickness);
1205  }
1206 #if( defined VISP_HAVE_X11 || defined VISP_HAVE_GDI )
1207  double top;
1208  double left;
1209  double width;
1210  double height;
1211 
1212  if (iP.get_i() <= (curveList+curveNb)->lastPoint.get_i()) {top = iP.get_i()-5; height = (curveList+curveNb)->lastPoint.get_i() - top+10;}
1213  else {top = (curveList+curveNb)->lastPoint.get_i()-5; height = iP.get_i() - top+10;}
1214  if (iP.get_j() <= (curveList+curveNb)->lastPoint.get_j()) {left = iP.get_j()-5; width = (curveList+curveNb)->lastPoint.get_j() - left+10;}
1215  else {left = (curveList+curveNb)->lastPoint.get_j()-5; width = iP.get_j() - left+10;}
1216  vpDisplay::flushROI(I,vpRect(left,top,width,height));
1217 #endif
1218 
1219  (curveList+curveNb)->lastPoint = iP;
1220  (curveList+curveNb)->pointListx.push_back(x);
1221  (curveList+curveNb)->pointListy.push_back(y);
1222  (curveList+curveNb)->pointListz.push_back(z);
1223  (curveList+curveNb)->nbPoint++;
1224 
1225 
1226 #if( !defined VISP_HAVE_X11 && defined FLUSH_ON_PLOT)
1227  vpDisplay::flushROI(I,graphZone);
1228 #endif
1229 }
1230 
1231 void
1232 vpPlotGraph::replot3D (vpImage<unsigned char> &I)
1233 {
1234  clearGraphZone(I);
1235  displayGrid3D(I);
1236 
1237  for (unsigned int i = 0; i < curveNbr; i++)
1238  {
1239  std::list<double>::const_iterator it_ptListx = (curveList+i)->pointListx.begin();
1240  std::list<double>::const_iterator it_ptListy = (curveList+i)->pointListy.begin();
1241  std::list<double>::const_iterator it_ptListz = (curveList+i)->pointListz.begin();
1242 
1243  unsigned int k = 0;
1244  vpImagePoint iP;
1245  vpPoint pointPlot;
1246  double x,y,z;
1247  while (k < (curveList+i)->nbPoint)
1248  {
1249  x = *it_ptListx;
1250  y = *it_ptListy;
1251  z = *it_ptListz;
1252  pointPlot.setWorldCoordinates(ptXorg+(zoomx_3D*x),ptYorg-(zoomy_3D*y),ptZorg+(zoomz_3D*z));
1253  pointPlot.track(cMo);
1254  double u=0.0, v=0.0;
1255  vpMeterPixelConversion::convertPoint(cam,pointPlot.get_x(),pointPlot.get_y(),u,v);
1256  iP.set_uv(u,v);
1257  iP = iP + dTopLeft3D;
1258 
1259  //vpDisplay::displayCross(I,iP,3,vpColor::cyan);
1260  if (k > 0)
1261  {
1262  if (check3Dline((curveList+i)->lastPoint,iP))
1263  vpDisplay::displayLine(I,(curveList+i)->lastPoint, iP, (curveList+i)->color);
1264  //vpDisplay::displayCross(I,iP,3,vpColor::orange);
1265  }
1266 
1267  (curveList+i)->lastPoint = iP;
1268 
1269  ++it_ptListx;
1270  ++it_ptListy;
1271  ++it_ptListz;
1272  k++;
1273  }
1274  }
1275  vpDisplay::flushROI(I,graphZone);
1276 }
1277 
1278 
1279 
1280 void
1281 vpPlotGraph::rescalez(unsigned int side, double extremity)
1282 {
1283  switch (side)
1284  {
1285  case 0:
1286  zmin = (3*extremity-zmax)/2;
1287  break;
1288  case 1:
1289  zmax = (3*extremity-zmin)/2;
1290  break;
1291  }
1292 
1293  zdelt = (zmax-zmin)/(double)nbDivisionz;
1294 }
1295 
1296 bool
1297 vpPlotGraph::move(const vpImage<unsigned char> &I)
1298 {
1299  bool changed = false;
1300  vpHomogeneousMatrix displacement = navigation(I,changed);
1301 
1302  //if (displacement[2][3] != 0)
1303  if (std::fabs(displacement[2][3]) > std::numeric_limits<double>::epsilon())
1304  cMf = cMf*displacement;
1305  vpHomogeneousMatrix fMo = cMf.inverse()*cMo;
1306 
1307  cMo = cMf* displacement * fMo;
1308  return changed;
1309 }
1310 
1312 vpPlotGraph::navigation(const vpImage<unsigned char> &I, bool &changed)
1313 {
1314  vpImagePoint iP;
1315  vpImagePoint trash;
1316  bool clicked = false;
1317  bool clickedUp = false;
1319 
1320  vpHomogeneousMatrix mov(0,0,0,0,0,0);
1321  changed = false;
1322 
1323  //if(!blocked) vpDisplay::getClickUp(I,trash, b,false);
1324 
1325  if(!blocked) clicked = vpDisplay::getClick(I,iP,b,false);
1326 
1327  if(blocked) clickedUp = vpDisplay::getClickUp(I,trash, b,false);
1328 
1329  if (clicked)
1330  {
1331  if (!iP.inRectangle(graphZone))
1332  return mov;
1333  }
1334 
1335  if(clicked)
1336  {
1337  if (b == vpMouseButton::button1) blockedr = true;
1338  if (b == vpMouseButton::button2) blockedz = true;
1339  blocked = true;
1340  }
1341 
1342  else if(clickedUp)
1343  {
1344  if (b == vpMouseButton::button1)
1345  {
1346  old_iPr = vpImagePoint(-1,-1);
1347  blockedr = false;
1348  }
1349  if (b == vpMouseButton::button2)
1350  {
1351  old_iPz = vpImagePoint(-1,-1);
1352  blockedz = false;
1353  }
1354  if (!(blockedr || blockedz))
1355  {
1356  blocked = false;
1357  //while (vpDisplay::getClick(I,trash,b,false)) {};
1358  }
1359  }
1360 
1362 
1363  double anglei = 0;
1364  double anglej = 0;
1365 
1366  if (old_iPr != vpImagePoint(-1,-1) && blockedr)
1367  {
1368  double width = vpMath::minimum(I.getWidth(),I.getHeight());
1369 
1370  double diffi = iP.get_i() - old_iPr.get_i();
1371  double diffj = iP.get_j() - old_iPr.get_j();
1372 
1373  anglei = diffi*360/width;
1374  anglej = diffj*360/width;
1375  mov.buildFrom(0,0,0,vpMath::rad(anglei),vpMath::rad(-anglej),0);
1376  changed = true;
1377  }
1378 
1379  if (blockedr) old_iPr = iP;
1380 
1381  if (old_iPz != vpImagePoint(-1,-1) && blockedz)
1382  {
1383  double diffi = iP.get_i() - old_iPz.get_i();
1384  mov.buildFrom(0,0,diffi*0.01,0,0,0);
1385  changed = true;
1386  }
1387 
1388  if (blockedz) old_iPz = iP;
1389 
1390  return mov;
1391 }
1392 
1393 #endif
1394 #endif
void set_j(const double j)
Definition: vpImagePoint.h:156
bool inRectangle(const vpRect &rect) const
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
double get_i() const
Definition: vpImagePoint.h:181
unsigned int getWidth() const
Definition: vpImage.h:154
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
static const vpColor black
Definition: vpColor.h:159
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:123
void set_i(const double i)
Definition: vpImagePoint.h:145
virtual bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)=0
void set_x(const double x)
Set the point x coordinate in the image plane.
Definition: vpPoint.h:183
void track(const vpHomogeneousMatrix &cMo)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.h:145
static const vpColor green
Definition: vpColor.h:168
double get_j() const
Definition: vpImagePoint.h:192
void set_oX(const double X)
Set the point X coordinate in the object frame.
Definition: vpPoint.h:174
static const vpColor red
Definition: vpColor.h:165
Class that defines what is a point.
Definition: vpPoint.h:65
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
static const vpColor orange
Definition: vpColor.h:175
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
static const vpColor cyan
Definition: vpColor.h:174
void set_oZ(const double Z)
Set the point Z coordinate in the object frame.
Definition: vpPoint.h:178
virtual bool getPointerPosition(vpImagePoint &ip)=0
void set_ij(const double i, const double j)
Definition: vpImagePoint.h:167
Class used for pose computation from N points (pose from point only).
Definition: vpPose.h:80
void set_y(const double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.h:185
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.h:143
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:148
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
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
vpHomogeneousMatrix inverse() const
unsigned int getHeight() const
Definition: vpImage.h:145
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:225
Defines a rectangle in the plane.
Definition: vpRect.h:82
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition: vpDisplay.cpp:1981
void computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo)
compute the pose for a given method
Definition: vpPose.cpp:298
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition: vpDisplay.cpp:205
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:92
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static int sign(double x)
Definition: vpMath.h:248
void addPoint(const vpPoint &P)
Add a new point in this array.
Definition: vpPose.cpp:148
static const vpColor purple
Definition: vpColor.h:176
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:261
static const vpColor blue
Definition: vpColor.h:171
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
void set_oY(const double Y)
Set the point Y coordinate in the object frame.
Definition: vpPoint.h:176
void clearPoint()
suppress all the point in the array of point
Definition: vpPose.cpp:126