[vtkusers] vtkImageData: How to set the scalar pointer
Mathieu Malaterre
Mathieu.Malaterre at creatis.insa-lyon.fr
Wed Aug 27 03:55:00 EDT 2003
Steve,
You may have a look at vtkImageImport:
http://www.vtk.org/doc/nightly/html/classvtkImageImport.html
Or else,
usarray = vtkUnsignedShortArray::New( );
usarray->SetNumberOfComponents( 1 );
usarray->SetArray( ( ushort* )( my_c_array ), size, 1 );
//Pay attention in particular to the last param of SetArray:
//http://www.vtk.org/doc/nightly/html/classvtkUnsignedShortArray.html#z798_0
vtk = vtkImageData::New();
vtk->SetDimensions( blabla );
vtk->SetSpacing( blabla );
vtk->SetScalarType( VTK_UNSIGNED_SHORT );
vtk->GetPointData( )->SetScalars( usarray );
usarray->Delete( );
HTH
mathieu
Steve Boyd wrote:
> Hi,
>
> How can I modify the pointer to the scalar data in vtkImageData? In a
> reader class I'm working on, the image data is already in memory (from a
> C function). Previously, I've been allocating memory in my vtkImageData
> class and then copying to that allocated memory, but this requires two
> copies of the image data in memory at the same time. Can't I just set
> the vtkImageData pointer to point at the data already in memory (taking
> care to set extents, dim, etc)?
>
> I want to do something like this:
>
> vtkImageData *data = this->GetOutput();
> data->SetScalarTypeToChar();
> data->SetDimensions(10,10,10);
> data->SetScalarPointer( *mydata ); // SetScalarPointer() does not
> exist
>
> WHERE: mydata is an array of 1000 char.
>
> I know there is a function to "GetScalarPointer()", but can't figure out
> how to modify the pointer.
>
> HELP Please!
>
> Cheers,
>
> Steve
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
--
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