Fade2D Examples

Progress Bar Mechanism – Example 10

Fade is fast and most of the time you will not need progress updates at all. But for very large triangulations you may still want to connect your own progress bar to Fade2D’s update mechanism.

Your own Progress Receiver Class

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

// Create a simple command line progress bar that 
// derives from MsgBase so that it can receive messages
class MyProgressBar:public MsgBase
    // Fade will later call the update method with d={0.0,...,1.0} 
    void update(MsgType ,const char* 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;

Connect your Progress Bar Class with Fade2D

The code below creates an object MyProgressBar myPBar of the new derived class and connects it to Fade.

“Make sure that myPBar is not deleted before the Fade object. Otherwise Fade could try to notify a deleted object”

// * 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. Observe that
//         myPBar receives progress updates
std::vector<Segment2> vInputSegments;
dt.createConstraint(vInputSegments, CIS_CONSTRAINED_DELAUNAY);

Leave a Reply

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