Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpMomentDatabase Class Reference

#include <visp3/core/vpMomentDatabase.h>

+ Inheritance diagram for vpMomentDatabase:

Public Member Functions

 vpMomentDatabase ()
 
virtual ~vpMomentDatabase ()
 

Inherited functionalities from vpMomentDatabase

class vpMoment
 
VISP_EXPORT std::ostream & operator<< (std::ostream &os, const vpMomentDatabase &v)
 
const vpMomentget (const std::string &moment_name, bool &found) const
 
vpMomentget_first ()
 
virtual void updateAll (vpMomentObject &object)
 

Detailed Description

This class allows to register all vpMoments so they can access each other according to their dependencies.

Sometimes, a moment needs to have access to other moment's values to be computed. For example vpMomentCentered needs additional information about the gravity center vpMomentGravityCenter in order to compute the moment's value from a vpMomentObject. This gravity center should be stored in a vpMomentDatabase where it can be accessed.

All moments in a database can access each other freely at any time. They can also verify if a moment is present in the database or not. Here is a example of a dependency between two moments using a vpMomentDatabase:

#include <iostream>
#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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
std::vector<vpPoint> vec_p; // 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);
vpMomentObject obj(1); // Create an image moment object with 1 as
// maximum order (sufficient for gravity center)
obj.setType(vpMomentObject::DISCRETE); // The object is defined by
// two discrete points
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
db.updateAll(obj); // All of the moments must be updated, not just mc
//There is no global compute method since the order of compute calls
//depends on the implementation
g.compute(); // compute the moment
mc.compute(); //compute centered moments AFTER gravity center
std::cout << "Gravity center: " << g << std:: endl; // print gravity center moment
std::cout << "Centered moments: " << mc << std:: endl; // print centered moment
return 0;
}
This class defines the double-indexed centered moment descriptor .
This class allows to register all vpMoments so they can access each other according to their dependen...
virtual void updateAll(vpMomentObject &object)
Class describing 2D gravity center moment.
Class for generic objects.
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:114
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:79
void set_x(double x)
Set the point x coordinate in the image plane.
Definition: vpPoint.cpp:464
void set_y(double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.cpp:466

The following code outputs:

Gravity center:
Xg=1.5, Yg=1.5
Centered moments:
2 0
0 x

A moment is identified in the database by it's vpMoment::name method. Consequently, a database can contain at most one moment of each type. Often it is useful to update all moments with the same object. Shortcuts (vpMomentDatabase::updateAll) are provided for that matter.

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

Definition at line 132 of file vpMomentDatabase.h.

Constructor & Destructor Documentation

◆ vpMomentDatabase()

vpMomentDatabase::vpMomentDatabase ( )
inline

Definition at line 145 of file vpMomentDatabase.h.

◆ ~vpMomentDatabase()

virtual vpMomentDatabase::~vpMomentDatabase ( )
inlinevirtual

Definition at line 146 of file vpMomentDatabase.h.

Member Function Documentation

◆ get()

◆ get_first()

vpMoment& vpMomentDatabase::get_first ( )
inline

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 158 of file vpMomentDatabase.h.

◆ updateAll()

void vpMomentDatabase::updateAll ( vpMomentObject object)
virtual

Updates the moment object for all moments in the database

Parameters
object: Moment object for which all the moments in the database should be updated.

Sometimes, it might be useful to update the whole database when computing only one moment when this moment depends on other moments. The example provided in the header of this class gives an example that shows how to compute gravity center moment and the centered moment using a mass update.

Reimplemented in vpMomentCommon.

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

Definition at line 83 of file vpMomentDatabase.cpp.

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

Friends And Related Function Documentation

◆ operator<<

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

Outputs all the moments values in the database to a stream.

Definition at line 94 of file vpMomentDatabase.cpp.

◆ vpMoment

friend class vpMoment
friend

Definition at line 163 of file vpMomentDatabase.h.