[Insight-users] Re: Question About Connected Threshold Filter

Luis Ibanez luis . ibanez at kitware . com
Mon, 15 Sep 2003 12:24:40 -0400


Hi Neha,

I'm assuming that you are making reference to the example

        ConnectedThresholdImageFilter.cxx

in the directory

         Insight/Examples/Segmentation

and to the lines 221-221:

>
>   const InternalPixelType lowerThreshold = atof( argv[5] );
>   const InternalPixelType upperThreshold = atof( argv[6] );
>

If that's the case,   The answer to your question:  

                "Why is it made constant ? "
is:

     "Because these values are not expected to change"


In this example, the threshold values are read from the command
line arguments and used for setting the parameters of the filter.
The filter is run once, and then we quit the application.  In this
circumstances, there is no reason for changing the threshold values,
and henceforth they should be declared 'const'.

You are not forced to do so, but it is a healthy practice. It sets the
compiler on your side, since it will help you to detect undesired
attempts for modifiying the value of these variables.


Now that,.... if you are introducing changes in this code for reusing
the filter and runing with several different values of the threshold,
then.... your values are now expected to change and you are fully
entitled to discard the "const" qualifier.

ITK is enforcing const-correctess as a modern C++ practice.
You will find the usage of "const" in many places on the toolkit.


  Regards,


    Luis


-------------------
Neha D wrote:

> Hi All,
>
> I am trying to use ConenctedThreshold Filter to check on Breast MRIs. 
> For that i want to use different upper and lower threshold values. But 
> since they are made of "const float" i can not use them dynamically. 
> Would like to know why is it made constant.
>
> Thanks,
>
> Neha
>
>  
>
>  
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Yahoo! SiteBuilder 
> <http://us . rd . yahoo . com/evt=10469/*http://sitebuilder . yahoo . com> - 
> Free, easy-to-use web site design software