ViSP  2.10.0
vpImageSimulator.cpp
1 /****************************************************************************
2  *
3  * $Id: vpPose.h 2453 2010-01-07 10:01:10Z nmelchio $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description: Class which enables to project an image in the 3D space
35  * and get the view of a virtual camera.
36  *
37  *
38  * Authors:
39  * Amaury Dame
40  * Nicolas Melchior
41  *
42  *****************************************************************************/
43 
44 #include <visp/vpImageSimulator.h>
45 #include <visp/vpRotationMatrix.h>
46 #include <visp/vpImageIo.h>
47 #include <visp/vpImageConvert.h>
48 #include <visp/vpPixelMeterConversion.h>
49 #include <visp/vpMeterPixelConversion.h>
50 #include <visp/vpMatrixException.h>
51 #include <visp/vpMbtPolygon.h>
52 
63  : cMt(), pt(), ptClipped(), interp(SIMPLE), normal_obj(), normal_Cam(), normal_Cam_optim(),
64  distance(1.), visible_result(1.), visible(false), X0_2_optim(NULL),
65  euclideanNorm_u(0.), euclideanNorm_v(0.), vbase_u(), vbase_v(),
66  vbase_u_optim(NULL), vbase_v_optim(NULL), Xinter_optim(NULL), listTriangle(),
67  colorI(col), Ig(), Ic(), rect(), cleanPrevImage(false),
68  setBackgroundTexture(false), bgColor(vpColor::white), focal(), needClipping(false)
69 {
70  for(int i=0;i<4;i++)
71  X[i].resize(3);
72 
73  for(int i=0;i<4;i++)
74  X2[i].resize(3);
75 
76  normal_obj.resize(3);
77  visible=false;
78  normal_Cam.resize(3);
79 
80  //Xinter.resize(3);
81 
82  vbase_u.resize(3);
83  vbase_v.resize(3);
84 
85  focal.resize(3);
86  focal=0;
87  focal[2]=1;
88 
89  normal_Cam_optim = new double[3];
90  X0_2_optim = new double[3];
91  vbase_u_optim = new double[3];
92  vbase_v_optim = new double[3];
93  Xinter_optim = new double[3];
94 
95  pt.resize(4);
96 }
97 
98 
103  : cMt(), pt(), ptClipped(), interp(SIMPLE), normal_obj(), normal_Cam(), normal_Cam_optim(),
104  distance(1.), visible_result(1.), visible(false), X0_2_optim(NULL),
105  euclideanNorm_u(0.), euclideanNorm_v(0.), vbase_u(), vbase_v(),
106  vbase_u_optim(NULL), vbase_v_optim(NULL), Xinter_optim(NULL), listTriangle(),
107  colorI(GRAY_SCALED), Ig(), Ic(), rect(), cleanPrevImage(false),
108  setBackgroundTexture(false), bgColor(vpColor::white), focal(), needClipping(false)
109 {
110  pt.resize(4);
111  for(unsigned int i=0;i<4;i++)
112  {
113  X[i] = text.X[i];
114  pt[i] = text.pt[i];
115  }
116 
117  for(int i=0;i<4;i++)
118  X2[i].resize(3);
119 
120  Ic = text.Ic;
121  Ig = text.Ig;
122 
123  focal.resize(3);
124  focal=0;
125  focal[2]=1;
126 
127  normal_obj = text.normal_obj;
128  euclideanNorm_u = text.euclideanNorm_u;
129  euclideanNorm_v = text.euclideanNorm_v;
130 
131  normal_Cam.resize(3);
132  vbase_u.resize(3);
133  vbase_v.resize(3);
134 
135 
136  normal_Cam_optim = new double[3];
137  X0_2_optim = new double[3];
138  vbase_u_optim = new double[3];
139  vbase_v_optim = new double[3];
140  Xinter_optim = new double[3];
141 
142  colorI = text.colorI;
143  interp = text.interp;
144  bgColor = text.bgColor;
145  cleanPrevImage = text.cleanPrevImage;
146  setBackgroundTexture = false;
147 
148  setCameraPosition(text.cMt);
149 }
150 
155 {
156  delete[] normal_Cam_optim;
157  delete[] X0_2_optim;
158  delete[] vbase_u_optim;
159  delete[] vbase_v_optim;
160  delete[] Xinter_optim;
161 }
162 
163 
166 {
167  for(unsigned int i=0;i<4;i++)
168  {
169  X[i] = sim.X[i];
170  pt[i] = sim.pt[i];
171  }
172 
173  Ic = sim.Ic;
174  Ig = sim.Ig;
175 
176  bgColor = sim.bgColor;
177  cleanPrevImage = sim.cleanPrevImage;
178 
179  focal = sim.focal;
180 
181  normal_obj = sim.normal_obj;
182  euclideanNorm_u = sim.euclideanNorm_u;
183  euclideanNorm_v = sim.euclideanNorm_v;
184 
185  colorI = sim.colorI;
186  interp = sim.interp;
187 
188  setCameraPosition(sim.cMt);
189 
190  return *this;
191 }
192 
198 void
200  const vpCameraParameters &cam)
201 {
202  int nb_point_dessine = 0;
203  if (setBackgroundTexture)
204  // The Ig has been set to a previously defined background texture
205  I = Ig;
206  else
207  {
208  if (cleanPrevImage)
209  {
210  unsigned char col = (unsigned char) (0.2126 * bgColor.R
211  + 0.7152 * bgColor.G + 0.0722 * bgColor.B);
212  for (unsigned int i = 0; i < I.getHeight(); i++)
213  {
214  for (unsigned int j = 0; j < I.getWidth(); j++)
215  {
216  I[i][j] = col;
217  }
218  }
219  }
220  }
221 
222  if(visible)
223  {
224  if(!needClipping)
225  getRoi(I.getWidth(),I.getHeight(),cam,pt,rect);
226  else
227  getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect);
228 
229  double top = rect.getTop();
230  double bottom = rect.getBottom();
231  double left = rect.getLeft();
232  double right= rect.getRight();
233 
234  unsigned char *bitmap = I.bitmap;
235  unsigned int width = I.getWidth();
236  vpImagePoint ip;
237 
238  for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++)
239  {
240  for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++)
241  {
242  double x=0,y=0;
243  ip.set_ij(i,j);
245  ip.set_ij(y,x);
246  if (colorI == GRAY_SCALED)
247  {
248  unsigned char Ipixelplan = 0;
249  if(getPixel(ip,Ipixelplan))
250  {
251  *(bitmap+i*width+j)=Ipixelplan;
252  nb_point_dessine++;
253  }
254  }
255  else if (colorI == COLORED)
256  {
257  vpRGBa Ipixelplan;
258  if(getPixel(ip,Ipixelplan))
259  {
260  unsigned char pixelgrey = (unsigned char)(0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B);
261  *(bitmap+i*width+j)=pixelgrey;
262  nb_point_dessine++;
263  }
264  }
265  }
266  }
267  }
268 }
269 
270 
278 void
281  const vpCameraParameters &cam)
282 {
283  int nb_point_dessine = 0;
284  if (cleanPrevImage)
285  {
286  unsigned char col = (unsigned char)(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B);
287  for (unsigned int i = 0; i < I.getHeight(); i++)
288  {
289  for (unsigned int j = 0; j < I.getWidth(); j++)
290  {
291  I[i][j] = col;
292  }
293  }
294  }
295  if(visible)
296  {
297  if(!needClipping)
298  getRoi(I.getWidth(),I.getHeight(),cam,pt,rect);
299  else
300  getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect);
301 
302  double top = rect.getTop();
303  double bottom = rect.getBottom();
304  double left = rect.getLeft();
305  double right= rect.getRight();
306 
307  unsigned char *bitmap = I.bitmap;
308  unsigned int width = I.getWidth();
309  vpImagePoint ip;
310 
311  for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++)
312  {
313  for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++)
314  {
315  double x=0,y=0;
316  ip.set_ij(i,j);
318  ip.set_ij(y,x);
319  unsigned char Ipixelplan = 0;
320  if(getPixel(Isrc,ip,Ipixelplan))
321  {
322  *(bitmap+i*width+j)=Ipixelplan;
323  nb_point_dessine++;
324  }
325  }
326  }
327  }
328 }
329 
339 void
341  const vpCameraParameters &cam, vpMatrix &zBuffer)
342 {
343  if (I.getWidth() != (unsigned int)zBuffer.getCols() || I.getHeight() != (unsigned int)zBuffer.getRows())
344  throw (vpMatrixException(vpMatrixException::incorrectMatrixSizeError, " zBuffer must have the same size as the image I ! "));
345 
346  int nb_point_dessine = 0;
347  if (cleanPrevImage)
348  {
349  unsigned char col = (unsigned char)(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B);
350  for (unsigned int i = 0; i < I.getHeight(); i++)
351  {
352  for (unsigned int j = 0; j < I.getWidth(); j++)
353  {
354  I[i][j] = col;
355  }
356  }
357  }
358  if(visible)
359  {
360  if(!needClipping)
361  getRoi(I.getWidth(),I.getHeight(),cam,pt,rect);
362  else
363  getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect);
364 
365  double top = rect.getTop();
366  double bottom = rect.getBottom();
367  double left = rect.getLeft();
368  double right= rect.getRight();
369 
370  unsigned char *bitmap = I.bitmap;
371  unsigned int width = I.getWidth();
372  vpImagePoint ip;
373 
374  for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++)
375  {
376  for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++)
377  {
378  double x=0,y=0;
379  ip.set_ij(i,j);
381  ip.set_ij(y,x);
382  if (colorI == GRAY_SCALED)
383  {
384  unsigned char Ipixelplan;
385  if(getPixel(ip,Ipixelplan))
386  {
387  if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0)
388  {
389  *(bitmap+i*width+j)=Ipixelplan;
390  nb_point_dessine++;
391  zBuffer[i][j] = Xinter_optim[2];
392  }
393  }
394  }
395  else if (colorI == COLORED)
396  {
397  vpRGBa Ipixelplan;
398  if(getPixel(ip,Ipixelplan))
399  {
400  if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0)
401  {
402  unsigned char pixelgrey = (unsigned char)(0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B);
403  *(bitmap+i*width+j)=pixelgrey;
404  nb_point_dessine++;
405  zBuffer[i][j] = Xinter_optim[2];
406  }
407  }
408  }
409  }
410  }
411  }
412 }
413 
420 void
422 {
423  int nb_point_dessine = 0;
424  if (cleanPrevImage)
425  {
426  for (unsigned int i = 0; i < I.getHeight(); i++)
427  {
428  for (unsigned int j = 0; j < I.getWidth(); j++)
429  {
430  I[i][j] = bgColor;
431  }
432  }
433  }
434 
435  if(visible)
436  {
437  if(!needClipping)
438  getRoi(I.getWidth(),I.getHeight(),cam,pt,rect);
439  else
440  getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect);
441 
442  double top = rect.getTop();
443  double bottom = rect.getBottom();
444  double left = rect.getLeft();
445  double right= rect.getRight();
446 
447  vpRGBa *bitmap = I.bitmap;
448  unsigned int width = I.getWidth();
449  vpImagePoint ip;
450 
451  for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++)
452  {
453  for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++)
454  {
455  double x=0,y=0;
456  ip.set_ij(i,j);
458  ip.set_ij(y,x);
459  if (colorI == GRAY_SCALED)
460  {
461  unsigned char Ipixelplan;
462  if(getPixel(ip,Ipixelplan))
463  {
464  vpRGBa pixelcolor;
465  pixelcolor.R = Ipixelplan;
466  pixelcolor.G = Ipixelplan;
467  pixelcolor.B = Ipixelplan;
468  *(bitmap+i*width+j) = pixelcolor;
469  nb_point_dessine++;
470  }
471  }
472  else if (colorI == COLORED)
473  {
474  vpRGBa Ipixelplan;
475  if(getPixel(ip,Ipixelplan))
476  {
477  *(bitmap+i*width+j) = Ipixelplan;
478  nb_point_dessine++;
479  }
480  }
481  }
482  }
483  }
484 }
485 
486 
494 void
496  const vpCameraParameters &cam)
497 {
498  int nb_point_dessine = 0;
499  if (cleanPrevImage)
500  {
501  for (unsigned int i = 0; i < I.getHeight(); i++)
502  {
503  for (unsigned int j = 0; j < I.getWidth(); j++)
504  {
505  I[i][j] = bgColor;
506  }
507  }
508  }
509 
510  if(visible)
511  {
512  if(!needClipping)
513  getRoi(I.getWidth(),I.getHeight(),cam,pt,rect);
514  else
515  getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect);
516 
517  double top = rect.getTop();
518  double bottom = rect.getBottom();
519  double left = rect.getLeft();
520  double right= rect.getRight();
521 
522  vpRGBa *bitmap = I.bitmap;
523  unsigned int width = I.getWidth();
524  vpImagePoint ip;
525 
526  for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++)
527  {
528  for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++)
529  {
530  double x=0,y=0;
531  ip.set_ij(i,j);
533  ip.set_ij(y,x);
534  vpRGBa Ipixelplan;
535  if(getPixel(Isrc,ip,Ipixelplan))
536  {
537  *(bitmap+i*width+j) = Ipixelplan;
538  nb_point_dessine++;
539  }
540  }
541  }
542  }
543 }
544 
554 void
556  vpMatrix &zBuffer)
557 {
558  if (I.getWidth() != (unsigned int)zBuffer.getCols() || I.getHeight() != (unsigned int)zBuffer.getRows())
559  throw (vpMatrixException(vpMatrixException::incorrectMatrixSizeError, " zBuffer must have the same size as the image I ! "));
560 
561  int nb_point_dessine = 0;
562  if (cleanPrevImage)
563  {
564  for (unsigned int i = 0; i < I.getHeight(); i++)
565  {
566  for (unsigned int j = 0; j < I.getWidth(); j++)
567  {
568  I[i][j] = bgColor;
569  }
570  }
571  }
572  if(visible)
573  {
574  if(!needClipping)
575  getRoi(I.getWidth(),I.getHeight(),cam,pt,rect);
576  else
577  getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect);
578 
579  double top = rect.getTop();
580  double bottom = rect.getBottom();
581  double left = rect.getLeft();
582  double right= rect.getRight();
583 
584  vpRGBa *bitmap = I.bitmap;
585  unsigned int width = I.getWidth();
586  vpImagePoint ip;
587 
588  for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++)
589  {
590  for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++)
591  {
592  double x=0,y=0;
593  ip.set_ij(i,j);
595  ip.set_ij(y,x);
596  if (colorI == GRAY_SCALED)
597  {
598  unsigned char Ipixelplan;
599  if(getPixel(ip,Ipixelplan))
600  {
601  if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0)
602  {
603  vpRGBa pixelcolor;
604  pixelcolor.R = Ipixelplan;
605  pixelcolor.G = Ipixelplan;
606  pixelcolor.B = Ipixelplan;
607  *(bitmap+i*width+j) = pixelcolor;
608  nb_point_dessine++;
609  zBuffer[i][j] = Xinter_optim[2];
610  }
611  }
612  }
613  else if (colorI == COLORED)
614  {
615  vpRGBa Ipixelplan;
616  if(getPixel(ip,Ipixelplan))
617  {
618  if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0)
619  {
620  *(bitmap+i*width+j) = Ipixelplan;
621  nb_point_dessine++;
622  zBuffer[i][j] = Xinter_optim[2];
623  }
624  }
625  }
626  }
627  }
628  }
629 }
630 
631 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
632 
738 void
741  const vpCameraParameters &cam)
742 {
743 
744  unsigned int width = I.getWidth();
745  unsigned int height = I.getHeight();
746 
747  unsigned int nbsimList = list.nbElements();
748 
749  if (nbsimList < 1)
750  return;
751 
752  vpImageSimulator** simList = new vpImageSimulator* [nbsimList];
753 
754  double topFinal = height+1;;
755  double bottomFinal = -1;
756  double leftFinal = width+1;
757  double rightFinal = -1;
758 
759  list.front();
760 
761  unsigned int unvisible = 0;
762  for (unsigned int i = 0; i < nbsimList; i++)
763  {
764  vpImageSimulator* sim = &(list.value());
765  list.next();
766  if (sim->visible)
767  simList[i] = sim;
768  else
769  unvisible++;
770  }
771  nbsimList = nbsimList - unvisible;
772 
773  if (nbsimList < 1)
774  {
775  delete[] simList;
776  return;
777  }
778 
779 
780  for (unsigned int i = 0; i < nbsimList; i++)
781  {
782  if(!simList[i]->needClipping)
783  simList[i]->getRoi(width,height,cam,simList[i]->pt,simList[i]->rect);
784  else
785  simList[i]->getRoi(width,height,cam,simList[i]->ptClipped,simList[i]->rect);
786 
787  if (topFinal > simList[i]->rect.getTop()) topFinal = simList[i]->rect.getTop();
788  if (bottomFinal < simList[i]->rect.getBottom()) bottomFinal = simList[i]->rect.getBottom();
789  if (leftFinal > simList[i]->rect.getLeft()) leftFinal = simList[i]->rect.getLeft();
790  if (rightFinal < simList[i]->rect.getRight()) rightFinal = simList[i]->rect.getRight();
791  }
792 
793  double zmin = -1;
794  int indice = -1;
795  unsigned char *bitmap = I.bitmap;
796  vpImagePoint ip;
797 
798  for (unsigned int i = (unsigned int)topFinal; i < (unsigned int)bottomFinal; i++)
799  {
800  for (unsigned int j = (unsigned int)leftFinal; j < (unsigned int)rightFinal; j++)
801  {
802  zmin = -1;
803  double x=0,y=0;
804  ip.set_ij(i,j);
806  ip.set_ij(y,x);
807  for (int k = 0; k < (int)nbsimList; k++)
808  {
809  double z = 0;
810  if(simList[k]->getPixelDepth(ip,z))
811  {
812  if (z < zmin || zmin < 0)
813  {
814  zmin = z;
815  indice = k;
816  }
817  }
818  }
819  if (indice >= 0)
820  {
821  if (simList[indice]->colorI == GRAY_SCALED)
822  {
823  unsigned char Ipixelplan = 255;
824  simList[indice]->getPixel(ip,Ipixelplan);
825  *(bitmap+i*width+j)=Ipixelplan;
826  }
827  else if (simList[indice]->colorI == COLORED)
828  {
829  vpRGBa Ipixelplan(255,255,255);
830  simList[indice]->getPixel(ip,Ipixelplan);
831  unsigned char pixelgrey = (unsigned char)(0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B);
832  *(bitmap+i*width+j)=pixelgrey;
833  }
834  }
835  }
836  }
837 
838  delete[] simList;
839 }
840 
841 
947 void
949  const vpCameraParameters &cam)
950 {
951 
952  unsigned int width = I.getWidth();
953  unsigned int height = I.getHeight();
954 
955  unsigned int nbsimList = list.nbElements();
956 
957  if (nbsimList < 1)
958  return;
959 
960  vpImageSimulator** simList = new vpImageSimulator* [nbsimList];
961 
962  double topFinal = height+1;;
963  double bottomFinal = -1;
964  double leftFinal = width+1;
965  double rightFinal = -1;
966 
967  list.front();
968 
969  unsigned int unvisible = 0;
970  for (unsigned int i = 0; i < nbsimList; i++)
971  {
972  vpImageSimulator* sim = &(list.value());
973  list.next();
974  if (sim->visible)
975  simList[i] = sim;
976  else
977  unvisible++;
978  }
979  nbsimList = nbsimList - unvisible;
980 
981  if (nbsimList < 1)
982  {
983  delete[] simList;
984  return;
985  }
986 
987  for (unsigned int i = 0; i < nbsimList; i++)
988  {
989  if(!simList[i]->needClipping)
990  simList[i]->getRoi(width,height,cam,simList[i]->pt,simList[i]->rect);
991  else
992  simList[i]->getRoi(width,height,cam,simList[i]->ptClipped,simList[i]->rect);
993 
994  if (topFinal > simList[i]->rect.getTop()) topFinal = simList[i]->rect.getTop();
995  if (bottomFinal < simList[i]->rect.getBottom()) bottomFinal = simList[i]->rect.getBottom();
996  if (leftFinal > simList[i]->rect.getLeft()) leftFinal = simList[i]->rect.getLeft();
997  if (rightFinal < simList[i]->rect.getRight()) rightFinal = simList[i]->rect.getRight();
998  }
999 
1000  double zmin = -1;
1001  int indice = -1;
1002  vpRGBa *bitmap = I.bitmap;
1003  vpImagePoint ip;
1004 
1005  for (unsigned int i = (unsigned int)topFinal; i < (unsigned int)bottomFinal; i++)
1006  {
1007  for (unsigned int j = (unsigned int)leftFinal; j < (unsigned int)rightFinal; j++)
1008  {
1009  zmin = -1;
1010  double x=0,y=0;
1011  ip.set_ij(i,j);
1013  ip.set_ij(y,x);
1014  for (int k = 0; k < (int)nbsimList; k++)
1015  {
1016  double z = 0;
1017  if(simList[k]->getPixelDepth(ip,z))
1018  {
1019  if (z < zmin || zmin < 0)
1020  {
1021  zmin = z;
1022  indice = k;
1023  }
1024  }
1025  }
1026  if (indice >= 0)
1027  {
1028  if (simList[indice]->colorI == GRAY_SCALED)
1029  {
1030  unsigned char Ipixelplan = 255;
1031  simList[indice]->getPixel(ip,Ipixelplan);
1032  vpRGBa pixelcolor;
1033  pixelcolor.R = Ipixelplan;
1034  pixelcolor.G = Ipixelplan;
1035  pixelcolor.B = Ipixelplan;
1036  *(bitmap+i*width+j) = pixelcolor;
1037  }
1038  else if (simList[indice]->colorI == COLORED)
1039  {
1040  vpRGBa Ipixelplan(255,255,255);
1041  simList[indice]->getPixel(ip,Ipixelplan);
1042  //unsigned char pixelgrey = 0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B;
1043  *(bitmap+i*width+j)=Ipixelplan;
1044  }
1045  }
1046  }
1047  }
1048 
1049  delete[] simList;
1050 }
1051 #endif
1052 
1153 void
1155  std::list<vpImageSimulator> &list,
1156  const vpCameraParameters &cam)
1157 {
1158 
1159  unsigned int width = I.getWidth();
1160  unsigned int height = I.getHeight();
1161 
1162  unsigned int nbsimList = (unsigned int)list.size();
1163 
1164  if (nbsimList < 1)
1165  return;
1166 
1167  vpImageSimulator** simList = new vpImageSimulator* [nbsimList];
1168 
1169  double topFinal = height+1;;
1170  double bottomFinal = -1;
1171  double leftFinal = width+1;
1172  double rightFinal = -1;
1173 
1174  unsigned int unvisible = 0;
1175  unsigned int indexSimu=0;
1176  for(std::list<vpImageSimulator>::iterator it=list.begin(); it!=list.end(); ++it, ++indexSimu){
1177  vpImageSimulator* sim = &(*it);
1178  if (sim->visible)
1179  simList[indexSimu] = sim;
1180  else
1181  unvisible++;
1182  }
1183  nbsimList = nbsimList - unvisible;
1184 
1185  if (nbsimList < 1)
1186  {
1187  delete[] simList;
1188  return;
1189  }
1190 
1191 
1192  for (unsigned int i = 0; i < nbsimList; i++)
1193  {
1194  if(!simList[i]->needClipping)
1195  simList[i]->getRoi(width,height,cam,simList[i]->pt,simList[i]->rect);
1196  else
1197  simList[i]->getRoi(width,height,cam,simList[i]->ptClipped,simList[i]->rect);
1198 
1199  if (topFinal > simList[i]->rect.getTop()) topFinal = simList[i]->rect.getTop();
1200  if (bottomFinal < simList[i]->rect.getBottom()) bottomFinal = simList[i]->rect.getBottom();
1201  if (leftFinal > simList[i]->rect.getLeft()) leftFinal = simList[i]->rect.getLeft();
1202  if (rightFinal < simList[i]->rect.getRight()) rightFinal = simList[i]->rect.getRight();
1203  }
1204 
1205  double zmin = -1;
1206  int indice = -1;
1207  unsigned char *bitmap = I.bitmap;
1208  vpImagePoint ip;
1209 
1210  for (unsigned int i = (unsigned int)topFinal; i < (unsigned int)bottomFinal; i++)
1211  {
1212  for (unsigned int j = (unsigned int)leftFinal; j < (unsigned int)rightFinal; j++)
1213  {
1214  zmin = -1;
1215  double x=0,y=0;
1216  ip.set_ij(i,j);
1218  ip.set_ij(y,x);
1219  for (int k = 0; k < (int)nbsimList; k++)
1220  {
1221  double z = 0;
1222  if(simList[k]->getPixelDepth(ip,z))
1223  {
1224  if (z < zmin || zmin < 0)
1225  {
1226  zmin = z;
1227  indice = k;
1228  }
1229  }
1230  }
1231  if (indice >= 0)
1232  {
1233  if (simList[indice]->colorI == GRAY_SCALED)
1234  {
1235  unsigned char Ipixelplan = 255;
1236  simList[indice]->getPixel(ip,Ipixelplan);
1237  *(bitmap+i*width+j)=Ipixelplan;
1238  }
1239  else if (simList[indice]->colorI == COLORED)
1240  {
1241  vpRGBa Ipixelplan(255,255,255);
1242  simList[indice]->getPixel(ip,Ipixelplan);
1243  unsigned char pixelgrey = (unsigned char)(0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B);
1244  *(bitmap+i*width+j)=pixelgrey;
1245  }
1246  }
1247  }
1248  }
1249 
1250  delete[] simList;
1251 }
1252 
1253 
1355 void
1357  std::list<vpImageSimulator> &list,
1358  const vpCameraParameters &cam)
1359 {
1360 
1361  unsigned int width = I.getWidth();
1362  unsigned int height = I.getHeight();
1363 
1364  unsigned int nbsimList = (unsigned int)list.size();
1365 
1366  if (nbsimList < 1)
1367  return;
1368 
1369  vpImageSimulator** simList = new vpImageSimulator* [nbsimList];
1370 
1371  double topFinal = height+1;;
1372  double bottomFinal = -1;
1373  double leftFinal = width+1;
1374  double rightFinal = -1;
1375 
1376  unsigned int unvisible = 0;
1377  unsigned int indexSimu = 0;
1378  for(std::list<vpImageSimulator>::iterator it=list.begin(); it!=list.end(); ++it, ++indexSimu){
1379  vpImageSimulator* sim = &(*it);
1380  if (sim->visible)
1381  simList[indexSimu] = sim;
1382  else
1383  unvisible++;
1384  }
1385 
1386  nbsimList = nbsimList - unvisible;
1387 
1388  if (nbsimList < 1)
1389  {
1390  delete[] simList;
1391  return;
1392  }
1393 
1394  for (unsigned int i = 0; i < nbsimList; i++)
1395  {
1396  if(!simList[i]->needClipping)
1397  simList[i]->getRoi(width,height,cam,simList[i]->pt,simList[i]->rect);
1398  else
1399  simList[i]->getRoi(width,height,cam,simList[i]->ptClipped,simList[i]->rect);
1400 
1401  if (topFinal > simList[i]->rect.getTop()) topFinal = simList[i]->rect.getTop();
1402  if (bottomFinal < simList[i]->rect.getBottom()) bottomFinal = simList[i]->rect.getBottom();
1403  if (leftFinal > simList[i]->rect.getLeft()) leftFinal = simList[i]->rect.getLeft();
1404  if (rightFinal < simList[i]->rect.getRight()) rightFinal = simList[i]->rect.getRight();
1405  }
1406 
1407  double zmin = -1;
1408  int indice = -1;
1409  vpRGBa *bitmap = I.bitmap;
1410  vpImagePoint ip;
1411 
1412  for (unsigned int i = (unsigned int)topFinal; i < (unsigned int)bottomFinal; i++)
1413  {
1414  for (unsigned int j = (unsigned int)leftFinal; j < (unsigned int)rightFinal; j++)
1415  {
1416  zmin = -1;
1417  double x=0,y=0;
1418  ip.set_ij(i,j);
1420  ip.set_ij(y,x);
1421  for (int k = 0; k < (int)nbsimList; k++)
1422  {
1423  double z = 0;
1424  if(simList[k]->getPixelDepth(ip,z))
1425  {
1426  if (z < zmin || zmin < 0)
1427  {
1428  zmin = z;
1429  indice = k;
1430  }
1431  }
1432  }
1433  if (indice >= 0)
1434  {
1435  if (simList[indice]->colorI == GRAY_SCALED)
1436  {
1437  unsigned char Ipixelplan = 255;
1438  simList[indice]->getPixel(ip,Ipixelplan);
1439  vpRGBa pixelcolor;
1440  pixelcolor.R = Ipixelplan;
1441  pixelcolor.G = Ipixelplan;
1442  pixelcolor.B = Ipixelplan;
1443  *(bitmap+i*width+j) = pixelcolor;
1444  }
1445  else if (simList[indice]->colorI == COLORED)
1446  {
1447  vpRGBa Ipixelplan(255,255,255);
1448  simList[indice]->getPixel(ip,Ipixelplan);
1449  //unsigned char pixelgrey = 0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B;
1450  *(bitmap+i*width+j)=Ipixelplan;
1451  }
1452  }
1453  }
1454  }
1455 
1456  delete[] simList;
1457 }
1458 
1464 void
1466 {
1467  cMt = cMt_;
1468  vpRotationMatrix R;
1469  cMt.extract(R);
1470  needClipping = false;
1471 
1472  normal_Cam = R * normal_obj;
1473 
1474  visible_result = vpColVector::dotProd(normal_Cam,focal);
1475 
1476  for(unsigned int i = 0; i < 4; i++)
1477  pt[i].track(cMt);
1478 
1479  vpColVector e1(3) ;
1480  vpColVector e2(3) ;
1481  vpColVector facenormal(3) ;
1482 
1483  e1[0] = pt[1].get_X() - pt[0].get_X() ;
1484  e1[1] = pt[1].get_Y() - pt[0].get_Y() ;
1485  e1[2] = pt[1].get_Z() - pt[0].get_Z() ;
1486 
1487  e2[0] = pt[2].get_X() - pt[1].get_X() ;
1488  e2[1] = pt[2].get_Y() - pt[1].get_Y() ;
1489  e2[2] = pt[2].get_Z() - pt[1].get_Z() ;
1490 
1491  facenormal = vpColVector::crossProd(e1,e2) ;
1492 
1493  double angle = pt[0].get_X()*facenormal[0] + pt[0].get_Y()*facenormal[1] + pt[0].get_Z()*facenormal[2] ;
1494 
1495  if (angle > 0){
1496  visible=true;
1497  }
1498  else {
1499  visible=false;
1500  }
1501 
1502  if(visible)
1503  {
1504  for(unsigned int i = 0; i < 4; i++)
1505  {
1506  project(X[i],cMt,X2[i]);
1507  pt[i].track(cMt);
1508  if(pt[i].get_Z() < 0)
1509  needClipping = true;
1510  }
1511 
1512  vbase_u = X2[1]-X2[0];
1513  vbase_v = X2[3]-X2[0];
1514 
1515  distance = vpColVector::dotProd(normal_Cam,X2[1]);
1516 
1517 
1518  if(distance < 0)
1519  {
1520  visible = false;
1521  return;
1522  }
1523 
1524  for(unsigned int i = 0; i < 3; i++)
1525  {
1526  normal_Cam_optim[i] = normal_Cam[i];
1527  X0_2_optim[i] = X2[0][i];
1528  vbase_u_optim[i] = vbase_u[i];
1529  vbase_v_optim[i] = vbase_v[i];
1530  }
1531 
1532  std::vector<vpPoint> *ptPtr = &pt;
1533  if(needClipping){
1535  ptPtr = &ptClipped;
1536  }
1537 
1538  listTriangle.clear();
1539  for(unsigned int i = 1 ; i < (*ptPtr).size()-1 ; i++){
1540  vpImagePoint ip1, ip2, ip3;
1541  ip1.set_j((*ptPtr)[0].get_x());
1542  ip1.set_i((*ptPtr)[0].get_y());
1543 
1544  ip2.set_j((*ptPtr)[i].get_x());
1545  ip2.set_i((*ptPtr)[i].get_y());
1546 
1547  ip3.set_j((*ptPtr)[i+1].get_x());
1548  ip3.set_i((*ptPtr)[i+1].get_y());
1549 
1550  vpTriangle tri(ip1,ip2,ip3);
1551  listTriangle.push_back(tri);
1552  }
1553  }
1554 }
1555 
1556 void
1557 vpImageSimulator::initPlan(vpColVector* X_)
1558 {
1559  for (unsigned int i = 0; i < 4; i++)
1560  {
1561  X[i]=X_[i];
1562  pt[i].setWorldCoordinates(X_[i][0],X_[i][1],X_[i][2]);
1563  }
1564 
1565  normal_obj=vpColVector::crossProd(X[1]-X[0],X[3]-X[0]);
1566  normal_obj=normal_obj/normal_obj.euclideanNorm();
1567 
1568  euclideanNorm_u=(X[1]-X[0]).euclideanNorm();
1569  euclideanNorm_v=(X[3]-X[0]).euclideanNorm();
1570 }
1571 
1585 void
1587 {
1588  Ig = I;
1590  initPlan(X_);
1591 }
1592 
1606 void
1608 {
1609  Ic = I;
1611  initPlan(X_);
1612 }
1613 
1627 void
1628 vpImageSimulator::init(const char* file_image,vpColVector* X_)
1629 {
1630  vpImageIo::read(Ig,file_image);
1631  vpImageIo::read(Ic,file_image);
1632  initPlan(X_);
1633 }
1634 
1649 void
1650 vpImageSimulator::init(const vpImage<unsigned char> &I, const std::vector<vpPoint>& X_)
1651 {
1652  if(X_.size() != 4){
1653  throw vpException(vpException::dimensionError, "the vector must contains 4 points to initialise the simulator");
1654  }
1655  vpColVector Xvec[4];
1656  for(unsigned int i=0; i<4; ++i){
1657  Xvec[i].resize(3);
1658  Xvec[i][0] = X_[i].get_oX();
1659  Xvec[i][1] = X_[i].get_oY();
1660  Xvec[i][2] = X_[i].get_oZ();
1661  }
1662 
1663  Ig = I;
1665  initPlan(Xvec);
1666 }
1681 void
1682 vpImageSimulator::init(const vpImage<vpRGBa> &I, const std::vector<vpPoint>& X_)
1683 {
1684  if(X_.size() != 4){
1685  throw vpException(vpException::dimensionError, "the vector must contains 4 points to initialise the simulator");
1686  }
1687  vpColVector Xvec[4];
1688  for(unsigned int i=0; i<4; ++i){
1689  Xvec[i].resize(3);
1690  Xvec[i][0] = X_[i].get_oX();
1691  Xvec[i][1] = X_[i].get_oY();
1692  Xvec[i][2] = X_[i].get_oZ();
1693  }
1694 
1695  Ic = I;
1697  initPlan(Xvec);
1698 }
1713 void
1714 vpImageSimulator::init(const char* file_image, const std::vector<vpPoint>& X_)
1715 {
1716  if(X_.size() != 4){
1717  throw vpException(vpException::dimensionError, "the vector must contains 4 points to initialise the simulator");
1718  }
1719  vpColVector Xvec[4];
1720  for(unsigned int i=0; i<4; ++i){
1721  Xvec[i].resize(3);
1722  Xvec[i][0] = X_[i].get_oX();
1723  Xvec[i][1] = X_[i].get_oY();
1724  Xvec[i][2] = X_[i].get_oZ();
1725  }
1726 
1727  vpImageIo::read(Ig,file_image);
1728  vpImageIo::read(Ic,file_image);
1729  initPlan(Xvec);
1730 }
1731 
1732 bool
1733 vpImageSimulator::getPixel(const vpImagePoint &iP, unsigned char &Ipixelplan)
1734 {
1735 // std::cout << "In get Pixel" << std::endl;
1736  //test si pixel dans zone projetee
1737  bool inside = false;
1738  for(unsigned int i = 0 ; i < listTriangle.size() ; i++)
1739  if(listTriangle[i].inTriangle(iP)){
1740  inside = true;
1741  break;
1742  }
1743  if(!inside) return false;
1744 
1745 // if(!T1.inTriangle(iP) && !T2.inTriangle(iP)){
1747 // return false;}
1748 
1749  //methoed algebrique
1750  double z;
1751 
1752  //calcul de la profondeur de l'intersection
1753  z = distance/(normal_Cam_optim[0]*iP.get_u()+normal_Cam_optim[1]*iP.get_v()+normal_Cam_optim[2]);
1754  //calcul coordonnees 3D intersection
1755  Xinter_optim[0]=iP.get_u()*z;
1756  Xinter_optim[1]=iP.get_v()*z;
1757  Xinter_optim[2]=z;
1758 
1759  //recuperation des coordonnes de l'intersection dans le plan objet
1760  //repere plan object :
1761  // centre = X0_2_optim[i] (premier point definissant le plan)
1762  // base = u:(X[1]-X[0]) et v:(X[3]-X[0])
1763  //ici j'ai considere que le plan est un rectangle => coordonnees sont simplement obtenu par un produit scalaire
1764  double u = 0, v = 0;
1765  double diff = 0;
1766  for(unsigned int i = 0; i < 3; i++)
1767  {
1768  diff = (Xinter_optim[i]-X0_2_optim[i]);
1769  u += diff*vbase_u_optim[i];
1770  v += diff*vbase_v_optim[i];
1771  }
1772  u = u/(euclideanNorm_u*euclideanNorm_u);
1773  v = v/(euclideanNorm_v*euclideanNorm_v);
1774 
1775  if( u > 0 && v > 0 && u < 1. && v < 1.)
1776  {
1777  double i2,j2;
1778  i2=v*(Ig.getHeight()-1);
1779  j2=u*(Ig.getWidth()-1);
1780  if (interp == BILINEAR_INTERPOLATION)
1781  Ipixelplan = Ig.getValue(i2,j2);
1782  else if (interp == SIMPLE)
1783  Ipixelplan = Ig[(unsigned int)i2][(unsigned int)j2];
1784  return true;
1785  }
1786  else
1787  return false;
1788 }
1789 
1790 bool
1791 vpImageSimulator::getPixel(vpImage<unsigned char> &Isrc,
1792  const vpImagePoint &iP, unsigned char &Ipixelplan)
1793 {
1794  //test si pixel dans zone projetee
1795  bool inside = false;
1796  for(unsigned int i = 0 ; i < listTriangle.size() ; i++)
1797  if(listTriangle[i].inTriangle(iP)){
1798  inside = true;
1799  break;
1800  }
1801  if(!inside) return false;
1802 
1803 // if(!T1.inTriangle(iP) && !T2.inTriangle(iP))
1804 // return false;
1805 
1806  //methoed algebrique
1807  double z;
1808 
1809  //calcul de la profondeur de l'intersection
1810  z = distance/(normal_Cam_optim[0]*iP.get_u()+normal_Cam_optim[1]*iP.get_v()+normal_Cam_optim[2]);
1811  //calcul coordonnees 3D intersection
1812  Xinter_optim[0]=iP.get_u()*z;
1813  Xinter_optim[1]=iP.get_v()*z;
1814  Xinter_optim[2]=z;
1815 
1816  //recuperation des coordonnes de l'intersection dans le plan objet
1817  //repere plan object :
1818  // centre = X0_2_optim[i] (premier point definissant le plan)
1819  // base = u:(X[1]-X[0]) et v:(X[3]-X[0])
1820  //ici j'ai considere que le plan est un rectangle => coordonnees sont simplement obtenu par un produit scalaire
1821  double u = 0, v = 0;
1822  double diff = 0;
1823  for(unsigned int i = 0; i < 3; i++)
1824  {
1825  diff = (Xinter_optim[i]-X0_2_optim[i]);
1826  u += diff*vbase_u_optim[i];
1827  v += diff*vbase_v_optim[i];
1828  }
1829  u = u/(euclideanNorm_u*euclideanNorm_u);
1830  v = v/(euclideanNorm_v*euclideanNorm_v);
1831 
1832  if( u > 0 && v > 0 && u < 1. && v < 1.)
1833  {
1834  double i2,j2;
1835  i2=v*(Isrc.getHeight()-1);
1836  j2=u*(Isrc.getWidth()-1);
1837  if (interp == BILINEAR_INTERPOLATION)
1838  Ipixelplan = Isrc.getValue(i2,j2);
1839  else if (interp == SIMPLE)
1840  Ipixelplan = Isrc[(unsigned int)i2][(unsigned int)j2];
1841  return true;
1842  }
1843  else
1844  return false;
1845 }
1846 
1847 
1848 bool
1849 vpImageSimulator::getPixel(const vpImagePoint &iP, vpRGBa &Ipixelplan)
1850 {
1851  //test si pixel dans zone projetee
1852  bool inside = false;
1853  for(unsigned int i = 0 ; i < listTriangle.size() ; i++)
1854  if(listTriangle[i].inTriangle(iP)){
1855  inside = true;
1856  break;
1857  }
1858  if(!inside) return false;
1859 // if(!T1.inTriangle(iP) && !T2.inTriangle(iP))
1860 // return false;
1861 
1862  //methoed algebrique
1863  double z;
1864 
1865  //calcul de la profondeur de l'intersection
1866  z = distance/(normal_Cam_optim[0]*iP.get_u()+normal_Cam_optim[1]*iP.get_v()+normal_Cam_optim[2]);
1867  //calcul coordonnees 3D intersection
1868  Xinter_optim[0]=iP.get_u()*z;
1869  Xinter_optim[1]=iP.get_v()*z;
1870  Xinter_optim[2]=z;
1871 
1872  //recuperation des coordonnes de l'intersection dans le plan objet
1873  //repere plan object :
1874  // centre = X0_2_optim[i] (premier point definissant le plan)
1875  // base = u:(X[1]-X[0]) et v:(X[3]-X[0])
1876  //ici j'ai considere que le plan est un rectangle => coordonnees sont simplement obtenu par un produit scalaire
1877  double u = 0, v = 0;
1878  double diff = 0;
1879  for(unsigned int i = 0; i < 3; i++)
1880  {
1881  diff = (Xinter_optim[i]-X0_2_optim[i]);
1882  u += diff*vbase_u_optim[i];
1883  v += diff*vbase_v_optim[i];
1884  }
1885  u = u/(euclideanNorm_u*euclideanNorm_u);
1886  v = v/(euclideanNorm_v*euclideanNorm_v);
1887 
1888  if( u > 0 && v > 0 && u < 1. && v < 1.)
1889  {
1890  double i2,j2;
1891  i2=v*(Ic.getHeight()-1);
1892  j2=u*(Ic.getWidth()-1);
1893  if (interp == BILINEAR_INTERPOLATION)
1894  Ipixelplan = Ic.getValue(i2,j2);
1895  else if (interp == SIMPLE)
1896  Ipixelplan = Ic[(unsigned int)i2][(unsigned int)j2];
1897  return true;
1898  }
1899  else
1900  return false;
1901 }
1902 
1903 bool
1904 vpImageSimulator::getPixel(vpImage<vpRGBa> &Isrc, const vpImagePoint &iP,
1905  vpRGBa &Ipixelplan)
1906 {
1907  //test si pixel dans zone projetee
1908 // if(!T1.inTriangle(iP) && !T2.inTriangle(iP))
1909 // return false;
1910  bool inside = false;
1911  for(unsigned int i = 0 ; i < listTriangle.size() ; i++)
1912  if(listTriangle[i].inTriangle(iP)){
1913  inside = true;
1914  break;
1915  }
1916  if(!inside) return false;
1917 
1918  //methoed algebrique
1919  double z;
1920 
1921  //calcul de la profondeur de l'intersection
1922  z = distance/(normal_Cam_optim[0]*iP.get_u()+normal_Cam_optim[1]*iP.get_v()+normal_Cam_optim[2]);
1923  //calcul coordonnees 3D intersection
1924  Xinter_optim[0]=iP.get_u()*z;
1925  Xinter_optim[1]=iP.get_v()*z;
1926  Xinter_optim[2]=z;
1927 
1928  //recuperation des coordonnes de l'intersection dans le plan objet
1929  //repere plan object :
1930  // centre = X0_2_optim[i] (premier point definissant le plan)
1931  // base = u:(X[1]-X[0]) et v:(X[3]-X[0])
1932  //ici j'ai considere que le plan est un rectangle => coordonnees sont simplement obtenu par un produit scalaire
1933  double u = 0, v = 0;
1934  double diff = 0;
1935  for(unsigned int i = 0; i < 3; i++)
1936  {
1937  diff = (Xinter_optim[i]-X0_2_optim[i]);
1938  u += diff*vbase_u_optim[i];
1939  v += diff*vbase_v_optim[i];
1940  }
1941  u = u/(euclideanNorm_u*euclideanNorm_u);
1942  v = v/(euclideanNorm_v*euclideanNorm_v);
1943 
1944  if( u > 0 && v > 0 && u < 1. && v < 1.)
1945  {
1946  double i2,j2;
1947  i2=v*(Isrc.getHeight()-1);
1948  j2=u*(Isrc.getWidth()-1);
1949  if (interp == BILINEAR_INTERPOLATION)
1950  Ipixelplan = Isrc.getValue(i2,j2);
1951  else if (interp == SIMPLE)
1952  Ipixelplan = Isrc[(unsigned int)i2][(unsigned int)j2];
1953  return true;
1954  }
1955  else
1956  return false;
1957 }
1958 
1959 bool
1960 vpImageSimulator::getPixelDepth(const vpImagePoint &iP, double &Zpixelplan)
1961 {
1962  //test si pixel dans zone projetee
1963  bool inside = false;
1964  for(unsigned int i = 0 ; i < listTriangle.size() ; i++)
1965  if(listTriangle[i].inTriangle(iP)){
1966  inside = true;
1967  break;
1968  }
1969  if(!inside) return false;
1970 // if(!T1.inTriangle(iP) && !T2.inTriangle(iP))
1971 // return false;
1972 
1973  Zpixelplan = distance/(normal_Cam_optim[0]*iP.get_u()+normal_Cam_optim[1]*iP.get_v()+normal_Cam_optim[2]);
1974  return true;
1975 }
1976 
1977 bool
1978 vpImageSimulator::getPixelVisibility(const vpImagePoint &iP,
1979  double &Visipixelplan)
1980 {
1981  //test si pixel dans zone projetee
1982  bool inside = false;
1983  for(unsigned int i = 0 ; i < listTriangle.size() ; i++)
1984  if(listTriangle[i].inTriangle(iP)){
1985  inside = true;
1986  break;
1987  }
1988  if(!inside) return false;
1989 // if(!T1.inTriangle(iP) && !T2.inTriangle(iP))
1990 // return false;
1991 
1992  Visipixelplan = visible_result;
1993  return true;
1994 }
1995 
1996 void
1997 vpImageSimulator::project(const vpColVector &_vin,
1998  const vpHomogeneousMatrix &_cMt, vpColVector &_vout)
1999 {
2000  vpColVector XH(4);
2001  getHomogCoord(_vin,XH);
2002  getCoordFromHomog(_cMt*XH,_vout);
2003 }
2004 
2005 void
2006 vpImageSimulator::getHomogCoord(const vpColVector &_v, vpColVector &_vH)
2007 {
2008  for(unsigned int i=0;i<3;i++)
2009  _vH[i]=_v[i];
2010  _vH[3]=1.;
2011 }
2012 
2013 void
2014 vpImageSimulator::getCoordFromHomog(const vpColVector &_vH, vpColVector &_v)
2015 {
2016  for(unsigned int i=0;i<3;i++)
2017  _v[i]=_vH[i]/_vH[3];
2018 }
2019 
2020 
2021 void
2022 vpImageSimulator::getRoi(const unsigned int &Iwidth,
2023  const unsigned int &Iheight,
2024  const vpCameraParameters &cam,
2025  const std::vector<vpPoint> &point,
2026  vpRect &rectangle)
2027 {
2028  double top = Iheight+1;
2029  double bottom = -1;
2030  double right = -1;
2031  double left= Iwidth+1;
2032 
2033  for( unsigned int i = 0; i < point.size(); i++)
2034  {
2035  double u=0,v=0;
2036  vpMeterPixelConversion::convertPoint(cam,point[i].get_x(),point[i].get_y(),u,v);
2037  if (v < top) top = v;
2038  if (v > bottom) bottom = v;
2039  if (u < left) left = u;
2040  if (u > right) right = u;
2041  }
2042  if (top < 0) top = 0;
2043  if(top >= Iheight) top = Iheight-1;
2044  if (bottom < 0) bottom = 0;
2045  if(bottom >= Iheight) bottom = Iheight-1;
2046  if(left < 0) left = 0;
2047  if(left >= Iwidth) left = Iwidth-1;
2048  if(right < 0) right = 0;
2049  if(right >= Iwidth) right = Iwidth-1;
2050 
2051  rectangle.setTop(top);
2052  rectangle.setBottom(bottom);
2053  rectangle.setLeft(left);
2054  rectangle.setRight(right);
2055 }
2056 
2057 std::vector<vpColVector>
2059 {
2060  std::vector<vpColVector> X_;
2061  for (int i=0; i<4; i++)
2062  X_.push_back(X[i]);
2063  return X_;
2064 }
2065 
2066 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImageSimulator& /*ip*/)
2067 {
2068  os << "";
2069  return os;
2070 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
double getTop() const
Definition: vpRect.h:180
double get_v() const
Definition: vpImagePoint.h:264
unsigned int nbElements(void)
return the number of element in the list
Definition: vpList.h:259
void init(const vpImage< unsigned char > &I, vpColVector *X)
unsigned int getWidth() const
Definition: vpImage.h:161
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
unsigned char B
Blue component.
Definition: vpRGBa.h:148
Provide simple list management.
Definition: vpList.h:113
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
void setLeft(double pos)
Definition: vpRect.h:246
static void getClippedPolygon(const std::vector< vpPoint > &ptIn, std::vector< vpPoint > &ptOut, const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags, const vpCameraParameters &cam=vpCameraParameters(), const double &znear=0.001, const double &zfar=100)
double get_u() const
Definition: vpImagePoint.h:253
Defines a 2D triangle.
Definition: vpTriangle.h:58
error that can be emited by ViSP classes.
Definition: vpException.h:76
Type getValue(double i, double j) const
Definition: vpImage.h:1068
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...
unsigned char G
Green component.
Definition: vpRGBa.h:147
double getRight() const
Definition: vpRect.h:167
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
void next(void)
position the current element on the next one
Definition: vpList.h:273
The vpRotationMatrix considers the particular case of a rotation matrix.
double getBottom() const
Definition: vpRect.h:103
void set_i(const double ii)
Definition: vpImagePoint.h:159
void setTop(double pos)
Definition: vpRect.h:280
void setCameraPosition(const vpHomogeneousMatrix &cMt)
void front(void)
Position the current element on the first element of the list.
Definition: vpList.h:384
type & value(void)
return the value of the current element
Definition: vpList.h:301
vpImageSimulator & operator=(const vpImageSimulator &sim)
Generic class defining intrinsic camera parameters.
Class which enables to project an image in the 3D space and get the view of a virtual camera...
void extract(vpRotationMatrix &R) const
vpImageSimulator(const vpColorPlan &col=COLORED)
void set_j(const double jj)
Definition: vpImagePoint.h:170
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
void setRight(double pos)
Definition: vpRect.h:271
std::vector< vpColVector > get3DcornersTextureRectangle()
double euclideanNorm() const
Definition: vpMatrix.cpp:3168
unsigned char R
Red component.
Definition: vpRGBa.h:146
unsigned int getCols() const
Return the number of columns of the matrix.
Definition: vpMatrix.h:163
static double dotProd(const vpColVector &a, const vpColVector &b)
Dot Product.
error that can be emited by the vpMatrix class and its derivates
unsigned int getHeight() const
Definition: vpImage.h:152
Defines a rectangle in the plane.
Definition: vpRect.h:85
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
Compute the cross product of two vectors C = a x b.
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:278
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161
double getLeft() const
Definition: vpRect.h:161
void setBottom(double pos)
Definition: vpRect.h:217
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:181
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:98