Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpWireFrameSimulator.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
38
39#ifndef vpWireFrameSimulator_HH
40#define vpWireFrameSimulator_HH
41
42#include <cmath> // std::fabs
43#include <iostream>
44#include <limits> // numeric_limits
45#include <list>
46#include <stdio.h>
47#include <string>
48
49#include <visp3/core/vpConfig.h>
50#include <visp3/core/vpDisplay.h>
51#include <visp3/core/vpHomogeneousMatrix.h>
52#include <visp3/core/vpImage.h>
53#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
54#include <visp3/core/vpList.h>
55#endif
56#include <visp3/core/vpImagePoint.h>
57#include <visp3/robot/vpImageSimulator.h>
58#include <visp3/robot/vpWireFrameSimulatorTypes.h>
59
161
162class VISP_EXPORT vpWireFrameSimulator
163{
164public:
211
220 typedef enum
221 {
226 } vpSceneDesiredObject;
227
228 typedef enum { CT_LINE, CT_POINT } vpCameraTrajectoryDisplayType;
229
230protected:
231 Bound_scene scene;
232 Bound_scene desiredScene;
233 Bound_scene camera;
234 std::list<vpImageSimulator> objectImage;
235
242
245
250
252
254 std::list<vpImagePoint> cameraTrajectory;
255 std::list<vpHomogeneousMatrix> poseList;
256 std::list<vpHomogeneousMatrix> fMoList;
257 unsigned int nbrPtLimit;
258
266
269
270 double px_int;
271 double py_int;
272 double px_ext;
273 double py_ext;
274
279
281
283
285
287
288 unsigned int thickness_;
289
290private:
291 std::string scene_dir;
292
293public:
295 virtual ~vpWireFrameSimulator();
296
299
304 {
305 cameraTrajectory.clear();
306 poseList.clear();
307 fMoList.clear();
308 }
309
310 void displayTrajectory(const vpImage<unsigned char> &I, const std::list<vpHomogeneousMatrix> &list_cMo,
311 const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
312 void displayTrajectory(const vpImage<vpRGBa> &I, const std::list<vpHomogeneousMatrix> &list_cMo,
313 const std::list<vpHomogeneousMatrix> &list_fMo, const vpHomogeneousMatrix &camMf);
314
323 {
324 // if(px_ext != 1 && py_ext != 1)
325 // we assume px_ext and py_ext > 0
326 if ((std::fabs(px_ext - 1.) > vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
327 (std::fabs(py_ext - 1) > vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon()))
328 return vpCameraParameters(px_ext, py_ext, I.getWidth() / 2, I.getHeight() / 2);
329 else {
330 unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
331 return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
332 }
333 }
334
342 {
343 // if(px_ext != 1 && py_ext != 1)
344 // we assume px_ext and py_ext > 0
345 if ((std::fabs(px_ext - 1.) > vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
346 (std::fabs(py_ext - 1) > vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon()))
347 return vpCameraParameters(px_ext, py_ext, I.getWidth() / 2, I.getHeight() / 2);
348 else {
349 unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
350 return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
351 }
352 }
353
361
362 void getExternalImage(vpImage<unsigned char> &I);
363 void getExternalImage(vpImage<unsigned char> &I, const vpHomogeneousMatrix &camMf);
364 void getExternalImage(vpImage<vpRGBa> &I);
365 void getExternalImage(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &camMf);
366
375 {
376 // if(px_int != 1 && py_int != 1)
377 // we assume px_int and py_int > 0
378 if ((std::fabs(px_int - 1.) > vpMath::maximum(px_int, 1.) * std::numeric_limits<double>::epsilon()) &&
379 (std::fabs(py_int - 1) > vpMath::maximum(py_int, 1.) * std::numeric_limits<double>::epsilon()))
380 return vpCameraParameters(px_int, py_int, I.getWidth() / 2, I.getHeight() / 2);
381 else {
382 unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
383 return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
384 }
385 }
386
394 {
395 // if(px_int != 1 && py_int != 1)
396 // we assume px_int and py_int > 0
397 if ((std::fabs(px_int - 1.) > vpMath::maximum(px_int, 1.) * std::numeric_limits<double>::epsilon()) &&
398 (std::fabs(py_int - 1) > vpMath::maximum(py_int, 1.) * std::numeric_limits<double>::epsilon()))
399 return vpCameraParameters(px_int, py_int, I.getWidth() / 2, I.getHeight() / 2);
400 else {
401 unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
402 return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
403 }
404 }
405
406 void getInternalImage(vpImage<unsigned char> &I);
407 void getInternalImage(vpImage<vpRGBa> &I);
408
414 vpHomogeneousMatrix get_cMo() const { return rotz * cMo; }
415
422 void get_cMo_History(std::list<vpHomogeneousMatrix> &cMo_history)
423 {
424 cMo_history.clear();
425 for (std::list<vpHomogeneousMatrix>::const_iterator it = poseList.begin(); it != poseList.end(); ++it) {
426 cMo_history.push_back(rotz * (*it));
427 }
428 }
429
435 vpHomogeneousMatrix get_fMo() const { return fMo; }
436
443 void get_fMo_History(std::list<vpHomogeneousMatrix> &fMo_history) { fMo_history = fMoList; }
444
445 void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
446 void initScene(const char *obj, const char *desiredObject);
447 void initScene(const vpSceneObject &obj);
448 void initScene(const char *obj);
449
450 void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject,
451 const std::list<vpImageSimulator> &imObj);
452 void initScene(const char *obj, const char *desiredObject, const std::list<vpImageSimulator> &imObj);
453 void initScene(const vpSceneObject &obj, const std::list<vpImageSimulator> &imObj);
454 void initScene(const char *obj, const std::list<vpImageSimulator> &imObj);
455
461 void setCameraColor(const vpColor &col) { camColor = col; }
468 {
469 this->cMo = rotz * cMo_;
470 fMc = fMo * this->cMo.inverse();
471 }
472
480 {
481 this->fMc = fMc_ * rotz;
482 cMo = this->fMc.inverse() * fMo;
483 }
484
491 inline void setCameraSizeFactor(float factor) { cameraFactor = factor; }
492
500
509 {
510 this->camTrajType = camTraj_type;
511 }
512
518 void setCurrentViewColor(const vpColor &col) { curColor = col; }
524 void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_) { this->cdMo = rotz * cdMo_; }
530 void setDesiredViewColor(const vpColor &col) { desColor = col; }
539 void setDisplayCameraTrajectory(const bool &do_display) { this->displayCameraTrajectory = do_display; }
540
547 {
548 px_ext = cam.get_px();
549 py_ext = cam.get_py();
550 }
551
558 {
559 this->camMf = rotz * cam_Mf;
561 this->camMf.extract(T);
562 this->camMf2.buildFrom(0, 0, T[2], 0, 0, 0);
563 f2Mf = camMf2.inverse() * this->camMf;
564 extCamChanged = true;
565 }
566
570 void setGraphicsThickness(unsigned int thickness) { this->thickness_ = thickness; }
571
578 {
579 px_int = cam.get_px();
580 py_int = cam.get_py();
581 }
582
590 inline void setNbPtTrajectory(unsigned int nbPt) { nbrPtLimit = nbPt; }
591
597 void set_fMo(const vpHomogeneousMatrix &fMo_) { this->fMo = fMo_; /*this->cMo = fMc.inverse()*fMo;*/ }
599
600protected:
603 void display_scene(Matrix mat, Bound_scene &sc, const vpImage<vpRGBa> &I, const vpColor &color);
604 void display_scene(Matrix mat, Bound_scene &sc, const vpImage<unsigned char> &I, const vpColor &color);
605 vpHomogeneousMatrix navigation(const vpImage<vpRGBa> &I, bool &changed);
606 vpHomogeneousMatrix navigation(const vpImage<unsigned char> &I, bool &changed);
607 vpImagePoint projectCameraTrajectory(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo,
608 const vpHomogeneousMatrix &fMo);
609 vpImagePoint projectCameraTrajectory(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo,
610 const vpHomogeneousMatrix &fMo);
611 vpImagePoint projectCameraTrajectory(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo,
612 const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
613 vpImagePoint projectCameraTrajectory(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo,
614 const vpHomogeneousMatrix &fMo, const vpHomogeneousMatrix &cMf);
616};
617END_VISP_NAMESPACE
618#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 of the vpImage class member functions.
Definition vpImage.h:131
static Type maximum(const Type &a, const Type &b)
Definition vpMath.h:257
static Type minimum(const Type &a, const Type &b)
Definition vpMath.h:265
Class that consider the case of a translation vector.
vpHomogeneousMatrix getExternalCameraPosition() const
vpSceneDesiredObject desiredObject
vpHomogeneousMatrix camMf2
vpHomogeneousMatrix f2Mf
@ D_CIRCLE
The object displayed at the desired position is a circle.
@ D_TOOL
A cylindrical tool is attached to the camera.
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