From cb4642df27e021e1bcbe9429ee092ea13dc406b7 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Fri, 17 Nov 2023 10:00:08 +0100 Subject: [PATCH] Modify vpMoment and vpFeatureMoment classes to replace char* usage by std::string - Profit to indent code and make doc cleaner --- modules/core/include/visp3/core/vpMoment.h | 119 ++++++------ .../core/include/visp3/core/vpMomentAlpha.h | 2 +- .../core/include/visp3/core/vpMomentArea.h | 2 +- .../visp3/core/vpMomentAreaNormalized.h | 2 +- .../core/include/visp3/core/vpMomentBasic.h | 2 +- .../include/visp3/core/vpMomentCInvariant.h | 2 +- .../include/visp3/core/vpMomentCentered.h | 2 +- .../include/visp3/core/vpMomentDatabase.h | 177 +++++++++--------- .../visp3/core/vpMomentGravityCenter.h | 142 +++++++------- .../core/vpMomentGravityCenterNormalized.h | 28 +-- .../core/src/tracking/moments/vpMoment.cpp | 149 +++++++-------- .../src/tracking/moments/vpMomentCommon.cpp | 5 +- .../src/tracking/moments/vpMomentDatabase.cpp | 58 +++--- .../visp3/visual_features/vpFeatureMoment.h | 15 +- .../visual_features/vpFeatureMomentAlpha.h | 4 +- .../visual_features/vpFeatureMomentArea.h | 8 +- .../vpFeatureMomentAreaNormalized.h | 12 +- .../visual_features/vpFeatureMomentBasic.h | 4 +- .../vpFeatureMomentCInvariant.h | 8 +- .../visual_features/vpFeatureMomentCentered.h | 4 +- .../visual_features/vpFeatureMomentDatabase.h | 11 +- .../vpFeatureMomentGravityCenter.h | 8 +- .../vpFeatureMomentGravityCenterNormalized.h | 8 +- .../src/visual-feature/vpFeatureMoment.cpp | 17 +- .../vpFeatureMomentDatabase.cpp | 14 +- 25 files changed, 398 insertions(+), 405 deletions(-) diff --git a/modules/core/include/visp3/core/vpMoment.h b/modules/core/include/visp3/core/vpMoment.h index bfdb378b35..60ccc96ed4 100644 --- a/modules/core/include/visp3/core/vpMoment.h +++ b/modules/core/include/visp3/core/vpMoment.h @@ -49,71 +49,70 @@ class vpMomentDatabase; class vpMomentObject; /*! - \class vpMoment - - \ingroup group_core_moments - - \brief This class defines shared methods/attributes for 2D moments. - - All moments or combination of moments in the moments module are based on - this class. A moment uses a vpMomentObject object to access all useful - information. Moment values are obtained by a 4-step process common for all - moment types: - - Declaration. - \code - vpMoment moment; - \endcode - - Update with object. - \code - moment.update(object); - \endcode - - Compute the moment value - \code - moment.compute(); - \endcode - - Access the values: - \code - std::vector values = moment.get(); - \endcode - - A moment may also be linked to a vpMomentDatabase. Moments linked to a - database are able to access each others values. Some moments can be computed - only if they are linked to a a database containing their dependencies. - Linking to a database is done using the vpMoment::linkTo(...) method. - - There are no constraints about format of the array returned by - vpMoment::get(); any implementation is fine. - - Each moment must have a string name by implementing the char* - vpMoment::name() method which allows to identify the moment in the database. - Each moment must also implement a compute method describing how to obtain - its values from the object. - - \attention Order of moment computation DOES matter: when you compute a - moment using vpMoment::compute(), all moment dependencies must be computed. - We recall that implemented moments are: - - vpMomentAlpha - - vpMomentArea - - vpMomentAreaNormalized - - vpMomentBasic - - vpMomentCentered - - vpMomentCInvariant - - vpMomentGravityCenter - - vpMomentGravityCenterNormalized - -*/ + * \class vpMoment + * + * \ingroup group_core_moments + * + * \brief This class defines shared methods/attributes for 2D moments. + * + * All moments or combination of moments in the moments module are based on + * this class. A moment uses a vpMomentObject object to access all useful + * information. Moment values are obtained by a 4-step process common for all + * moment types: + * - Declaration. + * \code + * vpMoment moment; + * \endcode + * - Update with object. + * \code + * moment.update(object); + * \endcode + * - Compute the moment value + * \code + * moment.compute(); + * \endcode + * - Access the values: + * \code + * std::vector values = moment.get(); + * \endcode + * + * A moment may also be linked to a vpMomentDatabase. Moments linked to a + * database are able to access each others values. Some moments can be computed + * only if they are linked to a a database containing their dependencies. + * Linking to a database is done using the vpMoment::linkTo(...) method. + * + * There are no constraints about format of the array returned by + * vpMoment::get(); any implementation is fine. + * + * Each moment must have a string name by implementing the char* + * vpMoment::name() method which allows to identify the moment in the database. + * Each moment must also implement a compute method describing how to obtain + * its values from the object. + * + * \attention Order of moment computation DOES matter: when you compute a + * moment using vpMoment::compute(), all moment dependencies must be computed. + * We recall that implemented moments are: + * - vpMomentAlpha + * - vpMomentArea + * - vpMomentAreaNormalized + * - vpMomentBasic + * - vpMomentCentered + * - vpMomentCInvariant + * - vpMomentGravityCenter + * - vpMomentGravityCenterNormalized + */ class VISP_EXPORT vpMoment { private: vpMomentObject *object; vpMomentDatabase *moments; - char _name[255]; + std::string m_name; protected: std::vector values; /*! - Returns the linked moment database. - \return the moment database + * Returns the linked moment database. + * \return the moment database */ inline vpMomentDatabase &getMoments() const { return *moments; } @@ -137,19 +136,19 @@ class VISP_EXPORT vpMoment /*! Virtual destructor. */ - virtual ~vpMoment() {} + virtual ~vpMoment() { } /** @name Inherited functionalities from vpMoment */ //@{ virtual void compute() = 0; inline const vpMomentObject &getObject() const { return *object; } /*! - Returns all values computed by the moment. - \return vector of values + * Returns all values computed by the moment. + * \return vector of values */ const std::vector &get() const { return values; } void linkTo(vpMomentDatabase &moments); - virtual const char *name() const = 0; + virtual const std::string name() const = 0; virtual void printDependencies(std::ostream &os) const; void update(vpMomentObject &object); //@} diff --git a/modules/core/include/visp3/core/vpMomentAlpha.h b/modules/core/include/visp3/core/vpMomentAlpha.h index 56eada8a9c..1e0a991482 100644 --- a/modules/core/include/visp3/core/vpMomentAlpha.h +++ b/modules/core/include/visp3/core/vpMomentAlpha.h @@ -220,7 +220,7 @@ class VISP_EXPORT vpMomentAlpha : public vpMoment /*! * Moment name. */ - const char *name() const { return "vpMomentAlpha"; } + const std::string name() const { return "vpMomentAlpha"; } /*! * Returns true if the alpha moment was constructed as a reference with values in \f$ [-\pi/2 ; \pi/2] \f$, false diff --git a/modules/core/include/visp3/core/vpMomentArea.h b/modules/core/include/visp3/core/vpMomentArea.h index 9a05d6f8b7..ccef048ad6 100644 --- a/modules/core/include/visp3/core/vpMomentArea.h +++ b/modules/core/include/visp3/core/vpMomentArea.h @@ -62,7 +62,7 @@ class VISP_EXPORT vpMomentArea : public vpMoment //@{ void compute(); //! Moment name. - const char *name() const { return "vpMomentArea"; } + const std::string name() const { return "vpMomentArea"; } void printDependencies(std::ostream &os) const; //@} friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentArea &m); diff --git a/modules/core/include/visp3/core/vpMomentAreaNormalized.h b/modules/core/include/visp3/core/vpMomentAreaNormalized.h index 342bbf6c83..212ad34ffe 100644 --- a/modules/core/include/visp3/core/vpMomentAreaNormalized.h +++ b/modules/core/include/visp3/core/vpMomentAreaNormalized.h @@ -177,7 +177,7 @@ class VISP_EXPORT vpMomentAreaNormalized : public vpMoment /*! * Moment name. */ - const char *name() const { return "vpMomentAreaNormalized"; } + const std::string name() const { return "vpMomentAreaNormalized"; } friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentAreaNormalized &v); void printDependencies(std::ostream &os) const; }; diff --git a/modules/core/include/visp3/core/vpMomentBasic.h b/modules/core/include/visp3/core/vpMomentBasic.h index 7597478402..e0bc51abb2 100644 --- a/modules/core/include/visp3/core/vpMomentBasic.h +++ b/modules/core/include/visp3/core/vpMomentBasic.h @@ -77,7 +77,7 @@ class VISP_EXPORT vpMomentBasic : public vpMoment /*! Moment name. */ - const char *name() const { return "vpMomentBasic"; } + const std::string name() const { return "vpMomentBasic"; } friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentBasic &v); void printDependencies(std::ostream &os) const; }; diff --git a/modules/core/include/visp3/core/vpMomentCInvariant.h b/modules/core/include/visp3/core/vpMomentCInvariant.h index 106d576f61..58290fd9e4 100644 --- a/modules/core/include/visp3/core/vpMomentCInvariant.h +++ b/modules/core/include/visp3/core/vpMomentCInvariant.h @@ -223,7 +223,7 @@ class VISP_EXPORT vpMomentCInvariant : public vpMoment /*! Moment name. */ - const char *name() const { return "vpMomentCInvariant"; } + const std::string name() const { return "vpMomentCInvariant"; } /*! Print partial invariant. diff --git a/modules/core/include/visp3/core/vpMomentCentered.h b/modules/core/include/visp3/core/vpMomentCentered.h index 90b0a00f78..0f6afae38c 100644 --- a/modules/core/include/visp3/core/vpMomentCentered.h +++ b/modules/core/include/visp3/core/vpMomentCentered.h @@ -83,7 +83,7 @@ class VISP_EXPORT vpMomentCentered : public vpMoment /*! Moment name. */ - inline const char *name() const { return "vpMomentCentered"; } + inline const std::string name() const { return "vpMomentCentered"; } friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentCentered &v); void printWithIndices(std::ostream &os) const; diff --git a/modules/core/include/visp3/core/vpMomentDatabase.h b/modules/core/include/visp3/core/vpMomentDatabase.h index bb66dc2525..0cd4d7cee1 100644 --- a/modules/core/include/visp3/core/vpMomentDatabase.h +++ b/modules/core/include/visp3/core/vpMomentDatabase.h @@ -30,10 +30,11 @@ * Description: * Pseudo-database used to handle dependencies between moments */ + /*! - \file vpMomentDatabase.h - \brief Pseudo-database used to handle dependencies between moments. -*/ + * \file vpMomentDatabase.h + * \brief Pseudo-database used to handle dependencies between moments. + */ #ifndef _vpMomentDatabase_h_ #define _vpMomentDatabase_h_ @@ -47,93 +48,93 @@ class vpMoment; class vpMomentObject; /*! - \class vpMomentDatabase - - \ingroup group_core_moments - - \brief 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: - - \code -#include -#include -#include -#include -#include -#include - -int main() -{ - vpPoint p; - std::vector 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 - - vpMomentDatabase db; - 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; -} - \endcode - - The following code outputs: - \code -Gravity center: -Xg=1.5, Yg=1.5 -Centered moments: -2 0 -0 x - \endcode - - 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. -*/ + * \class vpMomentDatabase + * + * \ingroup group_core_moments + * + * \brief 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: + * + * \code + * #include + * #include + * #include + * #include + * #include + * #include + * + * int main() + * { + * vpPoint p; + * std::vector 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 + * + * vpMomentDatabase db; + * 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; + * } + * \endcode + * + * The following code outputs: + * \code + * Gravity center: + * Xg=1.5, Yg=1.5 + * Centered moments: + * 2 0 + * 0 x + * \endcode + * + * 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. + */ class VISP_EXPORT vpMomentDatabase { private: #ifndef DOXYGEN_SHOULD_SKIP_THIS struct vpCmpStr_t { - bool operator()(char const *a, char const *b) const { return std::strcmp(a, b) < 0; } + bool operator()(const std::string &a, const std::string &b) const { return std::strcmp(a.c_str(), b.c_str()) < 0; } }; #endif - std::map moments; - void add(vpMoment &moment, const char *name); + std::map moments; + void add(vpMoment &moment, const std::string &name); public: vpMomentDatabase() : moments() { } @@ -141,12 +142,14 @@ class VISP_EXPORT vpMomentDatabase /** @name Inherited functionalities from vpMomentDatabase */ //@{ - const vpMoment &get(const char *type, bool &found) const; + const vpMoment &get(const std::string &moment_name, bool &found) const; /*! - 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. \return the first element in the database. - */ + * 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. + * + * \return the first element in the database. + */ vpMoment &get_first() { return *(moments.begin()->second); } virtual void updateAll(vpMomentObject &object); diff --git a/modules/core/include/visp3/core/vpMomentGravityCenter.h b/modules/core/include/visp3/core/vpMomentGravityCenter.h index 39171649ff..83e61ecfb2 100644 --- a/modules/core/include/visp3/core/vpMomentGravityCenter.h +++ b/modules/core/include/visp3/core/vpMomentGravityCenter.h @@ -31,10 +31,10 @@ * 2D Gravity Center moment descriptor (usually described by the pair Xg,Yg) */ /*! - \file vpMomentGravityCenter.h - \brief 2D Gravity Center moment descriptor (usually described by the pair - Xg,Yg). -*/ + * \file vpMomentGravityCenter.h + * \brief 2D Gravity Center moment descriptor (usually described by the pair + * Xg,Yg). + */ #ifndef _vpMomentGravityCenter_h_ #define _vpMomentGravityCenter_h_ @@ -43,67 +43,67 @@ class vpMomentObject; /*! - \class vpMomentGravityCenter - - \ingroup group_core_moments - - \brief 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 \f$x_g\f$ and \f$y_g\f$. - - These coordinates are defined as follows: \f$x_g = \frac{m_{01}}{m_{00}} - \f$,\f$y_g = \frac{m_{10}}{m_{00}} \f$ - \code -#include -#include -#include -#include - -int main() -{ - // Define the contour of an object by a 5 clockwise vertices on a plane - vpPoint p; - std::vector 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; -} - \endcode - - This example produces the following results: - \code -Xg=0.0166667 -Yg=-0.00833333 -Xg=0.0166667, Yg=-0.00833333 - \endcode -*/ + * \class vpMomentGravityCenter + * + * \ingroup group_core_moments + * + * \brief 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 \f$x_g\f$ and \f$y_g\f$. + * + * These coordinates are defined as follows: \f$x_g = \frac{m_{01}}{m_{00}} + * \f$,\f$y_g = \frac{m_{10}}{m_{00}} \f$ + * \code + * #include + * #include + * #include + * #include + * + * int main() + * { + * // Define the contour of an object by a 5 clockwise vertices on a plane + * vpPoint p; + * std::vector 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 contour 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; + * } + * \endcode + * + * This example produces the following results: + * \code + * Xg=0.0166667 + * Yg=-0.00833333 + * Xg=0.0166667, Yg=-0.00833333 + * \endcode + */ class VISP_EXPORT vpMomentGravityCenter : public vpMoment { @@ -115,19 +115,19 @@ class VISP_EXPORT vpMomentGravityCenter : public vpMoment void compute(); const std::vector &get() const; /*! - Shortcut function to retrieve \f$x_g\f$. - \return The first gravity center coordinate. + * Shortcut function to retrieve \f$x_g\f$. + * \return The first gravity center coordinate. */ double getXg() const { return values[0]; } /*! - Shortcut function to retrieve \f$y_g\f$. - \return The second gravity center coordinate. + * Shortcut function to retrieve \f$y_g\f$. + * \return The second gravity center coordinate. */ double getYg() const { return values[1]; } /*! - The class's string name. + * The class's string name. */ - const char *name() const { return "vpMomentGravityCenter"; } + const std::string name() const { return "vpMomentGravityCenter"; } void printDependencies(std::ostream &os) const; //@} friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentGravityCenter &v); diff --git a/modules/core/include/visp3/core/vpMomentGravityCenterNormalized.h b/modules/core/include/visp3/core/vpMomentGravityCenterNormalized.h index aeb9d02b5b..6523a74a17 100644 --- a/modules/core/include/visp3/core/vpMomentGravityCenterNormalized.h +++ b/modules/core/include/visp3/core/vpMomentGravityCenterNormalized.h @@ -44,26 +44,26 @@ class vpMomentObject; /*! - \class vpMomentGravityCenterNormalized - - \ingroup group_core_moments - - \brief Class describing 2D normalized gravity center moment. - - Centered and normalized gravity center moment is defined as follows: - \f$(x_n,y_n)\f$ where \f$x_n = x_g a_n\f$ and \f$y_n = y_g a_n\f$. - - vpMomentGravityCenterNormalized depends on vpMomentAreaNormalized to get - access to \f$a_n\f$ and on vpMomentGravityCenter to get access to - \f$(x_g,y_g)\f$ . -*/ + * \class vpMomentGravityCenterNormalized + * + * \ingroup group_core_moments + * + * \brief Class describing 2D normalized gravity center moment. + * + * Centered and normalized gravity center moment is defined as follows: + * \f$(x_n,y_n)\f$ where \f$x_n = x_g a_n\f$ and \f$y_n = y_g a_n\f$. + * + * vpMomentGravityCenterNormalized depends on vpMomentAreaNormalized to get + * access to \f$a_n\f$ and on vpMomentGravityCenter to get access to + * \f$(x_g,y_g)\f$ . + */ class VISP_EXPORT vpMomentGravityCenterNormalized : public vpMomentGravityCenter { public: vpMomentGravityCenterNormalized(); void compute(); //! Moment name. - const char *name() const { return "vpMomentGravityCenterNormalized"; } + const std::string name() const { return "vpMomentGravityCenterNormalized"; } void printDependencies(std::ostream &os) const; friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentGravityCenterNormalized &v); }; diff --git a/modules/core/src/tracking/moments/vpMoment.cpp b/modules/core/src/tracking/moments/vpMoment.cpp index dced3cf428..121ab5dc81 100644 --- a/modules/core/src/tracking/moments/vpMoment.cpp +++ b/modules/core/src/tracking/moments/vpMoment.cpp @@ -1,5 +1,4 @@ -/**************************************************************************** - * +/* * ViSP, open source Visual Servoing Platform software. * Copyright (C) 2005 - 2023 by Inria. All rights reserved. * @@ -30,95 +29,89 @@ * * Description: * Base for 2D moment descriptor - * - * Authors: - * Filip Novotny - * -*****************************************************************************/ + */ /*! - \file vpMoment.cpp - \brief Base class for all 2D moments. -*/ + * \file vpMoment.cpp + * \brief Base class for all 2D moments. + */ #include #include #include #include /*! - Default constructor -*/ -vpMoment::vpMoment() : object(nullptr), moments(nullptr), values() {} + * Default constructor + */ +vpMoment::vpMoment() : object(nullptr), moments(nullptr), values() { } /*! - 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 -\code -#include -#include -#include -#include -#include - -int main() -{ - vpPoint p; - std::vector 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) - - vpMomentObject obj(2); - obj.setType(vpMomentObject::DISCRETE); // Discrete mode. - obj.fromVector(vec_p); // Init the dense object with the polygon - - vpMomentDatabase db; - 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; -} - - \endcode - - \param data_base : database of moment primitives. -*/ + * 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 + * \code + * #include + * #include + * #include + * #include + * #include + * + * int main() + * { + * vpPoint p; + * std::vector 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) + * vec_p.push_back(p); + * + * vpMomentObject obj(2); + * obj.setType(vpMomentObject::DISCRETE); // Discrete mode. + * obj.fromVector(vec_p); // Init the dense object with the polygon + * + * vpMomentDatabase db; + * 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; + * } + * \endcode + * + * \param data_base : database of moment primitives. + */ void vpMoment::linkTo(vpMomentDatabase &data_base) { - if (strlen(name()) >= 255) { - throw(vpException(vpException::memoryAllocationError, "Not enough memory to initialize the moment name")); - } - - std::strcpy(_name, name()); + m_name = name(); this->moments = &data_base; - data_base.add(*this, _name); + data_base.add(*this, m_name); } /*! - Updates the moment with the current object. This does not compute any - values. \param moment_object : object descriptor of the current camera - vision. -*/ + * Updates the moment with the current object. This does not compute any + * values. + * \param moment_object : object descriptor of the current camera vision. + */ void vpMoment::update(vpMomentObject &moment_object) { this->object = &moment_object; } /*! - Prints the moment contents to a stream - \param os : a std::stream. - \param m : a moment instance. -*/ + * Prints the moment contents to a stream + * \param os : a std::stream. + * \param m : a moment instance. + */ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMoment &m) { for (std::vector::const_iterator i = m.values.begin(); i != m.values.end(); ++i) @@ -128,14 +121,14 @@ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMoment &m) } /*! -Prints values of all dependent moments required to calculate a specific -vpMoment. Not made pure to maintain compatibility Recommended : Types -inheriting from vpMoment should implement this function -*/ + * Prints values of all dependent moments required to calculate a specific + * vpMoment. Not made pure to maintain compatibility Recommended : Types + * inheriting from vpMoment should implement this function + */ void vpMoment::printDependencies(std::ostream &os) const { os << " WARNING : Falling back to base class version of " - "printDependencies(). To prevent that, this has to be implemented in " - "the derived classes!" - << std::endl; + "printDependencies(). To prevent that, this has to be implemented in " + "the derived classes!" + << std::endl; } diff --git a/modules/core/src/tracking/moments/vpMomentCommon.cpp b/modules/core/src/tracking/moments/vpMomentCommon.cpp index 93082bcd30..e890a0fb77 100644 --- a/modules/core/src/tracking/moments/vpMomentCommon.cpp +++ b/modules/core/src/tracking/moments/vpMomentCommon.cpp @@ -135,10 +135,9 @@ void vpMomentCommon::updateAll(vpMomentObject &object) momentSurfaceNormalized.compute(); momentGravityNormalized.compute(); momentArea.compute(); - } - catch (const char *ex) { - std::cout << "exception:" << ex << std::endl; + catch (const vpException &e) { + std::cout << "Exception in vpMomentCommon:" << e.getStringMessage() << std::endl; } } diff --git a/modules/core/src/tracking/moments/vpMomentDatabase.cpp b/modules/core/src/tracking/moments/vpMomentDatabase.cpp index 12e28b9d96..aab0306600 100644 --- a/modules/core/src/tracking/moments/vpMomentDatabase.cpp +++ b/modules/core/src/tracking/moments/vpMomentDatabase.cpp @@ -43,56 +43,56 @@ #include /*! - Adds a moment to the database. - \param moment : moment to add - \param : name of the moment's class - - \attention You cannot add two moments with the same name. The rules - for insersion are the same as those of std::map. -*/ -void vpMomentDatabase::add(vpMoment &moment, const char *name) + * Adds a moment to the database. + * \param moment : Moment to add. + * \param name : Name of the moment's class. + * + * \attention You cannot add two moments with the same name. The rules + * for insertion are the same as those of std::map. + */ +void vpMomentDatabase::add(vpMoment &moment, const std::string &name) { - moments.insert(std::pair((const char *)name, &moment)); + moments.insert(std::pair(name, &moment)); } /*! - Retrieves a moment from the database. - \param type : Name of the moment's class. - \param found : true if the moment's type exists in the database, false - otherwise. \return Moment corresponding to \e type. -*/ -const vpMoment &vpMomentDatabase::get(const char *type, bool &found) const + * Retrieves a moment from the database. + * \param moment_name : Name of the moment's class. + * \param found : true if the moment's type exists in the database, false otherwise. + * \return Moment corresponding to \e type. + */ +const vpMoment &vpMomentDatabase::get(const std::string &moment_name, bool &found) const { - std::map::const_iterator it = moments.find(type); + std::map::const_iterator it = moments.find(moment_name); found = (it != moments.end()); return *(it->second); } /*! - Updates the moment object for all moments in the database - \param 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. -*/ + * Updates the moment object for all moments in the database + * \param 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. + */ void vpMomentDatabase::updateAll(vpMomentObject &object) { - std::map::const_iterator itr; + std::map::const_iterator itr; for (itr = moments.begin(); itr != moments.end(); ++itr) { (*itr).second->update(object); } } /*! - Outputs all the moments values in the database to a stream. -*/ + * Outputs all the moments values in the database to a stream. + */ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentDatabase &m) { - std::map::const_iterator itr; + std::map::const_iterator itr; os << "{"; for (itr = m.moments.begin(); itr != m.moments.end(); ++itr) { diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h index 0881c74a3e..6022914d71 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h @@ -42,6 +42,7 @@ #define _vpFeatureMoment_h_ #include +#include #include #include #include @@ -164,7 +165,7 @@ class VISP_EXPORT vpFeatureMoment : public vpBasicFeature double A; double B; double C; - char _name[255]; + std::string m_name; // private: //#ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -200,7 +201,7 @@ class VISP_EXPORT vpFeatureMoment : public vpBasicFeature vpFeatureMoment(vpMomentDatabase &data_base, double A_ = 0.0, double B_ = 0.0, double C_ = 0.0, vpFeatureMomentDatabase *featureMoments = nullptr, unsigned int nbmatrices = 1) : vpBasicFeature(), moment(nullptr), moments(data_base), featureMomentsDataBase(featureMoments), - interaction_matrices(nbmatrices), A(A_), B(B_), C(C_), _name() + interaction_matrices(nbmatrices), A(A_), B(B_), C(C_), m_name() { } /** @name Inherited functionalities from vpFeatureMoment */ @@ -221,11 +222,13 @@ class VISP_EXPORT vpFeatureMoment : public vpBasicFeature * Name of the moment corresponding to the feature. This allows to locate * the moment associated with the feature in the provided database. */ - virtual const char *momentName() const = 0; + virtual const std::string momentName() const = 0; + /*! * Name of the feature used to locate it in the database of features. */ - virtual const char *name() const = 0; + virtual const std::string name() const = 0; + void print(unsigned int select = FEATURE_ALL) const override; virtual void printDependencies(std::ostream &os) const; @@ -265,12 +268,12 @@ class VISP_EXPORT vpMomentGenericFeature : public vpFeatureMoment /*! * No specific moment name. */ - const char *momentName() const { return nullptr; } + const std::string momentName() const { return std::string(); } /*! * No specific feature name. */ - virtual const char *name() const { return nullptr; } + virtual const std::string name() const { return std::string(); } }; #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h index 0c5966cf5d..eed6971d19 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h @@ -119,12 +119,12 @@ class VISP_EXPORT vpFeatureMomentAlpha : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentAlpha"; } + const std::string momentName() const override { return "vpMomentAlpha"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentAlpha"; } + const std::string name() const override { return "vpFeatureMomentAlpha"; } vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) override; }; diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h index cee3586df5..b862c3182d 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h @@ -71,13 +71,13 @@ class VISP_EXPORT vpFeatureMomentArea : public vpFeatureMoment void compute_interaction() override; /*! - * associated moment name + * Associated moment name. */ - const char *momentName() const override { return "vpMomentArea"; } + const std::string momentName() const override { return "vpMomentArea"; } /*! - * feature name + * Feature name. */ - const char *name() const override { return "vpFeatureMomentArea"; } + const std::string name() const override { return "vpFeatureMomentArea"; } }; #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h index dfaf6fc045..3e9e46fb07 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h @@ -99,12 +99,12 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentAreaNormalized"; } + const std::string momentName() const override { return "vpMomentAreaNormalized"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentAreaNormalized"; } + const std::string name() const override { return "vpFeatureMomentAreaNormalized"; } }; #else @@ -192,14 +192,14 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment void compute_interaction() override; /*! - * Associated moment name + * Associated moment name. */ - const char *momentName() const override { return "vpMomentAreaNormalized"; } + const std::string momentName() const override { return "vpMomentAreaNormalized"; } /*! - * Feature name + * Feature name. */ - const char *name() const override { return "vpFeatureMomentAreaNormalized"; } + const std::string name() const override { return "vpFeatureMomentAreaNormalized"; } }; #endif #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h index 02195d8ea5..235c1249b7 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h @@ -96,11 +96,11 @@ class VISP_EXPORT vpFeatureMomentBasic : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentBasic"; } + const std::string momentName() const override { return "vpMomentBasic"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentBasic"; } + const std::string name() const override { return "vpFeatureMomentBasic"; } }; #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h index 0f5b5da2de..ed01b28183 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h @@ -108,12 +108,12 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentCInvariant"; } + const std::string momentName() const override { return "vpMomentCInvariant"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentCInvariant"; } + const std::string name() const override { return "vpFeatureMomentCInvariant"; } /*! * Shortcut selector for \f$C_1\f$. @@ -246,11 +246,11 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentCInvariant"; } + const std::string momentName() const override { return "vpMomentCInvariant"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentCInvariant"; } + const std::string name() const override { return "vpFeatureMomentCInvariant"; } /*! * Shortcut selector for \f$C_1\f$. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h index 8762be8960..1e3f957b68 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h @@ -100,12 +100,12 @@ class VISP_EXPORT vpFeatureMomentCentered : public vpFeatureMoment /*! * Associated moment name */ - const char *momentName() const override { return "vpMomentCentered"; } + const std::string momentName() const override { return "vpMomentCentered"; } /*! * Feature name */ - const char *name() const override { return "vpFeatureMomentCentered"; } + const std::string name() const override { return "vpFeatureMomentCentered"; } friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpFeatureMomentCentered &v); }; diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h index 858f5b1a93..d6530fac82 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h @@ -42,6 +42,7 @@ #include #include #include +#include #include class vpFeatureMoment; @@ -154,11 +155,11 @@ class VISP_EXPORT vpFeatureMomentDatabase private: struct vpCmpStr_t { - bool operator()(const char *a, const char *b) const { return std::strcmp(a, b) < 0; } - char *operator=(const char *) { return nullptr; } // Only to avoid a warning under Visual with /Wall flag + bool operator()(const std::string &a, const std::string &b) const { return std::strcmp(a.c_str(), b.c_str()) < 0; } + std::string operator=(const std::string) { return std::string(); } // Only to avoid a warning under Visual with /Wall flag }; - std::map featureMomentsDataBase; - void add(vpFeatureMoment &featureMoment, char *name); + std::map featureMomentsDataBase; + void add(vpFeatureMoment &featureMoment, const std::string &name); public: /*! @@ -173,7 +174,7 @@ class VISP_EXPORT vpFeatureMomentDatabase virtual void updateAll(double A = 0.0, double B = 0.0, double C = 1.0); - vpFeatureMoment &get(const char *type, bool &found); + vpFeatureMoment &get(const std::string &feature_name, bool &found); // friend VISP_EXPORT std::ostream & operator<<(std::ostream& os, const // vpFeatureMomentDatabase& m); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h index 8958915f68..942ee4f6fd 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h @@ -166,12 +166,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenter : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentGravityCenter"; } + const std::string momentName() const override { return "vpMomentGravityCenter"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentGravityCenter"; } + const std::string name() const override { return "vpFeatureMomentGravityCenter"; } /*! * Shortcut selector for \f$x_g\f$. @@ -238,12 +238,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenter : public vpFeatureMoment /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentGravityCenter"; } + const std::string momentName() const override { return "vpMomentGravityCenter"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentGravityCenter"; } + const std::string name() const override { return "vpFeatureMomentGravityCenter"; } /*! * Shortcut selector for \f$x_g\f$. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h index c75dc0d401..24e2a10480 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h @@ -106,12 +106,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenterNormalized : public vpFeatureMomen /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentGravityCenterNormalized"; } + const std::string momentName() const override { return "vpMomentGravityCenterNormalized"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentGravityCenterNormalized"; } + const std::string name() const override { return "vpFeatureMomentGravityCenterNormalized"; } /*! * Shortcut selector for \f$x_n\f$. @@ -260,12 +260,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenterNormalized : public vpFeatureMomen /*! * Associated moment name. */ - const char *momentName() const override { return "vpMomentGravityCenterNormalized"; } + const std::string momentName() const override { return "vpMomentGravityCenterNormalized"; } /*! * Feature name. */ - const char *name() const override { return "vpFeatureMomentGravityCenterNormalized"; } + const std::string name() const override { return "vpFeatureMomentGravityCenterNormalized"; } /*! * Shortcut selector for \f$x_n\f$. diff --git a/modules/visual_features/src/visual-feature/vpFeatureMoment.cpp b/modules/visual_features/src/visual-feature/vpFeatureMoment.cpp index 490f4cc90f..bf8222a83b 100644 --- a/modules/visual_features/src/visual-feature/vpFeatureMoment.cpp +++ b/modules/visual_features/src/visual-feature/vpFeatureMoment.cpp @@ -103,9 +103,9 @@ void vpFeatureMoment::print(unsigned int select) const } /*! - Not implemented since visual representation of a moment doesn't often make - sense. -*/ + * Not implemented since visual representation of a moment doesn't often make + * sense. + */ void vpFeatureMoment::display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color, unsigned int thickness) const { @@ -235,19 +235,14 @@ vpBasicFeature *vpFeatureMoment::duplicate() const * Links the feature to the feature's database. * * \note The feature's database is different from the moment's database. - * \param featureMoments : database in - * which the moment features are stored. + * \param featureMoments : database in which the moment features are stored. */ void vpFeatureMoment::linkTo(vpFeatureMomentDatabase &featureMoments) { - if (strlen(name()) >= 255) { - throw(vpException(vpException::memoryAllocationError, "Not enough memory to initialize the moment name")); - } - - std::strcpy(_name, name()); + m_name = name(); this->featureMomentsDataBase = &featureMoments; - featureMoments.add(*this, _name); + featureMoments.add(*this, m_name); } void vpFeatureMoment::compute_interaction() { } diff --git a/modules/visual_features/src/visual-feature/vpFeatureMomentDatabase.cpp b/modules/visual_features/src/visual-feature/vpFeatureMomentDatabase.cpp index 35a30a1aaf..58a8e2c6ec 100644 --- a/modules/visual_features/src/visual-feature/vpFeatureMomentDatabase.cpp +++ b/modules/visual_features/src/visual-feature/vpFeatureMomentDatabase.cpp @@ -43,23 +43,23 @@ * \param name : the feature's name, usually the string naming it's class. Each * name must be unique */ -void vpFeatureMomentDatabase::add(vpFeatureMoment &featureMoment, char *name) +void vpFeatureMomentDatabase::add(vpFeatureMoment &featureMoment, const std::string &name) { - featureMomentsDataBase.insert(std::pair((const char *)name, &featureMoment)); + featureMomentsDataBase.insert(std::pair(name, &featureMoment)); } /*! * Retrieves a moment feature from the database - * \param type : the name of the feature, the one specified when using add + * \param feature_name : The name of the feature, the one specified when using add * \param found : true if the type string is found inside the database, false * otherwise * * \return the moment feature corresponding to the type string */ -vpFeatureMoment &vpFeatureMomentDatabase::get(const char *type, bool &found) +vpFeatureMoment &vpFeatureMomentDatabase::get(const std::string &feature_name, bool &found) { - std::map::const_iterator it = - featureMomentsDataBase.find(type); + std::map::const_iterator it = + featureMomentsDataBase.find(feature_name); found = (it != featureMomentsDataBase.end()); return *(it->second); @@ -73,7 +73,7 @@ vpFeatureMoment &vpFeatureMomentDatabase::get(const char *type, bool &found) */ void vpFeatureMomentDatabase::updateAll(double A, double B, double C) { - std::map::const_iterator itr; + std::map::const_iterator itr; #ifdef VISP_HAVE_OPENMP std::vector values; values.reserve(featureMomentsDataBase.size());