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