Visual Servoing Platform  version 3.2.0
vpMomentCommon Class Reference

#include <vpMomentCommon.h>

+ Inheritance diagram for vpMomentCommon:

Public Member Functions

 vpMomentCommon (double dstSurface, const std::vector< double > &ref, double refAlpha, double dstZ=1.0, bool flg_sxsyfromnormalized=false)
 
virtual ~vpMomentCommon ()
 
void updateAll (vpMomentObject &object)
 
Inherited functionalities from vpMomentDatabase
const vpMomentget (const char *type, bool &found) const
 
vpMomentget_first ()
 

Static Public Member Functions

static double getAlpha (vpMomentObject &object)
 
static std::vector< double > getMu3 (vpMomentObject &object)
 
static double getSurface (vpMomentObject &object)
 

Detailed Description

This class initializes and allows access to commonly used moments.

It is a vpMomentDatabase filled with the following moments:

There is no need to do the linkTo operations manually nor is it necessary to care about the order of moment computation.

This class carries an vpMomentCommon::updateAll() method capable of updating AND computing moments from an object (see 4-step process in vpMoment). The moments computed by this class are classical moments used in moment-based visual servoing. For more information see [Tahri05z].

To initialize this moment set the user needs to compute the following things:

  • the Mu3 value set: set of third-order centered moments computed for a reference object. ( $\mu_{ij}$ with $i+j = 3$ ). These values allow the system to save the reference angular position and to perform planar rotations of more than 180 degrees if needed.
  • the destination depth.
  • the surface of the destination object in the end of the visual servoing process.
  • the reference alpha: angular position of the object used to obtain the Mu3 set.

Shortcuts for each of these prerequisites are provided by this class except depth (methods vpMomentCommon::getMu3(), vpMomentCommon::getSurface(), vpMomentCommon::getAlpha()).

Attention
Make sure your object is at least of order 5 when using this pre-filled database.
Examples
manServoMomentsSimple.cpp, servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 103 of file vpMomentCommon.h.

Constructor & Destructor Documentation

◆ vpMomentCommon()

vpMomentCommon::vpMomentCommon ( double  dstSurface,
const std::vector< double > &  ref,
double  refAlpha,
double  dstZ = 1.0,
bool  flg_sxsyfromnormalized = false 
)

Default constructor. Initializes the common database with the following moments: basic, gravity,centered,centered+normalized,normalized gravity,normalized surface, scale-plane-rotation-translation invariant, alpha, symmetric invariant.

Parameters
dstSurface: destination surface. You may use vpMomentCommon::getSurface().
ref: reference 3rd order moments (see vpMomentAlpha). You may use vpMomentCommon::getMu3().
refAlpha: reference alpha (see vpMomentAlpha). You may use vpMomentCommon::getAlpha().
dstZ: destination depth.
flg_sxsyfromnormalized: flag to enable calculation of sx,sy from normalized moments.

Definition at line 53 of file vpMomentCommon.cpp.

◆ ~vpMomentCommon()

vpMomentCommon::~vpMomentCommon ( )
virtual

Definition at line 225 of file vpMomentCommon.cpp.

Member Function Documentation

◆ get()

const vpMoment & vpMomentDatabase::get ( const char *  type,
bool &  found 
) const
inherited

Retrieves a moment from the database.

Parameters
type: Name of the moment's class.
found: true if the moment's type exists in the database, false otherwise.
Returns
Moment corresponding to type.

Definition at line 63 of file vpMomentDatabase.cpp.

◆ get_first()

vpMoment& vpMomentDatabase::get_first ( )
inlineinherited

Get the first element in the database. May be useful in case an unnamed object is present but is the only element in the database.

Returns
the first element in the database.

Definition at line 153 of file vpMomentDatabase.h.

◆ getAlpha()

double vpMomentCommon::getAlpha ( vpMomentObject object)
static

Gets a reference alpha of an object.

Parameters
object: Moment object.
Examples
manServoMomentsSimple.cpp, servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 175 of file vpMomentCommon.cpp.

◆ getMu3()

std::vector< double > vpMomentCommon::getMu3 ( vpMomentObject object)
static

Gets the reference 3rd order moments of an object.

Parameters
object: Moment object.
Examples
manServoMomentsSimple.cpp, servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 198 of file vpMomentCommon.cpp.

◆ getSurface()

double vpMomentCommon::getSurface ( vpMomentObject object)
static

Gets the surface of an object

Parameters
object: moment object
Examples
manServoMomentsSimple.cpp, servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 148 of file vpMomentCommon.cpp.

◆ updateAll()

void vpMomentCommon::updateAll ( vpMomentObject object)
virtual

Updates all moments in the database with the object and computes all their values. This is possible because this particular database knows the link between the moments it contains. The order of computation is as follows: vpMomentGravityCenter,vpMomentCentered,vpMomentAlpha,vpMomentCInvariant,vpMomentSInvariant,vpMomentAreaNormalized,vpMomentGravityCenterNormalized

Parameters
object: Moment object.

Example of using a preconfigured database to compute one of the C-invariants:

#include <iostream>
#include <visp3/core/vpMomentCInvariant.h>
#include <visp3/core/vpMomentCommon.h>
#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
int main()
{
// Define two discrete points
std::vector<vpPoint> vec_p; // std::vector that contains the vertices of the contour polygon
p.set_x(1); p.set_y(1); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p);
p.set_x(2); p.set_y(2); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
p.set_x(-3);
p.set_y(0); // coordinates in meters in the image plane (vertex 3)
vec_p.push_back(p);
p.set_x(-3);
p.set_y(1); // coordinates in meters in the image plane (vertex 4)
vec_p.push_back(p);
vpMomentObject obj(5); // Object initialized up to order 5 to handle
// all computations required by vpMomentCInvariant
obj.setType(vpMomentObject::DENSE_POLYGON); // object is the inner part of a polygon
obj.fromstd::vector(vec_p); // Init the discrete object with two points
//initialisation with default values
bool success;
db.updateAll(obj); // Update AND compute all moments
//get C-invariant
vpMomentCInvariant& C = static_cast<vpMomentCInvariant&>(db.get("vpMomentCInvariant",success));
if(success) {
std::cout << C.get(0) << std:: std::endl;
} else
std::cout << "vpMomentCInvariant not found." << std::endl;
return 0;
}

Reimplemented from vpMomentDatabase.

Examples
servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 125 of file vpMomentCommon.cpp.

vpMomentCInvariant::get
double get(unsigned int i) const
Definition: vpMomentCInvariant.h:198
vpMomentCInvariant
Definition: vpMomentCInvariant.h:126
vpPoint::set_x
void set_x(const double x)
Set the point x coordinate in the image plane.
Definition: vpPoint.cpp:469
vpMomentCommon
This class initializes and allows access to commonly used moments.
Definition: vpMomentCommon.h:103
vpMomentDatabase::updateAll
virtual void updateAll(vpMomentObject &object)
Definition: vpMomentDatabase.cpp:81
vpMomentObject::DENSE_POLYGON
Definition: vpMomentObject.h:227
vpMomentCommon::getMu3
static std::vector< double > getMu3(vpMomentObject &object)
Definition: vpMomentCommon.cpp:198
vpMomentObject
Class for generic objects.
Definition: vpMomentObject.h:218
vpPoint::set_y
void set_y(const double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.cpp:471
vpMomentDatabase::get
const vpMoment & get(const char *type, bool &found) const
Definition: vpMomentDatabase.cpp:63
vpPoint
Class that defines what is a point.
Definition: vpPoint.h:57
vpMomentCommon::getSurface
static double getSurface(vpMomentObject &object)
Definition: vpMomentCommon.cpp:148
vpMomentCommon::getAlpha
static double getAlpha(vpMomentObject &object)
Definition: vpMomentCommon.cpp:175