[Insight-users] Demons observer

Luis Ibanez luis.ibanez at kitware.com
Tue Jun 8 12:01:16 EDT 2004


Hi Josiane,

Command/Observers have two Execute methods, they differ
on the constness of the (Object *) received as argument.

Since you are attempting to do dynamic casting on the
Execute() method that receives a const pointer to Object,
then you must respect the constness in the dynamic_cast.


Please try the following line:


  const RegistrationFilterType * filter=
     dynamic_cast< const RegistrationFilterType * >( object );
                   ^^^^^

You may want to see the identical code in the example:

   Insight/Examples/Registration/
             DeformableRegistration2.cxx


in lines 73 and 74.



Let us know if you still find any problem.


   Thanks


     Luis


-------------------------------------------------------
Josiane Yankam Njiwa--DEA Clarysse--Fin 11/04 wrote:

> Hi Luis
> 
> 
> Thanks for your answer. When I replace RegistrationFilterType::Pointer
> filter=dynamic_cast< RegistrationFilterType>( object );
> by
> const RegistrationFilterType * filter=dynamic_cast< RegistrationFilterType
> * >( object );
> I hae another message error, I don't know how to solve it. Th emessage is:
> cannot use dynamic_cast to convert from 'const class itk::Object *' to
> 'class itk::DemonsRegistrationFilter<class itk::Image<float,2>,class
> itk::Image<float,2>,class itk::Image<class itk:
> :Vector<float,2>,2> > *'
> 
> Can you help me?
> 
> Regards.
> 
> Josiane.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>>Hi Josiane,
>>
>>
>>As Lydia replied to you on June 4th:
>>http://www.itk.org/pipermail/insight-users/2004-June/008789.html
>>
>>You must modify the line
>>
>> >    dynamic_cast< RegistrationFilterType>( object );
>>
>>and put
>>
>> >    dynamic_cast< RegistrationFilterType * >( object );
>>
>>
>>Dynamic casting requires pointers or references to types.
>>It cannot be done on direct types.
>>
>>
>>    Regards,
>>
>>
>>       Luis
>>
>>
>>------------------------------------------------------
>>Josiane Yankam Njiwa--DEA Clarysse--Fin 11/04 wrote:
>>
>>
>>>Hi,
>>>
>>>I want to see how the demons registration compute the displacement at
>>>each
>>>iteration and i like to add to the program an obsever, but i have this
>>>message error during the compilation:error C2680: 'class
>>>itk::DemonsRegistrationFilter<class itk::Image<float,2>,class
>>>itk::Image<float,2>,class itk::Image<class itk::Vector<float,2>,2> >' :
>>>invalid target type for dynamic_cast
>>>Error executing cl.exe.
>>>
>>>I don't how to overpass my problem. Thanks for your help.
>>>
>>>Regards
>>>
>>>Josiane
>>>
>>>
>>>Here is my code:
>>>
>>>
>>>
>>>#include "itkCommand.h"
>>>class CommandIterationUpdate : public itk::Command
>>>{
>>>public:
>>>  typedef  CommandIterationUpdate   Self;
>>>  typedef  itk::Command             Superclass;
>>>  typedef itk::SmartPointer<Self>  Pointer;
>>>  itkNewMacro( Self );
>>>protected:
>>>  CommandIterationUpdate() {};
>>>public:
>>>
>>>  typedef float InternalPixelType;
>>>  typedef itk::Image< InternalPixelType, 2 > InternalImageType;
>>>  typedef itk::Vector< float, 2 >    VectorPixelType;
>>>  typedef itk::Image<  VectorPixelType, 2 > DeformationFieldType;
>>>  typedef itk::DemonsRegistrationFilter<
>>>                                InternalImageType,
>>>                                InternalImageType,
>>>                                DeformationFieldType>
>>>RegistrationFilterType;
>>>
>>>
>>>
>>>  void Execute(itk::Object *caller, const itk::EventObject & event)
>>>    {
>>>      Execute( (const itk::Object *)caller, event);
>>>    }
>>>
>>>  void Execute(const itk::Object * object, const itk::EventObject &
>>>event)
>>>    {
>>>
>>>          RegistrationFilterType::Pointer filter=
>>>                  dynamic_cast< RegistrationFilterType>( object );
>>>
>>>      if( typeid( event ) != typeid( itk::IterationEvent ) )
>>>        {
>>>        return;
>>>        }
>>>      std::cout << filter->GetElapsedIterations()<< "   ";
>>>
>>>
>>>
>>>
>>>
>>>
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
>>
>>
> 
> 





More information about the Insight-users mailing list