ViSP  2.6.2
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 - 2012 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  vpColor bgColor;
200 
201  vpColVector focal;
202 
203  public:
204  vpImageSimulator(const vpColorPlan &col = COLORED);
205  vpImageSimulator(const vpImageSimulator &text);
206  virtual ~vpImageSimulator();
207 
208  vpImageSimulator& operator=(const vpImageSimulator& sim);
209 
210 
211  //creation du plan a partir de ses coordonnees 3D ds repere objet et de son image texture
212  void init(const vpImage<unsigned char> &I,vpColVector* _X);
213  void init(const vpImage<vpRGBa> &I,vpColVector* _X);
214  void init(const char* file_image,vpColVector* _X);
215  void init(const vpImage<unsigned char> &I, const std::vector<vpPoint>& _X);
216  void init(const vpImage<vpRGBa> &I, const std::vector<vpPoint>& _X);
217  void init(const char* file_image, const std::vector<vpPoint>& _X);
218 
219  //projection du plan par cMo => creation des deux triangles definissant projection du plan sur plan image (coord en metre)
220  void setCameraPosition(const vpHomogeneousMatrix &_cMt);
221 
222  void setInterpolationType (const vpInterpolationType interp) {this->interp = interp;}
223 
224  void getImage(vpImage<unsigned char> &I, const vpCameraParameters &cam);
225  void getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam);
226 
227  void getImage(vpImage<unsigned char> &I, vpImage<unsigned char> &Isrc,
228  const vpCameraParameters &cam);
229  void getImage(vpImage<vpRGBa> &I, vpImage<vpRGBa> &Isrc,
230  const vpCameraParameters &cam);
231 
232  void getImage(vpImage<unsigned char> &I, const vpCameraParameters &cam,
233  vpMatrix &zBuffer);
234  void getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam,
235  vpMatrix &zBuffer);
236 
237  static void getImage(vpImage<unsigned char> &I,
238  std::list<vpImageSimulator> &list,
239  const vpCameraParameters &cam);
240  static void getImage(vpImage<vpRGBa> &I,
241  std::list <vpImageSimulator> &list,
242  const vpCameraParameters &cam);
243 
252  void setCleanPreviousImage(const bool &clean, const vpColor &color = vpColor::white) {
253  cleanPrevImage = clean;
254  bgColor = color;
255  }
256 
257 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
258 
261  vp_deprecated static void getImage(vpImage<unsigned char> &I,
263  const vpCameraParameters &cam);
264  vp_deprecated static void getImage(vpImage<vpRGBa> &I, vpList<vpImageSimulator> &list,
265  const vpCameraParameters &cam);
266 #endif
267 
268  private:
269  void initPlan(vpColVector* _X);
270 
271  //result = plan est visible.
272  //ie: un plan est oriente dans si normal_plan.focal < 0 => plan est visible sinon invisible.
273  bool isVisible() {return visible;};
274 
275  //function that project a point x,y on the plane, return true if the projection is on the limited plane
276  // and in this case return the corresponding image pixel Ipixelplan
277  bool getPixel(const vpImagePoint &iP,unsigned char &Ipixelplan);
278  bool getPixel(const vpImagePoint &iP,vpRGBa &Ipixelplan);
279  bool getPixel(vpImage<unsigned char> &Isrc, const vpImagePoint &iP,
280  unsigned char &Ipixelplan);
281  bool getPixel(vpImage<vpRGBa> &Isrc, const vpImagePoint &iP,
282  vpRGBa &Ipixelplan);
283  bool getPixelDepth(const vpImagePoint &iP, double &Zpixelplan);
284  bool getPixelVisibility(const vpImagePoint &iP, double &Zpixelplan);
285 
286  //operation 3D de base :
287  void project(const vpColVector &_vin, const vpHomogeneousMatrix &_cMt,
288  vpColVector &_vout);
289  //donne coordonnes homogenes de _v;
290  void getHomogCoord(const vpColVector &_v, vpColVector &_vH);
291  //donne coordonnes _v en fction coord homogenes _vH;
292  void getCoordFromHomog(const vpColVector &_vH, vpColVector &_v);
293 
294  void getRoi(const unsigned int &Iwidth, const unsigned int &Iheight,
295  const vpCameraParameters &cam, vpPoint* pt, vpRect &rect);
296 };
297 
298 VISP_EXPORT inline std::ostream& operator<< (std::ostream &os, const vpImageSimulator& /*ip*/)
299 {
300  os << "";
301  return os;
302 }
303 
304 
305 #endif
306 
307 /*
308  * Local variables:
309  * c-basic-offset: 2
310  * End:
311  */
312 
313 
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:123
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
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:160