[Insight-users] StopOptimization
Luis Ibanez
luis . ibanez at kitware . com
Wed, 03 Sep 2003 17:58:11 -0400
Hi Michael,
This is actually an API defect. GetMinimize() and GetMaximize() should
both be const methods. However, the way they are defined in
itkGradientDescentOptimizer.h and
itkRegularStepGradientDescentOptimizer.h
is
> itkSetMacro( Maximize, bool );
> itkGetMacro( Maximize, bool );
> bool GetMinimize( ) const
> { return !m_Maximize; }
> void SetMinimize(bool v)
> { this->SetMaximize(!v);
Instead of "itkGetMacro( Maximize, bool )" we should have the
const macro:
itkGetConstReferenceMacro( Maximize, bool );
The fundamental principle is that only const methods should be
allowed in the const version of the Execute() method in the observer.
"Get" methods should in general be declared const. Otherwise the
contaminate the functionality of their "Set" counterparts.
-----
Luis
---------------------------
Michael Kuhn wrote:
> Hi Luis,
>
> I've just noticed, that the GetMinimize() and GetMaximize() functions
> of the optimizer can only be called in the "non-const" Execute method
> of the observer. Where is the difference between e.g.
> GetCurrentPosition() and GetMinimize()?
>
> Thanks,
>
> Michael
>
>
>
> Luis Ibanez wrote:
>
>>
>> Hi Michael,
>>
>>
>> The error message that you posted seems to be originated by a
>> conflict in constness qualifications.
>>
>> Note that Observers should implement two Execute() methods, one
>> "const" and another "non-const". The StopOptimization() method is
>> non-const, so you can only invoke it from the non-const Execute()
>> method of the Observer.
>>
>>
>> The other calls are allowed in your const Execute() method, because
>> they are also const methods. (e.g. GetCurrentPosition() ).
>>
>>
>> Please try implementing a non-const Execute() method in your
>> observer and call StopOptimization from there.
>>
>>
>> Regards,
>>
>>
>> Luis
>>
>>
>> ----------------------
>> Michael Kuhn wrote:
>>
>>> Hi,
>>>
>>> When I'm trying to call optimizer->StopOptimization in my observer I
>>> get the following compiler error:
>>>
>>> D:\pack\vtkMy\src\Applications\Mixed\itkUtilities\quaternionObserverMultiResolution.cxx(49)
>>> : error C2662: 'StopOptimization' : cannot convert 'this' pointer
>>> from 'const class
>>> itk::QuaternionRigidTransformGradientDescentOptimizer' to 'class
>>> itk::Gra
>>> dientDescentOptimizer &'
>>> Conversion loses qualifiers
>>> C:\programs\vs6p\VC98\INCLUDE\xstring(583) : while compiling
>>> class-template member function 'void __thiscall
>>> QuaternionObserverMultiResolution<class
>>> itk::RegistrationModule<class itk::Image<short,3>,class
>>> itk::Image<short,3>,class itk::Image
>>> <short,3> > >::Execute(const class itk::Object *,const class
>>> itk::EventObject &)'
>>> Error executing cl.exe.
>>>
>>> In the execute method, I do a dynamic_cast from itk::Object caller
>>> to itk::QuaternionRigidTransformGradientDescentOptimizer optimizer:
>>>
>>> OptimizerPointer optimizer = dynamic_cast<OptimizerPointer>(caller);
>>>
>>> OptimizerPointer is defined as follows in the .h file of my observer:
>>>
>>> typedef itk::QuaternionRigidTransformGradientDescentOptimizer
>>> OptimizerType;
>>> typedef const OptimizerType* OptimizerPointer;
>>>
>>>
>>>
>>> Other calls to this optimizer (like optimizer->GetCurrentPosition())
>>> work fine (i.e. the program compiles if I comment the line that
>>> contains optimizer->StopOptimization() ).
>>>
>>> Can anybody tell me, what I'm doing wrong?
>>>
>>> Thanks,
>>>
>>> Michael
>>>
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk . org
>>> http://www . itk . org/mailman/listinfo/insight-users
>>>
>>
>>
>>
>>
>>
>
>
>