ViSP  2.8.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 - 2013 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];
155  vpPoint pt[4];
157  vpColVector X2[4];
158 
159  vpInterpolationType interp;
160 
161  //normal repere objet
162  vpColVector normal_obj;
163  //normal repere cam
164  vpColVector normal_Cam;
165  //normal repere cam sous forme de pointeur sinon vpColVector prend trop de temps
166  double *normal_Cam_optim;
167 
168  //distance du plan au centre de camera
169  double distance;
170  double visible_result;
171  bool visible;
172 
173 
174  //point 3D du plan definissant ou sera le pixel (0,0) de l'image
175  double *X0_2_optim;
176 
177  //variable pour intersection algebre : vecteurs de la base 2D et leur norme
178  double euclideanNorm_u,euclideanNorm_v;
179 
180  //2 vecteur 3D (typiquement deux cotes du plan) qui definissent le repere 2D u,v de l'image
181  vpColVector vbase_u,vbase_v;
182  //version pointeur des vecteurs de base
183  double *vbase_u_optim;
184  double *vbase_v_optim;
185 
186  //allocation memoire du point 3D d'intersection entre le vecteur (centre_cam - point_plan_image) et le plan
187  double *Xinter_optim;
188 
189  //triangles de projection du plan
190  vpTriangle T1,T2;
191 
192  //image de texture
193  vpColorPlan colorI;
195  vpImage<vpRGBa> Ic;
196 
197  vpRect rect;
198  bool cleanPrevImage;
199  bool setBackgroundTexture; // flag set when the background is to a texture using setBackGroundTexture()
200  vpColor bgColor;
201 
202  vpColVector focal;
203 
204  public:
205  vpImageSimulator(const vpColorPlan &col = COLORED);
206  vpImageSimulator(const vpImageSimulator &text);
207  virtual ~vpImageSimulator();
208 
209  vpImageSimulator& operator=(const vpImageSimulator& sim);
210 
211 
212  //creation du plan a partir de ses coordonnees 3D ds repere objet et de son image texture
213  void init(const vpImage<unsigned char> &I,vpColVector* _X);
214  void init(const vpImage<vpRGBa> &I,vpColVector* _X);
215  void init(const char* file_image,vpColVector* _X);
216  void init(const vpImage<unsigned char> &I, const std::vector<vpPoint>& _X);
217  void init(const vpImage<vpRGBa> &I, const std::vector<vpPoint>& _X);
218  void init(const char* file_image, const std::vector<vpPoint>& _X);
219 
220  //projection du plan par cMo => creation des deux triangles definissant projection du plan sur plan image (coord en metre)
221  void setCameraPosition(const vpHomogeneousMatrix &_cMt);
222 
223  void setInterpolationType (const vpInterpolationType interp) {this->interp = interp;}
224 
225  void getImage(vpImage<unsigned char> &I, const vpCameraParameters &cam);
226  void getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam);
227 
228  void getImage(vpImage<unsigned char> &I, vpImage<unsigned char> &Isrc,
229  const vpCameraParameters &cam);
230  void getImage(vpImage<vpRGBa> &I, vpImage<vpRGBa> &Isrc,
231  const vpCameraParameters &cam);
232 
233  void getImage(vpImage<unsigned char> &I, const vpCameraParameters &cam,
234  vpMatrix &zBuffer);
235  void getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam,
236  vpMatrix &zBuffer);
237 
238  static void getImage(vpImage<unsigned char> &I,
239  std::list<vpImageSimulator> &list,
240  const vpCameraParameters &cam);
241  static void getImage(vpImage<vpRGBa> &I,
242  std::list <vpImageSimulator> &list,
243  const vpCameraParameters &cam);
244 
253  void setCleanPreviousImage(const bool &clean, const vpColor &color = vpColor::white) {
254  cleanPrevImage = clean;
255  bgColor = color;
256  }
257 
263  inline void
265  setBackgroundTexture = true;
266  Ig = Iback;
267  }
268 
269 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
270 
273  vp_deprecated static void getImage(vpImage<unsigned char> &I,
275  const vpCameraParameters &cam);
276  vp_deprecated static void getImage(vpImage<vpRGBa> &I, vpList<vpImageSimulator> &list,
277  const vpCameraParameters &cam);
278 #endif
279 
280  private:
281  void initPlan(vpColVector* _X);
282 
283  //result = plan est visible.
284  //ie: un plan est oriente dans si normal_plan.focal < 0 => plan est visible sinon invisible.
285  bool isVisible() {return visible;};
286 
287  //function that project a point x,y on the plane, return true if the projection is on the limited plane
288  // and in this case return the corresponding image pixel Ipixelplan
289  bool getPixel(const vpImagePoint &iP,unsigned char &Ipixelplan);
290  bool getPixel(const vpImagePoint &iP,vpRGBa &Ipixelplan);
291  bool getPixel(vpImage<unsigned char> &Isrc, const vpImagePoint &iP,
292  unsigned char &Ipixelplan);
293  bool getPixel(vpImage<vpRGBa> &Isrc, const vpImagePoint &iP,
294  vpRGBa &Ipixelplan);
295  bool getPixelDepth(const vpImagePoint &iP, double &Zpixelplan);
296  bool getPixelVisibility(const vpImagePoint &iP, double &Zpixelplan);
297 
298  //operation 3D de base :
299  void project(const vpColVector &_vin, const vpHomogeneousMatrix &_cMt,
300  vpColVector &_vout);
301  //donne coordonnes homogenes de _v;
302  void getHomogCoord(const vpColVector &_v, vpColVector &_vH);
303  //donne coordonnes _v en fction coord homogenes _vH;
304  void getCoordFromHomog(const vpColVector &_vH, vpColVector &_v);
305 
306  void getRoi(const unsigned int &Iwidth, const unsigned int &Iheight,
307  const vpCameraParameters &cam, vpPoint* pt, vpRect &rect);
308 };
309 
310 VISP_EXPORT inline std::ostream& operator<< (std::ostream &os, const vpImageSimulator& /*ip*/)
311 {
312  os << "";
313  return os;
314 }
315 
316 
317 #endif
318 
319 /*
320  * Local variables:
321  * c-basic-offset: 2
322  * End:
323  */
324 
325 
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
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:112
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
Defines a 2D triangle.
Definition: vpTriangle.h:58
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
Class that defines what is a point.
Definition: vpPoint.h:65
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 setInterpolationType(const vpInterpolationType interp)
VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
Definition: vpImagePoint.h:529
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:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
static const vpColor white
Definition: vpColor.h:162