ViSP  2.6.2
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * $Id: vpWireFrameSimulator.h 3530 2012-01-03 10:52:12Z fspindle $
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:
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 
67 int open_display();
68 int close_display();
69 int open_clipping();
70 int close_clipping();
71 int open_keyword (Keyword *kwp);
72 int open_lex (void);
73 int open_source (FILE *fd, const char *str);
74 int malloc_Bound_scene (Bound_scene *bsp, const char *name,Index bn);
75 int free_Bound_scene (Bound_scene *bsp);
76 int parser (Bound_scene *bsp);
77 int close_source (void);
78 int close_lex (void);
79 int close_keyword (void);
80 void add_rfstack (int i);
81 void load_rfstack (int i);
82 void add_vwstack (const char* path, ... );
83 void display_scene(Matrix mat, Bound_scene sc);
84 int * get_rfstack (void);
85 Matrix * get_tmstack (void);
86 int View_to_Matrix (View_parameters *vp, Matrix m);
87 void postmult_matrix (Matrix a, Matrix b);
88 Bound *clipping_Bound (Bound *bp, Matrix m);
89 int set_Bound_face_display (Bound *bp, Byte b);
90 int point_3D_2D (Point3f *p3, Index size, unsigned int xsize, unsigned int ysize, Point2i *p2);
91 void point_3D_4D (Point3f *p3, int size, Matrix m, Point4f *p4);
92 int wireframe_Face (Face *fp, Point2i *pp);
93 }
94 
95 #include <visp/vpConfig.h>
96 #include <visp/vpImage.h>
97 #include <visp/vpHomogeneousMatrix.h>
98 #include <visp/vpDisplay.h>
99 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
100 # include <visp/vpList.h>
101 #endif
102 #include <visp/vpImagePoint.h>
103 #include <visp/vpImageSimulator.h>
104 
105 void set_scene (const char*, Bound_scene *, float);
106 void vp2jlc_matrix (const vpHomogeneousMatrix, Matrix&);
107 
108 
186 class VISP_EXPORT vpWireFrameSimulator
187 {
188  public:
189 
193  typedef enum
194  {
212  } vpSceneObject;
213 
220  typedef enum
221  {
224  D_TOOL
225  } vpSceneDesiredObject;
226 
227  typedef enum
228  {
230  CT_POINT
231  } vpCameraTrajectoryDisplayType;
232 
233 
234  protected:
235  Bound_scene scene;
236  Bound_scene desiredScene;
237  Bound_scene camera;
238  std::list<vpImageSimulator> objectImage;
239 
240 
247 
250 
255 
257 
259  std::list<vpImagePoint> cameraTrajectory;
260  std::list<vpHomogeneousMatrix> poseList;
261  std::list<vpHomogeneousMatrix> fMoList;
262  unsigned int nbrPtLimit;
263 
264 
268  bool blockedr;
269  bool blockedz;
270  bool blockedt;
271  bool blocked;
272 
275 
276  double px_int;
277  double py_int;
278  double px_ext;
279  double py_ext;
280 
285 
287 
289 
291 
293 
294  private:
295  std::string scene_dir;
296 
297  public:
299  virtual ~vpWireFrameSimulator();
300 
301  void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject);
302  void initScene(const char* obj, const char* desiredObject);
303  void initScene(vpSceneObject obj);
304  void initScene(const char* obj);
305 
306  void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject, const std::list<vpImageSimulator> &imObj);
307  void initScene(const char* obj, const char* desiredObject, const std::list<vpImageSimulator> &imObj);
308  void initScene(vpSceneObject obj, const std::list<vpImageSimulator> &imObj);
309  void initScene(const char* obj, const std::list<vpImageSimulator> &imObj);
310 
316  void setCameraPositionRelObj(const vpHomogeneousMatrix cMo) {this->cMo = rotz * cMo; fMc = fMo*this->cMo.inverse();}
317 
323  void setCameraPositionRelWorld(const vpHomogeneousMatrix fMc) {this->fMc = fMc*rotz; cMo = this->fMc.inverse()*fMo;}
324 
330  void setDesiredCameraPosition(const vpHomogeneousMatrix cdMo) {this->cdMo = rotz * cdMo;}
331 
338  {
339  this->camMf = rotz * camMf;
341  this->camMf.extract (T);
342  this->camMf2.buildFrom(0,0,T[2],0,0,0);
343  f2Mf = camMf2.inverse()*this->camMf;
344  extCamChanged = true;
345  }
346 
352  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf;}
353 
359  void setCameraColor(const vpColor col) {camColor = col;}
360 
366  void setCameraTrajectoryColor(const vpColor col) {camTrajColor = col;}
367 
373  void setCurrentViewColor(const vpColor col) {curColor = col;}
374 
380  void setDesiredViewColor(const vpColor col) {desColor = col;}
381 
389  void setDisplayCameraTrajectory (const bool displayCameraTrajectory) {this->displayCameraTrajectory = displayCameraTrajectory;}
390 
399  //if(px_int != 1 && py_int != 1)
400  // we assume px_int and py_int > 0
401  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
402  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
403  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
404  else
405  {
406  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
407  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
408  }
409  }
410 
419  //if(px_int != 1 && py_int != 1)
420  // we assume px_int and py_int > 0
421  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
422  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
423  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
424  else
425  {
426  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
427  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
428  }
429  }
430 
439  //if(px_ext != 1 && py_ext != 1)
440  // we assume px_ext and py_ext > 0
441  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
442  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
443  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
444  else
445  {
446  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
447  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
448  }
449  }
450 
459  //if(px_ext != 1 && py_ext != 1)
460  // we assume px_ext and py_ext > 0
461  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
462  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
463  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
464  else
465  {
466  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
467  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
468  }
469  }
470 
476  void set_fMo(const vpHomogeneousMatrix &fMo) {this->fMo = fMo;this->cMo = fMc.inverse()*fMo;}
477 
483  vpHomogeneousMatrix get_fMo() const {return fMo;}
484 
490  vpHomogeneousMatrix get_cMo() const {return rotz*cMo;}
491 
498  px_int = cam.get_px();
499  py_int = cam.get_py();
500  }
501 
508  px_ext = cam.get_px();
509  py_ext = cam.get_py();
510  }
511 
517  inline void setNbPtTrajectory(const unsigned int nbPt) {nbrPtLimit = nbPt;}
518 
524  inline void setCameraSizeFactor (const float factor) {cameraFactor = factor;}
525 
530  cameraTrajectory.clear();
531  poseList.clear();
532  fMoList.clear();}
533 
539  inline void setCameraTrajectoryDisplayType (const vpCameraTrajectoryDisplayType camTrajType) {this->camTrajType = camTrajType;}
540 
546  void get_cMo_History(std::list<vpHomogeneousMatrix>& cMo_history) {
547  cMo_history.clear();
548  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
549  cMo_history.push_back(rotz*(*it));
550  }
551  }
552 
558  void get_fMo_History(std::list<vpHomogeneousMatrix>& fMo_history) {fMo_history = fMoList;}
559 
560  void displayTrajectory(vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
561 
562  void displayTrajectory(vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
563 
564  void getInternalImage(vpImage<vpRGBa> &I);
565  void getExternalImage(vpImage<vpRGBa> &I);
566  void getExternalImage(vpImage<vpRGBa> &I, vpHomogeneousMatrix camMf);
567 
568  void getInternalImage(vpImage<unsigned char> &I);
569  void getExternalImage(vpImage<unsigned char> &I);
570  void getExternalImage(vpImage<unsigned char> &I, vpHomogeneousMatrix camMf);
571 
572  protected:
573  void display_scene(Matrix mat, Bound_scene &sc, vpImage<vpRGBa> &I, vpColor color);
574  void display_scene(Matrix mat, Bound_scene &sc, vpImage<unsigned char> &I, vpColor color);
575  vpHomogeneousMatrix navigation(vpImage<vpRGBa> &I, bool &changed);
576  vpHomogeneousMatrix navigation(vpImage<unsigned char> &I, bool &changed);
577  vpImagePoint projectCameraTrajectory (vpImage<vpRGBa> &I, vpHomogeneousMatrix cMo, vpHomogeneousMatrix fMo);
578  vpImagePoint projectCameraTrajectory (vpImage<unsigned char> &I, vpHomogeneousMatrix cMo, vpHomogeneousMatrix fMo);
579  vpImagePoint projectCameraTrajectory (vpImage<vpRGBa> &I, vpHomogeneousMatrix cMo, vpHomogeneousMatrix fMo, vpHomogeneousMatrix cMf);
581 
582  public:
583 
584 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
585 
598  vpList<vpHomogeneousMatrix> fMoHistory;
599  for(std::list<vpHomogeneousMatrix>::const_iterator iter = fMoList.begin(); iter != fMoList.end(); ++iter){
600  fMoHistory.addRight(*iter);
601  }
602  return fMoHistory;}
603 
614  vpHomogeneousMatrix tmp_;
615  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
616  tmp_ = (rotz*(*it));
617  list_cMo.addRight(tmp_);
618  }
619  return list_cMo;}
620 
621  vp_deprecated void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject, vpList<vpImageSimulator> &imObj);
622  vp_deprecated void initScene(const char* obj, const char* desiredObject, vpList<vpImageSimulator> &imObj);
623  vp_deprecated void initScene(vpSceneObject obj, vpList<vpImageSimulator> &imObj);
624  vp_deprecated void initScene(const char* obj, vpList<vpImageSimulator> &imObj);
625 
626  vp_deprecated void displayTrajectory(vpImage<unsigned char> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
627  vp_deprecated void displayTrajectory(vpImage<vpRGBa> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
628 #endif
629 };
630 
631 #endif
void setCameraTrajectoryColor(const vpColor col)
vpCameraParameters getInternalCameraParameters(const vpImage< vpRGBa > &I) const
unsigned int getWidth() const
Definition: vpImage.h:154
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
void setNbPtTrajectory(const unsigned int nbPt)
void get_cMo_History(std::list< vpHomogeneousMatrix > &cMo_history)
void setCameraTrajectoryDisplayType(const vpCameraTrajectoryDisplayType camTrajType)
std::list< vpImageSimulator > objectImage
void setDesiredViewColor(const vpColor col)
std::list< vpImagePoint > cameraTrajectory
void setCameraPositionRelObj(const vpHomogeneousMatrix cMo)
vp_deprecated vpList< vpHomogeneousMatrix > get_fMo_History()
void setCurrentViewColor(const vpColor col)
vpHomogeneousMatrix cdMo
double get_py() const
vpHomogeneousMatrix fMo
std::list< vpHomogeneousMatrix > fMoList
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
void setDisplayCameraTrajectory(const bool displayCameraTrajectory)
void setExternalCameraPosition(const vpHomogeneousMatrix camMf)
vpCameraParameters getExternalCameraParameters(const vpImage< unsigned char > &I) const
vpHomogeneousMatrix get_fMo() const
vpHomogeneousMatrix f2Mf
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:480
vpHomogeneousMatrix cMo
void setDesiredCameraPosition(const vpHomogeneousMatrix cdMo)
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:148
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
vpCameraTrajectoryDisplayType camTrajType
vpCameraParameters getExternalCameraParameters(const vpImage< vpRGBa > &I) const
vpSceneDesiredObject desiredObject
void setCameraPositionRelWorld(const vpHomogeneousMatrix fMc)
vpHomogeneousMatrix camMf
vpHomogeneousMatrix fMc
vp_deprecated vpList< vpHomogeneousMatrix > get_cMo_History()
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix get_cMo() const
vpHomogeneousMatrix rotz
void get_fMo_History(std::list< vpHomogeneousMatrix > &fMo_history)
vpHomogeneousMatrix refMo
unsigned int getHeight() const
Definition: vpImage.h:145
void setCameraColor(const vpColor col)
void setInternalCameraParameters(const vpCameraParameters cam)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
void setExternalCameraParameters(const vpCameraParameters cam)
Class that consider the case of a translation vector.
void setCameraSizeFactor(const float factor)
std::list< vpHomogeneousMatrix > poseList
void set_fMo(const vpHomogeneousMatrix &fMo)
vpHomogeneousMatrix getExternalCameraPosition() const
vpHomogeneousMatrix camMf2