Skip to content

Commit

Permalink
Modify vpMoment and vpFeatureMoment classes to replace char* usage by…
Browse files Browse the repository at this point in the history
… std::string

- Profit to indent code and make doc cleaner
  • Loading branch information
fspindle committed Nov 17, 2023
1 parent 60a39e7 commit cb4642d
Show file tree
Hide file tree
Showing 25 changed files with 398 additions and 405 deletions.
119 changes: 59 additions & 60 deletions modules/core/include/visp3/core/vpMoment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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<double> 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<double> 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; }

Expand All @@ -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<double> &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);
//@}
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpMomentAlpha.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpMomentArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpMomentAreaNormalized.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpMomentBasic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpMomentCInvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpMomentCentered.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit cb4642d

Please sign in to comment.