[vtkusers] Setting vtkImageData from regular float array

David Gobbi david.gobbi at gmail.com
Mon Jan 1 11:25:06 EST 2018


The most direct way of creating an image from an array is vtkImageImport:

https://lorensen.github.io/VTKExamples/site/Cxx/Images/ImageImport/
https://www.vtk.org/doc/nightly/html/classvtkImageImport.html

The vtkImageImport class provides two methods for using your array as
vtkImageData:

CopyImportVoidPointer(ptr) -> copy the array into the vtkImageData
SetImportVoidPointer(ptr) -> use your array directly (do not copy)

 - David


On Mon, Jan 1, 2018 at 8:32 AM, Aron Helser <aron.helser at kitware.com> wrote:

> HI!
> Check out this example:
> https://lorensen.github.io/VTKExamples/site/Cxx/
> ImageData/ImageIteratorDemo/
>
> it shows how to iterate through image data and modify it's value. You can
> assign values from your float array.
> HTH,
> Aron
>
> On Mon, Jan 1, 2018 at 4:20 AM, Gib Bogle <g.bogle at auckland.ac.nz> wrote:
>
>> There is probably a better way, but one way is to create an ITK image
>> then convert it to a VTK image:
>>
>> https://itk.org/ITKExamples/src/Bridge/VtkGlue/ConvertAnitkI
>> mageTovtkImageData/Documentation.html
>>
>> It is easy to create an ITK image, allocate the buffer then copy your
>> data into the buffer.  Of course this requires you to have ITK installed.
>> ________________________________________
>> From: vtkusers <vtkusers-bounces at vtk.org> on behalf of VTKJunky <
>> hadas.judah at gmail.com>
>> Sent: Monday, 1 January 2018 9:24 p.m.
>> To: vtkusers at vtk.org
>> Subject: [vtkusers] Setting vtkImageData from regular float array
>>
>> I have float array which represents a 2-D image. I'd like to set it into
>> vtkImageData, but can't work out how to do this. The problem is, all the
>> examples use a vtkReader to read in the data, I already have the data.
>>
>>
>> Any help would be greatly appreciated,
>> Thanks!
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180101/7a072f26/attachment.html>


More information about the vtkusers mailing list