<div dir="ltr">Instead of a DeepCopy, I think you may want ShallowCopy - IIRC, it detaches the imageImport like you want, but doesn't copy the data. <div>I remember seeing this go by on a blog post or email, so please double-check me :)</div><div>Aron</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 4, 2017 at 8:44 AM, kenichiro yoshimi <span dir="ltr"><<a href="mailto:rccm.kyoshimi@gmail.com" target="_blank">rccm.kyoshimi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am not sure, but it looks like vtkImageReader2 can read a raw volume<br>
directly from a file without using a temporary variable. Would the<br>
vtkImageReader2 reader solve your problem?<br>
<br>
Thanks,<br>
<div><div class="h5"><br>
2017-06-04 7:16 GMT+09:00 Mike Withascarf via vtkusers <<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>>:<br>
> Hi, I'm attempting to use vtkImageImport on an array in a function to return<br>
> a vtkImageData. It works, but once the vtkImageData is deleted the memory is<br>
> not freed unless I do a DeepCopy in the function for loading it.<br>
> Unfortunately if I do a DeepCopy it momentarily doubles the amount of memory<br>
> needed which is really bad for the large data sizes we are using. Here is a<br>
> stripped down version of the function I'm using. Any help would be very<br>
> appreciated!<br>
><br>
> vtkSmartPointer<vtkImageData> load_image(const std::string &fn)<br>
> {<br>
> unsigned long long size = <a href="tel:6144000000" value="+16144000000">6144000000</a>;<br>
> int dims[3]{ 800, 600, 6400 };<br>
><br>
> // load data<br>
> ifstream fs(fn, ifstream::binary);<br>
> char* data = new char[size];<br>
> fs.read(data, size);<br>
> fs.close();<br>
><br>
> // vtk import<br>
> vtkSmartPointer<<wbr>vtkImageImport> image_import =<br>
> vtkSmartPointer<<wbr>vtkImageImport>::New();<br>
> image_import->SetDataSpacing(<wbr>1, 1, 1);<br>
> image_import->SetDataOrigin(0, 0, 0);<br>
> image_import->SetWholeExtent(<wbr>0, dims[0] - 1, 0, dims[1] - 1, 0, dims[2] -<br>
> 1);<br>
> image_import-><wbr>SetDataExtentToWholeExtent();<br>
> image_import-><wbr>SetDataScalarTypeToUnsignedSho<wbr>rt();<br>
> image_import-><wbr>SetNumberOfScalarComponents(1)<wbr>;<br>
> image_import-><wbr>SetImportVoidPointer(data);<br>
> image_import->Update();<br>
><br>
> // This works, but the memory will never be released even when the<br>
> vtkImageData is deleted<br>
> return image_import->GetOutput();<br>
> // This prevents memory leaks, but means that I need twice the memory<br>
> available for a brief moment<br>
> vtkSmartPointer<vtkImageData> im = vtkSmartPointer<vtkImageData>:<wbr>:New();<br>
> im->DeepCopy(image_import-><wbr>GetOutput());<br>
> delete[] data;<br>
> return im;<br>
> }<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
><br>
> Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
><br>
______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
</blockquote></div><br></div>