[Insight-users] How to get a progess from an iterator?

Luis Ibanez luis.ibanez at kitware.com
Wed Dec 9 09:51:12 EST 2009


Hi Lynx,

Some compilers will warn you about uninitialized objects.

In GCC you could use the flag :   -Wuninitialized

that is one of the options turned on with :  -Wall

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

Note that you have to use it in combination with -O.

For example:

int main()
{
   int a;
   int b = a * 10;
   return 0;
}

compiled with:

          g++ -O -Wuninitialized main.cxx

produces:

main.cxx: In function ‘int main()’:
main.cxx:4: warning: ‘a’ is used uninitialized in this function


In addition, you could use Valgrind, to get a report of
uninitialized variables at run time.

---

About your second question:

Could you please post a more precise example of
what you would like to do for initializing a
ShapedNeighborhoodIterator  in 2D and/or 3D   ?

Are you referring to the size allocation for the Iterator ?
or to the selection of the Neighbors that will be ON ?


     Thanks


          Luis


--------------------------------------------------------------------------------
On Tue, Dec 8, 2009 at 3:09 PM,  <lynx.abraxas at freenet.de> wrote:
> On 06/12/09 18:24:51, Luis Ibanez wrote:
>> Hi  Lynx,
>>
>> A simpler option is to just insert a counter inside
>> the while-loop of the iterators. That's after all,
>> what the code of the ProgressReporter does.
>>
>
> Thank You very much Luis. This was exacly what I was trying to do but I didn't
> find a way to get the total number of pixels...
>
> I had some strange problem though:
> As I started from the ShapedNeighborhoodIterator example form the users  guide
> (which is in 2D) I had modified things to my need and changed to 3D.
> Somehow  that  all  worked  until I needed the new variables for the progress.
> Just from declaring a variable I got a segfault. Changing the position of  the
> declaration solved the problem for one variable but not for the rest.
> I finally figured out after hours that the problem was the uninitialized third
> dimension of the iterator neighbourhood. If I'm not mistaken  such  a  problem
> was discussed a few weeks before here on the list...
>
> I  now  wonder  if  there  is  a way to prevent this in futur programming by a
> cleaner or more secure programming style. Is  there  a  way  to  prevent  such
> faults?  Or  at least to help the compiler find uninitialized components of an
> array for reporting at compile time?
>
>
> Also I found the cool code below to easily implement 2D and  3D  programs.  Is
> there  any  chance  to  make  that work also with a ShapedNeighborhoodIterator
> who's neighbourhood (a ball) needs to be initialize once in 2D and once in 3D?
>
>
> Thanks again Luis for Your help.
> Lynx
>
> ___________________________
>
> int main( int argc, char *argv[] ){
>
>    if ( argc < 8 ){
>        std::cerr << "Missing parameters. " << std::endl;
>        std::cerr << "Usage: " << std::endl;
>        std::cerr << argv[0]
>                  << "ImageDimension inputImageFile outputImageFile element_radius foreground background maskground"
>                  << std::endl;
>        return -1;
>        }
>
>    unsigned int dim;
>
>    dim= atoi(argv[1]);
>    argv++; //shift();
>    argc--;
>
>    switch(dim)
>        {
>        case 2:
>            masked_mean_filter<2>( argc, argv );
>            break;
>        case 3:
>            masked_mean_filter<3>( argc, argv );
>            break;
>        default:
>            std::cerr << "Unsupported dimension" << std::endl;
>            exit( EXIT_FAILURE );
>        }
>    }
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list