[vtkusers] Pass data in reader without copying?

David Gobbi david.gobbi at gmail.com
Sun Jul 3 14:19:33 EDT 2016


On Sun, Jul 3, 2016 at 11:59 AM, Elvis Stansvik <
elvis.stansvik at orexplore.com> wrote:

> 2016-07-03 19:57 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>
>> If I'm writing my own custom volume reader, and I have the read data in
>> memory (say as a float*). If I know the data is in the right format/layout,
>> can I somehow pass ownership of that data to the output of the algorithm
>> without incurring a copy?
>>
>> I've been looking at some of the simpler readers that come with VTK, but
>> all of them seems to copy the read data to the output (?).
>>
>
> Looking at vtkImageData, what I would like (I think) is some way of
> setting the pointer that is returned by vtkImageData::GetScalarPointer.
>

Here is a cut & paste of code from vtkImageImport.  Read the the
documentation for vtkAbstractArray::SetVoidArray() carefully.

  vtkImageData *data = vtkImageData::SafeDownCast(output);
  data->SetExtent(0,0,0,0,0,0);
  data->AllocateScalars(outInfo);
  vtkIdType size = this->NumberOfScalarComponents;
  size *= this->DataExtent[1] - this->DataExtent[0] + 1;
  size *= this->DataExtent[3] - this->DataExtent[2] + 1;
  size *= this->DataExtent[5] - this->DataExtent[4] + 1;
  data->SetExtent(this->DataExtent);
  data->GetPointData()->GetScalars()->SetVoidArray(inputPtr, size, 1);
  data->GetPointData()->GetScalars()->SetName(this->ScalarArrayName);

 - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160703/c36d8af8/attachment.html>


More information about the vtkusers mailing list