Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpFeatureBuilderLine.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Conversion between tracker and visual feature line.
33  *
34 *****************************************************************************/
35 
42 #include <visp3/core/vpDebug.h>
43 #include <visp3/core/vpMath.h>
44 #include <visp3/visual_features/vpFeatureBuilder.h>
45 
46 BEGIN_VISP_NAMESPACE
60 {
61  try {
62  double A, B, C, D;
63  s.setRhoTheta(t.getRho(), t.getTheta());
64 
65  if (fabs(t.cP[3]) > fabs(t.cP[7])) // |D1| > |D2|
66  {
67  A = t.cP[0];
68  B = t.cP[1];
69  C = t.cP[2];
70  D = t.cP[3];
71  }
72  else {
73  A = t.cP[4];
74  B = t.cP[5];
75  C = t.cP[6];
76  D = t.cP[7];
77  }
78 
79  s.setABCD(A, B, C, D);
80 
81  }
82  catch (...) {
83  vpERROR_TRACE("Error caught");
84  throw;
85  }
86 }
87 
104 {
105  try {
106  double a = t.getA();
107  double b = t.getB();
108  double c = t.getC();
109 
110  double x0 = t.getX();
111  double y0 = t.getY();
112  double z0 = t.getZ();
113 
114  double R = t.getR();
115 
116  double D =
117  vpMath::sqr(x0) + vpMath::sqr(y0) + vpMath::sqr(z0) - vpMath::sqr(R) - vpMath::sqr(a * x0 + b * y0 + c * z0);
118 
119  double alpha1 = (1 - a * a) * x0 - a * b * y0 - a * c * z0;
120  double beta1 = -a * b * x0 + (1 - b * b) * y0 - b * c * z0;
121  double gamma1 = -a * c * x0 - b * c * y0 + (1 - c * c) * z0;
122 
123  D *= -1;
124 
125  if (D < 0) {
126  alpha1 *= -1;
127  beta1 *= -1;
128  gamma1 *= -1;
129  D *= -1;
130  }
131 
132  s.setABCD(alpha1, beta1, gamma1, D);
133 
134  if (line == vpCylinder::line1) {
135 
136  s.setRhoTheta(t.getRho1(), t.getTheta1());
137 
138  }
139  else {
140 
141  s.setRhoTheta(t.getRho2(), t.getTheta2());
142  }
143  }
144  catch (...) {
145  vpERROR_TRACE("Error caught");
146  throw;
147  }
148 }
149 
150 #ifdef VISP_HAVE_MODULE_ME
198 {
199  try {
200  double rhop = t.getRho();
201  double thetap = t.getTheta();
202  double rho;
203  double theta;
204 
205  // Gives the rho and theta coordinates in the (u,v) coordinate system.
206  if (thetap >= 0 && thetap < M_PI / 2) {
207  thetap = M_PI / 2 - thetap;
208  }
209 
210  else if (thetap >= M_PI / 2 && thetap < 3 * M_PI / 2) {
211  thetap = 3 * M_PI / 2 + M_PI - thetap;
212  }
213 
214  else if (thetap >= 3 * M_PI / 2 && thetap <= 2 * M_PI) {
215  thetap = M_PI / 2 + 2 * M_PI - thetap;
216  }
217 
218  // while (thetap > M_PI/2) { thetap -= M_PI ; rhop *= -1 ; }
219  // while (thetap < -M_PI/2) { thetap += M_PI ; rhop *= -1 ; }
220 
221  // vpTRACE("pixel %f %f",rhop, thetap) ;
222  vpPixelMeterConversion::convertLine(cam, rhop, thetap, rho, theta);
223 
224  while (theta > M_PI) {
225  theta -= 2 * M_PI;
226  }
227  while (theta < -M_PI) {
228  theta += 2 * M_PI;
229  }
230 
231  s.buildFrom(rho, theta);
232  }
233  catch (...) {
234  vpERROR_TRACE("Error caught");
235  throw;
236  }
237 }
238 #endif //#ifdef VISP_HAVE_MODULE_ME
239 END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
Definition: vpCylinder.h:101
double getZ() const
Definition: vpCylinder.h:183
double getRho1() const
Definition: vpCylinder.h:134
double getB() const
Definition: vpCylinder.h:163
double getX() const
Definition: vpCylinder.h:173
double getY() const
Definition: vpCylinder.h:178
double getA() const
Definition: vpCylinder.h:158
double getTheta1() const
Definition: vpCylinder.h:140
double getR() const
Definition: vpCylinder.h:188
double getC() const
Definition: vpCylinder.h:168
double getTheta2() const
Definition: vpCylinder.h:153
double getRho2() const
Definition: vpCylinder.h:147
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
void setRhoTheta(double rho, double theta)
vpFeatureLine & buildFrom(const double &rho, const double &theta)
void setABCD(double A, double B, double C, double D)
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition: vpLine.h:103
double getRho() const
Definition: vpLine.h:132
double getTheta() const
Definition: vpLine.h:143
static double sqr(double x)
Definition: vpMath.h:203
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:152
double getRho() const
Definition: vpMeLine.cpp:843
double getTheta() const
Definition: vpMeLine.cpp:845
static void convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p, double &rho_m, double &theta_m)
vpColVector cP
Definition: vpTracker.h:73