[Insight-users] Array of Iterators

Luis Ibanez luis . ibanez at kitware . com
Thu, 09 Oct 2003 22:31:48 -0400


Hi Bing,

Yeap, ITK iterators are not deriving from the itk::Object
class. They are light-weight objects, so they don't use
SmartPointers. You could use then just as raw pointers.

like:           ImageIterator       *   iterPtr;
instead of:     ImageIterator::Pointer  iterSmartPtr;

In any case, for what you are doing, there is no advantage
in creating an array of iterators, so please avoid doing
that because it is very very error prone.

Instead, simply instantiate a new iterator in the body of
the vector loop, use it for copying the images and then let
it die at the end of the loop's scope.


Something like:


int outputIndex = 0;
for( all the inputVector components )
    {
    setup the adaptor to select one input component
    gradient->SetInput( adaptor );
    gradient->Update();
    for( all the output vector components )
       {
       OutputIterType outIterator( outputImage[ outputIndex ], region );
       VectorIterType vecIterator( gradient->GetOutput(), region );
       outIterator.GoToBegin();
       vecIterator.GoToBegin();
       while( !outIterator.IsAtEnd() )
          {
          outIterator.Set( vecIterator.Value()[ component ] );
          ++outIterator;
          ++vecIterator;
          }
       outputIndex++;
       }  // iterators die here.
    }


Where outpuImage[] is an array of SmartPointers to
scalar images.

If performance is an issue,.. there are better ways of
rearranging these operations, but at least this set of
loops should give you a starting point.



    Regards,



      Luis



----------------------
Bing Jian wrote:
> 
> On Thu, 9 Oct 2003, Bing Jian wrote:
> 
> 
>>Hi Luis,
>>
>>   It's still from the Jacobian problem.
>>After the scalar comoponents are extracted by using ImageAdaptor,
>>passed to gradient filter and finally stored into an array of
>>vector images, then I need n input iterators and 1 output iterators to
>>combine those n gradient images into 1 Jacobian image.
>>  That's what I am trying to do.
>>
>> I have tried this way, but was told that Pointer is not the member of
>>IteratorType.
>>
>> ConstIteratorType::Pointer gradient_it[vector_dimension];
> 
>    If I changed this line to
>      ConstIteratorType* gradient_it[vector_dimension];
>    then it can pass the compiling.
> 
> 
>> for (i=0;i<vector_dimension;i++){
>>		gradient_it[i] = new
>>ConstIteratorType(gradient_out[i], inputRegion);
>>		gradient_it[i]->GoToBegin();
>>	}
>>
>>
>>
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>