Progress Bar Mechanism

Fade is very fast and most of the time you won’t need a progress bar. But for huge operations you may want to connect your progress bar to Fade’s progress update mechanism.


Step 1: Create your own class

Create some custom class that derives from MsgBase so that it can receive messages from Fade. The following example creates a simple terminal progress bar:

// Create a simple command line progress bar that derives from MsgBase
class MyProgressBar:public MsgBase
    // Fade will later call the update method with d={0.0,...,1.0} 
    void update(MsgType ,const std::string& s,double d)
        cout<<s<<" [";
        for(size_t i=0;i<10;++i)
           if(i/10.0<d) cout<<"=";
              else cout<<" ";
        cout<<"] "<<d*100.0<<" %    \r"<<flush;
        if(d==1.0) cout<<endl<<endl;

Step 2: Connect your message receiver with Fade

The code below creates an object myPBar of your custom class and connects it to Fade (make sure that myPBar is not deleted before Fade is finished).

// * 1 *   Create a Fade object dt
Fade_2D dt;

// * 2 *   Progress bar object: Subscribe to MSG_PROGRESS messages 
MyProgressBar myPBar;

// * 3 *   Insert some random segments
std::vector<Segment2> vInputSegments;
dt.createConstraint(vInputSegments, CIS_CONSTRAINED_DELAUNAY);

Message Types

For progress updates the message type is always MSG_PROGRESS. Other message types (MSG_WARNING) are possible in this extendable messaging concept and are planned for later versions of the library.

Spread the word. Share this post!

Leave A Reply

Your email address will not be published. Required fields are marked *


By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.