ViSP  2.8.0
vpProjectionDisplay.cpp
1 /****************************************************************************
2  *
3  * $Id: vpProjectionDisplay.cpp 4238 2013-05-06 13:29:30Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Interface with the image for feature display.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
48 #include <visp/vpConfig.h>
49 #if defined (VISP_HAVE_DISPLAY)
50 
51 // Meter/pixel conversion
52 #include <visp/vpCameraParameters.h>
53 #include <visp/vpMeterPixelConversion.h>
54 #include <visp/vpPoint.h>
55 #include <visp/vpMath.h>
56 
57 //Color / image / display
58 #include <visp/vpColor.h>
59 #include <visp/vpImage.h>
60 
61 #include <visp/vpDisplay.h>
62 
63 #include <visp/vpProjectionDisplay.h>
64 
65 #include <visp/vpBasicFeature.h>
66 
67 
68 void
70 {
71  // vpForwardProjection *f ;
72  // f = fp.duplicate() ;
73  // f->setDeallocate(vpForwardProjection::vpDisplayForwardProjection) ;
74 
75  listFp.push_back(&fp);
76 }
77 
78 void
80 {
81  o.setWorldCoordinates(0,0,0) ;
82  x.setWorldCoordinates(0.1,0,0) ;
83  y.setWorldCoordinates(0,0.1,0) ;
84  z.setWorldCoordinates(0,0,0.1) ;
85  traj.resize(0,2);
86 }
87 void
88 vpProjectionDisplay::init(const int select)
89 {
90  if (select & vpProjectionDisplay::internalView())
91  {
92  Icam.resize(256,256) ;
93  dIcam.init(Icam,100,100) ;
94  }
95  if (select & vpProjectionDisplay::externalView())
96  {
97  Iext.resize(256,256) ;
98  dIext.init(Iext,400,100) ;
99  }
100 
101  init() ;
102 }
103 
104 
105 void
107 {
108 
109 }
110 
111 void
113  const vpHomogeneousMatrix &cextMo,
114  const vpHomogeneousMatrix &cMo,
115  const vpCameraParameters &cam,
116  const vpColor &color,
117  const bool &displayTraj,
118  const unsigned int thickness)
119 {
120 
121  for (std::list<vpForwardProjection *>::const_iterator it = listFp.begin() ; it != listFp.end(); ++it )
122  {
123  vpForwardProjection *fp = *it ;
124  fp->display(I,cextMo, cam, color, thickness) ;
125  }
126 
127  if(displayTraj) // display past camera positions
128  for(unsigned int i=0;i<traj.getRows();++i)
129  vpDisplay::displayCircle(I,(int)traj[i][0],(int)traj[i][1],2,vpColor::green,true);
130 
131  displayCamera(I, cextMo, cMo, cam, thickness);
132 
133  if(displayTraj) // store current camera position
134  {
135  const unsigned int n = traj.getRows();
136  traj.resize(n+1, 2, false);
137  vpMeterPixelConversion::convertPoint(cam,o.p[0],o.p[1],traj[n][1],traj[n][0]);
138  }
139 }
140 
141 
142 void
144  const vpHomogeneousMatrix &cextMo,
145  const vpHomogeneousMatrix &cMo,
146  const vpCameraParameters &cam,
147  const unsigned int thickness)
148 {
149  vpHomogeneousMatrix c1Mc ;
150  c1Mc = cextMo*cMo.inverse() ;
151 
152  o.track(c1Mc) ;
153 
154  if(o.get_Z() < 0) // do not print camera if behind the external camera
155  return;
156 
157  x.track(c1Mc) ;
158  y.track(c1Mc) ;
159  z.track(c1Mc) ;
160 
161  vpImagePoint ipo;
162  vpImagePoint ipx;
163 
164  vpMeterPixelConversion::convertPoint(cam, o.p[0], o.p[1], ipo) ;
165 
166  vpMeterPixelConversion::convertPoint(cam, x.p[0], x.p[1], ipx) ;
167  vpDisplay::displayArrow(I, ipo, ipx, vpColor::green, 4+thickness, 2+thickness, thickness) ;
168 
169  vpMeterPixelConversion::convertPoint(cam, y.p[0], y.p[1], ipx) ;
170  vpDisplay::displayArrow(I, ipo, ipx, vpColor::blue, 4+thickness, 2+thickness, thickness) ;
171 
172  vpMeterPixelConversion::convertPoint(cam, z.p[0], z.p[1], ipx) ;
173  vpDisplay::displayArrow(I, ipo, ipx, vpColor::red, 4+thickness, 2+thickness, thickness) ;
174 }
175 
176 #endif
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:174
virtual void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)=0
void display(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color, const bool &displayTraj=false, const unsigned int thickness=1)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:535
virtual void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)=0
void track(const vpHomogeneousMatrix &cMo)
static const vpColor green
Definition: vpColor.h:170
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a generic geometric feature.
Generic class defining intrinsic camera parameters.
void insert(vpForwardProjection &fp)
double get_Z() const
Get the point Z coordinate in the camera frame.
Definition: vpPoint.h:122
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:92
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Definition: vpDisplayX.cpp:184
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:157
void displayCamera(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const unsigned int thickness=1)
vpColVector p
Definition: vpTracker.h:78
static const vpColor blue
Definition: vpColor.h:173
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
Definition: vpPoint.cpp:74