ViSP  2.7.0
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * $Id: vpWireFrameSimulator.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 protected:
234  Bound_scene scene;
235  Bound_scene desiredScene;
236  Bound_scene camera;
237  std::list<vpImageSimulator> objectImage;
238 
245 
248 
253 
255 
257  std::list<vpImagePoint> cameraTrajectory;
258  std::list<vpHomogeneousMatrix> poseList;
259  std::list<vpHomogeneousMatrix> fMoList;
260  unsigned int nbrPtLimit;
261 
265  bool blockedr;
266  bool blockedz;
267  bool blockedt;
268  bool blocked;
269 
272 
273  double px_int;
274  double py_int;
275  double px_ext;
276  double py_ext;
277 
282 
284 
286 
288 
290 
291 private:
292  std::string scene_dir;
293 
294 public:
296  virtual ~vpWireFrameSimulator();
297 
302  cameraTrajectory.clear();
303  poseList.clear();
304  fMoList.clear();}
305 
306  void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
307  void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
308 
317  //if(px_ext != 1 && py_ext != 1)
318  // we assume px_ext and py_ext > 0
319  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
320  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
321  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
322  else
323  {
324  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
325  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
326  }
327  }
336  //if(px_ext != 1 && py_ext != 1)
337  // we assume px_ext and py_ext > 0
338  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
339  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
340  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
341  else
342  {
343  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
344  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
345  }
346  }
352  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf;}
353 
354  void getExternalImage(vpImage<unsigned char> &I);
355  void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
356  void getExternalImage(vpImage<vpRGBa> &I);
357  void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
358 
367  //if(px_int != 1 && py_int != 1)
368  // we assume px_int and py_int > 0
369  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
370  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
371  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
372  else
373  {
374  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
375  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
376  }
377  }
386  //if(px_int != 1 && py_int != 1)
387  // we assume px_int and py_int > 0
388  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
389  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
390  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
391  else
392  {
393  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
394  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
395  }
396  }
397 
398  void getInternalImage(vpImage<unsigned char> &I);
399  void getInternalImage(vpImage<vpRGBa> &I);
400 
406  vpHomogeneousMatrix get_cMo() const {return rotz*cMo;}
407 
413  void get_cMo_History(std::list<vpHomogeneousMatrix>& cMo_history) {
414  cMo_history.clear();
415  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
416  cMo_history.push_back(rotz*(*it));
417  }
418  }
419 
425  vpHomogeneousMatrix get_fMo() const {return fMo;}
426 
432  void get_fMo_History(std::list<vpHomogeneousMatrix>& fMo_history) {fMo_history = fMoList;}
433 
434  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
435  void initScene(const char* obj, const char* desiredObject);
436  void initScene(const vpSceneObject &obj);
437  void initScene(const char* obj);
438 
439  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject, const std::list<vpImageSimulator> &imObj);
440  void initScene(const char* obj, const char* desiredObject, const std::list<vpImageSimulator> &imObj);
441  void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
442  void initScene(const char* obj, const std::list<vpImageSimulator> &imObj);
443 
449  void setCameraColor(const vpColor &col) {camColor = col;}
455  void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo) {this->cMo = rotz * cMo; fMc = fMo*this->cMo.inverse();}
456 
462  void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc) {this->fMc = fMc*rotz; cMo = this->fMc.inverse()*fMo;}
463 
469  inline void setCameraSizeFactor (const float factor) {cameraFactor = factor;}
470 
476  void setCameraTrajectoryColor(const vpColor &col) {camTrajColor = col;}
477 
483  inline void setCameraTrajectoryDisplayType (const vpCameraTrajectoryDisplayType &camTrajType) {this->camTrajType = camTrajType;}
484 
490  void setCurrentViewColor(const vpColor &col) {curColor = col;}
496  void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo) {this->cdMo = rotz * cdMo;}
502  void setDesiredViewColor(const vpColor &col) {desColor = col;}
510  void setDisplayCameraTrajectory (const bool &displayCameraTrajectory) {this->displayCameraTrajectory = displayCameraTrajectory;}
511 
518  px_ext = cam.get_px();
519  py_ext = cam.get_py();
520  }
527  {
528  this->camMf = rotz * camMf;
530  this->camMf.extract (T);
531  this->camMf2.buildFrom(0,0,T[2],0,0,0);
532  f2Mf = camMf2.inverse()*this->camMf;
533  extCamChanged = true;
534  }
535 
542  px_int = cam.get_px();
543  py_int = cam.get_py();
544  }
545 
551  inline void setNbPtTrajectory(const unsigned int nbPt) {nbrPtLimit = nbPt;}
552 
558  void set_fMo(const vpHomogeneousMatrix &fMo) {this->fMo = fMo;/*this->cMo = fMc.inverse()*fMo;*/}
559 
560 protected:
561  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
562  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
563  vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
564  vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
565  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
566  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
567  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
568  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
569 
570 public:
571 
572 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
573 
577  vp_deprecated void displayTrajectory(const vpImage<unsigned char> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
578  vp_deprecated void displayTrajectory(const vpImage<vpRGBa> &I, vpList<vpHomogeneousMatrix> &list_cMo, vpList<vpHomogeneousMatrix> &list_fMo, vpHomogeneousMatrix camMf);
579 
589  vpHomogeneousMatrix tmp_;
590  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
591  tmp_ = (rotz*(*it));
592  list_cMo.addRight(tmp_);
593  }
594  return list_cMo;}
603  vpList<vpHomogeneousMatrix> fMoHistory;
604  for(std::list<vpHomogeneousMatrix>::const_iterator iter = fMoList.begin(); iter != fMoList.end(); ++iter){
605  fMoHistory.addRight(*iter);
606  }
607  return fMoHistory;}
608 
609 
610  vp_deprecated void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject, vpList<vpImageSimulator> &imObj);
611  vp_deprecated void initScene(const char* obj, const char* desiredObject, vpList<vpImageSimulator> &imObj);
612  vp_deprecated void initScene(vpSceneObject obj, vpList<vpImageSimulator> &imObj);
613  vp_deprecated void initScene(const char* obj, vpList<vpImageSimulator> &imObj);
614 
615 #endif
616 };
617 
618 #endif
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
void setCameraColor(const vpColor &col)
void setDesiredViewColor(const vpColor &col)
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)
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
vpHomogeneousMatrix fMo
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo)
std::list< vpHomogeneousMatrix > fMoList
void setExternalCameraPosition(const vpHomogeneousMatrix &camMf)
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
void setCameraTrajectoryColor(const vpColor &col)
vpCameraParameters getExternalCameraParameters(const vpImage< unsigned char > &I) const
vpHomogeneousMatrix get_fMo() const
void setDisplayCameraTrajectory(const bool &displayCameraTrajectory)
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
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
void setExternalCameraParameters(const vpCameraParameters &cam)
vpCameraTrajectoryDisplayType camTrajType
vpCameraParameters getExternalCameraParameters(const vpImage< vpRGBa > &I) const
vpSceneDesiredObject desiredObject
vpHomogeneousMatrix camMf
vpHomogeneousMatrix fMc
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo)
vp_deprecated vpList< vpHomogeneousMatrix > get_cMo_History()
vpHomogeneousMatrix inverse() const
void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc)
vpHomogeneousMatrix get_cMo() const
vpHomogeneousMatrix rotz
void setInternalCameraParameters(const vpCameraParameters &cam)
void get_fMo_History(std::list< vpHomogeneousMatrix > &fMo_history)
vpHomogeneousMatrix refMo
unsigned int getHeight() const
Definition: vpImage.h:145
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
void setCameraTrajectoryDisplayType(const vpCameraTrajectoryDisplayType &camTrajType)
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