Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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/core/vpConfig.h>
55 #include <visp3/core/vpImage.h>
56 #include <visp3/core/vpHomogeneousMatrix.h>
57 #include <visp3/core/vpDisplay.h>
58 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
59 # include <visp3/core/vpList.h>
60 #endif
61 #include <visp3/core/vpImagePoint.h>
62 #include <visp3/robot/vpImageSimulator.h>
63 #include <visp3/robot/vpWireFrameSimulatorTypes.h>
64 
142 class VISP_EXPORT vpWireFrameSimulator
143 {
144 public:
145 
149  typedef enum
150  {
168  } vpSceneObject;
169 
176  typedef enum
177  {
180  D_TOOL
181  } vpSceneDesiredObject;
182 
183  typedef enum
184  {
186  CT_POINT
187  } vpCameraTrajectoryDisplayType;
188 
189 protected:
190  Bound_scene scene;
191  Bound_scene desiredScene;
192  Bound_scene camera;
193  std::list<vpImageSimulator> objectImage;
194 
201 
204 
209 
211 
213  std::list<vpImagePoint> cameraTrajectory;
214  std::list<vpHomogeneousMatrix> poseList;
215  std::list<vpHomogeneousMatrix> fMoList;
216  unsigned int nbrPtLimit;
217 
221  bool blockedr;
222  bool blockedz;
223  bool blockedt;
224  bool blocked;
225 
228 
229  double px_int;
230  double py_int;
231  double px_ext;
232  double py_ext;
233 
238 
240 
242 
244 
246 
247  unsigned int thickness_;
248 
249 private:
250  std::string scene_dir;
251 
252 public:
254  virtual ~vpWireFrameSimulator();
255 
262  cameraTrajectory.clear();
263  poseList.clear();
264  fMoList.clear();}
265 
266  void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
267  void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo, const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
268 
277  //if(px_ext != 1 && py_ext != 1)
278  // we assume px_ext and py_ext > 0
279  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
280  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
281  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
282  else
283  {
284  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
285  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
286  }
287  }
296  //if(px_ext != 1 && py_ext != 1)
297  // we assume px_ext and py_ext > 0
298  if( (std::fabs(px_ext-1.) > vpMath::maximum(px_ext,1.)*std::numeric_limits<double>::epsilon())
299  && (std::fabs(py_ext-1) > vpMath::maximum(py_ext,1.)*std::numeric_limits<double>::epsilon()))
300  return vpCameraParameters(px_ext,py_ext,I.getWidth()/2,I.getHeight()/2);
301  else
302  {
303  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
304  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
305  }
306  }
312  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf;}
313 
314  void getExternalImage(vpImage<unsigned char> &I);
315  void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
316  void getExternalImage(vpImage<vpRGBa> &I);
317  void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
318 
327  //if(px_int != 1 && py_int != 1)
328  // we assume px_int and py_int > 0
329  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
330  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
331  return vpCameraParameters(px_int,py_int,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  }
346  //if(px_int != 1 && py_int != 1)
347  // we assume px_int and py_int > 0
348  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
349  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
350  return vpCameraParameters(px_int,py_int,I.getWidth()/2,I.getHeight()/2);
351  else
352  {
353  unsigned int size = vpMath::minimum(I.getWidth(),I.getHeight())/2;
354  return vpCameraParameters(size,size,I.getWidth()/2,I.getHeight()/2);
355  }
356  }
357 
358  void getInternalImage(vpImage<unsigned char> &I);
359  void getInternalImage(vpImage<vpRGBa> &I);
360 
366  vpHomogeneousMatrix get_cMo() const {return rotz*cMo;}
367 
373  void get_cMo_History(std::list<vpHomogeneousMatrix>& cMo_history) {
374  cMo_history.clear();
375  for(std::list<vpHomogeneousMatrix>::const_iterator it=poseList.begin(); it!=poseList.end(); ++it){
376  cMo_history.push_back(rotz*(*it));
377  }
378  }
379 
385  vpHomogeneousMatrix get_fMo() const {return fMo;}
386 
392  void get_fMo_History(std::list<vpHomogeneousMatrix>& fMo_history) {fMo_history = fMoList;}
393 
394  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
395  void initScene(const char* obj, const char* desiredObject);
396  void initScene(const vpSceneObject &obj);
397  void initScene(const char* obj);
398 
399  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject, const std::list<vpImageSimulator> &imObj);
400  void initScene(const char* obj, const char* desiredObject, const std::list<vpImageSimulator> &imObj);
401  void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
402  void initScene(const char* obj, const std::list<vpImageSimulator> &imObj);
403 
409  void setCameraColor(const vpColor &col) {camColor = col;}
415  void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_) {this->cMo = rotz * cMo_; fMc = fMo*this->cMo.inverse();}
416 
422  void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc_) {this->fMc = fMc_*rotz; cMo = this->fMc.inverse()*fMo;}
423 
429  inline void setCameraSizeFactor (const float factor) {cameraFactor = factor;}
430 
436  void setCameraTrajectoryColor(const vpColor &col) {camTrajColor = col;}
437 
443  inline void setCameraTrajectoryDisplayType (const vpCameraTrajectoryDisplayType &camTraj_type) {this->camTrajType = camTraj_type;}
444 
450  void setCurrentViewColor(const vpColor &col) {curColor = col;}
456  void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_) {this->cdMo = rotz * cdMo_;}
462  void setDesiredViewColor(const vpColor &col) {desColor = col;}
470  void setDisplayCameraTrajectory (const bool &do_display) {this->displayCameraTrajectory = do_display;}
471 
478  px_ext = cam.get_px();
479  py_ext = cam.get_py();
480  }
487  {
488  this->camMf = rotz * cam_Mf;
490  this->camMf.extract (T);
491  this->camMf2.buildFrom(0,0,T[2],0,0,0);
492  f2Mf = camMf2.inverse()*this->camMf;
493  extCamChanged = true;
494  }
495 
499  void setGraphicsThickness(unsigned int thickness)
500  {
501  this->thickness_ = thickness;
502  }
503 
510  px_int = cam.get_px();
511  py_int = cam.get_py();
512  }
513 
519  inline void setNbPtTrajectory(const unsigned int nbPt) {nbrPtLimit = nbPt;}
520 
526  void set_fMo(const vpHomogeneousMatrix &fMo_) {this->fMo = fMo_;/*this->cMo = fMc.inverse()*fMo;*/}
528 
529 protected:
532  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
533  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
534  vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
535  vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
536  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
537  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo);
538  vpImagePoint projectCameraTrajectory (const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
539  vpImagePoint projectCameraTrajectory (const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
541 };
542 
543 #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:226
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:140
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
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:151
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...
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:175
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
vpTranslationVector buildFrom(const double tx, const double ty, const double tz)
vpHomogeneousMatrix getExternalCameraPosition() const
vpHomogeneousMatrix camMf2