45 #include <visp3/robot/vpWireFrameSimulator.h>
49 #include "vpClipping.h"
50 #include "vpCoreDisplay.h"
51 #include "vpKeyword.h"
55 #include "vpProjection.h"
56 #include "vpRfstack.h"
58 #include "vpTmstack.h"
61 #include "vpVwstack.h"
63 #include <visp3/core/vpDebug.h>
64 #include <visp3/core/vpCameraParameters.h>
65 #include <visp3/core/vpException.h>
66 #include <visp3/core/vpIoTools.h>
67 #include <visp3/core/vpMeterPixelConversion.h>
68 #include <visp3/core/vpPoint.h>
71 extern Point2i *point2i;
72 extern Point2i *listpoint2i;
82 Byte b = (Byte)*get_rfstack();
86 memmove((
char *)m, (
char *)mat,
sizeof(Matrix));
87 View_to_Matrix(get_vwstack(), *(get_tmstack()));
88 postmult_matrix(m, *(get_tmstack()));
90 bend = bp + sc.bound.nbr;
91 for (; bp < bend; bp++) {
92 if ((clip = clipping_Bound(bp, m)) != NULL) {
93 Face *fp = clip->face.ptr;
94 Face *fend = fp + clip->face.nbr;
96 set_Bound_face_display(clip, b);
98 point_3D_2D(clip->point.ptr, clip->point.nbr, (
int)I.
getWidth(), (
int)I.
getHeight(), point2i);
99 for (; fp < fend; fp++) {
100 if (fp->is_visible) {
101 wireframe_Face(fp, point2i);
102 Point2i *pt = listpoint2i;
103 for (
int i = 1; i < fp->vertex.nbr; i++) {
108 if (fp->vertex.nbr > 2) {
128 Byte b = (Byte)*get_rfstack();
132 memmove((
char *)m, (
char *)mat,
sizeof(Matrix));
133 View_to_Matrix(get_vwstack(), *(get_tmstack()));
134 postmult_matrix(m, *(get_tmstack()));
136 bend = bp + sc.bound.nbr;
137 for (; bp < bend; bp++) {
138 if ((clip = clipping_Bound(bp, m)) != NULL) {
139 Face *fp = clip->face.ptr;
140 Face *fend = fp + clip->face.nbr;
142 set_Bound_face_display(clip, b);
144 point_3D_2D(clip->point.ptr, clip->point.nbr, (
int)I.
getWidth(), (
int)I.
getHeight(), point2i);
145 for (; fp < fend; fp++) {
146 if (fp->is_visible) {
147 wireframe_Face(fp, point2i);
148 Point2i *pt = listpoint2i;
149 for (
int i = 1; i < fp->vertex.nbr; i++) {
154 if (fp->vertex.nbr > 2) {
175 : scene(), desiredScene(), camera(), objectImage(), fMo(), fMc(), camMf(), refMo(), cMo(), cdMo(), object(PLATE),
176 desiredObject(D_STANDARD), camColor(
vpColor::green), camTrajColor(
vpColor::green), curColor(
vpColor::blue),
177 desColor(
vpColor::red), sceneInitialized(false), displayCameraTrajectory(true), cameraTrajectory(), poseList(),
178 fMoList(), nbrPtLimit(1000), old_iPr(), old_iPz(), old_iPt(), blockedr(false), blockedz(false), blockedt(false),
179 blocked(false), camMf2(), f2Mf(), px_int(1), py_int(1), px_ext(1), py_ext(1), displayObject(false),
180 displayDesiredObject(false), displayCamera(false), displayImageSimulator(false), cameraFactor(1.),
181 camTrajType(CT_LINE), extCamChanged(false), rotz(), thickness_(1), scene_dir()
185 std::vector<std::string> scene_dirs =
vpIoTools::splitChain(std::string(VISP_SCENES_DIR), std::string(
";"));
186 bool sceneDirExists =
false;
187 for (
size_t i = 0; i < scene_dirs.size(); i++)
189 scene_dir = scene_dirs[i];
190 sceneDirExists =
true;
193 if (!sceneDirExists) {
196 std::cout <<
"The simulator uses data from VISP_SCENES_DIR=" << scene_dir << std::endl;
199 std::cout <<
"Cannot get VISP_SCENES_DIR environment variable" << std::endl;
213 scene.bound.ptr = NULL;
232 free_Bound_scene(&(this->
scene));
234 free_Bound_scene(&(this->
camera));
263 char name_cam[FILENAME_MAX];
264 char name[FILENAME_MAX];
269 const char *scene_dir_ = scene_dir.c_str();
270 if (strlen(scene_dir_) >= FILENAME_MAX) {
274 strcpy(name_cam, scene_dir_);
276 strcat(name_cam,
"/camera.bnd");
280 strcat(name_cam,
"/tool.bnd");
281 set_scene(name_cam, &(this->
camera), 1.0);
284 strcpy(name, scene_dir_);
287 strcat(name,
"/3pts.bnd");
291 strcat(name,
"/cube.bnd");
295 strcat(name,
"/plate.bnd");
299 strcat(name,
"/plate_6cm.bnd");
303 strcat(name,
"/rectangle.bnd");
307 strcat(name,
"/square10cm.bnd");
311 strcat(name,
"/diamond.bnd");
315 strcat(name,
"/trapezoid.bnd");
319 strcat(name,
"/line.bnd");
323 strcat(name,
"/road.bnd");
327 strcat(name,
"/circles2.bnd");
331 strcat(name,
"/pipe.bnd");
335 strcat(name,
"/circle.bnd");
339 strcat(name,
"/sphere.bnd");
343 strcat(name,
"/cylinder.bnd");
347 strcat(name,
"/plan.bnd");
351 strcat(name,
"/point_cloud.bnd");
355 set_scene(name, &(this->
scene), 1.0);
357 scene_dir_ = scene_dir.c_str();
358 if (strlen(scene_dir_) >= FILENAME_MAX) {
367 strcpy(name, scene_dir_);
368 strcat(name,
"/circle_sq2.bnd");
372 strcpy(name, scene_dir_);
373 strcat(name,
"/tool.bnd");
380 load_rfstack(IS_INSIDE);
382 add_rfstack(IS_BACK);
384 add_vwstack(
"start",
"depth", 0.0, 100.0);
385 add_vwstack(
"start",
"window", -0.1, 0.1, -0.1, 0.1);
386 add_vwstack(
"start",
"type", PERSPECTIVE);
415 const std::list<vpImageSimulator> &imObj)
435 char name_cam[FILENAME_MAX];
436 char name[FILENAME_MAX];
441 const char *scene_dir_ = scene_dir.c_str();
442 if (strlen(scene_dir_) >= FILENAME_MAX) {
446 strcpy(name_cam, scene_dir_);
447 strcat(name_cam,
"/camera.bnd");
450 if (strlen(obj) >= FILENAME_MAX) {
456 model = getExtension(obj);
457 if (model == BND_MODEL)
458 set_scene(name, &(this->
scene), 1.0);
459 else if (model == WRL_MODEL)
460 set_scene_wrl(name, &(this->
scene), 1.0);
461 else if (model == UNKNOWN_MODEL) {
462 vpERROR_TRACE(
"Unknown file extension for the 3D model");
465 if (strlen(desired_object) >= FILENAME_MAX) {
469 strcpy(name, desired_object);
470 model = getExtension(desired_object);
471 if (model == BND_MODEL)
473 else if (model == WRL_MODEL)
475 else if (model == UNKNOWN_MODEL) {
476 vpERROR_TRACE(
"Unknown file extension for the 3D model");
479 add_rfstack(IS_BACK);
481 add_vwstack(
"start",
"depth", 0.0, 100.0);
482 add_vwstack(
"start",
"window", -0.1, 0.1, -0.1, 0.1);
483 add_vwstack(
"start",
"type", PERSPECTIVE);
508 const std::list<vpImageSimulator> &imObj)
529 char name_cam[FILENAME_MAX];
530 char name[FILENAME_MAX];
534 const char *scene_dir_ = scene_dir.c_str();
535 if (strlen(scene_dir_) >= FILENAME_MAX) {
539 strcpy(name_cam, scene_dir_);
540 strcat(name_cam,
"/camera.bnd");
543 strcpy(name, scene_dir_);
546 strcat(name,
"/3pts.bnd");
550 strcat(name,
"/cube.bnd");
554 strcat(name,
"/plate.bnd");
558 strcat(name,
"/plate_6cm.bnd");
562 strcat(name,
"/rectangle.bnd");
566 strcat(name,
"/square10cm.bnd");
570 strcat(name,
"/diamond.bnd");
574 strcat(name,
"/trapezoid.bnd");
578 strcat(name,
"/line.bnd");
582 strcat(name,
"/road.bnd");
586 strcat(name,
"/circles2.bnd");
590 strcat(name,
"/pipe.bnd");
594 strcat(name,
"/circle.bnd");
598 strcat(name,
"/sphere.bnd");
602 strcat(name,
"/cylinder.bnd");
606 strcat(name,
"/plan.bnd");
610 strcat(name,
"/point_cloud.bnd");
614 set_scene(name, &(this->
scene), 1.0);
617 load_rfstack(IS_INSIDE);
619 add_rfstack(IS_BACK);
621 add_vwstack(
"start",
"depth", 0.0, 100.0);
622 add_vwstack(
"start",
"window", -0.1, 0.1, -0.1, 0.1);
623 add_vwstack(
"start",
"type", PERSPECTIVE);
668 char name_cam[FILENAME_MAX];
669 char name[FILENAME_MAX];
673 const char *scene_dir_ = scene_dir.c_str();
674 if (strlen(scene_dir_) >= FILENAME_MAX) {
678 strcpy(name_cam, scene_dir_);
679 strcat(name_cam,
"/camera.bnd");
682 if (strlen(obj) >= FILENAME_MAX) {
688 model = getExtension(obj);
689 if (model == BND_MODEL)
690 set_scene(name, &(this->
scene), 1.0);
691 else if (model == WRL_MODEL)
692 set_scene_wrl(name, &(this->
scene), 1.0);
693 else if (model == UNKNOWN_MODEL) {
694 vpERROR_TRACE(
"Unknown file extension for the 3D model");
697 add_rfstack(IS_BACK);
699 add_vwstack(
"start",
"depth", 0.0, 100.0);
700 add_vwstack(
"start",
"window", -0.1, 0.1, -0.1, 0.1);
701 add_vwstack(
"start",
"type", PERSPECTIVE);
757 float o44c[4][4], o44cd[4][4], x, y, z;
758 Matrix
id = IDENTITY_MATRIX;
776 add_vwstack(
"start",
"cop", o44c[3][0], o44c[3][1], o44c[3][2]);
777 x = o44c[2][0] + o44c[3][0];
778 y = o44c[2][1] + o44c[3][1];
779 z = o44c[2][2] + o44c[3][2];
780 add_vwstack(
"start",
"vrp", x, y, z);
781 add_vwstack(
"start",
"vpn", o44c[2][0], o44c[2][1], o44c[2][2]);
782 add_vwstack(
"start",
"vup", o44c[1][0], o44c[1][1], o44c[1][2]);
783 add_vwstack(
"start",
"window", -u, u, -v, v);
787 add_vwstack(
"start",
"cop", o44cd[3][0], o44cd[3][1], o44cd[3][2]);
788 x = o44cd[2][0] + o44cd[3][0];
789 y = o44cd[2][1] + o44cd[3][1];
790 z = o44cd[2][2] + o44cd[3][2];
791 add_vwstack(
"start",
"vrp", x, y, z);
792 add_vwstack(
"start",
"vpn", o44cd[2][0], o44cd[2][1], o44cd[2][2]);
793 add_vwstack(
"start",
"vup", o44cd[1][0], o44cd[1][1], o44cd[1][2]);
794 add_vwstack(
"start",
"window", -u, u, -v, v);
815 bool changed =
false;
820 if (std::fabs(displacement[2][3]) >
821 std::numeric_limits<double>::epsilon() )
842 float w44o[4][4], w44cext[4][4], w44c[4][4], x, y, z;
845 vp2jlc_matrix(
fMc, w44c);
846 vp2jlc_matrix(
fMo, w44o);
848 add_vwstack(
"start",
"cop", w44cext[3][0], w44cext[3][1], w44cext[3][2]);
849 x = w44cext[2][0] + w44cext[3][0];
850 y = w44cext[2][1] + w44cext[3][1];
851 z = w44cext[2][2] + w44cext[3][2];
852 add_vwstack(
"start",
"vrp", x, y, z);
853 add_vwstack(
"start",
"vpn", w44cext[2][0], w44cext[2][1], w44cext[2][2]);
854 add_vwstack(
"start",
"vup", w44cext[1][0], w44cext[1][1], w44cext[1][2]);
855 add_vwstack(
"start",
"window", -u, u, -v, v);
857 add_vwstack(
"start",
"type", PERSPECTIVE);
889 std::list<vpHomogeneousMatrix>::const_iterator iter_poseList =
poseList.begin();
890 std::list<vpHomogeneousMatrix>::const_iterator iter_fMoList =
fMoList.begin();
892 while ((iter_poseList !=
poseList.end()) && (iter_fMoList !=
fMoList.end())) {
949 float w44o[4][4], w44cext[4][4], w44c[4][4], x, y, z;
967 vp2jlc_matrix(camMft.
inverse(), w44cext);
969 vp2jlc_matrix(
fMo, w44o);
971 add_vwstack(
"start",
"cop", w44cext[3][0], w44cext[3][1], w44cext[3][2]);
972 x = w44cext[2][0] + w44cext[3][0];
973 y = w44cext[2][1] + w44cext[3][1];
974 z = w44cext[2][2] + w44cext[3][2];
975 add_vwstack(
"start",
"vrp", x, y, z);
976 add_vwstack(
"start",
"vpn", w44cext[2][0], w44cext[2][1], w44cext[2][2]);
977 add_vwstack(
"start",
"vup", w44cext[1][0], w44cext[1][1], w44cext[1][2]);
978 add_vwstack(
"start",
"window", -u, u, -v, v);
1026 float o44c[4][4], o44cd[4][4], x, y, z;
1027 Matrix
id = IDENTITY_MATRIX;
1045 add_vwstack(
"start",
"cop", o44c[3][0], o44c[3][1], o44c[3][2]);
1046 x = o44c[2][0] + o44c[3][0];
1047 y = o44c[2][1] + o44c[3][1];
1048 z = o44c[2][2] + o44c[3][2];
1049 add_vwstack(
"start",
"vrp", x, y, z);
1050 add_vwstack(
"start",
"vpn", o44c[2][0], o44c[2][1], o44c[2][2]);
1051 add_vwstack(
"start",
"vup", o44c[1][0], o44c[1][1], o44c[1][2]);
1052 add_vwstack(
"start",
"window", -u, u, -v, v);
1056 add_vwstack(
"start",
"cop", o44cd[3][0], o44cd[3][1], o44cd[3][2]);
1057 x = o44cd[2][0] + o44cd[3][0];
1058 y = o44cd[2][1] + o44cd[3][1];
1059 z = o44cd[2][2] + o44cd[3][2];
1060 add_vwstack(
"start",
"vrp", x, y, z);
1061 add_vwstack(
"start",
"vpn", o44cd[2][0], o44cd[2][1], o44cd[2][2]);
1062 add_vwstack(
"start",
"vup", o44cd[1][0], o44cd[1][1], o44cd[1][2]);
1063 add_vwstack(
"start",
"window", -u, u, -v, v);
1084 bool changed =
false;
1089 if (std::fabs(displacement[2][3]) >
1090 std::numeric_limits<double>::epsilon() )
1111 float w44o[4][4], w44cext[4][4], w44c[4][4], x, y, z;
1114 vp2jlc_matrix(
fMc, w44c);
1115 vp2jlc_matrix(
fMo, w44o);
1117 add_vwstack(
"start",
"cop", w44cext[3][0], w44cext[3][1], w44cext[3][2]);
1118 x = w44cext[2][0] + w44cext[3][0];
1119 y = w44cext[2][1] + w44cext[3][1];
1120 z = w44cext[2][2] + w44cext[3][2];
1121 add_vwstack(
"start",
"vrp", x, y, z);
1122 add_vwstack(
"start",
"vpn", w44cext[2][0], w44cext[2][1], w44cext[2][2]);
1123 add_vwstack(
"start",
"vup", w44cext[1][0], w44cext[1][1], w44cext[1][2]);
1124 add_vwstack(
"start",
"window", -u, u, -v, v);
1125 if ((
object ==
CUBE) || (
object ==
SPHERE)) {
1126 add_vwstack(
"start",
"type", PERSPECTIVE);
1156 std::list<vpHomogeneousMatrix>::const_iterator iter_poseList =
poseList.begin();
1157 std::list<vpHomogeneousMatrix>::const_iterator iter_fMoList =
fMoList.begin();
1159 while ((iter_poseList !=
poseList.end()) && (iter_fMoList !=
fMoList.end())) {
1217 float w44o[4][4], w44cext[4][4], w44c[4][4], x, y, z;
1235 vp2jlc_matrix(camMft.
inverse(), w44cext);
1237 vp2jlc_matrix(
fMo, w44o);
1239 add_vwstack(
"start",
"cop", w44cext[3][0], w44cext[3][1], w44cext[3][2]);
1240 x = w44cext[2][0] + w44cext[3][0];
1241 y = w44cext[2][1] + w44cext[3][1];
1242 z = w44cext[2][2] + w44cext[3][2];
1243 add_vwstack(
"start",
"vrp", x, y, z);
1244 add_vwstack(
"start",
"vpn", w44cext[2][0], w44cext[2][1], w44cext[2][2]);
1245 add_vwstack(
"start",
"vup", w44cext[1][0], w44cext[1][1], w44cext[1][2]);
1246 add_vwstack(
"start",
"window", -u, u, -v, v);
1283 const std::list<vpHomogeneousMatrix> &list_cMo,
1284 const std::list<vpHomogeneousMatrix> &list_fMo,
1287 if (list_cMo.size() != list_fMo.size())
1294 std::list<vpHomogeneousMatrix>::const_iterator it_cMo = list_cMo.begin();
1295 std::list<vpHomogeneousMatrix>::const_iterator it_fMo = list_fMo.begin();
1297 while ((it_cMo != list_cMo.end()) && (it_fMo != list_fMo.end())) {
1330 const std::list<vpHomogeneousMatrix> &list_fMo,
1333 if (list_cMo.size() != list_fMo.size())
1340 std::list<vpHomogeneousMatrix>::const_iterator it_cMo = list_cMo.begin();
1341 std::list<vpHomogeneousMatrix>::const_iterator it_fMo = list_fMo.begin();
1343 while ((it_cMo != list_cMo.end()) && (it_fMo != list_fMo.end())) {
1366 bool clicked =
false;
1367 bool clickedUp =
false;
1416 double anglei = diffi * 360 / width;
1417 double anglej = diffj * 360 / width;
1427 mov.
buildFrom(0, 0, diffi * 0.01, 0, 0, 0);
1437 mov.
buildFrom(diffj * 0.01, diffi * 0.01, 0, 0, 0, 0);
1455 bool clicked =
false;
1456 bool clickedUp =
false;
1507 double anglei = diffi * 360 / width;
1508 double anglej = diffj * 360 / width;
1518 mov.
buildFrom(0, 0, diffi * 0.01, 0, 0, 0);
1528 mov.
buildFrom(diffj * 0.01, diffi * 0.01, 0, 0, 0, 0);
Class to define RGB colors available for display functionalities.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
error that can be emitted by ViSP classes.
@ notInitialized
Used to indicate that a parameter is not initialized.
@ dimensionError
Bad dimension.
@ memoryAllocationError
Memory allocation error.
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Class which enables to project an image in the 3D space and get the view of a virtual camera.
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
void setCameraPosition(const vpHomogeneousMatrix &cMt)
unsigned int getWidth() const
unsigned int getHeight() const
static double rad(double deg)
static Type maximum(const Type &a, const Type &b)
static Type minimum(const Type &a, const Type &b)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_y() const
Get the point y coordinate in the image plane.
double get_x() const
Get the point x coordinate in the image plane.
void setWorldCoordinates(double oX, double oY, double oZ)
vpSceneDesiredObject desiredObject
vpHomogeneousMatrix camMf2
@ D_CIRCLE
The object displayed at the desired position is a circle.
@ D_TOOL
A cylindrical tool is attached to the camera.
vpCameraParameters getInternalCameraParameters(const vpImage< unsigned char > &I) const
bool displayCameraTrajectory
void getInternalImage(vpImage< unsigned char > &I)
bool displayImageSimulator
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
vpCameraTrajectoryDisplayType camTrajType
void display_scene(Matrix mat, Bound_scene &sc, const vpImage< vpRGBa > &I, const vpColor &color)
void displayTrajectory(const vpImage< unsigned char > &I, const std::list< vpHomogeneousMatrix > &list_cMo, const std::list< vpHomogeneousMatrix > &list_fMo, const vpHomogeneousMatrix &camMf)
vpCameraParameters getExternalCameraParameters(const vpImage< unsigned char > &I) const
vpHomogeneousMatrix camMf
std::list< vpImagePoint > cameraTrajectory
bool displayDesiredObject
std::list< vpHomogeneousMatrix > fMoList
virtual ~vpWireFrameSimulator()
std::list< vpImageSimulator > objectImage
vpImagePoint projectCameraTrajectory(const vpImage< vpRGBa > &I, const vpHomogeneousMatrix &cMo, const vpHomogeneousMatrix &fMo)
@ 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.
void getExternalImage(vpImage< unsigned char > &I)
vpHomogeneousMatrix navigation(const vpImage< vpRGBa > &I, bool &changed)
std::list< vpHomogeneousMatrix > poseList