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

J Mst gave_edgar at hotmail . com
Fri, 09 May 2003 17:51:46 +0000


hi Luis,

many thanks for your replay. I knew it wasn't a ITK related problem but I 
knew also that you guys know a lot about c++ :-). Therefore I am very happy 
you answered my question anyway. I'll try to make a sortlike construction.

greetings

Joris


>From: Luis Ibanez <luis.ibanez@kitware.com>
>To: J Mst <gave_edgar@hotmail.com>
>CC: insight-users@public.kitware.com
>Subject: Re: [Insight-users] how to connect the observer message to the 
>GUI?
>Date: Fri, 09 May 2003 13:12:43 -0400
>
>
>Hi Joris,
>
>Your current problem is not related with ITK at all.
>
>It seems to be a misunderstanding of the way you pass
>values in C++ (by value, reference or pointers).
>
>Unfortunately you are not 'connecting' the string from
>the observer to the string of your MFC GUI.
>
>Your Execute() method is simply filling in the content of
>m_TextOutput which is a member variable of the observer,
>and in no way is updating the content of the GUI.
>
>You may have to modify your Command/Observer in order to
>have a pointer or a reference to the GUI components that
>you want to update.  In that way, the last step of the
>Execute method will be to modify the GUI element, and then
>refresh the output.
>
>You may add a pointer to the top element of your GUI
>so inside the Execute method you could write something
>like:
>
>
>
>Execute()
>   {
>    ...
>   ...
>   *m_CStringOut = m_TextOutput;
>   ((CMainFrame *)AfxGetMainWnd())->RedrawWindow();
>   } // end of Execute.
>
>  SetString( CString * realString )
>  {
>   m_CStringOut = realString;
>  }
>
>private:
>  CString * m_CStringOut ;
>}; // end of Class Observer
>
>
>
>
>Luis
>
>
>------------
>
>J Mst wrote:
>>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
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users@public.kitware.com
>>http://public.kitware.com/mailman/listinfo/insight-users
>>
>
>
>

_________________________________________________________________
Hotmail en Messenger on the move 
http://www.msn.nl/communicatie/smsdiensten/hotmailsmsv2/