ViSP  2.9.0
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * $Id: vpWireFrameSimulator.h 4649 2014-02-07 14:57:11Z fspindle $
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:
35  * Wire frame simulator
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
42 
43 #ifndef vpWireFrameSimulator_HH
44 #define vpWireFrameSimulator_HH
45 
50 #include <visp/vpConfig.h>
51 #include <stdio.h>
52 #include <iostream>
53 #include <cmath> // std::fabs
54 #include <limits> // numeric_limits
55 #include <list>
56 #include <string>
57 
58 extern "C" {
59 #include <visp/vpMy.h>
60 #include <visp/vpArit.h>
61 #include <visp/vpBound.h>
62 #include <visp/vpView.h>
63 #include <visp/vpToken.h>
64 #include <visp/vpTmstack.h>
65 #include <visp/vpVwstack.h>
66 #include <visp/vpRfstack.h>
67 #include <visp/vpArit.h>
68 
69 int open_display();
70 int close_display();
71 int open_clipping();
72 int close_clipping();
73 int open_keyword (Keyword *kwp);
74 int open_lex (void);
75 int open_source (FILE *fd, const char *str);
76 int malloc_Bound_scene (Bound_scene *bsp, const char *name,Index bn);
77 int free_Bound_scene (Bound_scene *bsp);
78 int parser (Bound_scene *bsp);
79 int close_source (void);
80 int close_lex (void);
81 int close_keyword (void);
82 void display_scene(Matrix mat, Bound_scene sc);
83 int View_to_Matrix (View_parameters *vp, Matrix m);
84 Bound *clipping_Bound (Bound *bp, Matrix m);
85 int set_Bound_face_display (Bound *bp, Byte b);
86 int point_3D_2D (Point3f *p3, Index size, unsigned int xsize, unsigned int ysize, Point2i *p2);
87 int wireframe_Face (Face *fp, Point2i *pp);
88 }
89 
90 #include <visp/vpConfig.h>
91 #include <visp/vpImage.h>
92 #include <visp/vpHomogeneousMatrix.h>
93 #include <visp/vpDisplay.h>
94 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
95 # include <visp/vpList.h>
96 #endif
97 #include <visp/vpImagePoint.h>
98 #include <visp/vpImageSimulator.h>
99 
100 void set_scene (const char*, Bound_scene *, float);
101 void vp2jlc_matrix (const vpHomogeneousMatrix, Matrix&);
102 
103 
181 class VISP_EXPORT vpWireFrameSimulator
182 {
183 public:
184 
188  typedef enum
189  {
207  } vpSceneObject;
208 
215  typedef enum
216  {
219  D_TOOL
220  } vpSceneDesiredObject;
221 
222  typedef enum
223  {
225  CT_POINT
226  } vpCameraTrajectoryDisplayType;
227 
228 protected:
229  Bound_scene scene;
230  Bound_scene desiredScene;
231  Bound_scene camera;
232  std::list<vpImageSimulator> objectImage;
233 
240 
243 
248 
250 
252  std::list<vpImagePoint> cameraTrajectory;
253  std::list<vpHomogeneousMatrix> poseList;
254  std::list<vpHomogeneousMatrix> fMoList;
255  unsigned int nbrPtLimit;
256 
260  bool blockedr;
261  bool blockedz;
262  bool blockedt;
263  bool blocked;
264 
267 
268  double px_int;
269  double py_int;
270  double px_ext;
271  double py_ext;
272 
277 
279 
281 
283 
285 
286  unsigned int thickness_;
287 
288 private:
289  std::string scene_dir;
290 
291 public:
293  virtual ~vpWireFrameSimulator();
294 
299  cameraTrajectory.clear();
300  poseList.clear();
301  fMoList.clear();}
302 
303  void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
304  void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
305 
314  //if(px_ext != 1 && py_ext != 1)
315  // we assume px_ext and py_ext > 0
316  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
317  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
318  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
319  else
320  {
321  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
322  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
323  }
324  }
333  //if(px_ext != 1 && py_ext != 1)
334  // we assume px_ext and py_ext > 0
335  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
336  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
337  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
338  else
339  {
340  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
341  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
342  }
343  }
349  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf;}
350 
351  void getExternalImage(vpImage<unsigned char> &I);
352  void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
353  void getExternalImage(vpImage<vpRGBa> &I);
354  void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
355 
364  //if(px_int != 1 && py_int != 1)
365  // we assume px_int and py_int > 0
366  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
367  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
368  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
369  else
370  {
371  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
372  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
373  }
374  }
383  //if(px_int != 1 && py_int != 1)
384  // we assume px_int and py_int > 0
385  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
386  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
387  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
388  else
389  {
390  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
391  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
392  }
393  }
394 
395  void getInternalImage(vpImage<unsigned char> &I);
396  void getInternalImage(vpImage<vpRGBa> &I);
397 
403  vpHomogeneousMatrix get_cMo() const {return rotz*cMo;}
404 
410  void get_cMo_History(std::list<vpHomogeneousMatrix>& cMo_history) {
411  cMo_history.clear();
412  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
413  cMo_history.push_back(rotz*(*it));
414  }
415  }
416 
422  vpHomogeneousMatrix get_fMo() const {return fMo;}
423 
429  void get_fMo_History(std::list<vpHomogeneousMatrix>& fMo_history) {fMo_history = fMoList;}
430 
431  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
432  void initScene(const char* obj, const char* desiredObject);
433  void initScene(const vpSceneObject &obj);
434  void initScene(const char* obj);
435 
436  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject, const std::list<vpImageSimulator> &imObj);
437  void initScene(const char* obj, const char* desiredObject, const std::list<vpImageSimulator> &imObj);
438  void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
439  void initScene(const char* obj, const std::list<vpImageSimulator> &imObj);
440 
446  void setCameraColor(const vpColor &col) {camColor = col;}
452  void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_) {this->cMo = rotz * cMo_; fMc = fMo*this->cMo.inverse();}
453 
459  void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc_) {this->fMc = fMc_*rotz; cMo = this->fMc.inverse()*fMo;}
460 
466  inline void setCameraSizeFactor (const float factor) {cameraFactor = factor;}
467 
473  void setCameraTrajectoryColor(const vpColor &col) {camTrajColor = col;}
474 
480  inline void setCameraTrajectoryDisplayType (const vpCameraTrajectoryDisplayType &camTraj_type) {this->camTrajType = camTraj_type;}
481 
487  void setCurrentViewColor(const vpColor &col) {curColor = col;}
493  void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_) {this->cdMo = rotz * cdMo_;}
499  void setDesiredViewColor(const vpColor &col) {desColor = col;}
507  void setDisplayCameraTrajectory (const bool &do_display) {this->displayCameraTrajectory = do_display;}
508 
515  px_ext = cam.get_px();
516  py_ext = cam.get_py();
517  }
524  {
525  this->camMf = rotz * cam_Mf;
527  this->camMf.extract (T);
528  this->camMf2.buildFrom(0,0,T[2],0,0,0);
529  f2Mf = camMf2.inverse()*this->camMf;
530  extCamChanged = true;
531  }
532 
536  void setGraphicsThickness(unsigned int thickness)
537  {
538  this->thickness_ = thickness;
539  }
540 
547  px_int = cam.get_px();
548  py_int = cam.get_py();
549  }
550 
556  inline void setNbPtTrajectory(const unsigned int nbPt) {nbrPtLimit = nbPt;}
557 
563  void set_fMo(const vpHomogeneousMatrix &fMo_) {this->fMo = fMo_;/*this->cMo = fMc.inverse()*fMo;*/}
564 
565 protected:
566  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
567  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
568  vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
569  vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
570  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
571  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
572  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
573  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
574 
575 public:
576 
577 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
578 
582  vp_deprecated void displayTrajectory(const vpImage<unsigned char> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
583  vp_deprecated void displayTrajectory(const vpImage<vpRGBa> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
584 
594  vpHomogeneousMatrix tmp_;
595  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
596  tmp_ = (rotz*(*it));
597  list_cMo.addRight(tmp_);
598  }
599  return list_cMo;}
608  vpList<vpHomogeneousMatrix> fMoHistory;
609  for(std::list<vpHomogeneousMatrix>::const_iterator iter = fMoList.begin(); iter != fMoList.end(); ++iter){
610  fMoHistory.addRight(*iter);
611  }
612  return fMoHistory;}
613 
614 
615  vp_deprecated void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject, vpList<vpImageSimulator> &imObj);
616  vp_deprecated void initScene(const char* obj, const char* desiredObject, vpList<vpImageSimulator> &imObj);
617  vp_deprecated void initScene(vpSceneObject obj, vpList<vpImageSimulator> &imObj);
618  vp_deprecated void initScene(const char* obj, vpList<vpImageSimulator> &imObj);
619 
620 #endif
621 };
622 
623 #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:159
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.
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
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:125
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
vp_deprecated vpList< vpHomogeneousMatrix > get_fMo_History()
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:137
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.
void addRight(const type &el)
add a new element in the list, at the right of the current one
Definition: vpList.h:478
vpHomogeneousMatrix cMo
void extract(vpRotationMatrix &R) const
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:148
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)
Construction from translation vector and rotation matrix.
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
vp_deprecated vpList< vpHomogeneousMatrix > get_cMo_History()
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:150
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
Class that consider the case of a translation vector.
void setCameraSizeFactor(const float factor)
std::list< vpHomogeneousMatrix > poseList
vpHomogeneousMatrix getExternalCameraPosition() const
vpHomogeneousMatrix camMf2