ViSP  2.10.0
vpImageSimulator.h
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 #ifndef vpImageSimulator_h
45 #define vpImageSimulator_h
46 
126 #include <visp/vpHomogeneousMatrix.h>
127 #include <visp/vpColVector.h>
128 #include <visp/vpTriangle.h>
129 #include <visp/vpRect.h>
130 #include <visp/vpImage.h>
131 #include <visp/vpCameraParameters.h>
132 #include <visp/vpPoint.h>
133 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
134 # include <visp/vpList.h>
135 #endif
136 
137 #include <vector>
138 #include <list>
139 
140 class VISP_EXPORT vpImageSimulator
141 {
142  public:
143  typedef enum {
145  GRAY_SCALED
146  } vpColorPlan;
147 
148  typedef enum {
150  BILINEAR_INTERPOLATION
151  } vpInterpolationType;
152 
153  private:
154  vpColVector X[4];
156  vpColVector X2[4];
157  std::vector<vpPoint> pt;
158  std::vector<vpPoint> ptClipped;
159 
160  vpInterpolationType interp;
161 
162  //normal repere objet
163  vpColVector normal_obj;
164  //normal repere cam
165  vpColVector normal_Cam;
166  //normal repere cam sous forme de pointeur sinon vpColVector prend trop de temps
167  double *normal_Cam_optim;
168 
169  //distance du plan au centre de camera
170  double distance;
171  double visible_result;
172  bool visible;
173 
174 
175  //point 3D du plan definissant ou sera le pixel (0,0) de l'image
176  double *X0_2_optim;
177 
178  //variable pour intersection algebre : vecteurs de la base 2D et leur norme
179  double euclideanNorm_u,euclideanNorm_v;
180 
181  //2 vecteur 3D (typiquement deux cotes du plan) qui definissent le repere 2D u,v de l'image
182  vpColVector vbase_u,vbase_v;
183  //version pointeur des vecteurs de base
184  double *vbase_u_optim;
185  double *vbase_v_optim;
186 
187  //allocation memoire du point 3D d'intersection entre le vecteur (centre_cam - point_plan_image) et le plan
188  double *Xinter_optim;
189 
190  //triangles de projection du plan
191  std::vector<vpTriangle> listTriangle;
192 
193  //image de texture
194  vpColorPlan colorI;
196  vpImage<vpRGBa> Ic;
197 
198  vpRect rect;
199  bool cleanPrevImage;
200  bool setBackgroundTexture; // flag set when the background is to a texture using setBackGroundTexture()
201  vpColor bgColor;
202 
203  vpColVector focal;
204 
205  //boolean to tell if the points in the camera frame have to be clipped
206  bool needClipping;
207 
208  public:
209  vpImageSimulator(const vpColorPlan &col = COLORED);
210  vpImageSimulator(const vpImageSimulator &text);
211  virtual ~vpImageSimulator();
212 
213  vpImageSimulator& operator=(const vpImageSimulator& sim);
214 
215 
216  //creation du plan a partir de ses coordonnees 3D ds repere objet et de son image texture
217  void init(const vpImage<unsigned char> &I,vpColVector* X);
218  void init(const vpImage<vpRGBa> &I,vpColVector* X);
219  void init(const char* file_image,vpColVector* X);
220  void init(const vpImage<unsigned char> &I, const std::vector<vpPoint>& X);
221  void init(const vpImage<vpRGBa> &I, const std::vector<vpPoint>& X);
222  void init(const char* file_image, const std::vector<vpPoint>& X);
223 
224  //projection du plan par cMo => creation des deux triangles definissant projection du plan sur plan image (coord en metre)
225  void setCameraPosition(const vpHomogeneousMatrix &cMt);
226 
227  void setInterpolationType (const vpInterpolationType interplt) {this->interp = interplt;}
228 
229  void getImage(vpImage<unsigned char> &I, const vpCameraParameters &cam);
230  void getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam);
231 
232  void getImage(vpImage<unsigned char> &I, vpImage<unsigned char> &Isrc,
233  const vpCameraParameters &cam);
234  void getImage(vpImage<vpRGBa> &I, vpImage<vpRGBa> &Isrc,
235  const vpCameraParameters &cam);
236 
237  void getImage(vpImage<unsigned char> &I, const vpCameraParameters &cam,
238  vpMatrix &zBuffer);
239  void getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam,
240  vpMatrix &zBuffer);
241 
242  static void getImage(vpImage<unsigned char> &I,
243  std::list<vpImageSimulator> &list,
244  const vpCameraParameters &cam);
245  static void getImage(vpImage<vpRGBa> &I,
246  std::list <vpImageSimulator> &list,
247  const vpCameraParameters &cam);
248 
249  std::vector<vpColVector> get3DcornersTextureRectangle();
250 
251  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImageSimulator& /*ip*/);
252 
261  void setCleanPreviousImage(const bool &clean, const vpColor &color = vpColor::white) {
262  cleanPrevImage = clean;
263  bgColor = color;
264  }
265 
271  inline void
273  setBackgroundTexture = true;
274  Ig = Iback;
275  }
276 
277 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
278 
281  vp_deprecated static void getImage(vpImage<unsigned char> &I,
283  const vpCameraParameters &cam);
284  vp_deprecated static void getImage(vpImage<vpRGBa> &I, vpList<vpImageSimulator> &list,
285  const vpCameraParameters &cam);
286 #endif
287 
288  private:
289  void initPlan(vpColVector* X);
290 
291  //result = plan est visible.
292  //ie: un plan est oriente dans si normal_plan.focal < 0 => plan est visible sinon invisible.
293  bool isVisible() {return visible;}
294 
295  //function that project a point x,y on the plane, return true if the projection is on the limited plane
296  // and in this case return the corresponding image pixel Ipixelplan
297  bool getPixel(const vpImagePoint &iP,unsigned char &Ipixelplan);
298  bool getPixel(const vpImagePoint &iP,vpRGBa &Ipixelplan);
299  bool getPixel(vpImage<unsigned char> &Isrc, const vpImagePoint &iP,
300  unsigned char &Ipixelplan);
301  bool getPixel(vpImage<vpRGBa> &Isrc, const vpImagePoint &iP,
302  vpRGBa &Ipixelplan);
303  bool getPixelDepth(const vpImagePoint &iP, double &Zpixelplan);
304  bool getPixelVisibility(const vpImagePoint &iP, double &Zpixelplan);
305 
306  //operation 3D de base :
307  void project(const vpColVector &_vin, const vpHomogeneousMatrix &_cMt,
308  vpColVector &_vout);
309  //donne coordonnes homogenes de _v;
310  void getHomogCoord(const vpColVector &_v, vpColVector &_vH);
311  //donne coordonnes _v en fction coord homogenes _vH;
312  void getCoordFromHomog(const vpColVector &_vH, vpColVector &_v);
313 
314  void getRoi(const unsigned int &Iwidth, const unsigned int &Iheight,
315  const vpCameraParameters &cam, const std::vector<vpPoint> &point, vpRect &rect);
316 };
317 
318 
319 #endif
320 
321 /*
322  * Local variables:
323  * c-basic-offset: 2
324  * End:
325  */
326 
327 
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Provide simple list management.
Definition: vpList.h:113
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
void setInterpolationType(const vpInterpolationType interplt)
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 setBackGroundTexture(const vpImage< unsigned char > &Iback)
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 setCleanPreviousImage(const bool &clean, const vpColor &color=vpColor::white)
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 const vpColor white
Definition: vpColor.h:162