Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureBuilderVanishingPoint.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 vanishing point.
32  *
33  * Authors:
34  * Odile Bourquardez
35  *
36  *****************************************************************************/
37 
38 
44 #include <visp3/visual_features/vpFeatureBuilder.h>
45 #include <visp3/visual_features/vpFeatureException.h>
46 #include <visp3/core/vpException.h>
47 
48 
58 void
60 {
61  try
62  {
63  s.set_x( t.get_x()) ;
64  s.set_y( t.get_y()) ;
65  }
66  catch(...)
67  {
68  vpERROR_TRACE("Cannot create vanishing point feature") ;
69  throw ;
70  }
71 }
72 
73 
87 void
89 {
90  double rho_l;
91  double rho_r;
92  double theta_l;
93  double theta_r;
94  double c_l;
95  double s_l;
96  double c_r;
97  double s_r;
98 
99  rho_l = L1.getRho();
100  rho_r = L2.getRho();
101  theta_l = L1.getTheta();
102  theta_r = L2.getTheta();
103  c_l = cos(theta_l);
104  c_r = cos(theta_r);
105  s_l = sin(theta_l);
106  s_r = sin(theta_r);
107 
108 
109  double x,y;
110 
111  double min = 0.0001;
112  if(fabs(theta_r-theta_l)<min || fabs(fabs(theta_r-theta_l)-M_PI)<min \
113  || fabs(fabs(theta_r-theta_l)-2*M_PI)<min)
114  {
115  vpCERROR<<"There is no vanishing point : the lines are parallel in the image plane"<<std::endl;
117  "There is no vanishing point : the lines are parallel in the image plane")) ;
118  }
119 
120  y = (rho_r *c_l - rho_l * c_r) / (-s_l * c_r + s_r * c_l );
121  x = (rho_r *s_l - rho_l * s_r) / (-c_l * s_r + c_r * s_l );
122 
123  s.set_x ( x );
124  s.set_y ( y );
125 }
126 
127 
128 
142 void
144 {
145  vpFeatureLine l1,l2 ;
146  vpFeatureBuilder::create (l1,L1) ;
147  vpFeatureBuilder::create (l2,L2) ;
148 
149  vpFeatureBuilder::create (s, l1, l2) ;
150 
151 }
#define vpCERROR
Definition: vpDebug.h:365
#define vpERROR_TRACE
Definition: vpDebug.h:391
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:458
double getTheta() const
Class that defines what is a point.
Definition: vpPoint.h:59
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:456
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)