Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpFeatureBuilderVanishingPoint.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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 vanishing point.
33  *
34  * Authors:
35  * Odile Bourquardez
36  *
37  *****************************************************************************/
38 
44 #include <visp3/core/vpException.h>
45 #include <visp3/visual_features/vpFeatureBuilder.h>
46 #include <visp3/visual_features/vpFeatureException.h>
47 
58 {
59  try {
60  s.set_x(t.get_x());
61  s.set_y(t.get_y());
62  } catch (...) {
63  vpERROR_TRACE("Cannot create vanishing point feature");
64  throw;
65  }
66 }
67 
82 {
83  double rho_l;
84  double rho_r;
85  double theta_l;
86  double theta_r;
87  double c_l;
88  double s_l;
89  double c_r;
90  double s_r;
91 
92  rho_l = L1.getRho();
93  rho_r = L2.getRho();
94  theta_l = L1.getTheta();
95  theta_r = L2.getTheta();
96  c_l = cos(theta_l);
97  c_r = cos(theta_r);
98  s_l = sin(theta_l);
99  s_r = sin(theta_r);
100 
101  double x, y;
102 
103  double min = 0.0001;
104  if (fabs(theta_r - theta_l) < min || fabs(fabs(theta_r - theta_l) - M_PI) < min ||
105  fabs(fabs(theta_r - theta_l) - 2 * M_PI) < min) {
106  vpCERROR << "There is no vanishing point : the lines are parallel in the "
107  "image plane"
108  << std::endl;
109  throw(vpFeatureException(vpFeatureException::badInitializationError, "There is no vanishing point : the lines are "
110  "parallel in the image plane"));
111  }
112 
113  y = (rho_r * c_l - rho_l * c_r) / (-s_l * c_r + s_r * c_l);
114  x = (rho_r * s_l - rho_l * s_r) / (-c_l * s_r + c_r * s_l);
115 
116  s.set_x(x);
117  s.set_y(y);
118 }
119 
134 {
135  vpFeatureLine l1, l2;
136  vpFeatureBuilder::create(l1, L1);
137  vpFeatureBuilder::create(l2, L2);
138 
139  vpFeatureBuilder::create(s, l1, l2);
140 }
#define vpCERROR
Definition: vpDebug.h:365
#define vpERROR_TRACE
Definition: vpDebug.h:393
Class that defines 2D vanishing point visual feature (Z coordinate in 3D space is infinity)...
double getRho() const
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:431
double getTheta() const
Class that defines what is a point.
Definition: vpPoint.h:58
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
Error that can be emited by the vpBasicFeature class and its derivates.
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:429
void set_x(const double _x)
Set the point x-coordinates.
void set_y(const double _y)
Set the point y-coordinates.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)