[IGSTK-Users] Observe... methods generated by EventTransductionMacros

Luis Ibanez luis.ibanez at kitware.com
Thu Oct 4 14:18:23 EDT 2007


Hi Vincent,

Thanks for pointing this out.

We have created a bug report for this issue:
http://public.kitware.com/Bug/view.php?id=5826

Although it is mostly a matter of coding style, you are
right regarding the inconsistency of the method naming.

The challenge to fix it seems to be that there are situations
in which a class needs to listen to the same events from different
objects, and for each one, we need to generate a different input.


Strictly speaking the Observe method should probably
be named after the combination of:

          event + input + observedObject

However at that point, the name will be so long that we should probably
rather consider having an extra parameter in the macro and use it for
customizing the name of the Observe method.

Consider for example the usage of the macros in the method"

void
MR3DImageToUS3DImageRegistration::RequestCalculateRegistration()


   this->ObserveUSImageTransformInput(this->m_USFixedImage);
   this->ObserveMRImageTransformInput(this->m_MRMovingImage);

Where the methods were created by the following Transduction
macros in the header:

  igstkLoadedEventTransductionMacro( TransformModifiedEvent,
                                     MRImageTransformInput, Transform );
  igstkLoadedEventTransductionMacro( TransformModifiedEvent ,
                                     USImageTransformInput, Transform );


As you pointed out, we should have used the "Event" as the suffix of the
method name, but.... in this case we will have created two methods with
the same name.

A second approach chould have been to use as name of the method the
combination:

       Observe##event##input

The will lead to a method called:

     this->ObserveTransformModifiedEventUSImageTransformInput()


where the naming can easly go out of hand....

Granted, we use that naming method for

  *  the member variable of the observer itself
  *  the callback

but the application developer doesn't have to deal with this
member variable nor the callback at all.


The third suggested option is to have a third argument in
the transduction macro and use it as the Observe method.

For example

  igstkLoadedEventTransductionMacro( TransformModifiedEvent,
                                     MRImageTransformInput,
                                     ObserverMRImageTransform,
                                     Transform );

  igstkLoadedEventTransductionMacro( TransformModifiedEvent ,
                                     USImageTransformInput,
                                     ObserverMRImageTransform,
                                     Transform );

that will be used as:

   this->ObserveUSImageTransform(this->m_USFixedImage);
   this->ObserveMRImageTransform(this->m_MRMovingImage);


This last approach gives a bit more of flexibility...



    Please let us know what you think,



       Thanks


         Luis




--------------------------
Vincent Gratsac wrote:
> 
> Hi all,
> 
> I noticed something strange in the following macros :
> 
> igstkEventTransductionMacro ( event,  input  )
> igstkLoadedEventTransductionMacro ( event,  input  )
> igstkLoadedObjectEventTransductionMacro ( event,  input  )
> 
> In fact, generated "Observe..." public methods are completed with the 
> #event name in the first macro, and with the #input name with the two 
> last ones.
> 
> public:  void Observe##event(const ::itk::Object * object )
> 
> public:  void Observe##input(const ::itk::Object * object )
> 
> Is this difference normal or is this a bug ? Note that it is not a 
> problem for me... I just want to underline something that can be a 
> little error.
> 
> Thank you and have a nice day !
> 



More information about the IGSTK-Users mailing list