Hi Miri,

please keep the conversation on the list!

Is it an ITK filter, or MITK filter? The "MyPlugin" name is a little
misleading for a filter.

If ITK then you should add a listener to the filter that is notified
when the progress changes, and reports the progress to the progress
bar.

Look at this code:

-----------------
void
ItkPipelineThread::observeProcess(itk::ProcessObject* process, QString
statusMessage) {
 Q_D(ItkPipelineThread);
 d->process = process;
 d->statusMessage = statusMessage;

 typedef itk::SimpleMemberCommand<ItkPipelineThread> MemberCommand;

 MemberCommand::Pointer startCommand = MemberCommand::New();
 startCommand->SetCallbackFunction(this, &ItkPipelineThread::onProcessStart);
 process->AddObserver(itk::StartEvent(), startCommand);

 MemberCommand::Pointer endCommand = MemberCommand::New();
 endCommand->SetCallbackFunction(this, &ItkPipelineThread::onProcessEnd);
 process->AddObserver(itk::EndEvent(), endCommand);

 MemberCommand::Pointer progressCommand = MemberCommand::New();
 progressCommand->SetCallbackFunction(this,
&ItkPipelineThread::onProcessProgress);
 process->AddObserver(itk::ProgressEvent(), progressCommand);
}

void
ItkPipelineThread::onProcessStart() {
 Q_D(ItkPipelineThread);
 emit processStarted(d->statusMessage);
}

void
ItkPipelineThread::onProcessEnd() {
 emit processFinished();
}

void
ItkPipelineThread::onProcessProgress() {
 Q_D(ItkPipelineThread);
 emit processProgress(d->process->GetProgress());
}
---------------------------

This is how to add listeners to a filter.

I run the filters in a separate thread, but it is not necessary.
However, if you do like this, you have to pay attention not to use the
GUI (e.g. updating the progress bar) from the same thread. That's why
I sent Qt signals from the listeners, instead of updating the progress
bar directly.

The signals are connected to slots in the GUI thread, and these slots
update the progress bar. It looks like this here:

void
DceWorkflowStepWidget::onProcessStarted(QString message) {
 Q_D(DceWorkflowStepWidget);

 // 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.)
 d->m_StatusBar = mitk::StatusBar::GetInstance();
 d->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.
 d->m_StepsToDo = 100;
 d->m_StepsDone = 0;

 d->m_ProgressBar->AddStepsToDo(d->m_StepsToDo);

 d->m_StatusBar->DisplayText(message.toStdString().c_str());
 //  m_StatusBar->DisplayGreyValueText(m_ProcessName.c_str());
}

void
DceWorkflowStepWidget::onProcessProgress(double progress) {
 Q_D(DceWorkflowStepWidget);

 double stepsDone = static_cast<int>(progress * d->m_StepsToDo);
 if (stepsDone > d->m_StepsDone) {
   d->m_ProgressBar->Progress(stepsDone - d->m_StepsDone);
   d->m_StepsDone = stepsDone;
 }
}

void
DceWorkflowStepWidget::onProcessFinished() {
 Q_D(DceWorkflowStepWidget);

 d->m_StatusBar->DisplayText("");
//  m_StatusBar->DisplayGreyValueText("");
 // We make the progress bar reach 100%.
 d->m_ProgressBar->Progress(d->m_StepsToDo - d->m_StepsDone);
}
--------------------------------------------------------------



However, if you do not need to run the filter in the background, you
can just combine the two code snippets.

The behaviour of the progress bar was a bit unusual for me first. You
cannot set the progress as a percentage like in QProgressBar. Instead,
you can add the number of steps to do (AddStepsToDo), and report the
number of accomplished steps (Progress). The number of accomplished
steps is accumulated and if it reaches the number of steps to do, the
progress bar disappears.

Best,
Miklos

On Sat, Jan 14, 2012 at 6:30 PM, Miri Trope <[email protected]> wrote:
> Hi Miklos,
> Thank you very much for your answer.
>
> Indeed, I was searching for a progress bar to a plug in.
> Let's say that I'd like to see the progress of the command:
> myFilter->Update();
> while myFilter is an instance of myPlugIn and that command has written in
> myPlugInView like that:
>
>       myPlugIn::Pointer myFilter =  myPlugIn::New();
>       WaitCursorOn();
>       mitk::StatusBar::GetInstance()->DisplayText("In process ...");
>       mitk::ProgressBar::GetInstance()->AddStepsToDo(2);
>       mitk::ProgressBar::GetInstance()->Progress(2);
>
>       /*
>       some commands ...
>       */
>       myFilter->Update();
>
>       mitk::ProgressBar::GetInstance()->Delete();
>       mitk::StatusBar::GetInstance()->DisplayText("End Of Process ...");
>       WaitCursorOff();
>
>   a. what I should add/change in order to see that progressBar in the exact
> location relatively to the command's status? (now it's not progressing at
> all)
>   b. How this progress bar can be disappeared after its process ends?
>
>
>
>
> Thanks in advance!
>
>
> On Mon, Jan 9, 2012 at 10:24 AM, Miklos Espak <[email protected]> wrote:
>>
>> Hi Miri,
>>
>> MITK distinguishes modules and plugins. Modules are simple shared
>> object files (dll-s) and may not depend on MITK at all. You are
>> talking about plugins, I guess.
>>
>> The progress on status bar is easy, you only have to get an instance
>> of mitk::ProgressBar (singleton), and the reported progress appears on
>> the status bar.
>>
>> Best,
>> Miklos
>>
>> On Sun, Jan 8, 2012 at 10:40 PM, Miri Trope <[email protected]> wrote:
>> > Hi All,
>> >
>> > I'm wondering if it's possible to:
>> >
>> > a. Run my module (with some arguments) with Mitk but without its gui
>> > (like:
>> > command line operation)?
>> > b. Show a progress bar for my module? and where should I add this option
>> > (in
>> > myProjectView.cpp ?)?
>> >
>> >
>> > BTW, sorry for all my latest posts, It's because I'm having a huje
>> > progress
>> > in my project :-)
>> > Regards,
>> > Miri
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a
>> > complex
>> > infrastructure or vast IT resources to deliver seamless, secure access
>> > to
>> > virtual desktops. With this all-in-one solution, easily deploy virtual
>> > desktops for less than the cost of PCs and save 60% on VDI
>> > infrastructure
>> > costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
>> > _______________________________________________
>> > mitk-users mailing list
>> > [email protected]
>> > https://lists.sourceforge.net/lists/listinfo/mitk-users
>> >
>
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to