[Insight-users] how to connect the observer message to the GUI?

J Mst gave_edgar at hotmail . com
Fri, 09 May 2003 16:16:57 +0000


Hi all,

I think I've to simplify my question. I will clarify my problem with some 
code. I'll post a snippet of the commanIterationUpdate class and of the use 
of that class in my application. First the CommandIterationUpdate class:

*******************************************************************************
#ifndef __itkCommandIterationUpdate_h
#define __itkCommandIterationUpdate_h

#include <itkCommand.h>
#include "itkWeakPointer.h"

namespace itk {

template < class TOptimizer >
class ITK_EXPORT CommandIterationUpdate : public Command
{
public:
  typedef CommandIterationUpdate   Self;
  typedef itk::Command  Superclass;
  typedef itk::SmartPointer<Self>  Pointer;
  typedef itk::SmartPointer<const Self>  ConstPointer;

  void Execute(itk::Object *caller, const itk::EventObject & event)
  {
    Execute( (const itk::Object *)caller, event);
  }

  void Execute(const itk::Object *caller, const itk::EventObject & event)
  {
    if( typeid( event ) == typeid( itk::IterationEvent ) )
      {

      //std::cout << m_Optimizer->GetCurrentIteration() << " = ";       
//This is the method used !!!!
      //std::cout << m_Optimizer->GetValue() << " : ";                       
//   in the registration      !!!!!
      //std::cout << m_Optimizer->GetCurrentPosition() << std::endl;   //    
        examples          !!!!!

     std::StringStream text;
     text <<  m_Optimizer->GetCurrentIteration() << " : " << ;
     text <<  m_Optimizer->GetValue() << " : " <<;
     text <<  m_Optimizer->GetCurrentPosition() << std::endl;
     m_TextOut = text.str().c_str();
      }
  }

itkTypeMacro( CommandIterationUpdate, ::itk::Command );
itkNewMacro( Self );
typedef    TOptimizer     OptimizerType;

void SetOptimizer( OptimizerType * optimizer )
    {
    m_Optimizer = optimizer;
    m_Optimizer->AddObserver( itk::IterationEvent(), this );
    }

void SetOutput( CString m_Out )
{
	m_Out = m_TextOut;
}

protected:


  CommandIterationUpdate() {};

private:

  WeakPointer<OptimizerType>   m_Optimizer;

  CString			m_TextOut;

};
}
#endif
********************************************************************************

As can be seen, I've put the update message into a stream and I want that 
stream te be seen in the GUI. Therefore I created the funtion SetOutput. 
I've used this class in the following way.

****************ApplicationDlg.h******************

typedef	CommandIterationUpdate<OptimizerType>   IterationObserverType;

IterationObserverType::Pointer	  m_observer;

***************************************************

***************ApplicationDlg.cpp*******************

m_observer = IterationObserverType::New();


void ApplicationDlg::onStartRegistration()
{

m_observer->SetOptimizer( RegularStepOptimizer );
m_observer->SetOutput( m_TextOutput );

m_registration->StartRegistration();
}
**************************************************

The m_TextOutput variavbe is connected to the edit box in my GUI, and with 
the funtion SetOutput() I hoped to connect the output of the 
CommandIterationUpdate class to the GUI. But this didn't work unfortunately.

Does someone know what I am doing wrong? Or is there a easier way do do the 
thing that I want??

Thanks in advance.

Joris

_________________________________________________________________
MSN Zoeken, voor duidelijke zoekresultaten! http://search.msn.nl