[Insight-developers] Const Missing in inputs for Process Obje ct

Luis Ibanez luis.ibanez@kitware.com
Mon, 25 Mar 2002 09:30:01 -0500


Yeap,  
I gave up on the const-correctness for Inputs...

Propagating that through the ProcesObject/DataObject
if pretty hard.   This require something like adding "const"
derivation to C++, or rather "mutable" derivation like:

class ImageFilter : public mutable DataObject
{
};

So a const ImageFilter can still have normal activity at the
DataObject level... maybe for gcc 4.0      :-)


In spite of that,  I think we should at least encourage
filter writers to get the pointers as const pointers. The
typical first part of  a GenerateData() section is:

    TInputImage::Pointer  inputImage =
            dynamic_cast< TInputImage *>( this->GetInput(0) );

This should be:

    TInputImage::ConstPointer inputImage =
            dynamic_cast< const TInputImage * >( this->GetInput(0) );

And then instead of  ImageRegionIterator  use
ImageRegionConstIterator for getting access to input pixels.
BTW the ImageRegionConstIterator was just updated on saturday.
And Const versions of the FloodFill Iterator were added too.


Even if the ProcessObject doesn't force us to follow const-correctness
on the filters it will be a good practice to do it.  It is very easy to 
end up
modifying the input image by accident if const is not declared explicitly.


    Luis

================================

Miller, James V (CRD) wrote:

>I would avoid making the input arrays hold const pointers.
>
>Not only is it a barrel or worms, it will make inplace filters
>problematic.  I do not want to re-implement large sections of 
>ProcessObject to support inplace filters.
>
>As for the separation of the pipeline mechanism from the data
>portion of the image, I don't think the separation will help 
>with the const-correctness issues you are hitting up against.
>I think it will just move the problem but the same issues
>will re-appear.
>
>As for streaming of inplace filters, I don't see any reason
>why they wouldn't stream.
>
>
>
>-----Original Message-----
>From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
>Sent: Saturday, March 23, 2002 11:24 AM
>To: Insight Developers
>Subject: [Insight-developers] Const Missing in inputs for Process Object
>
>
>Hi,
>
>The array of inputs for Process Object is not const-correct.
>
>In principle there is no reason for a filter to modify its input
>so the input should be stored as ConstSmartPointers.
>
>Currently this is done using just SmartPointers.
>
>This constness-defect is propagated through all the Filters
>which  basically means that you cannot pass a const image
>as input to any filter.      :-/
>
>Does anybody see a conflict in making the array of m_Inputs
>in itk::ProcessObject   an array of SmartConstPointers   ?
>
>
>   Luis
>
>_______________________________________________
>Insight-developers mailing list
>Insight-developers@public.kitware.com
>http://public.kitware.com/mailman/listinfo/insight-developers
>