Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpPlotGraph.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  (curveList+i)->legend.clear();
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 std::string &title_)
232 {
233  title = title_;
234  dispTitle = true;
235 }
236 
237 void
238 vpPlotGraph::setUnitX (const std::string &unit_x)
239 {
240  unitx = unit_x;
241  dispUnit = true;
242 }
243 
244 void
245 vpPlotGraph::setUnitY (const std::string &unit_y)
246 {
247  unity = unit_y;
248  dispUnit = true;
249 }
250 
251 void
252 vpPlotGraph::setUnitZ (const std::string &unit_z)
253 {
254  unitz = unit_z;
255  dispUnit = true;
256 }
257 
258 void
259 vpPlotGraph::setLegend (const unsigned int curveNum, const std::string &newlegend)
260 {
261  (curveList+curveNum)->legend = newlegend;
262  dispLegend = true;
263 }
264 
265 void
266 vpPlotGraph::setCurveThickness(const unsigned int curveNum, const unsigned int thickness)
267 {
268  (curveList+curveNum)->thickness = thickness;
269 }
270 
271 int
272 laFonctionSansNom (const double delta)
273 {
274  double d = delta;
275  int power = 0;
276  if (d < 1)
277  {
278  while (d < 1)
279  {
280  d = d * 10;
281  power++;
282  }
283  power--;
284  return power;
285  }
286 
287  if (d >= 10)
288  {
289  while (d > 10)
290  {
291  d = d / 10;
292  power--;
293  }
294  power--;
295  return power;
296  }
297 
298  return 0;
299 }
300 
301 void
302 vpPlotGraph::displayGrid (vpImage<unsigned char> &I)
303 {
304  computeGraphParameters();
305 
306  xdelt = (xmax-xmin)/nbDivisionx;
307  ydelt = (ymax-ymin)/nbDivisiony;
308 
309  double t;
310  char valeur[20];
311  int power;
312 
313  power = laFonctionSansNom(xdelt);
314  for(t=xmin;t<=xmax;t=t+xdelt)
315  {
316  double x = xorg+(zoomx*t);
317  if(gridy)
318  vpDisplay::displayDotLine(I,vpImagePoint(dTopLeft.get_i(),x), vpImagePoint(dTopLeft.get_i()+dHeight,x), gridColor, gridThickness);
319  else
320  vpDisplay::displayDotLine(I,vpImagePoint(yorg,x), vpImagePoint(yorg-3,x), vpColor::black, gridThickness);
321 
322  if (t+xdelt <= xmax+1e-10)
323  {
324  double ttemp;
325  if (power!=0)
326  ttemp = t*pow(10.0,power);
327  else ttemp = t;
328  sprintf(valeur, "%.2f", ttemp);
329 #if defined VISP_HAVE_X11
330  vpDisplay::displayText(I,vpImagePoint(yorg + 3*epsi,x),valeur, vpColor::black);
331 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK)
332  vpDisplay::displayText(I,vpImagePoint(yorg + epsi,x),valeur, vpColor::black);
333 #endif
334  }
335  }
336  if (power != 0)
337  {
338  sprintf(valeur, "x10e%d", -power);
339 #if defined VISP_HAVE_X11
340  vpDisplay::displayText(I,vpImagePoint(yorg+4*epsi,dTopLeft.get_j()+dWidth-6*epsj),valeur, vpColor::black);
341 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK)
342  vpDisplay::displayText(I,vpImagePoint(yorg+4*epsi,dTopLeft.get_j()+dWidth-10*epsj),valeur, vpColor::black);
343 #endif
344  }
345 
346  power = laFonctionSansNom(ydelt);
347  for(t=ymin;t<=ymax;t=t+ydelt)
348  {
349  double y = yorg-(zoomy*t);
350  if(gridx)
351  vpDisplay::displayDotLine(I,vpImagePoint(y,dTopLeft.get_j()), vpImagePoint(y,dTopLeft.get_j()+dWidth), gridColor, gridThickness);
352  else
353  vpDisplay::displayDotLine(I,vpImagePoint(y,xorg), vpImagePoint(y,xorg+3), vpColor::black, gridThickness);
354 
355  double ttemp;
356  if (power!=0)
357  ttemp = t*pow(10.0,power);
358  else ttemp = t;
359 
360  sprintf(valeur, "%.2f", ttemp);
361 #if defined VISP_HAVE_X11
362  vpDisplay::displayText(I,vpImagePoint(y+epsi,topLeft.get_j()+epsj),valeur, vpColor::black);
363 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK)
364  vpDisplay::displayText(I,vpImagePoint(y-epsi,topLeft.get_j()+epsj),valeur, vpColor::black);
365 #endif
366  }
367  if (power != 0)
368  {
369  sprintf(valeur, "x10e%d", -power);
370 #if defined VISP_HAVE_X11
371  vpDisplay::displayText(I,vpImagePoint(dTopLeft.get_i()-3*epsi,dTopLeft.get_j()-6*epsj),valeur, vpColor::black);
372 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK)
373  vpDisplay::displayText(I,vpImagePoint(dTopLeft.get_i()-3*epsi,dTopLeft.get_j()-6*epsj),valeur, vpColor::black);
374 #endif
375  }
376 
377  //Ligne horizontal
378  vpDisplay::displayArrow(I,vpImagePoint(yorg,dTopLeft.get_j()), vpImagePoint(yorg,dTopLeft.get_j()+dWidth), vpColor::black, 4*gridThickness, 2*gridThickness, gridThickness);
379  //Ligne verticale
380  vpDisplay::displayArrow(I, vpImagePoint(dTopLeft.get_i()+dHeight,xorg), vpImagePoint(dTopLeft.get_i(),xorg), vpColor::black, 4*gridThickness, 2*gridThickness, gridThickness);
381 
382  if (dispUnit)
383  displayUnit(I);
384  if (dispTitle)
385  displayTitle(I);
386  if (dispLegend)
387  displayLegend(I);
388 
389  //vpDisplay::flushROI(I,graphZone);
390 }
391 
392 void
393 vpPlotGraph::displayUnit (vpImage<unsigned char> &
394 #if defined(VISP_HAVE_X11) || defined (VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK)
395  I
396 #endif
397  )
398 {
399  unsigned int offsetx = vpMath::minimum<unsigned int>((unsigned int)unitx.size(), dWidth);
400 
401 #if defined VISP_HAVE_X11
402  vpDisplay::displayText(I,vpImagePoint(yorg-2*epsi,dTopLeft.get_j()+dWidth-offsetx*epsj),unitx.c_str(), vpColor::black);
403  vpDisplay::displayText(I,vpImagePoint(dTopLeft.get_i(),dTopLeft.get_j()+epsj),unity.c_str(), vpColor::black);
404 #elif defined (VISP_HAVE_GDI) || defined (VISP_HAVE_OPENCV) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK)
405  vpDisplay::displayText(I,vpImagePoint(yorg-5*epsi,dTopLeft.get_j()+dWidth-offsetx*epsj),unitx.c_str(), vpColor::black);
406  vpDisplay::displayText(I,vpImagePoint(dTopLeft.get_i(),dTopLeft.get_j()+epsj),unity.c_str(), vpColor::black);
407 #endif
408 }
409 
410 void
411 vpPlotGraph::displayTitle (vpImage<unsigned char> &I)
412 {
413  double size = (double)title.size();
414  size = size/2.0;
416  vpImagePoint(dTopLeft.get_i()-3*epsi,
417  dTopLeft.get_j()+dWidth/2.0-4*size),
418  title.c_str(),
420 }
421 
422 void
423 vpPlotGraph::displayLegend (vpImage<unsigned char> &I)
424 {
425  size_t offsetj = 0;
426  for (unsigned int i = 0; i < curveNbr; i++) {
427  size_t offset = epsj * (curveList+i)->legend.size();
428  offsetj = vpMath::maximum(offset, offsetj);
429  }
430  if (offsetj > dWidth) offsetj = dWidth;
431 
432  for (unsigned int i = 0; i < curveNbr; i++) {
434  vpImagePoint(dTopLeft.get_i()+i*5*epsi,
435  dTopLeft.get_j()+dWidth-offsetj),
436  (curveList+i)->legend.c_str(),
437  (curveList+i)->color);
438  }
439 }
440 
441 void
442 vpPlotGraph::rescalex(unsigned int side, double extremity)
443 {
444  switch (side)
445  {
446  case 0:
447  xmin = (3*extremity-xmax)/2;
448  break;
449  case 1:
450  xmax = (3*extremity-xmin)/2;
451  break;
452  }
453 
454  xdelt = (xmax-xmin)/(double)nbDivisionx;
455 }
456 
457 void
458 vpPlotGraph::rescaley(unsigned int side, double extremity)
459 {
460  switch (side)
461  {
462  case 0:
463  ymin = (3*extremity-ymax)/2;
464  break;
465  case 1:
466  ymax = (3*extremity-ymin)/2;
467  break;
468  }
469 
470  ydelt = (ymax-ymin)/(double)nbDivisiony;
471 }
472 
473 void
474 vpPlotGraph::initScale(vpImage<unsigned char> &I, const double x_min, const double x_max, const int nbDivx,
475  const double y_min, const double y_max, const int nbDivy, const bool gx, const bool gy)
476 {
477  this->xmin = x_min;
478  this->xmax = x_max;
479  this->ymin = y_min;
480  this->ymax = y_max;
481  this->gridx = gx;
482  this->gridy = gy;
483  this->nbDivisionx = nbDivx;
484  this->nbDivisiony = nbDivy;
485  computeGraphParameters();
486  clearGraphZone(I);
487  displayGrid(I);
488  vpDisplay::flushROI(I,graphZone);
489  scaleInitialized = true;
490 }
491 
492 
493 void
494 vpPlotGraph::initScale(vpImage<unsigned char> &I, const double x_min, const double x_max, const int nbDivx,
495  const double y_min, const double y_max, const int nbDivy,
496  const double z_min, const double z_max, const int nbDivz, const bool gx, const bool gy)
497 {
498  this->xmin = x_min;
499  this->xmax = x_max;
500  this->ymin = y_min;
501  this->ymax = y_max;
502  this->zmin = z_min;
503  this->zmax = z_max;
504  this->gridx = gx;
505  this->gridy = gy;
506  this->nbDivisionx = nbDivx;
507  this->nbDivisiony = nbDivy;
508  this->nbDivisionz = nbDivz;
509  computeGraphParameters();
510  clearGraphZone(I);
511  displayGrid(I);
512  vpDisplay::flushROI(I,graphZone);
513  scaleInitialized = true;
514 }
515 
516 void
517 vpPlotGraph::plot (vpImage<unsigned char> &I, const unsigned int curveNb, const double x, const double y)
518 {
519  if (!scaleInitialized)
520  {
521  if (x < 0)
522  {
523  xmax = 0;
524  rescalex(0,x);
525  }
526  if (x > 0)
527  {
528  xmin = 0;
529  rescalex(1,x);
530  }
531  if (y < 0)
532  {
533  ymax = 0;
534  rescaley(0,y);
535  }
536  if (y > 0)
537  {
538  ymin = 0;
539  rescaley(1,y);
540  }
541  scaleInitialized = true;
542  computeGraphParameters();
543  clearGraphZone(I);
544  displayGrid(I);
545  //if (y == 0)
546  if (std::fabs(y) <= std::numeric_limits<double>::epsilon())
547  scaleInitialized = false;
548  }
549 
550  if (firstPoint)
551  {
552 // clearGraphZone(I);
553 // displayGrid(I);
554 // vpDisplay::flushROI(I,graphZone);
555  replot(I);
556  firstPoint = false;
557  }
558 
559  double i = yorg-(zoomy*y);
560  double j = xorg+(zoomx*x);
561 
562  vpImagePoint iP(i,j);
563 
564  if (!iP.inRectangle(dGraphZone))
565  {
566  if (x > xmax) rescalex(1,x);
567  else if(x < xmin) rescalex(0,x);
568 
569  if (y > ymax) rescaley(1,y);
570  else if(y < ymin) rescaley(0,y);
571 
572  computeGraphParameters();
573 
574  replot(I);
575  i = yorg-(zoomy*y);
576  j = xorg+(zoomx*x);
577 
578  iP.set_ij(i,j);
579  }
580 
581  (curveList+curveNb)->plotPoint(I, iP, x, y);
582 #if (!defined VISP_HAVE_X11 && defined FLUSH_ON_PLOT)
583  vpDisplay::flushROI(I,graphZone);
584  //vpDisplay::flush(I);
585 #endif
586 }
587 
588 void
589 vpPlotGraph::replot (vpImage<unsigned char> &I)
590 {
591  clearGraphZone(I);
592  displayGrid(I);
593  for (unsigned int i = 0; i < curveNbr; i++)
594  (curveList+i)->plotList(I,xorg,yorg,zoomx,zoomy);
595  vpDisplay::flushROI(I,graphZone);
596 }
597 
598 void
599 vpPlotGraph::clearGraphZone(vpImage<unsigned char> &I)
600 {
601  vpDisplay::displayROI(I,graphZone);
602 }
603 
604 bool
605 vpPlotGraph::getPixelValue(vpImage<unsigned char> &I, vpImagePoint &iP)
606 {
607  if (iP.inRectangle(dGraphZone))
608  {
609  double x = (iP.get_j()-xorg)/zoomx;
610  double y = (yorg-iP.get_i())/zoomy;
611 
612  vpDisplay::displayROI(I,vpRect(vpImagePoint(topLeft.get_i()+height-20,topLeft.get_j()),width-1,19));
613  char valeur[200];
614  sprintf(valeur, " x: %f", x);
615  vpDisplay::displayText(I,vpImagePoint(topLeft.get_i()+height-2,topLeft.get_j()+5*epsj),valeur, vpColor::black);
616  sprintf(valeur, " y: %f", y);
617  vpDisplay::displayText(I,vpImagePoint(topLeft.get_i()+height-2,topLeft.get_j()+width/2.0),valeur, vpColor::black);
618 // vpDisplay::flush(I);
619  vpDisplay::flushROI(I,vpRect(vpImagePoint(topLeft.get_i()+height-20,topLeft.get_j()),width-1,19));
620  return true;
621  }
622  return false;
623 }
624 
625 void
626 vpPlotGraph::resetPointList(const unsigned int curveNum)
627 {
628  (curveList+curveNum)->pointListx.clear();
629  (curveList+curveNum)->pointListy.clear();
630  (curveList+curveNum)->pointListz.clear();
631  (curveList+curveNum)->nbPoint = 0;
632  firstPoint = true;
633 }
634 
635 
636 /************************************************************************************************/
637 
638 bool
639 vpPlotGraph::check3Dline(vpImagePoint &iP1, vpImagePoint &iP2)
640 {
641  bool iP1In = iP1.inRectangle(dGraphZone3D);
642  bool iP2In = iP2.inRectangle(dGraphZone3D);
643 
644  if (!iP1In || !iP2In)
645  {
646  double dTopLeft_i = dTopLeft3D.get_i();
647  double dTopLeft_j = dTopLeft3D.get_j();
648  double dBottomRight_i = dTopLeft_i+dHeight;
649  double dBottomRight_j = dTopLeft_j+dWidth;
650 
651  //Cas vertical
652  if (vpImagePoint::distance(iP1,iP2) < 9)
653  return false;
654  if (fabs(iP2.get_j()-iP1.get_j()) <=2)
655  {
656  if (!iP1In && !iP2In)
657  {
658  if (iP1.get_i() < dTopLeft_i && iP2.get_i() < dTopLeft_i)
659  return false;
660  if (iP1.get_i() > dBottomRight_i && iP2.get_i() > dBottomRight_i)
661  return false;
662  if (iP1.get_j() < dTopLeft_j || iP1.get_j() > dBottomRight_j)
663  return false;
664  if (iP1.get_i() < dTopLeft_i) iP1.set_i(dTopLeft_i);
665  else iP1.set_i(dBottomRight_i);
666  if (iP2.get_i() < dTopLeft_i) iP2.set_i(dTopLeft_i);
667  else iP2.set_i(dBottomRight_i);
668  }
669  else if (!iP1In)
670  {
671  if (iP1.get_j() < dTopLeft_j) iP1.set_j(dTopLeft_j);
672  if (iP1.get_j() > dBottomRight_j) iP1.set_j(dBottomRight_j);
673  if (iP1.get_i() < dTopLeft_i) iP1.set_i(dTopLeft_i);
674  if (iP1.get_i() > dBottomRight_i) iP1.set_i(dBottomRight_i);
675  return true;
676  }
677  else if (!iP2In)
678  {
679  if (iP2.get_j() < dTopLeft_j) iP2.set_j(dTopLeft_j);
680  if (iP2.get_j() > dBottomRight_j) iP2.set_j(dBottomRight_j);
681  if (iP2.get_i() < dTopLeft_i) iP2.set_i(dTopLeft_i);
682  if (iP2.get_i() > dBottomRight_i) iP2.set_i(dBottomRight_i);
683  return true;
684  }
685  }
686  //cas horizontal
687  else if (fabs(iP2.get_i()-iP1.get_i()) <= 2)
688  {
689  if (!iP1In && !iP2In)
690  {
691  if (iP1.get_j() < dTopLeft_j && iP2.get_j() < dTopLeft_j)
692  return false;
693  if (iP1.get_j() > dBottomRight_j && iP2.get_j() > dBottomRight_j)
694  return false;
695  if (iP1.get_i() < dTopLeft_i || iP1.get_i() > dBottomRight_i)
696  return false;
697  if (iP1.get_j() < dTopLeft_j) iP1.set_j(dTopLeft_j);
698  else iP1.set_j(dBottomRight_j);
699  if (iP2.get_j() < dTopLeft_j) iP2.set_j(dTopLeft_j);
700  else iP2.set_j(dBottomRight_j);
701  }
702  else if (!iP1In)
703  {
704  if (iP1.get_j() < dTopLeft_j) iP1.set_j(dTopLeft_j);
705  if (iP1.get_j() > dBottomRight_j) iP1.set_j(dBottomRight_j);
706  if (iP1.get_i() < dTopLeft_i) iP1.set_i(dTopLeft_i);
707  if (iP1.get_i() > dBottomRight_i) iP1.set_i(dBottomRight_i);
708  return true;
709  }
710  else if (!iP2In)
711  {
712  if (iP2.get_j() < dTopLeft_j) iP2.set_j(dTopLeft_j);
713  if (iP2.get_j() > dBottomRight_j) iP2.set_j(dBottomRight_j);
714  if (iP2.get_i() < dTopLeft_i) iP2.set_i(dTopLeft_i);
715  if (iP2.get_i() > dBottomRight_i) iP2.set_i(dBottomRight_i);
716  return true;
717  }
718  }
719 
720  double a = (iP2.get_i()-iP1.get_i())/(iP2.get_j()-iP1.get_j());
721  double b = iP1.get_i()-a*iP1.get_j();
722 
723  //test horizontal
724  double jtop = (dTopLeft_i-b)/a;
725  double jlow = (dBottomRight_i-b)/a;
726  //test vertical
727  double ileft = dTopLeft_j*a+b;
728  double iright = (dBottomRight_j)*a+b;
729 
730  vpImagePoint iP[2];
731  int n = 0;
732 
733  if(jtop >= dTopLeft_j && jtop <= dBottomRight_j)
734  {
735  iP[n].set_ij(dTopLeft_i,jtop);
736  n++;
737  }
738  if(jlow >= dTopLeft_j && jlow <= dBottomRight_j)
739  {
740  iP[n].set_ij(dBottomRight_i,jlow);
741  n++;
742  }
743  if(ileft >= dTopLeft_i && ileft <= dBottomRight_i && n <2)
744  {
745  iP[n].set_ij(ileft,dTopLeft_j);
746  n++;
747  }
748  if(iright >= dTopLeft_i && iright <= dBottomRight_i && n <2)
749  {
750  iP[n].set_ij(iright,dBottomRight_j);
751  n++;
752  }
753 
754  if (n < 2)
755  return false;
756 
757  if (!iP1In && !iP2In)
758  {
759  if (fabs(a) < 1)
760  {
761  if (vpMath::sign(iP1.get_j()-iP[0].get_j()) == vpMath::sign(iP2.get_j()-iP[0].get_j()))
762  return false;
763  int sign = vpMath::sign(iP1.get_j() - iP2.get_j());
764  if (sign == vpMath::sign(iP[0].get_j()-iP[1].get_j()))
765  {
766  iP1 = iP[0]; iP2 = iP[1];
767  }
768  else
769  {
770  iP1 = iP[1]; iP2 = iP[0];
771  }
772  }
773  else
774  {
775  if (vpMath::sign(iP1.get_i()-iP[0].get_i()) == vpMath::sign(iP2.get_i()-iP[0].get_i()))
776  return false;
777  int sign = vpMath::sign(iP1.get_i() - iP2.get_i());
778  if (sign == vpMath::sign(iP[0].get_i()-iP[1].get_i()))
779  {
780  iP1 = iP[0];iP2 = iP[1];
781  }
782  else
783  {
784  iP1 = iP[1];iP2 = iP[0];
785  }
786  }
787  }
788  else if (!iP1In)
789  {
790  vpImagePoint iPtemp = iP1;
791  if (fabs(a) < 1)
792  {
793  int sign = vpMath::sign(iP1.get_j() - iP2.get_j());
794  if (fabs(iP[0].get_j()-iP2.get_j()) > 5)
795  {
796  if (sign == vpMath::sign(iP[0].get_j()-iP2.get_j())) iP1 = iP[0];
797  else iP1 = iP[1];
798  }
799  else
800  {
801  if (sign == vpMath::sign(iP[1].get_j()-iP2.get_j())) iP1 = iP[1];
802  else iP1 = iP[0];
803  }
804  }
805  else
806  {
807  int sign = vpMath::sign(iP1.get_i() - iP2.get_i());
808  if (fabs(iP[0].get_i()-iP2.get_i()) > 5)
809  {
810  if (sign == vpMath::sign(iP[0].get_i()-iP2.get_i())) iP1 = iP[0];
811  else iP1 = iP[1];
812  }
813  else
814  {
815  if (sign == vpMath::sign(iP[1].get_i()-iP2.get_i())) iP1 = iP[1];
816  else iP1 = iP[0];
817  }
818  }
819  if (vpImagePoint::distance(iP1,iP2) < 9)
820  {
821  iP1 = iPtemp;
822  return false;
823  }
824  }
825  else if (!iP2In)
826  {
827  vpImagePoint iPtemp = iP2;
828  if (fabs(a) < 1)
829  {
830  int sign = vpMath::sign(iP2.get_j() - iP1.get_j());
831  if (fabs(iP[0].get_j()-iP1.get_j()) > 5)
832  {
833  if (sign == vpMath::sign(iP[0].get_j()-iP1.get_j())) iP2 = iP[0];
834  else iP2 = iP[1];
835  }
836  else
837  {
838  if (sign == vpMath::sign(iP[1].get_j()-iP1.get_j())) iP2 = iP[1];
839  else iP2 = iP[0];
840  }
841  }
842  else
843  {
844  int sign = vpMath::sign(iP2.get_i() - iP1.get_i());
845  if (fabs(iP[0].get_i()-iP1.get_i()) > 5)
846  {
847  if (sign == vpMath::sign(iP[0].get_i()-iP1.get_i())) iP2 = iP[0];
848  else iP2 = iP[1];
849  }
850  else
851  {
852  if (sign == vpMath::sign(iP[1].get_i()-iP1.get_i())) iP2 = iP[1];
853  else iP2 = iP[0];
854  }
855  }
856  if (vpImagePoint::distance(iP1,iP2) < 9)
857  {
858  iP2 = iPtemp;
859  return false;
860  }
861  }
862  }
863  return true;
864 }
865 
866 bool
867 vpPlotGraph::check3Dpoint(vpImagePoint &iP)
868 {
869  if (!iP.inRectangle(dGraphZone3D))
870  {
871  if (iP.get_i() < dTopLeft3D.get_i())
872  iP.set_i(dTopLeft3D.get_i());
873  else if (iP.get_i() > dTopLeft3D.get_i()+dHeight)
874  iP.set_i(dTopLeft3D.get_i()+dHeight-1);
875  if (iP.get_j() <dTopLeft3D.get_j())
876  iP.set_j(dTopLeft3D.get_j());
877  else if (iP.get_j() > dTopLeft3D.get_j()+dWidth)
878  iP.set_j(dTopLeft3D.get_j()+dWidth-1);
879  return false;
880  }
881  return true;
882 }
883 
884 void
885 vpPlotGraph::computeGraphParameters3D()
886 {
887  zoomx_3D = w_xsize/(xmax-xmin);
888  zoomy_3D = w_ysize/(ymax-ymin);
889  zoomz_3D = w_zsize/(zmax-zmin);
890  ptXorg = w_xval - zoomx_3D*xmax;
891  ptYorg = w_yval + zoomy_3D*ymin;
892  ptZorg = w_zval - zoomz_3D*zmax;
893 }
894 
895 void getGrid3DPoint(const double pente, vpImagePoint &iPunit, vpImagePoint &ip1, vpImagePoint &ip2, vpImagePoint &ip3)
896 {
897  if (pente <= 1)
898  {
899  ip1 = iPunit-vpImagePoint(3,0);
900  ip2 = iPunit+vpImagePoint(3,0);
901  ip3 = iPunit-vpImagePoint(6,6);
902  }
903  else
904  {
905  ip1 = iPunit-vpImagePoint(0,3);
906  ip2 = iPunit+vpImagePoint(0,3);
907  ip3 = iPunit+vpImagePoint(6,6);
908  }
909 }
910 
911 void
912 vpPlotGraph::displayGrid3D (vpImage<unsigned char> &I)
913 {
914  computeGraphParameters3D();
915 
916  xdelt = (xmax-xmin)/nbDivisionx;
917  ydelt = (ymax-ymin)/nbDivisiony;
918  zdelt = (zmax-zmin)/nbDivisionz;
919 
920  vpPoint pt[6];
921  pt[0].setWorldCoordinates(-w_xval,ptYorg,ptZorg);
922  pt[1].setWorldCoordinates(w_xval,ptYorg,ptZorg);
923  pt[2].setWorldCoordinates(ptXorg,-w_yval,ptZorg);
924  pt[3].setWorldCoordinates(ptXorg,w_yval,ptZorg);
925  pt[4].setWorldCoordinates(ptXorg,ptYorg,-w_zval);
926  pt[5].setWorldCoordinates(ptXorg,ptYorg,w_zval);
927 
928  vpImagePoint iP[6];
929  for (unsigned int i = 0; i < 6; i++)
930  {
931  pt[i].track(cMo);
932  double u=0.0,v=0.0;
933  vpMeterPixelConversion::convertPoint(cam,pt[i].get_x(),pt[i].get_y(),u,v);
934  iP[i].set_uv(u,v);
935  iP[i] = iP[i] + dTopLeft3D;
936  }
937 
938  int power;
939  double t;
940  char valeur[20];
941  vpPoint ptunit;
942  vpImagePoint iPunit;
943  double pente;
944  vpImagePoint ip1;
945  vpImagePoint ip2;
946  vpImagePoint ip3;
947  vpImagePoint ip4;
948 
949  power = laFonctionSansNom(xdelt);
950  ptunit.setWorldCoordinates(-w_xval,ptYorg,ptZorg);
951  //if (iP[0].get_j()-iP[1].get_j() != 0)
952  if (std::fabs(iP[0].get_j()-iP[1].get_j()) >
953  vpMath::maximum(std::fabs(iP[0].get_j()), std::fabs(iP[1].get_j()))* std::numeric_limits<double>::epsilon())
954  pente = fabs((iP[0].get_i()-iP[1].get_i())/(iP[0].get_j()-iP[1].get_j()));
955  else pente = 2;
956 
957  unsigned int count = 1;
958  for(t=xmin;t<=xmax;t=t+xdelt)
959  {
960  double x = ptXorg+(zoomx_3D*t);
961  ptunit.set_oX(x);
962  ptunit.track(cMo);
963  double u=0.0, v=0.0;
964  vpMeterPixelConversion::convertPoint(cam,ptunit.get_x(),ptunit.get_y(),u,v);
965  iPunit.set_uv(u,v);
966  iPunit = iPunit + dTopLeft3D;
967 
968  getGrid3DPoint(pente,iPunit,ip1,ip2,ip3);
969 
970  if(check3Dline(ip1,ip2))
971  {
973  if (count%2 == 1)
974  {
975  double ttemp;
976  if (power!=0)
977  ttemp = t*pow(10.0,power);
978  else ttemp = t;
979  sprintf(valeur, "%.1f", ttemp);
980  vpDisplay::displayText(I,ip3,valeur, vpColor::black);
981  }
982  }
983  count++;
984  }
985  if (power != 0)
986  {
987  ip4 = iP[1] -vpImagePoint(-15,10);
988  sprintf(valeur, "x10e%d", -power);
989  if(check3Dpoint(ip4))
990  vpDisplay::displayText(I,ip4,valeur, vpColor::black);
991  }
992 
993  power = laFonctionSansNom(ydelt);
994  ptunit.setWorldCoordinates(ptXorg,-w_yval,ptZorg);
995  //if (iP[2].get_j()-iP[3].get_j() != 0)
996  if (std::fabs(iP[2].get_j()-iP[3].get_j()) >
997  vpMath::maximum(std::fabs(iP[2].get_j()), std::fabs(iP[3].get_j()))* std::numeric_limits<double>::epsilon())
998  pente = fabs((iP[2].get_i()-iP[3].get_i())/(iP[2].get_j()-iP[3].get_j()));
999  else pente = 2;
1000  count = 0;
1001  for(t=ymin;t<=ymax;t=t+ydelt)
1002  {
1003  double y = ptYorg-(zoomy_3D*t);
1004  ptunit.set_oY(y);
1005  ptunit.track(cMo);
1006  double u=0.0, v=0.0;
1007  vpMeterPixelConversion::convertPoint(cam,ptunit.get_x(),ptunit.get_y(),u,v);
1008  iPunit.set_uv(u,v);
1009  iPunit = iPunit + dTopLeft3D;
1010 
1011  getGrid3DPoint(pente,iPunit,ip1,ip2,ip3);
1012 
1013  if(check3Dline(ip1,ip2))
1014  {
1016  if (count%2 == 1)
1017  {
1018  double ttemp;
1019  if (power!=0)
1020  ttemp = t*pow(10.0,power);
1021  else ttemp = t;
1022  sprintf(valeur, "%.1f", ttemp);
1023  vpDisplay::displayText(I,ip3,valeur, vpColor::black);
1024  }
1025  }
1026  count++;
1027  }
1028  if (power != 0)
1029  {
1030  ip4 = iP[2] -vpImagePoint(-15,10);
1031  sprintf(valeur, "x10e%d", -power);
1032  if(check3Dpoint(ip4))
1033  vpDisplay::displayText(I,ip4,valeur, vpColor::black);
1034  }
1035 
1036  power = laFonctionSansNom(zdelt);
1037  ptunit.setWorldCoordinates(ptXorg,ptYorg,-w_zval);
1038  //if (iP[4].get_j()-iP[5].get_j() != 0)
1039  if (std::fabs(iP[4].get_j()-iP[5].get_j()) >
1040  vpMath::maximum(std::fabs(iP[4].get_j()), std::fabs(iP[5].get_j()))* std::numeric_limits<double>::epsilon())
1041  pente = fabs((iP[4].get_i()-iP[5].get_i())/(iP[4].get_j()-iP[5].get_j()));
1042  else pente = 2;
1043  count = 0;
1044  for(t=zmin;t<=zmax;t=t+zdelt)
1045  {
1046  double z = ptZorg+(zoomz_3D*t);
1047  ptunit.set_oZ(z);
1048  ptunit.track(cMo);
1049  double u=0.0, v=0.0;
1050  vpMeterPixelConversion::convertPoint(cam,ptunit.get_x(),ptunit.get_y(),u,v);
1051  iPunit.set_uv(u,v);
1052  iPunit = iPunit + dTopLeft3D;
1053 
1054  getGrid3DPoint(pente,iPunit,ip1,ip2,ip3);
1055 
1056  if(check3Dline(ip1,ip2))
1057  {
1059  if (count%2 == 1)
1060  {
1061  double ttemp;
1062  if (power!=0)
1063  ttemp = t*pow(10.0,power);
1064  else ttemp = t;
1065  sprintf(valeur, "%.1f", ttemp);
1066  vpDisplay::displayText(I,ip3,valeur, vpColor::black);
1067  }
1068  }
1069  count++;
1070  }
1071  if (power != 0)
1072  {
1073  ip4 = iP[5] -vpImagePoint(-15,10);
1074  sprintf(valeur, "x10e%d", -power);
1075  if(check3Dpoint(ip4))
1076  vpDisplay::displayText(I,ip4,valeur, vpColor::black);
1077  }
1078 
1079 
1080 //Ligne horizontal
1081  if (check3Dline(iP[0],iP[1]))
1082  {
1083  vpDisplay::displayArrow(I,iP[0],iP[1], vpColor::black, gridThickness);
1084  if (dispUnit)
1085  {
1086  iPunit.set_ij(iP[1].get_i(),iP[1].get_j()-10*epsj);
1087  check3Dpoint (iPunit);
1088  vpDisplay::displayText(I,iPunit,unitx.c_str(), vpColor::black);
1089  }
1090  }
1091  if (check3Dline(iP[3],iP[2]))
1092  {
1093  vpDisplay::displayArrow(I,iP[3],iP[2], vpColor::black, gridThickness);
1094  if (dispUnit)
1095  {
1096  iPunit.set_ij(iP[2].get_i(),iP[2].get_j()-10*epsj);
1097  check3Dpoint (iPunit);
1098  vpDisplay::displayText(I,iPunit,unity.c_str(), vpColor::black);
1099  }
1100  }
1101  if (check3Dline(iP[4],iP[5]))
1102  {
1103  vpDisplay::displayArrow(I,iP[4],iP[5], vpColor::black, gridThickness);
1104  if (dispUnit)
1105  {
1106  iPunit.set_ij(iP[5].get_i(),iP[5].get_j()-10*epsj);
1107  check3Dpoint (iPunit);
1108  vpDisplay::displayText(I,iPunit,unitz.c_str(), vpColor::black);
1109  }
1110  }
1111 
1112  if (dispTitle)
1113  displayTitle(I);
1114  if (dispLegend)
1115  displayLegend(I);
1116 }
1117 
1119 vpPlotGraph::plot (vpImage<unsigned char> &I, const unsigned int curveNb, const double x, const double y, const double z)
1120 {
1121  if (!scaleInitialized)
1122  {
1123  if (x < 0)
1124  {
1125  xmax = 0;
1126  rescalex(0,x);
1127  }
1128  if (x > 0)
1129  {
1130  xmin = 0;
1131  rescalex(1,x);
1132  }
1133  if (y < 0)
1134  {
1135  ymax = 0;
1136  rescaley(0,y);
1137  }
1138  if (y > 0)
1139  {
1140  ymin = 0;
1141  rescaley(1,y);
1142  }
1143  if (z < 0)
1144  {
1145  zmax = 0;
1146  rescalez(0,z);
1147  }
1148  if (z > 0)
1149  {
1150  zmin = 0;
1151  rescalez(1,z);
1152  }
1153  scaleInitialized = true;
1154  computeGraphParameters3D();
1155  clearGraphZone(I);
1156  displayGrid3D(I);
1157  //if (std::fabs(y) == 0 || z == 0)
1158  if (std::fabs(y) <= std::numeric_limits<double>::epsilon() || std::fabs(z) <= std::numeric_limits<double>::epsilon())
1159  scaleInitialized = false;
1160  }
1161 
1162  if (firstPoint)
1163  {
1164  clearGraphZone(I);
1165  displayGrid3D(I);
1166  vpDisplay::flushROI(I,graphZone);
1167  firstPoint = false;
1168  }
1169 
1170  bool changed = false;
1171  if (x > xmax) {rescalex(1,x); changed = true;}
1172  else if(x < xmin) {rescalex(0,x);changed = true;}
1173 
1174  if (y > ymax) {rescaley(1,y);changed = true;}
1175  else if(y < ymin) {rescaley(0,y);changed = true;}
1176 
1177  if (z > zmax) {rescalez(1,z);changed = true;}
1178  else if(z < zmin) {rescalez(0,z);changed = true;}
1179 
1181 
1182  if (changed || move(I, button))
1183  {
1184  computeGraphParameters3D();
1185  replot3D(I);
1186  }
1187 
1188  vpPoint pointPlot;
1189  pointPlot.setWorldCoordinates(ptXorg+(zoomx_3D*x),ptYorg-(zoomy_3D*y),ptZorg+(zoomz_3D*z));
1190  pointPlot.track(cMo);
1191  double u=0.0, v=0.0;
1192  vpMeterPixelConversion::convertPoint(cam,pointPlot.get_x(),pointPlot.get_y(),u,v);
1193  vpImagePoint iP;
1194  iP.set_uv(u,v);
1195  iP = iP + dTopLeft3D;
1196 
1197  (curveList+curveNb)->pointListz.end();
1198  if((curveList+curveNb)->nbPoint)
1199  {
1200  if (check3Dline((curveList+curveNb)->lastPoint,iP))
1201  vpDisplay::displayLine(I,(curveList+curveNb)->lastPoint, iP, (curveList+curveNb)->color, (curveList+curveNb)->thickness);
1202  }
1203 #if( defined VISP_HAVE_X11 || defined VISP_HAVE_GDI )
1204  double top;
1205  double left;
1206  double width_;
1207  double height_;
1208 
1209  if (iP.get_i() <= (curveList+curveNb)->lastPoint.get_i()) {top = iP.get_i()-5; height_ = (curveList+curveNb)->lastPoint.get_i() - top+10;}
1210  else {top = (curveList+curveNb)->lastPoint.get_i()-5; height_ = iP.get_i() - top+10;}
1211  if (iP.get_j() <= (curveList+curveNb)->lastPoint.get_j()) {left = iP.get_j()-5; width_ = (curveList+curveNb)->lastPoint.get_j() - left+10;}
1212  else {left = (curveList+curveNb)->lastPoint.get_j()-5; width_ = iP.get_j() - left+10;}
1213  vpDisplay::flushROI(I,vpRect(left,top,width_,height_));
1214 #endif
1215 
1216  (curveList+curveNb)->lastPoint = iP;
1217  (curveList+curveNb)->pointListx.push_back(x);
1218  (curveList+curveNb)->pointListy.push_back(y);
1219  (curveList+curveNb)->pointListz.push_back(z);
1220  (curveList+curveNb)->nbPoint++;
1221 
1222 #if( !defined VISP_HAVE_X11 && defined FLUSH_ON_PLOT)
1223  vpDisplay::flushROI(I,graphZone);
1224 #endif
1225  return button;
1226 }
1227 
1228 void
1229 vpPlotGraph::replot3D (vpImage<unsigned char> &I)
1230 {
1231  clearGraphZone(I);
1232  displayGrid3D(I);
1233 
1234  for (unsigned int i = 0; i < curveNbr; i++)
1235  {
1236  std::list<double>::const_iterator it_ptListx = (curveList+i)->pointListx.begin();
1237  std::list<double>::const_iterator it_ptListy = (curveList+i)->pointListy.begin();
1238  std::list<double>::const_iterator it_ptListz = (curveList+i)->pointListz.begin();
1239 
1240  unsigned int k = 0;
1241  vpImagePoint iP;
1242  vpPoint pointPlot;
1243  while (k < (curveList+i)->nbPoint)
1244  {
1245  double x = *it_ptListx;
1246  double y = *it_ptListy;
1247  double z = *it_ptListz;
1248  pointPlot.setWorldCoordinates(ptXorg+(zoomx_3D*x),ptYorg-(zoomy_3D*y),ptZorg+(zoomz_3D*z));
1249  pointPlot.track(cMo);
1250  double u=0.0, v=0.0;
1251  vpMeterPixelConversion::convertPoint(cam,pointPlot.get_x(),pointPlot.get_y(),u,v);
1252  iP.set_uv(u,v);
1253  iP = iP + dTopLeft3D;
1254 
1255  //vpDisplay::displayCross(I,iP,3,vpColor::cyan);
1256  if (k > 0)
1257  {
1258  if (check3Dline((curveList+i)->lastPoint,iP))
1259  vpDisplay::displayLine(I,(curveList+i)->lastPoint, iP, (curveList+i)->color);
1260  //vpDisplay::displayCross(I,iP,3,vpColor::orange);
1261  }
1262 
1263  (curveList+i)->lastPoint = iP;
1264 
1265  ++it_ptListx;
1266  ++it_ptListy;
1267  ++it_ptListz;
1268  k++;
1269  }
1270  }
1271  vpDisplay::flushROI(I,graphZone);
1272 }
1273 
1274 
1275 
1276 void
1277 vpPlotGraph::rescalez(unsigned int side, double extremity)
1278 {
1279  switch (side)
1280  {
1281  case 0:
1282  zmin = (3*extremity-zmax)/2;
1283  break;
1284  case 1:
1285  zmax = (3*extremity-zmin)/2;
1286  break;
1287  }
1288 
1289  zdelt = (zmax-zmin)/(double)nbDivisionz;
1290 }
1291 
1296 bool
1297 vpPlotGraph::move(const vpImage<unsigned char> &I, vpMouseButton::vpMouseButtonType &button)
1298 {
1299  bool changed = false;
1300  vpHomogeneousMatrix displacement = navigation(I, changed, button);
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, vpMouseButton::vpMouseButtonType &b)
1313 {
1314  vpImagePoint iP;
1315  vpImagePoint trash;
1316  bool clicked = false;
1317  bool clickedUp = false;
1318 
1319  vpHomogeneousMatrix mov(0,0,0,0,0,0);
1320  changed = false;
1321 
1322  //if(!blocked) vpDisplay::getClickUp(I,trash, b,false);
1323 
1324  if(!blocked) clicked = vpDisplay::getClick(I,iP,b,false);
1325 
1326  if(blocked) clickedUp = vpDisplay::getClickUp(I,trash, b,false);
1327 
1328  if (clicked)
1329  {
1330  if (!iP.inRectangle(graphZone))
1331  return mov;
1332  }
1333 
1334  if(clicked)
1335  {
1336  if (b == vpMouseButton::button1) blockedr = true;
1337  if (b == vpMouseButton::button2) blockedz = true;
1338  blocked = true;
1339  }
1340 
1341  else if(clickedUp)
1342  {
1343  if (b == vpMouseButton::button1)
1344  {
1345  old_iPr = vpImagePoint(-1,-1);
1346  blockedr = false;
1347  }
1348  if (b == vpMouseButton::button2)
1349  {
1350  old_iPz = vpImagePoint(-1,-1);
1351  blockedz = false;
1352  }
1353  if (!(blockedr || blockedz))
1354  {
1355  blocked = false;
1356  //while (vpDisplay::getClick(I,trash,b,false)) {};
1357  }
1358  }
1359 
1360  vpTime::sleepMs(5);
1362 
1363  if (old_iPr != vpImagePoint(-1,-1) && blockedr)
1364  {
1365  double width_ = vpMath::minimum(I.getWidth(),I.getHeight());
1366 
1367  double diffi = iP.get_i() - old_iPr.get_i();
1368  double diffj = iP.get_j() - old_iPr.get_j();
1369 
1370  double anglei = diffi*360/width_;
1371  double anglej = diffj*360/width_;
1372  mov.buildFrom(0,0,0,vpMath::rad(anglei),vpMath::rad(-anglej),0);
1373  changed = true;
1374  }
1375 
1376  if (blockedr) old_iPr = iP;
1377 
1378  if (old_iPz != vpImagePoint(-1,-1) && blockedz)
1379  {
1380  double diffi = iP.get_i() - old_iPz.get_i();
1381  mov.buildFrom(0,0,diffi*0.01,0,0,0);
1382  changed = true;
1383  }
1384 
1385  if (blockedz) old_iPz = iP;
1386 
1387  return mov;
1388 }
1389 
1390 #elif !defined(VISP_BUILD_SHARED_LIBS)
1391 // Work arround to avoid warning: libvisp_core.a(vpPlotGraph.cpp.o) has no symbols
1392 void dummy_vpPlotGraph() {};
1393 #endif
1394 #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
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
double get_i() const
Definition: vpImagePoint.h:199
unsigned int getWidth() const
Definition: vpImage.h:226
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
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
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:210
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:140
static const vpColor orange
Definition: vpColor.h:173
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void set_i(const double ii)
Definition: vpImagePoint.h:163
static const vpColor cyan
Definition: vpColor.h:172
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
VISP_EXPORT void sleepMs(double t)
Definition: vpTime.cpp:266
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Definition: vpPose.h:76
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
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
Definition: vpPose.cpp:372
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:151
static double rad(double deg)
Definition: vpMath.h:104
void set_j(const double jj)
Definition: vpImagePoint.h:174
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
vpHomogeneousMatrix inverse() const
unsigned int getHeight() const
Definition: vpImage.h:175
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:243
Defines a rectangle in the plane.
Definition: vpRect.h:82
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static int() sign(double x)
Definition: vpMath.h:275
void addPoint(const vpPoint &P)
Definition: vpPose.cpp:145
static const vpColor purple
Definition: vpColor.h:174
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:279
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:185
static const vpColor blue
Definition: vpColor.h:169
void clearPoint()
Definition: vpPose.cpp:130