[vtkusers] How to create an image from scratch in memory in VTK
Steve M. Robbins
steven.robbins at videotron.ca
Fri Dec 9 20:56:33 EST 2005
On Fri, Dec 09, 2005 at 10:26:46AM -0800, Deepak Roy wrote:
> hello,
> Does anyone know how to create an image from scratch in memory in VTK.
> I tried this and many other things but it doesnt work.....
>
> **************************************************************************************************
> vtkImageData *pZImage = vtkImageData::New();
> pZImage->SetDimensions( wx , wy , 1 );
> pZImage->SetOrigin( 0 , 0 , 0 );
> pZImage->SetSpacing( 1 , 1 , 1 );
> pZImage->SetScalarTypeToUnsignedChar();
> pZImage->SetNumberOfScalarComponents( 1 );
> pZImage->AllocateScalars();
My observation is that you need to add:
pZImage->SetWholeExtent( 0, wx-1, 0, wy-1, 0, 0 );
>
> vtkUnsignedCharArray *pScalars = (vtkUnsignedCharArray *) pZImage->GetPointData()->GetScalars();
>
>
> for( int i = 0 ; i < wx ; i++ )
> {
> for( int j = 0 ; j < wy ; j++ )
> {
> int index = i * j;
Um ... that's not the correct formula for index.
Regards,
-Steve
More information about the vtkusers
mailing list