[vtkusers] vtkImageAlgorithm output to preallocated buffer

Alessandro Volz alessandro.volz at gmail.com
Sun Jan 22 12:15:31 EST 2017


Thanks David,

So yes, I got there this way: 
    reslice->GetOutput()->GetPointData()->SetScalars(vtkSmartPointer<vtkFloatArray>::New());
    reslice->GetOutput()->GetPointData()->GetScalars()->SetVoidArray(myBufferPtr, myBufferBytesLen, 1);

It works fine, but could you explain why in vtkImageData::AllocateScalars we have:

  if (scalars && scalars->GetDataType() == dataType
      && scalars->GetReferenceCount() == 1)

Why does it matter, the ReferenceCount be equal to 1 ?

Alessandro

> On Jan 21, 2017, at 2:56 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> 
> On Sat, Jan 21, 2017 at 4:34 AM, Alessandro Volz <alessandro.volz at gmail.com <mailto:alessandro.volz at gmail.com>> wrote:
> I'm using vtkImageReslice to obtain a vtkImageData object that I read the output scalars from. All works fine.
> I'm now in a situation where it would make sense that I preallocate thee output buffer for the reslice to write into.
> Is there a way to do this?
> I thought I'd create a vtkImageData and SetScalarPointer on it, then SetOutput on the reslice. But I haven't been able to.
> Is there a way I could do this? Maybe I should create a vtkImageData subclass?
> 
> Instead of subclassing vtkImageData, it might be better to subclass vtkImageReslice and override the AllocateOutputData() methods.  See the current implementation of AllocateOutputData() here:
> https://gitlab.kitware.com/vtk/vtk/blob/master/Common/ExecutionModel/vtkImageAlgorithm.cxx#L198 <https://gitlab.kitware.com/vtk/vtk/blob/master/Common/ExecutionModel/vtkImageAlgorithm.cxx#L198>
> 
> But your idea of calling SetOutput() should work as long as you provide a large enough output buffer of the correct data type.
> 
>  - David
> 

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


More information about the vtkusers mailing list