[Insight-users] itk::Array

Luis Ibanez luis.ibanez@kitware.com
Wed, 29 Jan 2003 09:27:48 -0500


Hi Kumar,


itk::Array is a dynamic array.
It derives from the vnl_vector<>.

This class requires initialization for
its size and memory allocation.

If you have a constant number of elements
you may want to consider using itk::FixedArray
instead.

itk::Array can be initialized by giving a size
argument to the constructor, like

        itk::Array<double>   A( 100 );

or by assignment from another array, like

        itk::Array<double>   B;

        B = A;

This is as far as memory allocation goes.
Now, for initializing the array values, you
may use the Fill() method.  Like


       B.Fill(  0.0  );

or more generic-programming-like:


   B.Fill( itk::NumericTraits<double>::Zero );



Please let us know if you have further questions,


Thanks


Luis


-----------------------------------

kumar wrote:

> Hello Everyone
> I am using itk::Array and there were strange results that I was getting, 
> if the Array was not initialized
> 
> I had declared a Array variable using the following statement
> Array<double> epsiloni_square(ns);
> 
> 
> And I was filling it up in a for loop
> But the ns-1 index was giving me problems
> 
> epsiloni_square(indx_i)  = epsiloni_square(indx_i) +  (Oxi(l)-Rxi(l))* 
> (Oxi(l)-Rxi(l));
>  if(indx_i == (ns-1))
>          cout  << "\n " << epsiloni_square(indx_i) << " " <<  Oxi(l) <<" 
> " <<  Rxi(l);
> 
> Everything was in order , but the result was as follows
> -NaN        5                     1.47095
> -NaN       7                 3.72159
> -NaN       9                 2.84563
> -NaN       4                     6.18214
> -NaN        6                 4.01261
> -NaN        2                 4.88857
> -NaN        9                 6.37723
> -NaN        3             7.30397
> -NaN        2             4.08111
> 
> 
> See epsiloni_square [65.9847, 46.6313, 76.5233, -NaN]
> The first column is epsiloni_square , then Oxi and then Rxi
> 
> 
> After some debugging I could set it up using the following initialization
> epsiloni_square.fill(0);
> 
> 
> This I think may  not be the expected way to get it working
> 
> Is it that all arrays should be initialized to zero , and otherwise one 
> should expect strange results :-)
> 
> Any comments on this is welcome
> 
> Thanks and Regards
> Kumar
> 
> 
> 
> 
> 
> 
> 
> 
>