ViSP  2.6.2
vpFeatureBuilderLine.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureBuilderLine.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  * Conversion between tracker and visual feature line.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
49 #include <visp/vpFeatureBuilder.h>
50 
51 
52 #include <visp/vpMath.h>
53 
54 
55 
67 {
68  try
69  {
70  double A,B,C,D ;
71  s.setRhoTheta(t.getRho(),t.getTheta()) ;
72 
73  if (fabs(t.cP[3]) > fabs(t.cP[7])) // |D1| > |D2|
74  {
75  A = t.cP[0] ;
76  B = t.cP[1] ;
77  C = t.cP[2] ;
78  D = t.cP[3] ;
79  }
80  else
81  {
82  A = t.cP[4] ;
83  B = t.cP[5] ;
84  C = t.cP[6] ;
85  D = t.cP[7] ;
86  }
87 
88 
89  s.setABCD(A,B,C,D) ;
90 
91  }
92  catch(...)
93  {
94  vpERROR_TRACE("Error caught") ;
95  throw ;
96  }
97 
98 }
99 
115  const vpCylinder &t,
116  const int line)
117 {
118  try
119  {
120 
121  double a = t.getA() ;
122  double b = t.getB() ;
123  double c = t.getC() ;
124 
125  double x0 = t.getX() ;
126  double y0 = t.getY() ;
127  double z0 = t.getZ() ;
128 
129  double R = t.getR() ;
130 
131  double D =
132  vpMath::sqr(x0) + vpMath::sqr(y0) + vpMath::sqr(z0)
133  - vpMath::sqr(R)
134  - vpMath::sqr(a*x0 + b*y0 + c*z0);
135 
136  double alpha1 = (1 - a*a)*x0 - a*b*y0 - a*c*z0;
137  double beta1 = -a*b*x0 + (1 - b*b)*y0 - b*c*z0;
138  double gamma1 = -a*c*x0 - b*c*y0 + (1 - c*c)*z0;
139 
140  D*=-1 ;
141 
142  if (D<0)
143  {
144  alpha1*=-1 ;
145  beta1*=-1 ;
146  gamma1*=-1 ;
147  D*=-1 ;
148  }
149 
150  s.setABCD(alpha1,beta1,gamma1,D) ;
151 
152  if (line==vpCylinder::line1)
153  {
154 
155  s.setRhoTheta(t.getRho1(),t.getTheta1()) ;
156 
157  }
158  else
159  {
160 
161  s.setRhoTheta(t.getRho2(),t.getTheta2()) ;
162  }
163  }
164  catch(...)
165  {
166  vpERROR_TRACE("Error caught") ;
167  throw ;
168  }
169 }
170 
171 
215 void
217  const vpCameraParameters &cam,
218  const vpMeLine &t)
219 {
220  double rhop ;
221  double thetap ;
222 
223  double rho ;
224  double theta ;
225 
226  try{
227  rhop = t.getRho() ;
228  thetap = t.getTheta();
229 
230  //Gives the rho and theta coordinates in the (u,v) coordinate system.
231  if (thetap >= 0 && thetap < M_PI/2)
232  {
233  thetap = M_PI/2 - thetap;
234  }
235 
236  else if (thetap >= M_PI/2 && thetap < 3*M_PI/2)
237  {
238  thetap = 3*M_PI/2 + M_PI - thetap;
239  }
240 
241  else if (thetap >= 3*M_PI/2 && thetap <= 2*M_PI)
242  {
243  thetap = M_PI/2 + 2*M_PI - thetap;
244  }
245 
246  //while (thetap > M_PI/2) { thetap -= M_PI ; rhop *= -1 ; }
247  //while (thetap < -M_PI/2) { thetap += M_PI ; rhop *= -1 ; }
248 
249  // vpTRACE("pixel %f %f",rhop, thetap) ;
250  vpPixelMeterConversion::convertLine(cam,rhop,thetap, rho,theta) ;
251 
252  while (theta > M_PI) { thetap -= 2*M_PI ; }
253  while (theta < -M_PI) { thetap += 2*M_PI ; }
254  // vpTRACE("meter %f %f",rho, theta) ;
255  /*
256 
257  while(theta < -M_PI) theta += 2*M_PI ;
258  while(theta >= M_PI) theta -= 2*M_PI ;
259 
260  // If theta is between -90 and -180 get the equivalent
261  // between 0 and 90
262  if(theta <-M_PI/2)
263  {
264  theta += M_PI ;
265  rho *= -1 ;
266  }
267  // If theta is between 90 and 180 get the equivalent
268  // between 0 and -90
269  if(theta >M_PI/2)
270  {
271  theta -= M_PI ;
272  rho *= -1 ;
273  }
274  */
275  s.buildFrom(rho,theta) ;
276  // vpTRACE("meter %f %f",rho, theta) ;
277 
278  }
279  catch(...)
280  {
281  vpERROR_TRACE("Error caught") ;
282  throw ;
283  }
284 }
285 
286 /*
287  * Local variables:
288  * c-basic-offset: 2
289  * End:
290  */
void setABCD(const double A, const double B, const double C, const double D)
double getY() const
Definition: vpCylinder.h:175
#define vpERROR_TRACE
Definition: vpDebug.h:379
double getTheta() const
Definition: vpMeLine.cpp:1029
double getZ() const
Definition: vpCylinder.h:179
double getRho2() const
Definition: vpCylinder.h:148
double getTheta() const
Definition: vpLine.h:166
vpColVector cP
Definition: vpTracker.h:82
double getRho() const
Definition: vpLine.h:177
void buildFrom(const double rho, const double theta)
double getTheta1() const
Definition: vpCylinder.h:141
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:124
double getC() const
Definition: vpCylinder.h:167
static double sqr(double x)
Definition: vpMath.h:106
double getB() const
Definition: vpCylinder.h:163
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:149
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:97
double getA() const
Definition: vpCylinder.h:159
double getRho1() const
Definition: vpCylinder.h:135
double getTheta2() const
Definition: vpCylinder.h:154
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:1020
double getX() const
Definition: vpCylinder.h:171
double getR() const
Definition: vpCylinder.h:183
void setRhoTheta(const double rho, const double theta)