[Insight-users] Cast itk Objects

Kajetan Berlinger kaje at kaje.info
Wed May 24 17:45:03 EDT 2006


Hi,

first of all, I would like to excuse for this very simple question.

I have a member within a class of type 
itk::SingleValuedNonLinearOptimizer::Pointer, called optimizer.

I initialize this object with different optimizers (depending on the 
user selection), which all inherit from 
itk::SingleValuedNonLinearOptimizer e.g. PowellOptimizer or 
GradientDescentOptimizer.

And now I wonder why I can't perform a cast:
((RegularStepGradientDescentOptimizerType::Pointer)optimizer)->GetCurrentIteration() 


The compiler returns the following error message:

invalid conversion from `itk::SingleValuedNonLinearOptimizer*' to 
`itk::RegularStepGradientDescentOptimizer*'
RegistrationThread.cpp:302: error:   initializing argument 1 of 
`itk::SmartPointer<TObjectType>::SmartPointer(TObjectType*) [with 
TObjectType = itk::RegularStepGradientDescentOptimizer]'


What is wrong with my way of performing casts of itk Objects?

Thanks a lot!

Kaj


More information about the Insight-users mailing list