ViSP  2.6.2
vpProjectionDisplay.cpp
1 /****************************************************************************
2  *
3  * $Id: vpProjectionDisplay.cpp 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
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 {
119 
120  for (std::list<vpForwardProjection *>::const_iterator it = listFp.begin() ; it != listFp.end(); ++it )
121  {
122  vpForwardProjection *fp = *it ;
123  fp->display(I,cextMo,cam, color) ;
124  }
125 
126  if(displayTraj) // display past camera positions
127  for(unsigned int i=0;i<traj.getRows();++i)
128  vpDisplay::displayCircle(I,(int)traj[i][0],(int)traj[i][1],2,vpColor::green,true);
129 
130  displayCamera(I,cextMo,cMo, cam);
131 
132  if(displayTraj) // store current camera position
133  {
134  const unsigned int n = traj.getRows();
135  traj.resize(n+1,2,false);
136  vpMeterPixelConversion::convertPoint(cam,o.p[0],o.p[1],traj[n][1],traj[n][0]);
137  }
138 }
139 
140 
141 void
143  const vpHomogeneousMatrix &cextMo,
144  const vpHomogeneousMatrix &cMo,
145  const vpCameraParameters &cam)
146 {
147  vpHomogeneousMatrix c1Mc ;
148  c1Mc = cextMo*cMo.inverse() ;
149 
150  o.track(c1Mc) ;
151 
152  if(o.get_Z() < 0) // do not print camera if behind the external camera
153  return;
154 
155  x.track(c1Mc) ;
156  y.track(c1Mc) ;
157  z.track(c1Mc) ;
158 
159  vpImagePoint ipo;
160  vpImagePoint ipx;
161 
162  vpMeterPixelConversion::convertPoint(cam, o.p[0], o.p[1], ipo) ;
163 
164  vpMeterPixelConversion::convertPoint(cam, x.p[0], x.p[1], ipx) ;
166 
167  vpMeterPixelConversion::convertPoint(cam, y.p[0], y.p[1], ipx) ;
168  vpDisplay::displayArrow(I, ipo, ipx, vpColor::blue) ;
169 
170  vpMeterPixelConversion::convertPoint(cam, z.p[0], z.p[1], ipx) ;
171  vpDisplay::displayArrow(I, ipo, ipx, vpColor::red) ;
172 }
173 
174 #endif
175 
176 /*
177  * Local variables:
178  * c-basic-offset: 2
179  * End:
180  */
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
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:123
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:530
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:168
static const vpColor red
Definition: vpColor.h:165
void displayCamera(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
Class that defines what is a generic geometric feature.
Generic class defining intrinsic camera parameters.
void insert(vpForwardProjection &fp)
void display(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor color, const bool &displayTraj=false)
double get_Z() const
Get the point Z coordinate in the camera frame.
Definition: vpPoint.h:129
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:196
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:157
vpColVector p
Definition: vpTracker.h:78
static const vpColor blue
Definition: vpColor.h:171
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