[vtkusers] vtkImageIterator: subregionning
Mathieu Malaterre
Mathieu.Malaterre at creatis.insa-lyon.fr
Mon Apr 28 12:51:50 EDT 2003
Hi all,
I wanted to take advantage of the vtkImageIterator but I have had some
problems. I hope somebody could help me figure out why these happens.
Here is the C++ file I used to understand what I do wrong:
int main( int argc, char ** argv )
{
int ext[6] = { 0, 100, 0, 100, 0, 100 };
vtkImageData *imagedata = vtkImageData::New();
imagedata->SetExtent( ext );
imagedata->SetScalarTypeToUnsignedShort ();
imagedata->AllocateScalars();
imagedata->Update(); //1
vtkImageData *imagedata2 = vtkImageData::New();
imagedata2->SetExtent( ext );
imagedata2->SetScalarTypeToUnsignedShort ();
imagedata2->AllocateScalars();
imagedata2->Update(); //1
int region[6];
for(int i=0; i<10; i++)
{
region[4] = region[2] = region[0] = 10*i;
region[5] = region[3] = region[1] = 10*i + 9;
imagedata->SetExtent( region ); //2
imagedata2->SetExtent( region ); //2
vtkImageIterator<unsigned short> inIt(imagedata, region);
vtkImageIterator<unsigned short> outIt(imagedata2, region);
while (!outIt.IsAtEnd())
{
unsigned short* inSI = inIt.BeginSpan();
unsigned short* outSI = outIt.BeginSpan();
unsigned short* outSIEnd = outIt.EndSpan();
while (outSI != outSIEnd)
{
*outSI = 255;
*inSI = 0;
++outSI;
++inSI;
}
inIt.NextSpan();
outIt.NextSpan();
}
}
imagedata2->SetExtent( ext ); //3
imagedata2->Print(std::cout);
imagedata->Delete();
imagedata2->Delete();
return 0;
}
You'll see that there are some comments //1,2,3. This corresponds to:
1. If I don't do an Update here the iterator won't get the good extent.
(Is this normal to explicitely call Update in a VTK pipeline ?). BTW I
thought SetWholeExtent would do the trick: seems to be worse.
2. I wanted to work on subregions. But vtkImageIterator only wants to
work on the whole extent. If I don't call SetExtent I obtained a
seg fault ! I don't understand why ?
3. Of course by rediffining each time a new SetExtent, the whole extent
is lost at the end of the pipeline. So I need to redefine it.
I really would like someone to told me how to use vtkImageIterator or
answer my questions. This is too bad a templated code is less handy than
a good ol' fortran 'for loop'.
thanks,
mathieu
--
Mathieu Malaterre
CREATIS
28 Avenue du Doyen LEPINE
B.P. Lyon-Montchat
69394 Lyon Cedex 03
http://www.creatis.insa-lyon.fr/~malaterre/
More information about the vtkusers
mailing list