Visual Servoing Platform  version 3.2.0 under development (2018-10-15)
vpLine Class Reference

#include <visp3/core/vpLine.h>

+ Inheritance diagram for vpLine:

Public Types

enum  vpForwardProjectionDeallocatorType { user, vpDisplayForwardProjection }
 

Public Member Functions

void init ()
 
 vpLine ()
 
virtual ~vpLine ()
 
void setRho (const double rho)
 
void setTheta (const double theta)
 
double getTheta () const
 
double getRho () const
 
void setWorldCoordinates (const double &A1, const double &B1, const double &C1, const double &D1, const double &A2, const double &B2, const double &C2, const double &D2)
 
void setWorldCoordinates (const vpColVector &oP1, const vpColVector &oP2)
 
void setWorldCoordinates (const vpColVector &oP)
 
void projection ()
 
void projection (const vpColVector &cP, vpColVector &p)
 
void changeFrame (const vpHomogeneousMatrix &cMo, vpColVector &cP)
 
void changeFrame (const vpHomogeneousMatrix &cMo)
 
void display (const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
 
void display (const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
 
vpLineduplicate () const
 
void project ()
 
void project (const vpHomogeneousMatrix &cMo)
 
void track (const vpHomogeneousMatrix &cMo)
 
virtual void print () const
 
void setDeallocate (vpForwardProjectionDeallocatorType d)
 
vpForwardProjectionDeallocatorType getDeallocate ()
 

Public Attributes

vpColVector oP
 
vpColVector p
 
vpColVector cP
 
bool cPAvailable
 

Detailed Description

Class that defines a line in the object frame, the camera frame and the image plane. All the parameters must be set in meter.

Object and camera frame parametrization:
In the 3D frames, the object frame parameters (oP) and the camera frame parameters (cP), the line is defined as the intersection between two plans. Thus, the parameters which define the line are the parameters which define the two equations of the two plans. Each point which belongs to the line is a solution of those two equations:

\[ A1 X + B1 Y + C1 Z +D1 = 0 \]

\[ A2 X + B2 Y + C2 Z +D2 = 0 \]

Here $ (X, Y, Z) $ are the 3D coordinates in one of the two 3D frames. In this class it is easily possible to compute the parameters (cP) of the line in the camera frame thanks to its parameters (oP) in the object frame. But you have to notes that four constraints are added in the planes equations.

\[ D1 = 0 \]

\[ D2 > 0 \]

\[ A1 A2 + B1 B2 + C1 C2 = 0 \]

\[ || A2 || = 1 \]

The line parameters oP corresponding to the object frame are located in the vpForwardProjection::oP public attribute, where oP is a vector defined as:

\[ oP = \left[\begin{array}{c}A1_o \\ B1_o \\ C1_o \\ D1_o \\ A2_o \\ B2_o \\ C2_o \\ D2_o \end{array}\right] \]

The line parameters corresponding to the camera frame are located in the vpTracker::cP public attribute, where cP is a vector defined as:

\[ cP = \left[\begin{array}{c}A1_c \\ B1_c \\ C1_c \\ D1_c \\ A2_c \\ B2_c \\ C2_c \\ D2_c \end{array}\right] \]

Image plane parametrization:
In the image plane, the line is defined thanks to its 2D equation.

\[ x \; cos(\theta) + y \; sin(\theta) -\rho = 0 \]

Here $ x $ and $ y $ are the coordinates of a point belonging to the line in the image plane while $ \rho $ and $ \theta $ are the parameters used to define the line. The value of $ \theta $ is between $ -\pi/2 $ and $ \pi/2 $ and the value of $ \rho $ can be positive or negative. The conventions used to choose the sign of $ \rho $ and the value of $ \theta $ are illustrated by the following image.
vpFeatureLine.gif
The line parameters corresponding to the image frame are located in the vpTracker::p public attribute, where p is a vector defined as:

\[ p = \left[\begin{array}{c} \rho \\ \theta \end{array}\right] \]

Examples:
manGeometricFeatures.cpp, servoAfma6Line2DCamVelocity.cpp, servoAfma6SquareLines2DCamVelocity.cpp, servoAfma6TwoLines2DCamVelocity.cpp, servoSimuLine2DCamVelocityDisplay.cpp, servoSimuSquareLine2DCamVelocityDisplay.cpp, and testPoseFeatures.cpp.

Definition at line 105 of file vpLine.h.

Member Enumeration Documentation

Used for memory issue especially in the vpServo class.

Enumerator
user 
vpDisplayForwardProjection 

Definition at line 211 of file vpForwardProjection.h.

Constructor & Destructor Documentation

vpLine::vpLine ( )

Default constructor.

Definition at line 67 of file vpLine.cpp.

References init().

Referenced by duplicate().

virtual vpLine::~vpLine ( )
inlinevirtual

Destructor.

Definition at line 113 of file vpLine.h.

Member Function Documentation

void vpLine::changeFrame ( const vpHomogeneousMatrix cMo,
vpColVector cP_ 
)
virtual

Computes the line parameters cP in the camera frame thanks to the line parameters oP given in the object frame and the homogeneous matrix relative to the pose between the camera frame and the object frame. Thus the computation gives the equations of the two planes needed to define the line in the desired frame thanks to the equations of the same two planes in the object frame.

In input of this method, the line parameters oP in the object frame are those from the vpForwardProjection::oP public attribute.

Parameters
cMo: The homogeneous matrix relative to the pose between the desired frame and the object frame.
cP_: The vector which will contain the parameters of the two planes in the camera frame.

\[ cP = \left[\begin{array}{c}A1 \\ B1 \\ C1 \\ D1 \\ A2 \\ B2 \\ C2 \\ D2 \end{array}\right] \]

The code below shows how to use this method.

//Create the line
vpLine line;
//Set the coordinates of the line in the object frame in meter.
line.setWorldCoordinates( 1, 0, 0, -0.5, 0, 0, 1, 0.5)
//The line is define by the intersection between the plane X = 0.5m and Z = 0.5m
//Create the homogeneous matrix
//Computes or set here the homogeneous matrix
//Creates the vector which will contain the line features
//Computes the equations of the two planes in the camera frame
line.changeFrame(cMo, cP);

Implements vpForwardProjection.

Definition at line 333 of file vpLine.cpp.

References vpTracker::cP, vpArray2D< Type >::getRows(), vpForwardProjection::oP, and vpColVector::resize().

Referenced by changeFrame(), vpMbtDistanceLine::computeInteractionMatrixError(), display(), vpMbtDistanceLine::initMovingEdge(), and vpMbtDistanceLine::updateMovingEdge().

void vpLine::changeFrame ( const vpHomogeneousMatrix cMo)
virtual

Computes the line parameters cP in the camera frame thanks to the line parameters oP given in the object frame and the homogeneous matrix relative to the pose cMo between the object frame and the camera frame. Thus the computation gives the equations of the two planes needed to define the line in the camera frame thanks to the equations of the same two planes in the object frame.

In input of this method, the line parameters oP in the object frame are those from the vpForwardProjection::oP public attribute.

As a result of this method, line parameters cP in the camera frame are updated in the vpTracker::cP public attribute.

Parameters
cMo: The homogeneous matrix corresponding to the pose between the camera frame and the object frame.

The code below shows how to use this method.

//Create the line
vpLine line;
//Set the coordinates of the line in the object frame in meter.
line.setWorldCoordinates( 1, 0, 0, -0.5, 0, 0, 1, 0.5)
//The line is define by the intersection between the plane X = 0.5m and Z =
0.5m
//Create the homogeneous matrix
//Computes or set here the homogeneous matrix
//Computes the equations of the two planes in the camera frame
line.changeFrame(cMo);

Implements vpForwardProjection.

Definition at line 290 of file vpLine.cpp.

References changeFrame(), and vpTracker::cP.

void vpLine::display ( const vpImage< unsigned char > &  I,
const vpCameraParameters cam,
const vpColor color = vpColor::green,
const unsigned int  thickness = 1 
)
virtual

Displays the line in the image I thanks to the 2D parameters of the line p in the image plane (vpTracker::p) and the camera parameters which enable to convert the parameters from meter to pixel.

Parameters
I: The image where the line must be displayed.
cam: The camera parameters to enable the conversion from meter to pixel.
color: The desired color to display the line in the image.
thickness: Thickness of the feature representation.

Implements vpForwardProjection.

Examples:
manGeometricFeatures.cpp.

Definition at line 470 of file vpLine.cpp.

References vpFeatureDisplay::displayLine(), and vpTracker::p.

void vpLine::display ( const vpImage< unsigned char > &  I,
const vpHomogeneousMatrix cMo,
const vpCameraParameters cam,
const vpColor color = vpColor::green,
const unsigned int  thickness = 1 
)
virtual

Displays the line in the image I thanks to the parameters in the object frame (vpForwardProjection::oP), the homogeneous matrix relative to the pose between the camera frame and the object frame and the camera parameters which enable to convert the features from meter to pixel.

Parameters
I: The image where the line must be displayed in overlay.
cMo: The homogeneous matrix corresponding to the pose between the camera frame and the object frame.
cam: The camera parameters to enable the conversion from meter to pixel.
color: The desired color to display the line in the image.
thickness: Thickness of the feature representation.

Implements vpForwardProjection.

Definition at line 497 of file vpLine.cpp.

References changeFrame(), vpFeatureDisplay::displayLine(), and projection().

vpLine * vpLine::duplicate ( ) const
virtual

Create an object with the same type.

vpLine line;
fp = line.duplicate(); // fp is now a vpLine

Implements vpForwardProjection.

Definition at line 516 of file vpLine.cpp.

References vpLine().

vpForwardProjectionDeallocatorType vpForwardProjection::getDeallocate ( )
inlineinherited

Definition at line 220 of file vpForwardProjection.h.

double vpLine::getRho ( ) const
inline

Gets the $ \rho $ value corresponding to one of the two parameters used to define the line parametrization in the image plane.

Returns
Returns the current value of $ \rho $.
See also
getTheta()
Examples:
servoAfma6Line2DCamVelocity.cpp.

Definition at line 157 of file vpLine.h.

References vpForwardProjection::changeFrame(), vpForwardProjection::display(), vpForwardProjection::duplicate(), vpColor::green, vpForwardProjection::projection(), and vpForwardProjection::setWorldCoordinates().

Referenced by vpFeatureBuilder::create(), vpMbtDistanceLine::initMovingEdge(), and vpMbtDistanceLine::updateMovingEdge().

double vpLine::getTheta ( ) const
inline

Gets the $ \theta $ angle value corresponding to one of the two parameters used to define the line parametrization in the image plane.

Returns
Returns the current value of $ \theta $.
See also
getRho()

Definition at line 146 of file vpLine.h.

Referenced by vpFeatureBuilder::create(), vpMbtDistanceLine::initMovingEdge(), and vpMbtDistanceLine::updateMovingEdge().

void vpLine::init ( )
virtual

Initialize the memory space requested for the 2D line parameters (p) in the image plane and for 3D line parameters (oP and cP) respectively in the object frame and the camera frame.

Implements vpForwardProjection.

Definition at line 57 of file vpLine.cpp.

References vpTracker::cP, vpForwardProjection::oP, vpTracker::p, and vpColVector::resize().

Referenced by vpLine().

void vpForwardProjection::print ( ) const
virtualinherited

Print to stdout the feature parameters in:

  • the object frame
  • the camera frame
  • the image plane.
Examples:
servoSimuCircle2DCamVelocityDisplay.cpp, servoSimuLine2DCamVelocityDisplay.cpp, and servoSimuSquareLine2DCamVelocityDisplay.cpp.

Definition at line 53 of file vpForwardProjection.cpp.

References vpTracker::cP, vpForwardProjection::oP, vpTracker::p, and vpColVector::t().

void vpForwardProjection::project ( const vpHomogeneousMatrix cMo)
inherited

Compute the feature parameters in the camera frame (vpTracker::cP) and than compute the projection of these parameters in the image plane (vpTracker::p).

Warning
The feature parameters in the object frame (vpForwardProjection:oP) need to be set prior the use of this method. To initialize these parameters see setWorldCoordinates().
Parameters
cMo: The homogeneous matrix corresponding to the pose between the camera frame and the object frame.

Definition at line 84 of file vpForwardProjection.cpp.

References vpForwardProjection::changeFrame(), vpForwardProjection::projection(), and vpERROR_TRACE.

void vpLine::projection ( )
virtual

Computes the 2D parameters p of the line in the image plane thanks to the 3D line parameters cP in the camera frame located in the vpTracker::cP public attribute. The parameters $p=(\rho, \theta)$ are updated in the vpTracker::p public attribute.

Warning
To compute these parameters p, the method exploit the feature parameters cP in the camera frame. Thus, vpTracker::cP need to be updated before the call of this method. For that, a call to changeFrame(const vpHomogeneousMatrix &) is requested.

The code below shows how to use this method.

//Create the line
vpLine line;
//Set the coordinates of the line in the object frame in meter.
line.setWorldCoordinates( 1, 0, 0, -0.5, 0, 0, 1, 0.5)
//Here the line is define by the intersection between the plane X = 0.5m and
Z = 0.5m
//Create the homogeneous matrix
//Computes or set here the homogeneous matrix
//Computes the equations of the two planes in the camera frame
line.changeFrame(cMo);
//Computes the line features in the camera frame( rho and theta)
line.projection();

Implements vpForwardProjection.

Definition at line 193 of file vpLine.cpp.

References vpTracker::cP, and vpTracker::p.

Referenced by vpMbtDistanceLine::computeInteractionMatrixError(), display(), vpMbtDistanceLine::initMovingEdge(), and vpMbtDistanceLine::updateMovingEdge().

void vpLine::projection ( const vpColVector cP_,
vpColVector p_ 
)
virtual

Computes the 2D parameters p of the line in the image plane thanks to the 3D line features cP expressed in the camera frame. The image plane parameters $p=(\rho , \theta)$ are updated in output.

Parameters
cP_: The vector containing the line features relative to the camera frame.

\[ cP = \left[\begin{array}{c}A1 \\ B1 \\ C1 \\ D1 \\ A2 \\ B2 \\ C2 \\ D2 \end{array}\right] \]

p_: The vector which contains the 2D line features expressed in the image plane.

\[ p = \left[\begin{array}{c} \rho \\ \theta \end{array}\right] \]

Exceptions
vpException::fatalError: Degenerate case, the image of the straight line is a point.

Implements vpForwardProjection.

Definition at line 213 of file vpLine.cpp.

References vpTracker::cP, vpException::dimensionError, vpException::fatalError, vpArray2D< Type >::getRows(), vpTracker::p, and vpColVector::resize().

void vpForwardProjection::setDeallocate ( vpForwardProjectionDeallocatorType  d)
inlineinherited

Definition at line 219 of file vpForwardProjection.h.

void vpLine::setRho ( const double  rho)
inline

Sets the $ \rho $ parameter used to define the line in the image plane.

Parameters
rho: The desired value for $ \rho $.
See also
setTheta()
Examples:
servoAfma6Line2DCamVelocity.cpp, servoAfma6SquareLines2DCamVelocity.cpp, and servoAfma6TwoLines2DCamVelocity.cpp.

Definition at line 124 of file vpLine.h.

void vpLine::setTheta ( const double  theta)
inline

Sets the $ \theta $ angle value used to define the line in the image plane.

Parameters
theta: The desired value for $ \theta $ angle.
See also
setRho()
Examples:
servoAfma6Line2DCamVelocity.cpp, servoAfma6SquareLines2DCamVelocity.cpp, and servoAfma6TwoLines2DCamVelocity.cpp.

Definition at line 134 of file vpLine.h.

void vpLine::setWorldCoordinates ( const double &  A1,
const double &  B1,
const double &  C1,
const double &  D1,
const double &  A2,
const double &  B2,
const double &  C2,
const double &  D2 
)

Sets the parameters oP which define the line in the object frame. As said in the class description, the line is defined as the intersection of two planes. The different parameters here define the equations of the two planes in the object frame. They are used to set the vpForwardProjection::oP public attribute.

\[ A1 X + B1 Y + C1 Z +D1 = 0 \]

\[ A2 X + B2 Y + C2 Z +D2 = 0 \]

Here $ (X, Y, Z) $ are the 3D coordinates in the object frame.

Parameters
A1,B1,C1,D1: The parameters used to define the first plane.
A2,B2,C2,D2: The parameters used to define the second plane.
Examples:
manGeometricFeatures.cpp, servoAfma6Line2DCamVelocity.cpp, servoAfma6SquareLines2DCamVelocity.cpp, servoAfma6TwoLines2DCamVelocity.cpp, servoSimuLine2DCamVelocityDisplay.cpp, servoSimuSquareLine2DCamVelocityDisplay.cpp, and testPoseFeatures.cpp.

Definition at line 85 of file vpLine.cpp.

References vpForwardProjection::oP.

Referenced by vpMbtDistanceLine::~vpMbtDistanceLine().

void vpLine::setWorldCoordinates ( const vpColVector oP1,
const vpColVector oP2 
)

Sets the parameters oP which define the line in the object frame. As said in the class description, the line is defined as the intersection of two planes. Eight parameters are required to define the equations of the two planes in the object frame. They are used to set the vpForwardProjection::oP public attribute.

\[ A1 X + B1 Y + C1 Z +D1 = 0 \]

\[ A2 X + B2 Y + C2 Z +D2 = 0 \]

Here $ (X, Y, Z) $ are the 3D coordinates in the object frame.

Parameters
oP1: The column vector which contains the four parameters needed to define the equations of the first plane.

\[ oP1 = \left[\begin{array}{c}A1 \\ B1 \\ C1 \\ D1 \end{array}\right] \]

oP2: The column vector which contains the four parameters needed to define the equations of the second plane.

\[ oP2 = \left[\begin{array}{c} A2 \\ B2 \\ C2 \\ D2 \end{array}\right] \]

Definition at line 146 of file vpLine.cpp.

References vpException::dimensionError, vpArray2D< Type >::getRows(), and vpForwardProjection::oP.

void vpLine::setWorldCoordinates ( const vpColVector oP_)
virtual

Sets the parameters oP which define the line in the object frame. As said in the class description, the line is defined as the intersection of two planes. Eight parameters are required to define the equations of the two planes in the object frame. They are used to set the vpForwardProjection::oP public attribute.

\[ A1 X + B1 Y + C1 Z +D1 = 0 \]

\[ A2 X + B2 Y + C2 Z +D2 = 0 \]

Here $ (X, Y, Z) $ are the 3D coordinates in the object frame.

Parameters
oP_: The column vector which contains the eight parameters needed to define the equations of the two planes in the object frame.

\[ oP = \left[\begin{array}{c}A1 \\ B1 \\ C1 \\ D1 \\ A2 \\ B2 \\ C2 \\ D2 \end{array}\right] \]

Implements vpForwardProjection.

Definition at line 117 of file vpLine.cpp.

References vpException::dimensionError, vpArray2D< Type >::getRows(), and vpForwardProjection::oP.

void vpForwardProjection::track ( const vpHomogeneousMatrix cMo)
inherited

Track the feature parameters in the camera frame (vpTracker::cP) and than compute the projection of these parameters in the image plane (vpTracker::p).

This method is similar to project(const vpHomogeneousMatrix &).

Warning
The feature parameters in the object frame (vpForwardProjection:oP) need to be set prior the use of this method. To initialize these parameters see setWorldCoordinates().
Parameters
cMo: The homogeneous matrix corresponding to the pose between the camera frame and the object frame.
Examples:
mbot-apriltag-ibvs.cpp, servoMomentPoints.cpp, servoMomentPolygon.cpp, servoSimu4Points.cpp, servoSimuAfma6FourPoints2DCamVelocity.cpp, servoSimuCircle2DCamVelocity.cpp, servoSimuCircle2DCamVelocityDisplay.cpp, servoSimuFourPoints2DCamVelocity.cpp, servoSimuFourPoints2DCamVelocityDisplay.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoSimuLine2DCamVelocityDisplay.cpp, servoSimuSphere.cpp, servoSimuSphere2DCamVelocity.cpp, servoSimuSphere2DCamVelocityDisplay.cpp, servoSimuSphere2DCamVelocityDisplaySecondaryTask.cpp, servoSimuSquareLine2DCamVelocityDisplay.cpp, servoSimuViper850FourPoints2DCamVelocity.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, simulateFourPoints2DPolarCamVelocity.cpp, tutorial-ibvs-4pts-ogre.cpp, tutorial-ibvs-4pts-plotter-continuous-gain-adaptive.cpp, tutorial-ibvs-4pts-plotter-gain-adaptive.cpp, tutorial-ibvs-4pts-plotter.cpp, tutorial-ibvs-4pts.cpp, tutorial-simu-pioneer-continuous-gain-adaptive.cpp, tutorial-simu-pioneer-continuous-gain-constant.cpp, tutorial-simu-pioneer-pan.cpp, and tutorial-simu-pioneer.cpp.

Definition at line 111 of file vpForwardProjection.cpp.

References vpForwardProjection::project(), and vpERROR_TRACE.

Referenced by vpPoseFeatures::addFeatureSegment(), vpPose::computeResidual(), vpProjectionDisplay::displayCamera(), vpPose::poseVirtualVS(), vpPose::poseVirtualVSrobust(), vpWireFrameSimulator::projectCameraTrajectory(), vpSimulatorAfma6::updateArticularPosition(), and vpSimulatorViper850::updateArticularPosition().

Member Data Documentation

bool vpTracker::cPAvailable
inherited

Flag used to indicate if the feature parameters cP expressed in the camera frame are available.

Definition at line 81 of file vpTracker.h.

Referenced by vpTracker::init(), vpTracker::operator=(), and vpPoint::operator=().