Thank you, meanwhile I solved the problem, I found the reset condition
by browsing the MITK source code. I attached the code, maybe someone
will find it useful. It displays a message on the status bar when a
process starts, clears it when it terminates and displays its
progress.
However, there is still an issue. The progress bar is not refreshed
after every progress report. This is especially disturbing at the
beginning. Sometimes the progress bar on the status bar appears only
when the process reaches 13% (after a few seconds), although it
reported its progress earlier as well.
Do you know any workaround for this? Maybe the QmitkProgressBar could
be modified so that it calls the QWidget::update() after every
progress report. Probably Qt spares some update, but it could be
forced.
Regards,
Miklos
On Sun, Jun 5, 2011 at 3:05 PM, Sascha Zelzer
<[email protected]> wrote:
> Hi Miklos,
>
> the mitk::ProgressBar is a very simple interface which provides a
> centralized view of the applications work progress. Hence you are only
> allowed to increment the progress with a relative value, because you cannot
> know what other tasks might still be pending. As far as I know, we do not
> have a helper class for reporting ITK filter iteration events. However, here
> is a simple code snippet which reports ITK events to the MITK progress bar
> (provided that the ITK filter supports iteration events):
>
> void SomeClass::DoFiltering()
> {
> mitk::ProgressBar::GetInstance()->AddStepsToDo(stepCount);
>
> itk::ReceptorMemberCommand<ITKFilterType>::Pointer command =
> itk::ReceptorMemberCommand<ITKFilterType>::New();
> command->SetCallbackFunction(this, &SomeClass::SetProgress);
> itkFilter->AddObserver(itk::IterationEvent(), command);
> ...
> itkFilter->Update();
> }
>
> void SomeClass::SetProgress()
> {
> mitk::ProgressBar::GetInstance()->Progress();
> }
>
> The progress bar will be reset if the sum of the progress steps given to
> Progress(int steps = 1) >= sum of the steps given to AddStepsToDo(int steps)
> (since the last reset).
>
> Best,
> Sascha
>
> On 05/26/2011 06:30 PM, Miklos Espak wrote:
>>
>> Hi,
>>
>> I would like to show the progress of some ITK filters on the status
>> bar. However, the API of mitk::ProgressBar follows different concepts
>> then e.g. QProgressBar or itk::ProcessObject::GetProgress(), e.g. it
>> does not allow to set the progress as an absolute value but as an
>> advancement since the last reported progress. It is also not possible
>> to reset the progress bar.
>>
>> When are the registered progress bars reset internally? Maybe after
>> the following?
>> mitk::RenderingManager::GetInstance()->RequestUpdateAll();
>>
>> Is there an adaptor class eventually to display the progress of a
>> filter? Or I have to preserve the last progress status at every
>> process event, and subtract from the current one?
>>
>> Thank you,
>> Miklos
>>
>>
>> ------------------------------------------------------------------------------
>> vRanger cuts backup time in half-while increasing security.
>> With the market-leading solution for virtual backup and recovery,
>> you get blazing-fast, flexible, and affordable data protection.
>> Download your free trial now.
>> http://p.sf.net/sfu/quest-d2dcopy1
>> _______________________________________________
>> mitk-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/mitk-users
>
>
/*
* ItkProcessObserver.cpp
*
* Created on: 2011.06.01.
* Author: espakm
*/
#include "ItkProcessObserver.h"
#include <mitkProgressBar.h>
#include <mitkStatusBar.h>
#include <itkCommand.h>
#include <itkProcessObject.h>
ItkProcessObserver::ItkProcessObserver(itk::ProcessObject* itkProcess, const char* statusBarMessage) {
m_ItkProcess = itkProcess;
m_StatusBarMessage = statusBarMessage;
// Not a nice thing to initialize static data members from constructors,
// but this way we can be sure that these functions return a valid value.
// (They are initialized at that time.)
m_StatusBar = mitk::StatusBar::GetInstance();
m_ProgressBar = mitk::ProgressBar::GetInstance();
// This can be an arbitrary number. ITK processes report their progress as
// a real number between 0 and 1. The MITK progress bar, however, expects integers,
// so the ITK progress has to be scaled to the [0 ; m_StepsToDo] interval.
m_StepsToDo = 100;
m_StepsDone = 0;
m_ProgressBar->AddStepsToDo(m_StepsToDo);
typedef itk::SimpleMemberCommand<ItkProcessObserver> MemberCommand;
MemberCommand::Pointer startCommand = MemberCommand::New();
startCommand->SetCallbackFunction(this, &ItkProcessObserver::onStartEvent);
m_ItkProcess->AddObserver(itk::StartEvent(), startCommand);
MemberCommand::Pointer endCommand = MemberCommand::New();
endCommand->SetCallbackFunction(this, &ItkProcessObserver::onEndEvent);
m_ItkProcess->AddObserver(itk::EndEvent(), endCommand);
MemberCommand::Pointer progressCommand = MemberCommand::New();
progressCommand->SetCallbackFunction(this, &ItkProcessObserver::onProgressEvent);
m_ItkProcess->AddObserver(itk::ProgressEvent(), progressCommand);
}
void
ItkProcessObserver::onStartEvent() {
// m_ProgressBar->AddStepsToDo(1);
// m_ProgressBar->Progress();
m_StatusBar->DisplayText(m_StatusBarMessage);
// m_StatusBar->DisplayGreyValueText(m_ProcessName.c_str());
}
void
ItkProcessObserver::onEndEvent() {
m_StatusBar->DisplayText("");
// m_StatusBar->DisplayGreyValueText("");
// We make the progress bar reach 100%.
m_ProgressBar->Progress(m_StepsToDo - m_StepsDone);
}
void
ItkProcessObserver::onProgressEvent() {
double progress = m_ItkProcess->GetProgress();
double stepsDone = static_cast<int>(progress * m_StepsToDo);
if (stepsDone > m_StepsDone) {
m_ProgressBar->Progress(stepsDone - m_StepsDone);
m_StepsDone = stepsDone;
}
}
/*
* ItkProcessObserver.h
*
* Created on: 2011.06.01.
* Author: espakm
*/
#ifndef ITKPROCESSOBSERVER_H_
#define ITKPROCESSOBSERVER_H_
namespace itk {
class ProcessObject;
}
namespace mitk {
class StatusBar;
class ProgressBar;
}
class ItkProcessObserver {
itk::ProcessObject* m_ItkProcess;
const char* m_StatusBarMessage;
int m_StepsToDo;
int m_StepsDone;
mitk::StatusBar* m_StatusBar;
mitk::ProgressBar* m_ProgressBar;
public:
ItkProcessObserver(itk::ProcessObject* itkProcess, const char* statusBarMessage);
private:
void onStartEvent();
void onEndEvent();
void onProgressEvent();
};
#endif /* ITKPROCESSOBSERVER_H_ */
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today.
http://p.sf.net/sfu/quest-dev2dev2
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users