vtkDICOMReader - Cache series/speed up files loading

I’m opening a study with multiple series using vtkDICOMDirectory and vtkDICOMReader.
Everything works well, but opening a series each time causes a delay because the files need to be loaded from scratch (using reader->SetFileNames and reader->Update).
I was wondering if it is possible to speed up this process. I’ve thought about two options:

  • cache the series’ files after they’ve been loaded once
  • pre-load all the series of the study at launch

Is it possible to implement one of these?
I’ve tried exploring the latter by setting up multiple vtkDICOMReader objects, but when I try to use one of them it doesn’t work.

If you have an application that loads multiple series, then using a cache is a very common way of keeping track of the data so that you don’t have to re-load a series every time you want to view it.

For our in-house applications, we have a class called the “DataManager” that acts as a cache. This class keeps a list of data nodes, where each node contains a vtkImageData along with any labels, metadata, transforms, etc. that we want to associate with that image data. The Slicer folks use MRML for this kind of thing, but it’s the same basic idea (though MRML is much more sophisticated).

So that’s my advice. Devise a cache that sits between the reader and your visualization/analysis pipelines. After the reader has finished reading the data, you can get rid of the reader… all that you need to keep in memory is the data/metadata.

1 Like

Thank you for the suggestion! I’m trying to follow your concept.

If I understood correctly, I should call:

vtkImageData *data = reader->GetOutput();

to get the vtkImageData and then store it somehow (is there an array type I can use?).
Then I can call imageMapper->SetInputData(_) with one of the stored vtkImageData objects to have it loaded onto my display chain.

I’m having difficulties figuring out how to store the image data; I’ve tried wrapping it in an NSObject and then saving the wrapper in an NSArray (I’m using VTK in a Cocoa app with Objective-C++ and Swift), but got EXC_BAD_ACCESS errors when trying to load the objects using SetInputData(_).

Use vtkSmartPointer when you store it.

1 Like

I was able to do it!
However I had to copy the reader’s output instead of using it directly:

vtkSmartPointer<vtkImageData> newImageData = vtkSmartPointer<vtkImageData>::New();