Documentation for Observer. refs #2366

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1199 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2015-01-16 07:47:33 +00:00
parent 76545e6c68
commit 771ee617d4

View File

@@ -70,28 +70,54 @@ namespace Decimater {
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
/** \brief Observer class
*
* Observers can be used to monitor the progress of the decimation and to
* abort it in between.
*/
class Observer class Observer
{ {
public: public:
Observer(size_t _step) :
step_(_step) { /** Create an observer
*
* @param _notificationIntervall Interval of decimation steps between notifications.
*/
Observer(size_t _notificationInterval) :
notificationInterval_(_notificationInterval) {
} }
/// Destructor
virtual ~Observer() { virtual ~Observer() {
} }
size_t get_step() const { return step_; } /// Get the interval between notification steps
// give the notification step size size_t get_interval() const { return notificationInterval_; }
void set_step(size_t _step) { step_ = _step; }
//notifies about a finished decimater step with the given step number /// Set the interval between notification steps
void set_interval(size_t _notificationInterval) { notificationInterval_ = _notificationInterval; }
/** \brief callback
*
* This function has to be overloaded. It will be called regularly during
* the decimation process and will return the current step.
*
* @param _step Current step of the decimater
*/
virtual void notify(size_t _step) = 0; virtual void notify(size_t _step) = 0;
//after notification, ask for abort or not, return true, if the decimater should abort
virtual bool abort() const = 0; /** \brief Abort callback
*
* After each notification, this function is called by the decimater. If the
* function returns true, the decimater will stop at a consistent state. Otherwise
* it will continue.
*
* @return abort Yes or No
*/
virtual bool abort() const { return false; };
private: private:
size_t step_; size_t notificationInterval_;
}; };
@@ -137,12 +163,19 @@ public: //------------------------------------------------------ public methods
public: //--------------------------------------------------- module management public: //--------------------------------------------------- module management
// Observer interface /** \brief Add observer
*
* You can set an observer which is used as a callback to check the decimators progress and to
* abort it if necessary.
*
* @param _o Observer to be used
*/
void set_observer(Observer* _o) void set_observer(Observer* _o)
{ {
observer_ = _o; observer_ = _o;
} }
/// Get current observer of a decimater
Observer* observer() Observer* observer()
{ {
return observer_; return observer_;
@@ -201,10 +234,10 @@ public: //--------------------------------------------------- module management
protected: protected:
//returns false, if abort requested by observer /// returns false, if abort requested by observer
bool notify_observer(size_t _n_collapses) bool notify_observer(size_t _n_collapses)
{ {
if (observer() && _n_collapses % observer()->get_step() == 0) if (observer() && _n_collapses % observer()->get_interval() == 0)
{ {
observer()->notify(_n_collapses); observer()->notify(_n_collapses);
return !observer()->abort(); return !observer()->abort();
@@ -212,7 +245,7 @@ protected:
return true; return true;
} }
// Reset the initialized flag, and clear the bmodules_ and cmodule_ /// Reset the initialized flag, and clear the bmodules_ and cmodule_
void set_uninitialized() { void set_uninitialized() {
initialized_ = false; initialized_ = false;
cmodule_ = 0; cmodule_ = 0;
@@ -265,22 +298,22 @@ protected: //---------------------------------------------------- private method
private: //------------------------------------------------------- private data private: //------------------------------------------------------- private data
// reference to mesh /// reference to mesh
Mesh& mesh_; Mesh& mesh_;
// list of binary modules /// list of binary modules
ModuleList bmodules_; ModuleList bmodules_;
// the current priority module /// the current priority module
Module* cmodule_; Module* cmodule_;
// list of all allocated modules (including cmodule_ and all of bmodules_) /// list of all allocated modules (including cmodule_ and all of bmodules_)
ModuleList all_modules_; ModuleList all_modules_;
// Flag if all modules were initialized /// Flag if all modules were initialized
bool initialized_; bool initialized_;
// observer /// observer
Observer* observer_; Observer* observer_;
}; };