Visual Servoing Platform  version 3.6.1 under development (2024-02-13)
vpProjectionDisplay.cpp
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  * Interface with the image for feature display.
33  *
34 *****************************************************************************/
35 
41 #include <visp3/core/vpConfig.h>
42 #if defined(VISP_HAVE_DISPLAY)
43 
44 // Meter/pixel conversion
45 #include <visp3/core/vpCameraParameters.h>
46 #include <visp3/core/vpMath.h>
47 #include <visp3/core/vpMeterPixelConversion.h>
48 #include <visp3/core/vpPoint.h>
49 
50 // Color / image / display
51 #include <visp3/core/vpColor.h>
52 #include <visp3/core/vpImage.h>
53 
54 #include <visp3/core/vpDisplay.h>
55 
56 #include <visp3/gui/vpProjectionDisplay.h>
57 
58 //#include <visp3/visual_features/vpBasicFeature.h>
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 }
77 void 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 {
121  vpHomogeneousMatrix c1Mc;
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 
148 #elif !defined(VISP_BUILD_SHARED_LIBS)
149 // Work around to avoid warning: libvisp_core.a(vpProjectionDisplay.cpp.o)
150 // has no symbols
151 void dummy_vpProjectionDisplay(){};
152 #endif
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:299
unsigned int getRows() const
Definition: vpArray2D.h:284
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor red
Definition: vpColor.h:211
static const vpColor blue
Definition: vpColor.h:217
static const vpColor green
Definition: vpColor.h:214
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
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
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:780
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
double get_Z() const
Get the point cZ coordinate in the camera frame.
Definition: vpPoint.cpp:445
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:110
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)
void insert(vpForwardProjection &fp)
vpColVector p
Definition: vpTracker.h:67