Visual Servoing Platform  version 3.3.0
vpMomentGravityCenter Class Reference

#include <vpMomentGravityCenter.h>

+ Inheritance diagram for vpMomentGravityCenter:

Public Member Functions

 vpMomentGravityCenter ()
 
virtual ~vpMomentGravityCenter ()
 

Protected Member Functions

vpMomentDatabasegetMoments () const
 

Protected Attributes

std::vector< double > values
 

Inherited functionalities from vpMomentGravityCenter

void compute ()
 
const std::vector< double > & get () const
 
double getXg () const
 
double getYg () const
 
const char * name () const
 
void printDependencies (std::ostream &os) const
 
VISP_EXPORT std::ostream & operator<< (std::ostream &os, const vpMomentGravityCenter &v)
 

Detailed Description

Class describing 2D gravity center moment.

This moment can be computed from scratch (no need to compute any different moments before computing this). It gives access to both coordinates of the gravity center $x_g$ and $y_g$.

These coordinates are defined as follows: $x_g = \frac{m_{01}}{m_{00}} $, $y_g = \frac{m_{10}}{m_{00}} $

#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
#include <visp3/core/vpMomentGravityCenter.h>
#include <iostream>
int main()
{
// Define the contour of an object by a 5 clockwise vertices on a plane
std::vector<vpPoint> vec_p; // vector that contains the vertices of the contour polygon
p.set_x(-0.2); p.set_y(0.1); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p);
p.set_x(+0.3); p.set_y(0.1); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
p.set_x(+0.2); p.set_y(-0.1); // coordinates in meters in the image plane (vertex 3)
vec_p.push_back(p);
p.set_x(-0.2); p.set_y(-0.15); // coordinates in meters in the image plane (vertex 4)
vec_p.push_back(p);
p.set_x(-0.2); p.set_y(0.1); // close the contour (vertex 5 = vertex 1)
vec_p.push_back(p);
vpMomentObject obj(1); // Create an image moment object with 1 as
// maximum order (because only m00,m01,m10
// are needed to compute the gravity center primitive.
obj.setType(vpMomentObject::DENSE_POLYGON); // The object is defined by a countour polygon
obj.fromVector(vec_p); // Init the dense object with the polygon
vpMomentGravityCenter g; // declaration of gravity center
g.update(obj); // specify the object
g.compute(); // compute the moment
std::cout << "Xg=" << g.getXg() << std::endl; // access to Xg
std::cout << "Yg=" << g.getYg() << std::endl; // access to Yg
std::cout << g << std:: endl; // print gravity center
return 0;
}

This example produces the following results:

Xg=0.0166667
Yg=-0.00833333
Xg=0.0166667, Yg=-0.00833333
Examples
mbot-apriltag-ibvs.cpp, servoBebop2.cpp, and testMomentAlpha.cpp.

Definition at line 113 of file vpMomentGravityCenter.h.

Constructor & Destructor Documentation

◆ vpMomentGravityCenter()

vpMomentGravityCenter::vpMomentGravityCenter ( )

Default constructor.

Definition at line 54 of file vpMomentGravityCenter.cpp.

References vpMoment::values.

◆ ~vpMomentGravityCenter()

virtual vpMomentGravityCenter::~vpMomentGravityCenter ( )
inlinevirtual

Definition at line 117 of file vpMomentGravityCenter.h.

Member Function Documentation

◆ compute()

void vpMomentGravityCenter::compute ( )
virtual

Computes the two gravity center coordinates commonly called $x_g$ and $y_g$.

Implements vpMoment.

Reimplemented in vpMomentGravityCenterNormalized.

Examples
mbot-apriltag-ibvs.cpp, servoBebop2.cpp, and testMomentAlpha.cpp.

Definition at line 45 of file vpMomentGravityCenter.cpp.

References vpMomentObject::get(), vpMoment::getObject(), and vpMoment::values.

Referenced by vpMomentCommon::getAlpha(), vpMomentCommon::getMu3(), vpMomentCommon::getSurface(), and vpMomentCommon::updateAll().

◆ get()

const std::vector< double > & vpMomentGravityCenter::get ( ) const

Returns a vector of the two gravity center coordinates.

Returns
Coordinates in the following moment: $(x_g,y_g)$.

Definition at line 60 of file vpMomentGravityCenter.cpp.

References vpMoment::values.

Referenced by vpMomentGravityCenterNormalized::compute(), vpMomentCentered::compute(), vpFeatureMomentCentered::compute_interaction(), and vpMomentGravityCenterNormalized::printDependencies().

◆ getMoments()

◆ getObject()

◆ getXg()

◆ getYg()

◆ linkTo()

void vpMoment::linkTo ( vpMomentDatabase data_base)
inherited

Links the moment to a database of moment primitives. If the moment depends on other moments, these moments must be linked to the same database.

Attention
Two moments of the same class cannot be stored in the same database
#include <visp3/core/vpMomentCentered.h>
#include <visp3/core/vpMomentDatabase.h>
#include <visp3/core/vpMomentGravityCenter.h>
#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
int main()
{
std::vector<vpPoint> vec_p;
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)
obj.setType(vpMomentObject::DISCRETE); // Discrete mode.
obj.fromVector(vec_p); // Init the dense object with the polygon
vpMomentGravityCenter G; // declaration of gravity center
vpMomentCentered mc; // mc contains centered moments
G.linkTo(db); //add gravity center to database
mc.linkTo(db); //centered moments depend on gravity, add them to the
//database to grant access
G.update(obj); // specify the object for gravity center
mc.update(obj); // and for centered moments
G.compute(); // compute the moment
mc.compute(); //compute centered moments AFTER gravity center
return 0;
}
Parameters
data_base: database of moment primitives.
Examples
mbot-apriltag-ibvs.cpp, servoBebop2.cpp, and testMomentAlpha.cpp.

Definition at line 98 of file vpMoment.cpp.

References vpException::memoryAllocationError, and vpMoment::name().

Referenced by vpMomentCommon::getAlpha(), vpMomentCommon::getMu3(), vpMomentCommon::getSurface(), and vpMomentCommon::vpMomentCommon().

◆ name()

const char* vpMomentGravityCenter::name ( ) const
inlinevirtual

The class's string name.

Implements vpMoment.

Reimplemented in vpMomentGravityCenterNormalized.

Definition at line 136 of file vpMomentGravityCenter.h.

◆ printDependencies()

void vpMomentGravityCenter::printDependencies ( std::ostream &  os) const
virtual

Prints its dependencies Basic moments m10, m01 and m00 from vpMomentObject

Reimplemented from vpMoment.

Reimplemented in vpMomentGravityCenterNormalized.

Definition at line 76 of file vpMomentGravityCenter.cpp.

References vpMomentObject::get(), and vpMoment::getObject().

◆ update()

void vpMoment::update ( vpMomentObject moment_object)
inherited

Updates the moment with the current object. This does not compute any values.

Parameters
moment_object: object descriptor of the current camera vision.

Definition at line 115 of file vpMoment.cpp.

Friends And Related Function Documentation

◆ operator<<

VISP_EXPORT std::ostream& operator<< ( std::ostream &  os,
const vpMomentGravityCenter v 
)
friend

Outputs the moment's values to a stream.

Definition at line 65 of file vpMomentGravityCenter.cpp.

Member Data Documentation

◆ values

vpMoment::linkTo
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:98
vpMomentCentered
This class defines the double-indexed centered moment descriptor .
Definition: vpMomentCentered.h:80
vpMomentGravityCenter::compute
void compute()
Definition: vpMomentGravityCenter.cpp:45
vpMomentObject::DENSE_POLYGON
@ DENSE_POLYGON
Definition: vpMomentObject.h:228
vpMomentGravityCenter::getYg
double getYg() const
Definition: vpMomentGravityCenter.h:132
vpMomentDatabase
This class allows to register all vpMoments so they can access each other according to their dependen...
Definition: vpMomentDatabase.h:132
vpMomentObject::DISCRETE
@ DISCRETE
Definition: vpMomentObject.h:231
vpMoment::update
void update(vpMomentObject &object)
Definition: vpMoment.cpp:115
vpPoint::set_y
void set_y(double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.cpp:474
vpMomentObject
Class for generic objects.
Definition: vpMomentObject.h:220
vpMomentGravityCenter::getXg
double getXg() const
Definition: vpMomentGravityCenter.h:127
vpMomentCentered::compute
void compute()
Definition: vpMomentCentered.cpp:65
vpPoint
Class that defines what is a point.
Definition: vpPoint.h:59
vpPoint::set_x
void set_x(double x)
Set the point x coordinate in the image plane.
Definition: vpPoint.cpp:472
vpMomentGravityCenter
Class describing 2D gravity center moment.
Definition: vpMomentGravityCenter.h:114