The Progress Library

 

 

 

This library provide functions to display a window with text feedback a progress bar, and a "Abort" button.

 

This window is used when the program perform calculation in separate threads.  It enable the threads to display their progress. Please note that the progress window can not be used to display progress of a computation done in the main program thread.

 

The library has the following functions:

 

 

Progress_Init

 

 

 

Progress_Title

 

 

 

Progress_Write

 

 

 

Progress_Total

 

 

 

Progress_Val

 

 

 

Progress_Inc

 

 

 

Progress_PingPong

 

 

 

Progress_Abort

 

 

 

Progress_End

 

 

 

 

Sample use:

 

 

#include          <windows.h>

#include          <process.h>          // --- for threads ---

 

#include          "threshold.hpp"

#include          "progress.hpp"

 

typedef struct          Segment_Threads {

          int              nb_frame ;

          SliceO_Window *window ;

          SliceO_Frame  **frame ;

          void              *progress ;

          ...

} Segment_Threads ;

 

 

// ----------------------------------------------------------------------------

int          Threshold_Compute( ... )

{

          ...

 

          memset( (void *) &data, NULL, sizeof(Segment_Threads) ) ;

 

          ...

 

          // --- how many images are selected/enabled ? ---

          data.nb_frame = 0 ;

          Iterator_Init( ITERATOR_2, "Threshold_Compute" ) ;

          while( SliceO_Frame *frame = (SliceO_Frame *) Iterator_Class( ITERATOR_2, CLASS_ID_FRAME, data.window, ITER_FLAG_SELECT ) ) {

              REALLOC( SliceO_Frame **, data.frame, data.nb_frame+1, sizeof(SliceO_Frame *) ) ;

              data.frame[data.nb_frame++] = frame ;

          }

          Iterator_End( ITERATOR_2 ) ;

 

          Error_Fct( hwnd, ERROR_CODE_TRACE_1, "%d selected frames", data.nb_frame ) ;

 

          ...

 

          // --- open the progress window ---

          data.progress = Progress_Init( hwnd, "Segmentation Progress", "Computing Threshold" ) ;

 

          HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, Threshold_Fct_Thread, &data, 0, NULL ) ;

 

          ...

 

          return( 1 ) ;

 

}

 

// ----------------------------------------------------------------------------

static           unsigned __stdcall Threshold_Fct_Thread( void *pvoid )

{

int                              nb_frame = ((Segment_Threads *) pvoid)->nb_frame ;

SliceO_Frame          **frame_list = ((Segment_Threads *) pvoid)->frame ;

void                              *progress = ((Segment_Threads *) pvoid)->progress ;

...

 

          Progress_Write( progress, "Computing Thresholds for \001%d\002 frames", nb_frame ) ;

 

          // --- Initialize the progress bar to the total number of frames ---

          Progress_Total( progress, nb_frame ) ;

          Progress_Val( progress, 0 ) ;

 

          for ( k=0; k < nb_frame; k++ ) {

 

                    SliceO_Frame *frame = frame_list[k] ;

 

                    // --- did we press the "Abort" button ? ---

                    if ( Progress_Abort( progress ) )

                              break ;

                    // --- Increment the progress bar ---

                    Progress_Inc( progress, 1 ) ;

 

                    // --- if we can, lock the frame ---

                    if ( frame->Lock_Get() ) {

                              Access_End( "Threshold_Thread" ) ;

                              Progress_Write( progress, "\xF1\005WARNING:\xF0\002 image locked!" ) ;

                              Progress_Write( progress, "\002   skipping: \001%s", frame->Name_Get() ) ;

                              continue ;

                    }

                        frame->Lock_Set( 1 ) ;

 

                    // --- compute actual segmentation ---

                    Progress_Write( progress, "Segmenting: \001%s", frame->Name_Get() ) ;

 

                    ...

 

                    // --- unlock the frame ---

                    frame->Lock_Set( -1 ) ;

          }

          // --- close the progress window ---

          Progress_End( progress ) ;

 

          _endthreadex( 1 ) ;

          return( 1 ) ;

}