Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpWireFrameSimulator.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Wire frame simulator
33  *
34 *****************************************************************************/
35 
41 #ifndef vpWireFrameSimulator_HH
42 #define vpWireFrameSimulator_HH
43 
44 #include <cmath> // std::fabs
45 #include <iostream>
46 #include <limits> // numeric_limits
47 #include <list>
48 #include <stdio.h>
49 #include <string>
50 
51 #include <visp3/core/vpConfig.h>
52 #include <visp3/core/vpDisplay.h>
53 #include <visp3/core/vpHomogeneousMatrix.h>
54 #include <visp3/core/vpImage.h>
55 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
56 #include <visp3/core/vpList.h>
57 #endif
58 #include <visp3/core/vpImagePoint.h>
59 #include <visp3/robot/vpImageSimulator.h>
60 #include <visp3/robot/vpWireFrameSimulatorTypes.h>
61 
62 BEGIN_VISP_NAMESPACE
156 class VISP_EXPORT vpWireFrameSimulator
157 {
158 public:
162  typedef enum
163  {
164  THREE_PTS,
168  PLATE,
171  SMALL_PLATE,
174  RECTANGLE,
178  SQUARE_10CM,
182  DIAMOND,
185  TRAPEZOID,
192  PIPE,
197  PLAN,
199  POINT_CLOUD,
204  } vpSceneObject;
205 
214  typedef enum
215  {
216  D_STANDARD,
219  D_TOOL
220  } vpSceneDesiredObject;
221 
222  typedef enum { CT_LINE, CT_POINT } vpCameraTrajectoryDisplayType;
223 
224 protected:
225  Bound_scene scene;
226  Bound_scene desiredScene;
227  Bound_scene camera;
228  std::list<vpImageSimulator> objectImage;
229 
236 
239 
244 
246 
248  std::list<vpImagePoint> cameraTrajectory;
249  std::list<vpHomogeneousMatrix> poseList;
250  std::list<vpHomogeneousMatrix> fMoList;
251  unsigned int nbrPtLimit;
252 
256  bool blockedr;
257  bool blockedz;
258  bool blockedt;
259  bool blocked;
260 
263 
264  double px_int;
265  double py_int;
266  double px_ext;
267  double py_ext;
268 
273 
275 
277 
279 
281 
282  unsigned int thickness_;
283 
284 private:
285  std::string scene_dir;
286 
287 public:
289  virtual ~vpWireFrameSimulator();
290 
298  {
299  cameraTrajectory.clear();
300  poseList.clear();
301  fMoList.clear();
302  }
303 
304  void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo,
305  const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
306  void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo,
307  const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
308 
317  {
318  // if(px_ext != 1 && py_ext != 1)
319  // we assume px_ext and py_ext > 0
320  if ((std::fabs(px_ext - 1.) > vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
321  (std::fabs(py_ext - 1) > vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon()))
322  return vpCameraParameters(px_ext, py_ext, I.getWidth() / 2, I.getHeight() / 2);
323  else {
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  {
337  // if(px_ext != 1 && py_ext != 1)
338  // we assume px_ext and py_ext > 0
339  if ((std::fabs(px_ext - 1.) > vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
340  (std::fabs(py_ext - 1) > vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon()))
341  return vpCameraParameters(px_ext, py_ext, I.getWidth() / 2, I.getHeight() / 2);
342  else {
343  unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
344  return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
345  }
346  }
354  inline vpHomogeneousMatrix getExternalCameraPosition() const { return rotz * camMf; }
355 
356  void getExternalImage(vpImage<unsigned char> &I);
357  void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
358  void getExternalImage(vpImage<vpRGBa> &I);
359  void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
360 
369  {
370  // if(px_int != 1 && py_int != 1)
371  // we assume px_int and py_int > 0
372  if ((std::fabs(px_int - 1.) > vpMath::maximum(px_int, 1.) * std::numeric_limits<double>::epsilon()) &&
373  (std::fabs(py_int - 1) > vpMath::maximum(py_int, 1.) * std::numeric_limits<double>::epsilon()))
374  return vpCameraParameters(px_int, py_int, I.getWidth() / 2, I.getHeight() / 2);
375  else {
376  unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
377  return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
378  }
379  }
388  {
389  // if(px_int != 1 && py_int != 1)
390  // we assume px_int and py_int > 0
391  if ((std::fabs(px_int - 1.) > vpMath::maximum(px_int, 1.) * std::numeric_limits<double>::epsilon()) &&
392  (std::fabs(py_int - 1) > vpMath::maximum(py_int, 1.) * std::numeric_limits<double>::epsilon()))
393  return vpCameraParameters(px_int, py_int, I.getWidth() / 2, I.getHeight() / 2);
394  else {
395  unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
396  return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
397  }
398  }
399 
400  void getInternalImage(vpImage<unsigned char> &I);
401  void getInternalImage(vpImage<vpRGBa> &I);
402 
408  vpHomogeneousMatrix get_cMo() const { return rotz * cMo; }
409 
416  void get_cMo_History(std::list<vpHomogeneousMatrix> &cMo_history)
417  {
418  cMo_history.clear();
419  for (std::list<vpHomogeneousMatrix>::const_iterator it = poseList.begin(); it != poseList.end(); ++it) {
420  cMo_history.push_back(rotz * (*it));
421  }
422  }
423 
429  vpHomogeneousMatrix get_fMo() const { return fMo; }
430 
437  void get_fMo_History(std::list<vpHomogeneousMatrix> &fMo_history) { fMo_history = fMoList; }
438 
439  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
440  void initScene(const char *obj, const char *desiredObject);
441  void initScene(const vpSceneObject &obj);
442  void initScene(const char *obj);
443 
444  void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject,
445  const std::list<vpImageSimulator> &imObj);
446  void initScene(const char *obj, const char *desiredObject, const std::list<vpImageSimulator> &imObj);
447  void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
448  void initScene(const char *obj, const std::list<vpImageSimulator> &imObj);
449 
455  void setCameraColor(const vpColor &col) { camColor = col; }
462  {
463  this->cMo = rotz * cMo_;
464  fMc = fMo * this->cMo.inverse();
465  }
466 
474  {
475  this->fMc = fMc_ * rotz;
476  cMo = this->fMc.inverse() * fMo;
477  }
478 
485  inline void setCameraSizeFactor(float factor) { cameraFactor = factor; }
486 
493  void setCameraTrajectoryColor(const vpColor &col) { camTrajColor = col; }
494 
503  {
504  this->camTrajType = camTraj_type;
505  }
506 
512  void setCurrentViewColor(const vpColor &col) { curColor = col; }
518  void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_) { this->cdMo = rotz * cdMo_; }
524  void setDesiredViewColor(const vpColor &col) { desColor = col; }
533  void setDisplayCameraTrajectory(const bool &do_display) { this->displayCameraTrajectory = do_display; }
534 
541  {
542  px_ext = cam.get_px();
543  py_ext = cam.get_py();
544  }
552  {
553  this->camMf = rotz * cam_Mf;
555  this->camMf.extract(T);
556  this->camMf2.buildFrom(0, 0, T[2], 0, 0, 0);
557  f2Mf = camMf2.inverse() * this->camMf;
558  extCamChanged = true;
559  }
560 
564  void setGraphicsThickness(unsigned int thickness) { this->thickness_ = thickness; }
565 
572  {
573  px_int = cam.get_px();
574  py_int = cam.get_py();
575  }
576 
584  inline void setNbPtTrajectory(unsigned int nbPt) { nbrPtLimit = nbPt; }
585 
591  void set_fMo(const vpHomogeneousMatrix &fMo_) { this->fMo = fMo_; /*this->cMo = fMc.inverse()*fMo;*/ }
593 
594 protected:
597  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
598  void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
599  vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
600  vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
601  vpImagePoint projectCameraTrajectory(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo,
602  const vpHomogeneousMatrix &fMo);
603  vpImagePoint projectCameraTrajectory(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo,
604  const vpHomogeneousMatrix &fMo);
605  vpImagePoint projectCameraTrajectory(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo,
606  const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
607  vpImagePoint projectCameraTrajectory(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo,
608  const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
610 };
611 END_VISP_NAMESPACE
612 #endif
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
void extract(vpRotationMatrix &R) const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:254
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:262
Class that consider the case of a translation vector.
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
vpHomogeneousMatrix getExternalCameraPosition() const
vpSceneDesiredObject desiredObject
vpHomogeneousMatrix camMf2
vpHomogeneousMatrix f2Mf
@ D_CIRCLE
The object displayed at the desired position is a circle.
vpHomogeneousMatrix refMo
vpCameraParameters getInternalCameraParameters(const vpImage< unsigned char > &I) const
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void get_cMo_History(std::list< vpHomogeneousMatrix > &cMo_history)
vpCameraParameters getExternalCameraParameters(const vpImage< vpRGBa > &I) const
void get_fMo_History(std::list< vpHomogeneousMatrix > &fMo_history)
vpCameraTrajectoryDisplayType camTrajType
void setCurrentViewColor(const vpColor &col)
void setNbPtTrajectory(unsigned int nbPt)
void setCameraTrajectoryDisplayType(const vpCameraTrajectoryDisplayType &camTraj_type)
vpHomogeneousMatrix get_cMo() const
vpCameraParameters getExternalCameraParameters(const vpImage< unsigned char > &I) const
vpHomogeneousMatrix fMo
void setCameraColor(const vpColor &col)
void setDesiredViewColor(const vpColor &col)
vpHomogeneousMatrix camMf
vpHomogeneousMatrix fMc
vpCameraParameters getInternalCameraParameters(const vpImage< vpRGBa > &I) const
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
void setCameraTrajectoryColor(const vpColor &col)
std::list< vpImagePoint > cameraTrajectory
vpHomogeneousMatrix cMo
std::list< vpHomogeneousMatrix > fMoList
void setCameraSizeFactor(float factor)
void setCameraPositionRelWorld(const vpHomogeneousMatrix &fMc_)
std::list< vpImageSimulator > objectImage
void set_fMo(const vpHomogeneousMatrix &fMo_)
vpHomogeneousMatrix get_fMo() const
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
void setInternalCameraParameters(const vpCameraParameters &cam)
void setExternalCameraParameters(const vpCameraParameters &cam)
@ CIRCLE
A 10cm radius circle.
@ THREE_LINES
Three parallel lines with equation y=-5, y=0, y=5.
@ ROAD
Three parallel lines representing a road.
@ SPHERE
A 15cm radius sphere.
@ CUBE
A 12.5cm size cube.
@ TIRE
A tire represented by 2 circles with radius 10cm and 15cm.
@ CYLINDER
A cylinder of 80cm length and 10cm radius.
vpHomogeneousMatrix rotz
void setGraphicsThickness(unsigned int thickness)
vpHomogeneousMatrix cdMo
void setDisplayCameraTrajectory(const bool &do_display)
std::list< vpHomogeneousMatrix > poseList