Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureBuilderLine.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Conversion between tracker and visual feature line.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
45 #include <visp3/visual_features/vpFeatureBuilder.h>
46 #include <visp3/core/vpMath.h>
47 
48 
49 
61 {
62  try
63  {
64  double A,B,C,D ;
65  s.setRhoTheta(t.getRho(),t.getTheta()) ;
66 
67  if (fabs(t.cP[3]) > fabs(t.cP[7])) // |D1| > |D2|
68  {
69  A = t.cP[0] ;
70  B = t.cP[1] ;
71  C = t.cP[2] ;
72  D = t.cP[3] ;
73  }
74  else
75  {
76  A = t.cP[4] ;
77  B = t.cP[5] ;
78  C = t.cP[6] ;
79  D = t.cP[7] ;
80  }
81 
82 
83  s.setABCD(A,B,C,D) ;
84 
85  }
86  catch(...)
87  {
88  vpERROR_TRACE("Error caught") ;
89  throw ;
90  }
91 
92 }
93 
109  const vpCylinder &t,
110  const int line)
111 {
112  try
113  {
114 
115  double a = t.getA() ;
116  double b = t.getB() ;
117  double c = t.getC() ;
118 
119  double x0 = t.getX() ;
120  double y0 = t.getY() ;
121  double z0 = t.getZ() ;
122 
123  double R = t.getR() ;
124 
125  double D =
126  vpMath::sqr(x0) + vpMath::sqr(y0) + vpMath::sqr(z0)
127  - vpMath::sqr(R)
128  - vpMath::sqr(a*x0 + b*y0 + c*z0);
129 
130  double alpha1 = (1 - a*a)*x0 - a*b*y0 - a*c*z0;
131  double beta1 = -a*b*x0 + (1 - b*b)*y0 - b*c*z0;
132  double gamma1 = -a*c*x0 - b*c*y0 + (1 - c*c)*z0;
133 
134  D*=-1 ;
135 
136  if (D<0)
137  {
138  alpha1*=-1 ;
139  beta1*=-1 ;
140  gamma1*=-1 ;
141  D*=-1 ;
142  }
143 
144  s.setABCD(alpha1,beta1,gamma1,D) ;
145 
146  if (line==vpCylinder::line1)
147  {
148 
149  s.setRhoTheta(t.getRho1(),t.getTheta1()) ;
150 
151  }
152  else
153  {
154 
155  s.setRhoTheta(t.getRho2(),t.getTheta2()) ;
156  }
157  }
158  catch(...)
159  {
160  vpERROR_TRACE("Error caught") ;
161  throw ;
162  }
163 }
164 
165 
166 #ifdef VISP_HAVE_MODULE_ME
167 
210 void
212  const vpCameraParameters &cam,
213  const vpMeLine &t)
214 {
215  try{
216  double rhop = t.getRho() ;
217  double thetap = t.getTheta();
218  double rho ;
219  double theta ;
220 
221  //Gives the rho and theta coordinates in the (u,v) coordinate system.
222  if (thetap >= 0 && thetap < M_PI/2)
223  {
224  thetap = M_PI/2 - thetap;
225  }
226 
227  else if (thetap >= M_PI/2 && thetap < 3*M_PI/2)
228  {
229  thetap = 3*M_PI/2 + M_PI - thetap;
230  }
231 
232  else if (thetap >= 3*M_PI/2 && thetap <= 2*M_PI)
233  {
234  thetap = M_PI/2 + 2*M_PI - thetap;
235  }
236 
237  //while (thetap > M_PI/2) { thetap -= M_PI ; rhop *= -1 ; }
238  //while (thetap < -M_PI/2) { thetap += M_PI ; rhop *= -1 ; }
239 
240  // vpTRACE("pixel %f %f",rhop, thetap) ;
241  vpPixelMeterConversion::convertLine(cam,rhop,thetap, rho,theta) ;
242 
243  while (theta > M_PI) { theta -= 2*M_PI ; }
244  while (theta < -M_PI) { theta += 2*M_PI ; }
245  // vpTRACE("meter %f %f",rho, theta) ;
246  /*
247 
248  while(theta < -M_PI) theta += 2*M_PI ;
249  while(theta >= M_PI) theta -= 2*M_PI ;
250 
251  // If theta is between -90 and -180 get the equivalent
252  // between 0 and 90
253  if(theta <-M_PI/2)
254  {
255  theta += M_PI ;
256  rho *= -1 ;
257  }
258  // If theta is between 90 and 180 get the equivalent
259  // between 0 and -90
260  if(theta >M_PI/2)
261  {
262  theta -= M_PI ;
263  rho *= -1 ;
264  }
265  */
266  s.buildFrom(rho,theta) ;
267  // vpTRACE("meter %f %f",rho, theta) ;
268 
269  }
270  catch(...)
271  {
272  vpERROR_TRACE("Error caught") ;
273  throw ;
274  }
275 }
276 #endif //#ifdef VISP_HAVE_MODULE_ME
void setABCD(const double A, const double B, const double C, const double D)
double getY() const
Definition: vpCylinder.h:173
double getTheta() const
Definition: vpMeLine.cpp:1055
#define vpERROR_TRACE
Definition: vpDebug.h:391
double getZ() const
Definition: vpCylinder.h:177
double getRho2() const
Definition: vpCylinder.h:146
double getTheta() const
Definition: vpLine.h:147
vpColVector cP
Definition: vpTracker.h:77
double getRho() const
Definition: vpLine.h:158
void buildFrom(const double rho, const double theta)
double getTheta1() const
Definition: vpCylinder.h:139
Class that defines a line in the object frame, the camera frame and the image plane. All the parameters must be set in meter.
Definition: vpLine.h:105
double getC() const
Definition: vpCylinder.h:165
static double sqr(double x)
Definition: vpMath.h:110
double getB() const
Definition: vpCylinder.h:161
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:152
Generic class defining intrinsic camera parameters.
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
Class that defines what is a cylinder.
Definition: vpCylinder.h:93
double getA() const
Definition: vpCylinder.h:157
double getRho1() const
Definition: vpCylinder.h:133
double getTheta2() const
Definition: vpCylinder.h:152
static void convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p, double &rho_m, double &theta_m)
line coordinates conversion (rho,theta)
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
double getRho() const
Definition: vpMeLine.cpp:1046
double getX() const
Definition: vpCylinder.h:169
double getR() const
Definition: vpCylinder.h:181
void setRhoTheta(const double rho, const double theta)