ViSP  2.10.0
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * $Id: vpWireFrameSimulator.h 5297 2015-02-10 11:19:24Z 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 #include <visp/vpMy.h>
59 #include <visp/vpArit.h>
60 #include <visp/vpBound.h>
61 #include <visp/vpView.h>
62 #include <visp/vpToken.h>
63 #include <visp/vpTmstack.h>
64 #include <visp/vpVwstack.h>
65 #include <visp/vpRfstack.h>
66 #include <visp/vpArit.h>
67 
68 void open_display();
69 void close_display();
70 void open_clipping();
71 void close_clipping();
72 void open_keyword (Keyword *kwp);
73 void open_lex (void);
74 void open_source (FILE *fd, const char *str);
75 void malloc_Bound_scene (Bound_scene *bsp, const char *name,Index bn);
76 void free_Bound_scene (Bound_scene *bsp);
77 void parser (Bound_scene *bsp);
78 void close_source (void);
79 void close_lex (void);
80 void close_keyword (void);
81 void display_scene(Matrix mat, Bound_scene sc);
82 void View_to_Matrix (View_parameters *vp, Matrix m);
83 Bound *clipping_Bound (Bound *bp, Matrix m);
84 void set_Bound_face_display (Bound *bp, Byte b);
85 void point_3D_2D (Point3f *p3, Index size, int xsize, int ysize, Point2i *p2);
86 void wireframe_Face (Face *fp, Point2i *pp);
87 
88 #include <visp/vpConfig.h>
89 #include <visp/vpImage.h>
90 #include <visp/vpHomogeneousMatrix.h>
91 #include <visp/vpDisplay.h>
92 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
93 # include <visp/vpList.h>
94 #endif
95 #include <visp/vpImagePoint.h>
96 #include <visp/vpImageSimulator.h>
97 
98 void set_scene (const char*, Bound_scene *, float);
99 void vp2jlc_matrix (const vpHomogeneousMatrix, Matrix&);
100 
101 
179 class VISP_EXPORT vpWireFrameSimulator
180 {
181 public:
182 
186  typedef enum
187  {
205  } vpSceneObject;
206 
213  typedef enum
214  {
217  D_TOOL
218  } vpSceneDesiredObject;
219 
220  typedef enum
221  {
223  CT_POINT
224  } vpCameraTrajectoryDisplayType;
225 
226 protected:
227  Bound_scene scene;
228  Bound_scene desiredScene;
229  Bound_scene camera;
230  std::list<vpImageSimulator> objectImage;
231 
238 
241 
246 
248 
250  std::list<vpImagePoint> cameraTrajectory;
251  std::list<vpHomogeneousMatrix> poseList;
252  std::list<vpHomogeneousMatrix> fMoList;
253  unsigned int nbrPtLimit;
254 
258  bool blockedr;
259  bool blockedz;
260  bool blockedt;
261  bool blocked;
262 
265 
266  double px_int;
267  double py_int;
268  double px_ext;
269  double py_ext;
270 
275 
277 
279 
281 
283 
284  unsigned int thickness_;
285 
286 private:
287  std::string scene_dir;
288 
289 public:
291  virtual ~vpWireFrameSimulator();
292 
297  cameraTrajectory.clear();
298  poseList.clear();
299  fMoList.clear();}
300 
301  void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
302  void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
303 
312  //if(px_ext != 1 && py_ext != 1)
313  // we assume px_ext and py_ext > 0
314  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
315  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
316  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
317  else
318  {
319  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
320  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
321  }
322  }
331  //if(px_ext != 1 && py_ext != 1)
332  // we assume px_ext and py_ext > 0
333  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
334  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
335  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
336  else
337  {
338  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
339  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
340  }
341  }
347  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf;}
348 
349  void getExternalImage(vpImage<unsigned char> &I);
350  void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
351  void getExternalImage(vpImage<vpRGBa> &I);
352  void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
353 
362  //if(px_int != 1 && py_int != 1)
363  // we assume px_int and py_int > 0
364  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
365  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
366  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
367  else
368  {
369  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
370  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
371  }
372  }
381  //if(px_int != 1 && py_int != 1)
382  // we assume px_int and py_int > 0
383  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
384  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
385  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
386  else
387  {
388  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
389  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
390  }
391  }
392 
393  void getInternalImage(vpImage<unsigned char> &I);
394  void getInternalImage(vpImage<vpRGBa> &I);
395 
401  vpHomogeneousMatrix get_cMo() const {return rotz*cMo;}
402 
408  void get_cMo_History(std::list<vpHomogeneousMatrix>& cMo_history) {
409  cMo_history.clear();
410  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
411  cMo_history.push_back(rotz*(*it));
412  }
413  }
414 
420  vpHomogeneousMatrix get_fMo() const {return fMo;}
421 
427  void get_fMo_History(std::list<vpHomogeneousMatrix>& fMo_history) {fMo_history = fMoList;}
428 
429  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
430  void initScene(const char* obj, const char* desiredObject);
431  void initScene(const vpSceneObject &obj);
432  void initScene(const char* obj);
433 
434  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject, const std::list<vpImageSimulator> &imObj);
435  void initScene(const char* obj, const char* desiredObject, const std::list<vpImageSimulator> &imObj);
436  void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
437  void initScene(const char* obj, const std::list<vpImageSimulator> &imObj);
438 
444  void setCameraColor(const vpColor &col) {camColor = col;}
450  void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_) {this->cMo = rotz * cMo_; fMc = fMo*this->cMo.inverse();}
451 
457  void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc_) {this->fMc = fMc_*rotz; cMo = this->fMc.inverse()*fMo;}
458 
464  inline void setCameraSizeFactor (const float factor) {cameraFactor = factor;}
465 
471  void setCameraTrajectoryColor(const vpColor &col) {camTrajColor = col;}
472 
478  inline void setCameraTrajectoryDisplayType (const vpCameraTrajectoryDisplayType &camTraj_type) {this->camTrajType = camTraj_type;}
479 
485  void setCurrentViewColor(const vpColor &col) {curColor = col;}
491  void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_) {this->cdMo = rotz * cdMo_;}
497  void setDesiredViewColor(const vpColor &col) {desColor = col;}
505  void setDisplayCameraTrajectory (const bool &do_display) {this->displayCameraTrajectory = do_display;}
506 
513  px_ext = cam.get_px();
514  py_ext = cam.get_py();
515  }
522  {
523  this->camMf = rotz * cam_Mf;
525  this->camMf.extract (T);
526  this->camMf2.buildFrom(0,0,T[2],0,0,0);
527  f2Mf = camMf2.inverse()*this->camMf;
528  extCamChanged = true;
529  }
530 
534  void setGraphicsThickness(unsigned int thickness)
535  {
536  this->thickness_ = thickness;
537  }
538 
545  px_int = cam.get_px();
546  py_int = cam.get_py();
547  }
548 
554  inline void setNbPtTrajectory(const unsigned int nbPt) {nbrPtLimit = nbPt;}
555 
561  void set_fMo(const vpHomogeneousMatrix &fMo_) {this->fMo = fMo_;/*this->cMo = fMc.inverse()*fMo;*/}
562 
563 protected:
564  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
565  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
566  vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
567  vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
568  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
569  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
570  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
571  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
572 
573 public:
574 
575 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
576 
580  vp_deprecated void displayTrajectory(const vpImage<unsigned char> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
581  vp_deprecated void displayTrajectory(const vpImage<vpRGBa> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
582 
592  vpHomogeneousMatrix tmp_;
593  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
594  tmp_ = (rotz*(*it));
595  list_cMo.addRight(tmp_);
596  }
597  return list_cMo;}
606  vpList<vpHomogeneousMatrix> fMoHistory;
607  for(std::list<vpHomogeneousMatrix>::const_iterator iter = fMoList.begin(); iter != fMoList.end(); ++iter){
608  fMoHistory.addRight(*iter);
609  }
610  return fMoHistory;}
611 
612 
613  vp_deprecated void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject, vpList<vpImageSimulator> &imObj);
614  vp_deprecated void initScene(const char* obj, const char* desiredObject, vpList<vpImageSimulator> &imObj);
615  vp_deprecated void initScene(vpSceneObject obj, vpList<vpImageSimulator> &imObj);
616  vp_deprecated void initScene(const char* obj, vpList<vpImageSimulator> &imObj);
617 
618 #endif
619 };
620 
621 #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.
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:152
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
Class that consider the case of a translation vector.
void setCameraSizeFactor(const float factor)
std::list< vpHomogeneousMatrix > poseList
vpHomogeneousMatrix getExternalCameraPosition() const
vpHomogeneousMatrix camMf2