| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkProgressReporter.cxx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:46 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
DEF |
=========================================================================*/ |
| 17 |
|
#include "itkProgressReporter.h" |
| 18 |
|
#include "itkNumericTraits.h" |
| 19 |
|
|
| 20 |
|
namespace itk |
| 21 |
|
{ |
| 22 |
|
|
| 23 |
|
//---------------------------------------------------------------------------- |
| 24 |
|
ProgressReporter::ProgressReporter(ProcessObject* filter, int threadId, |
| 25 |
|
unsigned long numberOfPixels, |
| 26 |
|
unsigned long numberOfUpdates, |
| 27 |
|
float initialProgress, |
| 28 |
|
float progressWeight): |
| 29 |
IND |
**m_Filter(filter), |
| 30 |
IND |
**m_ThreadId(threadId), |
| 31 |
IND |
**m_CurrentPixel(0), |
| 32 |
IND |
**m_InitialProgress( initialProgress ), |
| 33 |
IND |
**m_ProgressWeight( progressWeight ) |
| 34 |
|
{ |
| 35 |
|
|
| 36 |
|
float numPixels = numberOfPixels; |
| 37 |
|
float numUpdates = numberOfUpdates; |
| 38 |
|
|
| 39 |
|
// Make sure we have at least one pixel. |
| 40 |
|
if(numPixels < 1) |
| 41 |
|
{ |
| 42 |
|
numPixels = 1; |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
// We cannot update more times than there are pixels. |
| 46 |
|
if(numUpdates > numPixels) |
| 47 |
|
{ |
| 48 |
|
numUpdates = numPixels; |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
// Calculate the interval for updates. |
| 52 |
|
m_PixelsPerUpdate = static_cast<unsigned long>(numPixels/numUpdates); |
| 53 |
|
m_InverseNumberOfPixels = 1.0 / numPixels; |
| 54 |
|
|
| 55 |
|
// Only thread 0 should update progress. (But all threads need to |
| 56 |
|
// count pixels so they can check the abort flag.) |
| 57 |
|
if(m_ThreadId == 0) |
| 58 |
|
{ |
| 59 |
|
// Set the progress to initial progress. The filter is just starting. |
| 60 |
|
m_Filter->UpdateProgress( m_InitialProgress ); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
m_PixelsBeforeUpdate = m_PixelsPerUpdate; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
//---------------------------------------------------------------------------- |
| 67 |
|
ProgressReporter::~ProgressReporter() |
| 68 |
|
{ |
| 69 |
|
// Only thread 0 should update progress. |
| 70 |
|
if(m_ThreadId == 0) |
| 71 |
|
{ |
| 72 |
LEN |
// Set the progress to the end of its current range. The filter has finished. |
| 73 |
|
m_Filter->UpdateProgress( m_InitialProgress + m_ProgressWeight ); |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
} // end namespace itk |
| 78 |
|
|