Visual Servoing Platform  version 3.0.0
vpMomentDatabase Class Reference

#include <visp3/core/vpMomentDatabase.h>

+ Inheritance diagram for vpMomentDatabase:

Public Member Functions

 vpMomentDatabase ()
 
virtual ~vpMomentDatabase ()
 
const vpMomentget (const char *type, bool &found) const
 
vpMomentget_first ()
 
virtual void updateAll (vpMomentObject &object)
 

Friends

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

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 additionnal 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 <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
#include <visp3/core/vpMomentGravityCenter.h>
#include <visp3/core/vpMomentDatabase.h>
#include <visp3/core/vpMomentCentered.h>
#include <iostream>
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 containts 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;
}

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.

Definition at line 123 of file vpMomentDatabase.h.

Constructor & Destructor Documentation

vpMomentDatabase::vpMomentDatabase ( )
inline

Definition at line 135 of file vpMomentDatabase.h.

virtual vpMomentDatabase::~vpMomentDatabase ( )
inlinevirtual

Definition at line 136 of file vpMomentDatabase.h.

Member Function Documentation

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

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.

Definition at line 75 of file vpMomentDatabase.cpp.

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

Friends And Related Function Documentation

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 85 of file vpMomentDatabase.cpp.

friend class vpMoment
friend

Definition at line 148 of file vpMomentDatabase.h.