Visual Servoing Platform  version 3.0.0
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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  * Wire frame simulator
32  *
33  * Authors:
34  * Nicolas Melchior
35  *
36  *****************************************************************************/
37 
38 
39 #ifndef vpWireFrameSimulator_HH
40 #define vpWireFrameSimulator_HH
41 
46 #include <visp3/core/vpConfig.h>
47 #include <stdio.h>
48 #include <iostream>
49 #include <cmath> // std::fabs
50 #include <limits> // numeric_limits
51 #include <list>
52 #include <string>
53 
54 #include <visp3/robot/vpMy.h>
55 #include <visp3/robot/vpArit.h>
56 #include <visp3/robot/vpBound.h>
57 #include <visp3/robot/vpView.h>
58 #include <visp3/robot/vpToken.h>
59 #include <visp3/robot/vpTmstack.h>
60 #include <visp3/robot/vpVwstack.h>
61 #include <visp3/robot/vpRfstack.h>
62 #include <visp3/robot/vpArit.h>
63 
64 void open_display();
65 void close_display();
66 void open_clipping();
67 void close_clipping();
68 void open_keyword (Keyword *kwp);
69 void open_lex (void);
70 void open_source (FILE *fd, const char *str);
71 void malloc_Bound_scene (Bound_scene *bsp, const char *name,Index bn);
72 void free_Bound_scene (Bound_scene *bsp);
73 void parser (Bound_scene *bsp);
74 void close_source (void);
75 void close_lex (void);
76 void close_keyword (void);
77 void display_scene(Matrix mat, Bound_scene sc);
78 void View_to_Matrix (View_parameters *vp, Matrix m);
79 Bound *clipping_Bound (Bound *bp, Matrix m);
80 void set_Bound_face_display (Bound *bp, Byte b);
81 void point_3D_2D (Point3f *p3, Index size, int xsize, int ysize, Point2i *p2);
82 void wireframe_Face (Face *fp, Point2i *pp);
83 
84 #include <visp3/core/vpConfig.h>
85 #include <visp3/core/vpImage.h>
86 #include <visp3/core/vpHomogeneousMatrix.h>
87 #include <visp3/core/vpDisplay.h>
88 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
89 # include <visp3/core/vpList.h>
90 #endif
91 #include <visp3/core/vpImagePoint.h>
92 #include <visp3/robot/vpImageSimulator.h>
93 
94 void set_scene (const char*, Bound_scene *, float);
95 void vp2jlc_matrix (const vpHomogeneousMatrix, Matrix&);
96 
97 
175 class VISP_EXPORT vpWireFrameSimulator
176 {
177 public:
178 
182  typedef enum
183  {
201  } vpSceneObject;
202 
209  typedef enum
210  {
213  D_TOOL
214  } vpSceneDesiredObject;
215 
216  typedef enum
217  {
219  CT_POINT
220  } vpCameraTrajectoryDisplayType;
221 
222 protected:
223  Bound_scene scene;
224  Bound_scene desiredScene;
225  Bound_scene camera;
226  std::list<vpImageSimulator> objectImage;
227 
234 
237 
242 
244 
246  std::list<vpImagePoint> cameraTrajectory;
247  std::list<vpHomogeneousMatrix> poseList;
248  std::list<vpHomogeneousMatrix> fMoList;
249  unsigned int nbrPtLimit;
250 
254  bool blockedr;
255  bool blockedz;
256  bool blockedt;
257  bool blocked;
258 
261 
262  double px_int;
263  double py_int;
264  double px_ext;
265  double py_ext;
266 
271 
273 
275 
277 
279 
280  unsigned int thickness_;
281 
282 private:
283  std::string scene_dir;
284 
285 public:
287  virtual ~vpWireFrameSimulator();
288 
293  cameraTrajectory.clear();
294  poseList.clear();
295  fMoList.clear();}
296 
297  void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
298  void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
299 
308  //if(px_ext != 1 && py_ext != 1)
309  // we assume px_ext and py_ext > 0
310  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
311  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
312  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
313  else
314  {
315  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
316  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
317  }
318  }
327  //if(px_ext != 1 && py_ext != 1)
328  // we assume px_ext and py_ext > 0
329  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
330  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
331  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
332  else
333  {
334  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
335  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
336  }
337  }
343  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf;}
344 
345  void getExternalImage(vpImage<unsigned char> &I);
346  void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
347  void getExternalImage(vpImage<vpRGBa> &I);
348  void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
349 
358  //if(px_int != 1 && py_int != 1)
359  // we assume px_int and py_int > 0
360  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
361  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
362  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
363  else
364  {
365  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
366  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
367  }
368  }
377  //if(px_int != 1 && py_int != 1)
378  // we assume px_int and py_int > 0
379  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
380  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
381  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
382  else
383  {
384  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
385  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
386  }
387  }
388 
389  void getInternalImage(vpImage<unsigned char> &I);
390  void getInternalImage(vpImage<vpRGBa> &I);
391 
397  vpHomogeneousMatrix get_cMo() const {return rotz*cMo;}
398 
404  void get_cMo_History(std::list<vpHomogeneousMatrix>& cMo_history) {
405  cMo_history.clear();
406  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
407  cMo_history.push_back(rotz*(*it));
408  }
409  }
410 
416  vpHomogeneousMatrix get_fMo() const {return fMo;}
417 
423  void get_fMo_History(std::list<vpHomogeneousMatrix>& fMo_history) {fMo_history = fMoList;}
424 
425  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
426  void initScene(const char* obj, const char* desiredObject);
427  void initScene(const vpSceneObject &obj);
428  void initScene(const char* obj);
429 
430  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject, const std::list<vpImageSimulator> &imObj);
431  void initScene(const char* obj, const char* desiredObject, const std::list<vpImageSimulator> &imObj);
432  void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
433  void initScene(const char* obj, const std::list<vpImageSimulator> &imObj);
434 
440  void setCameraColor(const vpColor &col) {camColor = col;}
446  void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_) {this->cMo = rotz * cMo_; fMc = fMo*this->cMo.inverse();}
447 
453  void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc_) {this->fMc = fMc_*rotz; cMo = this->fMc.inverse()*fMo;}
454 
460  inline void setCameraSizeFactor (const float factor) {cameraFactor = factor;}
461 
467  void setCameraTrajectoryColor(const vpColor &col) {camTrajColor = col;}
468 
474  inline void setCameraTrajectoryDisplayType (const vpCameraTrajectoryDisplayType &camTraj_type) {this->camTrajType = camTraj_type;}
475 
481  void setCurrentViewColor(const vpColor &col) {curColor = col;}
487  void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_) {this->cdMo = rotz * cdMo_;}
493  void setDesiredViewColor(const vpColor &col) {desColor = col;}
501  void setDisplayCameraTrajectory (const bool &do_display) {this->displayCameraTrajectory = do_display;}
502 
509  px_ext = cam.get_px();
510  py_ext = cam.get_py();
511  }
518  {
519  this->camMf = rotz * cam_Mf;
521  this->camMf.extract (T);
522  this->camMf2.buildFrom(0,0,T[2],0,0,0);
523  f2Mf = camMf2.inverse()*this->camMf;
524  extCamChanged = true;
525  }
526 
530  void setGraphicsThickness(unsigned int thickness)
531  {
532  this->thickness_ = thickness;
533  }
534 
541  px_int = cam.get_px();
542  py_int = cam.get_py();
543  }
544 
550  inline void setNbPtTrajectory(const unsigned int nbPt) {nbrPtLimit = nbPt;}
551 
557  void set_fMo(const vpHomogeneousMatrix &fMo_) {this->fMo = fMo_;/*this->cMo = fMc.inverse()*fMo;*/}
558 
559 protected:
560  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
561  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
562  vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
563  vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
564  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
565  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
566  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
567  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
568 };
569 
570 #endif
The object displayed at the desired position is the same than the scene object defined in vpSceneObje...
A cylinder of 80cm length and 10cm radius.
A tire represented by 2 circles with radius 10cm and 15cm.
vpCameraParameters getInternalCameraParameters(const vpImage< vpRGBa > &I) const
unsigned int getWidth() const
Definition: vpImage.h:161
Three parallel lines with equation y=-5, y=0, y=5.
A plane represented by a 56cm by 56cm plate with a grid of 49 squares inside.
Implementation of an homogeneous matrix and operations on such kind of matrices.
A plate with 8 points at coordinates (0.05,0,0), (0.15,0.05,0), (0.2,0.2,0), (-0.05,0.2,0), (-0.15,-0.1,0), (-0.1,-0.1,0), (-0.05,0.05,0) and (0.5,0,0). ach point is represented by a circle with 2cm radius.
void setCameraColor(const vpColor &col)
void setDesiredViewColor(const vpColor &col)
A 40cm by 40cm plate with 4 points at coordinates (-0.1,-0.1,0), (0.1,-0.1,0), (0.1,0.1,0), (0.1,0.1,0). Each point is represented by a circle with 2cm radius.
void set_fMo(const vpHomogeneousMatrix &fMo_)
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void setNbPtTrajectory(const unsigned int nbPt)
void get_cMo_History(std::list< vpHomogeneousMatrix > &cMo_history)
void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc_)
std::list< vpImageSimulator > objectImage
void setCurrentViewColor(const vpColor &col)
std::list< vpImagePoint > cameraTrajectory
vpHomogeneousMatrix cdMo
double get_py() const
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
A 40cm by 40cm plate with 4 points at coordinates (-0.05,0.05,0), (0.05,0.05,0), (0.05,-0.05,0), (-0.05,-0.05,0). Each point is represented by a circle with 2cm radius.
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
vpHomogeneousMatrix fMo
void setGraphicsThickness(unsigned int thickness)
std::list< vpHomogeneousMatrix > fMoList
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:141
void setCameraTrajectoryDisplayType(const vpCameraTrajectoryDisplayType &camTraj_type)
void setCameraTrajectoryColor(const vpColor &col)
4 points at coordinates (-0.03,-0.03,0), (0.03,-0.03,0), (0.03,0.03,0), (0.03,0.03,0). Each point is represented by a circle with 1cm radius.
vpCameraParameters getExternalCameraParameters(const vpImage< unsigned char > &I) const
vpHomogeneousMatrix get_fMo() const
The object displayed at the desired position is a circle.
vpHomogeneousMatrix f2Mf
A 40cm by 40cm plate with 4 points at coordinates (-0.025,-0.05,0), (-0.075,0.05,0), (0.075,0.05,0), (0.025,-0.05,0). Each point is represented by a circle with 2cm radius.
Generic class defining intrinsic camera parameters.
vpHomogeneousMatrix cMo
void extract(vpRotationMatrix &R) const
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:152
A 40cm by 40cm plate with 3 points at coordinates (0,0,0), (0.1,0,0), (0,0.1,0). Each point is repres...
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
double get_px() const
vpCameraParameters getInternalCameraParameters(const vpImage< unsigned char > &I) const
void setExternalCameraParameters(const vpCameraParameters &cam)
vpCameraTrajectoryDisplayType camTrajType
A 40cm by 40cm plate with 4 points at coordinates (-0.07,-0.05,0), (0.07,0.05,0), (0...
vpCameraParameters getExternalCameraParameters(const vpImage< vpRGBa > &I) const
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
vpSceneDesiredObject desiredObject
A 40cm by 40cm plate with 4 points at coordinates (0,-0.1,0), (0.1,0,0), (0,0.1,0), (-0.1,0,0). Each point is represented by a circle with 2cm radius.
vpHomogeneousMatrix camMf
Three parallel lines representing a road.
vpHomogeneousMatrix fMc
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix get_cMo() const
vpHomogeneousMatrix rotz
void setInternalCameraParameters(const vpCameraParameters &cam)
void setDisplayCameraTrajectory(const bool &do_display)
void get_fMo_History(std::list< vpHomogeneousMatrix > &fMo_history)
vpHomogeneousMatrix refMo
A pipe represented by a cylinder of 25 cm length and 15cm radius.
unsigned int getHeight() const
Definition: vpImage.h:152
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
Class that consider the case of a translation vector.
void setCameraSizeFactor(const float factor)
std::list< vpHomogeneousMatrix > poseList
vpHomogeneousMatrix getExternalCameraPosition() const
vpHomogeneousMatrix camMf2