Visual Servoing Platform  version 3.0.0
vpFeatureBuilderLine.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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  double rhop ;
216  double thetap ;
217 
218  double rho ;
219  double theta ;
220 
221  try{
222  rhop = t.getRho() ;
223  thetap = t.getTheta();
224 
225  //Gives the rho and theta coordinates in the (u,v) coordinate system.
226  if (thetap >= 0 && thetap < M_PI/2)
227  {
228  thetap = M_PI/2 - thetap;
229  }
230 
231  else if (thetap >= M_PI/2 && thetap < 3*M_PI/2)
232  {
233  thetap = 3*M_PI/2 + M_PI - thetap;
234  }
235 
236  else if (thetap >= 3*M_PI/2 && thetap <= 2*M_PI)
237  {
238  thetap = M_PI/2 + 2*M_PI - thetap;
239  }
240 
241  //while (thetap > M_PI/2) { thetap -= M_PI ; rhop *= -1 ; }
242  //while (thetap < -M_PI/2) { thetap += M_PI ; rhop *= -1 ; }
243 
244  // vpTRACE("pixel %f %f",rhop, thetap) ;
245  vpPixelMeterConversion::convertLine(cam,rhop,thetap, rho,theta) ;
246 
247  while (theta > M_PI) { theta -= 2*M_PI ; }
248  while (theta < -M_PI) { theta += 2*M_PI ; }
249  // vpTRACE("meter %f %f",rho, theta) ;
250  /*
251 
252  while(theta < -M_PI) theta += 2*M_PI ;
253  while(theta >= M_PI) theta -= 2*M_PI ;
254 
255  // If theta is between -90 and -180 get the equivalent
256  // between 0 and 90
257  if(theta <-M_PI/2)
258  {
259  theta += M_PI ;
260  rho *= -1 ;
261  }
262  // If theta is between 90 and 180 get the equivalent
263  // between 0 and -90
264  if(theta >M_PI/2)
265  {
266  theta -= M_PI ;
267  rho *= -1 ;
268  }
269  */
270  s.buildFrom(rho,theta) ;
271  // vpTRACE("meter %f %f",rho, theta) ;
272 
273  }
274  catch(...)
275  {
276  vpERROR_TRACE("Error caught") ;
277  throw ;
278  }
279 }
280 #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:171
double getTheta() const
Definition: vpMeLine.cpp:1057
#define vpERROR_TRACE
Definition: vpDebug.h:391
double getZ() const
Definition: vpCylinder.h:175
double getRho2() const
Definition: vpCylinder.h:144
double getTheta() const
Definition: vpLine.h:162
vpColVector cP
Definition: vpTracker.h:77
double getRho() const
Definition: vpLine.h:173
void buildFrom(const double rho, const double theta)
double getTheta1() const
Definition: vpCylinder.h:137
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:120
double getC() const
Definition: vpCylinder.h:163
static double sqr(double x)
Definition: vpMath.h:110
double getB() const
Definition: vpCylinder.h:159
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:155
double getRho1() const
Definition: vpCylinder.h:131
double getTheta2() const
Definition: vpCylinder.h:150
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:1048
double getX() const
Definition: vpCylinder.h:167
double getR() const
Definition: vpCylinder.h:179
void setRhoTheta(const double rho, const double theta)