Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpProjectionDisplay.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 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 * Interface with the image for feature display.
32 */
33
38
39#include <visp3/core/vpConfig.h>
40#if defined(VISP_HAVE_DISPLAY)
41
42// Meter/pixel conversion
43#include <visp3/core/vpCameraParameters.h>
44#include <visp3/core/vpMath.h>
45#include <visp3/core/vpMeterPixelConversion.h>
46#include <visp3/core/vpPoint.h>
47
48// Color / image / display
49#include <visp3/core/vpColor.h>
50#include <visp3/core/vpImage.h>
51
52#include <visp3/core/vpDisplay.h>
53
54#include <visp3/gui/vpProjectionDisplay.h>
55
56//#include <visp3/visual_features/vpBasicFeature.h>
57
59
61{
62 // vpForwardProjection *f ;
63 // f = fp.duplicate() ;
64 // f->setDeallocate(vpForwardProjection::vpDisplayForwardProjection) ;
65
66 listFp.push_back(&fp);
67}
68
70{
71 o.setWorldCoordinates(0, 0, 0);
72 x.setWorldCoordinates(0.1, 0, 0);
73 y.setWorldCoordinates(0, 0.1, 0);
74 z.setWorldCoordinates(0, 0, 0.1);
75 traj.resize(0, 2);
76}
77void vpProjectionDisplay::init(const int select)
78{
79 if (select & vpProjectionDisplay::internalView()) {
80 Icam.resize(256, 256);
81 dIcam.init(Icam, 100, 100);
82 }
83 if (select & vpProjectionDisplay::externalView()) {
84 Iext.resize(256, 256);
85 dIext.init(Iext, 400, 100);
86 }
87
88 init();
89}
90
92
94 const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color,
95 const bool &displayTraj, unsigned int thickness)
96{
97
98 for (std::list<vpForwardProjection *>::const_iterator it = listFp.begin(); it != listFp.end(); ++it) {
99 vpForwardProjection *fp = *it;
100 fp->display(I, cextMo, cam, color, thickness);
101 }
102
103 if (displayTraj) // display past camera positions
104 for (unsigned int i = 0; i < traj.getRows(); ++i)
105 vpDisplay::displayCircle(I, static_cast<int>(traj[i][0]), static_cast<int>(traj[i][1]), 2, vpColor::green, true);
106
107 displayCamera(I, cextMo, cMo, cam, thickness);
108
109 if (displayTraj) // store current camera position
110 {
111 const unsigned int n = traj.getRows();
112 traj.resize(n + 1, 2, false);
113 vpMeterPixelConversion::convertPoint(cam, o.p[0], o.p[1], traj[n][1], traj[n][0]);
114 }
115}
116
118 const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
119 unsigned int thickness)
120{
122 c1Mc = cextMo * cMo.inverse();
123
124 o.track(c1Mc);
125
126 if (o.get_Z() < 0) // do not print camera if behind the external camera
127 return;
128
129 x.track(c1Mc);
130 y.track(c1Mc);
131 z.track(c1Mc);
132
133 vpImagePoint ipo;
134 vpImagePoint ip;
135
136 vpMeterPixelConversion::convertPoint(cam, o.p[0], o.p[1], ipo);
137
138 vpMeterPixelConversion::convertPoint(cam, x.p[0], x.p[1], ip);
139 vpDisplay::displayArrow(I, ipo, ip, vpColor::red, 4 + thickness, 2 + thickness, thickness);
140
141 vpMeterPixelConversion::convertPoint(cam, y.p[0], y.p[1], ip);
142 vpDisplay::displayArrow(I, ipo, ip, vpColor::green, 4 + thickness, 2 + thickness, thickness);
143
144 vpMeterPixelConversion::convertPoint(cam, z.p[0], z.p[1], ip);
145 vpDisplay::displayArrow(I, ipo, ip, vpColor::blue, 4 + thickness, 2 + thickness, thickness);
146}
147
148END_VISP_NAMESPACE
149
150#elif !defined(VISP_BUILD_SHARED_LIBS)
151// Work around to avoid warning: libvisp_gui.a(vpProjectionDisplay.cpp.o)
152// has no symbols
153void dummy_vpProjectionDisplay() { }
154#endif
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor red
Definition vpColor.h:198
static const vpColor blue
Definition vpColor.h:204
static const vpColor green
Definition vpColor.h:201
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
Class that defines what is a generic geometric feature.
virtual void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1)=0
Implementation of an homogeneous matrix and operations on such kind of matrices.
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 void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
void insert(vpForwardProjection &fp)
void displayCamera(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, unsigned int thickness=1)
void display(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color, const bool &displayTraj=false, unsigned int thickness=1)