ViSP  2.10.0

#include <vpMbtPolygon.h>

Public Types

enum  vpMbtPolygonClippingType {
  NO_CLIPPING = 0, NEAR_CLIPPING = 1, FAR_CLIPPING = 2, LEFT_CLIPPING = 4,
  RIGHT_CLIPPING = 8, UP_CLIPPING = 16, DOWN_CLIPPING = 32, FOV_CLIPPING = 60,
  ALL_CLIPPING = 63
}
 

Public Member Functions

 vpMbtPolygon ()
 
 vpMbtPolygon (const vpMbtPolygon &mbtp)
 
virtual ~vpMbtPolygon ()
 
void addPoint (const unsigned int n, const vpPoint &P)
 
void changeFrame (const vpHomogeneousMatrix &cMo)
 
void computeRoiClipped (const vpCameraParameters &cam=vpCameraParameters())
 
unsigned int getClipping () const
 
double getFarClippingDistance () const
 
int getIndex () const
 
std::string getName () const
 
unsigned int getNbPoint () const
 
unsigned int getNbCornerInsidePrevImage () const
 
unsigned int getNbCornerInsideImage (const vpImage< unsigned char > &I, const vpCameraParameters &cam)
 
double getNearClippingDistance () const
 
vpPointgetPoint (const unsigned int _index)
 
std::vector< vpImagePointgetRoi (const vpCameraParameters &cam)
 
std::vector< vpImagePointgetRoi (const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo)
 
void getRoiClipped (std::vector< vpPoint > &points)
 
void getRoiClipped (const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
 
void getRoiClipped (const vpCameraParameters &cam, std::vector< vpImagePoint > &roi, const vpHomogeneousMatrix &cMo)
 
void getRoiClipped (const vpCameraParameters &cam, std::vector< std::pair< vpImagePoint, unsigned int > > &roi)
 
void getRoiClipped (const vpCameraParameters &cam, std::vector< std::pair< vpImagePoint, unsigned int > > &roi, const vpHomogeneousMatrix &cMo)
 
bool isAppearing () const
 
virtual bool isVisible (const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), const vpImage< unsigned char > &I=vpImage< unsigned char >())
 
bool isVisible () const
 
vpMbtPolygonoperator= (const vpMbtPolygon &mbtp)
 
void setClipping (const unsigned int &flags)
 
void setFarClippingDistance (const double &dist)
 
virtual void setIndex (const int i)
 
void setLod (const bool use_lod)
 
void setMinLineLengthThresh (const double min_line_length)
 
void setMinPolygonAreaThresh (const double min_polygon_area)
 
void setName (const std::string &face_name)
 
virtual void setNbPoint (const unsigned int nb)
 
void setNearClippingDistance (const double &dist)
 
Deprecated functions
bool isVisible (const vpHomogeneousMatrix &cMo, const bool &depthTest=false)
 

Static Public Member Functions

static void getClippedPolygon (const std::vector< vpPoint > &ptIn, std::vector< vpPoint > &ptOut, const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags, const vpCameraParameters &cam=vpCameraParameters(), const double &znear=0.001, const double &zfar=100)
 
static void getMinMaxRoi (const std::vector< vpImagePoint > &roi, int &i_min, int &i_max, int &j_min, int &j_max)
 
static bool roiInsideImage (const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &corners)
 

Public Attributes

int index
 
unsigned int nbpt
 
unsigned int nbCornersInsidePrev
 
bool isvisible
 
bool isappearing
 
vpPointp
 
std::vector< std::pair< vpPoint, unsigned int > > roiPointsClip
 
unsigned int clippingFlag
 
double distNearClip
 
double distFarClip
 
bool useLod
 
double minLineLengthThresh
 
double minPolygonAreaThresh
 
std::string name
 

Detailed Description

Implementation of a polygon of the model used by the model-based tracker.

Definition at line 67 of file vpMbtPolygon.h.

Member Enumeration Documentation

Enumerator
NO_CLIPPING 
NEAR_CLIPPING 
FAR_CLIPPING 
LEFT_CLIPPING 
RIGHT_CLIPPING 
UP_CLIPPING 
DOWN_CLIPPING 
FOV_CLIPPING 
ALL_CLIPPING 

Definition at line 70 of file vpMbtPolygon.h.

Constructor & Destructor Documentation

vpMbtPolygon::vpMbtPolygon ( )

Basic constructor.

Definition at line 59 of file vpMbtPolygon.cpp.

vpMbtPolygon::vpMbtPolygon ( const vpMbtPolygon mbtp)

Definition at line 67 of file vpMbtPolygon.cpp.

vpMbtPolygon::~vpMbtPolygon ( )
virtual

Basic destructor.

Definition at line 103 of file vpMbtPolygon.cpp.

References p.

Member Function Documentation

void vpMbtPolygon::addPoint ( const unsigned int  n,
const vpPoint P 
)

Add a corner point to the list of polygon's corners.

Parameters
n: The index of the corner.
P: The point to add.

Definition at line 149 of file vpMbtPolygon.cpp.

References p.

Referenced by vpMbTracker::addPolygon(), vpMbtDistanceLine::buildFrom(), and getClippedPolygon().

void vpMbtPolygon::changeFrame ( const vpHomogeneousMatrix cMo)

Project the 3D corner points into the image thanks to the pose of the camera.

Parameters
cMo: The pose of the camera.

Definition at line 161 of file vpMbtPolygon.cpp.

References vpPoint::changeFrame(), nbpt, p, and vpPoint::projection().

Referenced by vpMbKltTracker::display(), getClippedPolygon(), getRoi(), getRoiClipped(), and isVisible().

void vpMbtPolygon::computeRoiClipped ( const vpCameraParameters cam = vpCameraParameters())

Compute the region of interest in the image according to the used clipping.

Warning
If the FOV clipping is used, camera normals have to be precomputed.
Parameters
cam: camera parameters used to compute the field of view.

Definition at line 307 of file vpMbtPolygon.cpp.

References clippingFlag, distFarClip, distNearClip, DOWN_CLIPPING, FAR_CLIPPING, vpCameraParameters::getFovNormals(), vpCameraParameters::isFovComputed(), LEFT_CLIPPING, nbpt, NO_CLIPPING, p, vpPoint::projection(), RIGHT_CLIPPING, roiPointsClip, and UP_CLIPPING.

Referenced by vpMbtDistanceLine::display(), vpMbKltTracker::display(), getClippedPolygon(), getRoiClipped(), vpMbtDistanceLine::initMovingEdge(), isVisible(), vpMbKltTracker::reinit(), vpMbKltTracker::setPose(), and vpMbtDistanceLine::updateMovingEdge().

void vpMbtPolygon::getClippedPolygon ( const std::vector< vpPoint > &  ptIn,
std::vector< vpPoint > &  ptOut,
const vpHomogeneousMatrix cMo,
const unsigned int &  clippingFlags,
const vpCameraParameters cam = vpCameraParameters(),
const double &  znear = 0.001,
const double &  zfar = 100 
)
static

Static method to compute the clipped points from a set of initial points.

Warning
When using FOV clipping and personnal camera parameters, camera normals have to be computed before (see vpCameraParameters::computeFov())
Parameters
ptIn: Input points
ptOut: Output points (result of the clipping).
cMo: Pose considered for the clipping.
clippingFlagsClipping flag (see vpMbtPolygon::vpMbtPolygonClippingType).
cam: Camera parameters (Only used if clipping flags contain FOV clipping).
znear: Near clipping distance value (Only used if clipping flags contain Near clipping).
zfar: Far clipping distance value (Only used if clipping flags contain Far clipping).

Definition at line 684 of file vpMbtPolygon.cpp.

References addPoint(), changeFrame(), computeRoiClipped(), FAR_CLIPPING, getRoiClipped(), NEAR_CLIPPING, setClipping(), setFarClippingDistance(), setNbPoint(), and setNearClippingDistance().

Referenced by vpImageSimulator::setCameraPosition().

unsigned int vpMbtPolygon::getClipping ( ) const
inline

Get the clipping used.

See also
vpMbtPolygonClipping
Returns
Clipping flags.

Definition at line 143 of file vpMbtPolygon.h.

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

double vpMbtPolygon::getFarClippingDistance ( ) const
inline

Get the far distance for clipping.

Returns
Far clipping value.

Definition at line 150 of file vpMbtPolygon.h.

int vpMbtPolygon::getIndex ( ) const
inline

Get the index of the face.

Returns
index : the index of the face.

Definition at line 157 of file vpMbtPolygon.h.

Referenced by vpMbEdgeTracker::addPolygon(), vpMbEdgeTracker::initFaceFromCorners(), and vpMbEdgeTracker::initFaceFromLines().

void vpMbtPolygon::getMinMaxRoi ( const std::vector< vpImagePoint > &  roi,
int &  i_min,
int &  i_max,
int &  j_min,
int &  j_max 
)
static

Definition at line 707 of file vpMbtPolygon.cpp.

Referenced by vpMbtDistanceKltPoints::updateMask().

std::string vpMbtPolygon::getName ( ) const
inline

Get the name of the face.

Returns
Name of the face.

Definition at line 164 of file vpMbtPolygon.h.

Referenced by vpMbEdgeTracker::initFaceFromCorners(), and vpMbEdgeTracker::initFaceFromLines().

unsigned int vpMbtPolygon::getNbCornerInsideImage ( const vpImage< unsigned char > &  I,
const vpCameraParameters cam 
)

Static method to check the number of points of a region defined by the vector of image point that are inside the image.

Parameters
I: The image used for its size.
cam: The camera parameters.

Definition at line 649 of file vpMbtPolygon.cpp.

References vpMeterPixelConversion::convertPoint(), vpImagePoint::get_i(), vpImagePoint::get_j(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), nbCornersInsidePrev, nbpt, and p.

unsigned int vpMbtPolygon::getNbCornerInsidePrevImage ( ) const
inline

Return the number of corners at the previous computation.

Returns
number of corner of the face at the previous computation

Definition at line 178 of file vpMbtPolygon.h.

double vpMbtPolygon::getNearClippingDistance ( ) const
inline

Get the near distance for clipping.

Returns
Near clipping value.

Definition at line 187 of file vpMbtPolygon.h.

vpPoint & vpMbtPolygon::getPoint ( const unsigned int  _index)

Get a reference to a corner.

Exceptions
vpException::dimensionErrorif the _index is out of range.
Parameters
_index: the index of the corner

Definition at line 120 of file vpMbtPolygon.cpp.

References vpException::dimensionError, nbpt, and p.

Referenced by vpMbtDistanceKltPoints::init().

std::vector< vpImagePoint > vpMbtPolygon::getRoi ( const vpCameraParameters cam)

Get the region of interest in the image.

Warning
Suppose that changeFrame() has already been called.
Parameters
cam: camera parameters.
Returns
Image point corresponding to the region of interest.

Definition at line 530 of file vpMbtPolygon.cpp.

References vpMeterPixelConversion::convertPoint(), nbpt, and p.

Referenced by getRoi().

std::vector< vpImagePoint > vpMbtPolygon::getRoi ( const vpCameraParameters cam,
const vpHomogeneousMatrix cMo 
)

Get the region of interest in the image.

Parameters
cam: camera parameters.
cMo: pose.
Returns
Image point corresponding to the region of interest.

Definition at line 551 of file vpMbtPolygon.cpp.

References changeFrame(), and getRoi().

void vpMbtPolygon::getRoiClipped ( std::vector< vpPoint > &  points)

Get the 3D points of the clipped region of interest.

Warning
Suppose that changeFrame() and computeRoiClipped() have already been called.
Parameters
points: resulting points.

Definition at line 565 of file vpMbtPolygon.cpp.

References roiPointsClip.

Referenced by vpMbKltTracker::display(), getClippedPolygon(), getRoiClipped(), vpMbtDistanceKltPoints::init(), isVisible(), and vpMbtDistanceKltPoints::updateMask().

void vpMbtPolygon::getRoiClipped ( const vpCameraParameters cam,
std::vector< vpImagePoint > &  roi 
)

Get the region of interest clipped in the image.

Warning
Suppose that changeFrame() and computeRoiClipped() have already been called.
Parameters
cam: camera parameters.
roi: image point corresponding to the region of interest.

Definition at line 581 of file vpMbtPolygon.cpp.

References vpMeterPixelConversion::convertPoint(), and roiPointsClip.

void vpMbtPolygon::getRoiClipped ( const vpCameraParameters cam,
std::vector< vpImagePoint > &  roi,
const vpHomogeneousMatrix cMo 
)

Get the region of interest clipped in the image.

Parameters
cam: camera parameters.
cMo: pose.
roi: image point corresponding to the region of interest.

Definition at line 599 of file vpMbtPolygon.cpp.

References changeFrame(), computeRoiClipped(), and getRoiClipped().

void vpMbtPolygon::getRoiClipped ( const vpCameraParameters cam,
std::vector< std::pair< vpImagePoint, unsigned int > > &  roi 
)

Get the region of interest clipped in the image and the information to know if it's a clipped point.

Warning
Suppose that changeFrame() and computeRoiClipped() have already been called.
Parameters
cam: camera parameters.
roi: image point corresponding to the region of interest with clipping information.

Definition at line 615 of file vpMbtPolygon.cpp.

References vpMeterPixelConversion::convertPoint(), and roiPointsClip.

void vpMbtPolygon::getRoiClipped ( const vpCameraParameters cam,
std::vector< std::pair< vpImagePoint, unsigned int > > &  roi,
const vpHomogeneousMatrix cMo 
)

Get the region of interest clipped in the image and the information to know if it's a clipped point.

Parameters
cam: camera parameters.
roi: image point corresponding to the region of interest with clipping information.
cMo: pose.

Definition at line 633 of file vpMbtPolygon.cpp.

References changeFrame(), computeRoiClipped(), and getRoiClipped().

bool vpMbtPolygon::isAppearing ( ) const
inline

Definition at line 205 of file vpMbtPolygon.h.

bool vpMbtPolygon::isVisible ( const vpHomogeneousMatrix cMo,
const double  alpha,
const bool &  modulo = false,
const vpCameraParameters cam = vpCameraParameters(),
const vpImage< unsigned char > &  I = vpImage<unsigned char>() 
)
virtual

Check if the polygon is visible in the image and if the angle between the normal to the face and the line vector going from the optical center to the cog of the face is below the given threshold. To do that, the polygon is projected into the image thanks to the camera pose.

Parameters
cMo: The pose of the camera.
alpha: Maximum angle to detect if the face is visible (in rad).
modulo: Indicates if the test should also consider faces that are not oriented counter clockwise. If true, the orientation of the face is without importance.
cam: Camera parameters (intrinsics parameters)
I: Image used to consider level of detail.
Returns
Return true if the polygon is visible.

Definition at line 186 of file vpMbtPolygon.cpp.

References changeFrame(), clippingFlag, vpCameraParameters::computeFov(), computeRoiClipped(), vpTracker::cP, vpColVector::dotProd(), vpPoint::get_X(), vpPoint::get_Y(), vpPoint::get_Z(), vpPolygon::getArea(), vpImage< Type >::getHeight(), getRoiClipped(), vpImage< Type >::getWidth(), isappearing, isvisible, minLineLengthThresh, minPolygonAreaThresh, nbpt, vpColVector::normalize(), p, vpMath::rad(), vpPoint::set_X(), vpPoint::set_Y(), vpPoint::set_Z(), and useLod.

Referenced by vpMbEdgeKltTracker::computeVVS(), vpMbKltTracker::computeVVS(), vpMbEdgeKltTracker::display(), vpMbKltTracker::display(), vpMbKltTracker::postTracking(), vpMbKltTracker::preTracking(), vpMbKltTracker::reinit(), vpMbKltTracker::setPose(), and vpMbKltTracker::testTracking().

bool vpMbtPolygon::isVisible ( ) const
inline

Definition at line 208 of file vpMbtPolygon.h.

Referenced by isVisible().

bool vpMbtPolygon::isVisible ( const vpHomogeneousMatrix cMo,
const bool &  depthTest = false 
)
Deprecated:
This method is deprecated since it is no more used since ViSP 2.7.2.

Check if the polygon is visible in the image. To do that, the polygon is projected into the image thanks to the camera pose.

Parameters
cMo: The pose of the camera.
depthTest: True if a face has to be entirely visible (in front of the camera). False if it can be partially visible.
Returns
Return true if the polygon is visible.

Definition at line 827 of file vpMbtPolygon.cpp.

References changeFrame(), isappearing, isvisible, isVisible(), nbpt, p, and vpMath::rad().

bool vpMbtPolygon::roiInsideImage ( const vpImage< unsigned char > &  I,
const std::vector< vpImagePoint > &  corners 
)
static

Static method to check whether the region defined by the vector of image point is contained entirely in the image.

Parameters
I: The image used for its size.
corners: The vector of points defining a region

Definition at line 748 of file vpMbtPolygon.cpp.

References vpImage< Type >::getHeight(), and vpImage< Type >::getWidth().

void vpMbtPolygon::setClipping ( const unsigned int &  flags)
inline

Specify which clipping to use.

See also
vpMbtPolygonClipping
Parameters
flags: New clipping flags.

Definition at line 219 of file vpMbtPolygon.h.

Referenced by vpMbEdgeTracker::addLine(), getClippedPolygon(), and vpMbEdgeTracker::setClipping().

void vpMbtPolygon::setFarClippingDistance ( const double &  dist)
inline

Set the far distance for clipping.

Parameters
dist: Far clipping value.

Definition at line 226 of file vpMbtPolygon.h.

References FAR_CLIPPING.

Referenced by vpMbEdgeTracker::addLine(), getClippedPolygon(), and vpMbEdgeTracker::setFarClippingDistance().

virtual void vpMbtPolygon::setIndex ( const int  i)
inlinevirtual

Set the index of the face.

Parameters
i: the new index of the face.

Definition at line 233 of file vpMbtPolygon.h.

Referenced by vpMbTracker::addPolygon().

void vpMbtPolygon::setLod ( const bool  use_lod)

Set the flag to consider if the level of detail (LOD) is used or not. When activated, lines and faces of the 3D model are tracked if respectively their projected lenght and area in the image are significative enough. By significative, we mean:

Parameters
use_lod: true if level of detail must be used, false otherwise.

The sample code below shows how to introduce this feature:

#include <visp/vpMbEdgeTracker.h>
#include <visp/vpImageIo.h>
int main()
{
// Acquire an image
vpImageIo::read(I, "my-image.pgm");
std::string object = "my-object";
tracker.loadConfigFile( object+".xml" );
tracker.loadModel( object+".cao" );
tracker.setLod(true);
tracker.setMinPolygonAreaThresh(20.*20.);
tracker.initClick(I, object+".init" );
while (true) {
// tracking loop
}
return 0;
}
See also
setMinLineLengthThresh(), setMinPolygonAreaThresh()

Definition at line 810 of file vpMbtPolygon.cpp.

References useLod.

Referenced by vpMbTracker::addPolygon().

void vpMbtPolygon::setMinLineLengthThresh ( const double  min_line_length)
inline

Set the threshold for the minimum line length to be considered as visible in the LOD (level of detail) case. This threshold is only used when setLoD() is turned on.

Parameters
min_line_length: threshold for the minimum line length in pixel. When a single line that doesn't belong to a face is considered by the tracker, this line is tracked only if its lenght in pixel is greater than min_line_length.
See also
setLoD()

Definition at line 247 of file vpMbtPolygon.h.

Referenced by vpMbTracker::addPolygon().

void vpMbtPolygon::setMinPolygonAreaThresh ( const double  min_polygon_area)
inline

Set the minimum polygon area to be considered as visible in the LOD (level of detail) case. This threshold is only used when setLoD() is turned on.

Parameters
min_polygon_area: threshold for the minimum polygon area in pixel. When a face is considered by the tracker, this face is tracked only if its area in pixel is greater than min_polygon_area.
See also
setLoD()

Definition at line 260 of file vpMbtPolygon.h.

Referenced by vpMbTracker::addPolygon().

void vpMbtPolygon::setName ( const std::string &  face_name)
inline

Set the name of the face.

Parameters
face_name: name of the face.

Definition at line 269 of file vpMbtPolygon.h.

Referenced by vpMbTracker::addPolygon().

void vpMbtPolygon::setNbPoint ( const unsigned int  nb)
virtual

Set the number of points which are the corners of the polygon.

Parameters
nb: The number of corners.

Definition at line 134 of file vpMbtPolygon.cpp.

References nbpt, and p.

Referenced by vpMbTracker::addPolygon(), vpMbtDistanceLine::buildFrom(), and getClippedPolygon().

void vpMbtPolygon::setNearClippingDistance ( const double &  dist)
inline

Set the near distance for clipping.

Parameters
dist: Near clipping value.

Definition at line 280 of file vpMbtPolygon.h.

References NEAR_CLIPPING.

Referenced by vpMbEdgeTracker::addLine(), getClippedPolygon(), and vpMbEdgeTracker::setNearClippingDistance().

Member Data Documentation

unsigned int vpMbtPolygon::clippingFlag

Clipping flag.

Definition at line 99 of file vpMbtPolygon.h.

Referenced by computeRoiClipped(), isVisible(), and operator=().

double vpMbtPolygon::distFarClip

Distance for near clipping.

Definition at line 103 of file vpMbtPolygon.h.

Referenced by computeRoiClipped(), and operator=().

double vpMbtPolygon::distNearClip

Distance for near clipping.

Definition at line 101 of file vpMbtPolygon.h.

Referenced by computeRoiClipped(), and operator=().

int vpMbtPolygon::index

Index of the polygon. Cannot be unsigned int because default value is -1.

Definition at line 85 of file vpMbtPolygon.h.

Referenced by operator=().

bool vpMbtPolygon::isappearing

flag to specify whether the face is appearing or not

Definition at line 93 of file vpMbtPolygon.h.

Referenced by isVisible(), and operator=().

bool vpMbtPolygon::isvisible

flag to specify whether the face is visible or not

Definition at line 91 of file vpMbtPolygon.h.

Referenced by isVisible(), and operator=().

double vpMbtPolygon::minLineLengthThresh

Threshold for minimum line length in pixel to consider if the line is visible or not in LOD case.

Definition at line 107 of file vpMbtPolygon.h.

Referenced by isVisible(), and operator=().

double vpMbtPolygon::minPolygonAreaThresh

Threshold for minimum polygon area in pixel to consider if the polygon is visible or not in LOD case.

Definition at line 109 of file vpMbtPolygon.h.

Referenced by isVisible(), and operator=().

std::string vpMbtPolygon::name

Name of the polygon.

Definition at line 111 of file vpMbtPolygon.h.

Referenced by operator=().

unsigned int vpMbtPolygon::nbCornersInsidePrev

Number of corners inside the image during the last call to getNbCornerInsideImage.

Definition at line 89 of file vpMbtPolygon.h.

Referenced by getNbCornerInsideImage(), and operator=().

unsigned int vpMbtPolygon::nbpt

Number of points used to define the polygon.

Definition at line 87 of file vpMbtPolygon.h.

Referenced by changeFrame(), computeRoiClipped(), getNbCornerInsideImage(), getPoint(), vpMbTracker::getPolygonFaces(), getRoi(), isVisible(), operator=(), and setNbPoint().

std::vector<std::pair<vpPoint,unsigned int> > vpMbtPolygon::roiPointsClip
bool vpMbtPolygon::useLod

Flag to specify if the visibility of the polygon depends also of the current level of detail (LOD)

Definition at line 105 of file vpMbtPolygon.h.

Referenced by isVisible(), operator=(), and setLod().