[Insight-users] ImageFunction Evaluate constness
Dan Mueller
dan.muel at gmail.com
Sun Dec 13 02:44:48 EST 2009
Hi Insight community,
I am writing an ImageFunction for which the value depends on the image
point AND previous calls to the function.
To implement this I have added a member variable (a double) to my
subclassed image function. I want to set this member variable within:
virtual TOutput Evaluate( const PointType& point ) const
I guess you can see my issue: Evaluate is marked const, so calls such as
this->m_MemberVariable = 123.456;
do not compile. I get the following error with Visual Studio 2005:
error C2166: l-value specifies const object
Of course I can get around this using const_cast on the this pointer:
MyImageFunction<TInputImage,TOutput>* function =
const_cast<MyImageFunction<TInputImage,TOutput>*>( this );
function->m_MemberVariable = 123.456;
Some questions:
Am I abusing ImageFunction?
Does use of const_cast on the this pointer invoke the wrath of the
const-correctness police?
Is there a better way?
I guess I could create my own NonConstSingleThreadedImageFunction, but
then I'd bring the code-reuse police knocking...
Any suggestions appreciated.
Regards, Dan
More information about the Insight-users
mailing list