ImFusion SDK 4.3
DicomLoader Class Reference

#include <ImFusion/Dicom/DicomLoader.h>

The DicomLoader class loads images from DICOM files. More...

+ Inheritance diagram for DicomLoader:

Detailed Description

The DicomLoader class loads images from DICOM files.

A DicomLoader instance can be created from a single file or multiple files. Images with the same series instance UID are combined to volumes if possible. Each image is represented by a Dicom::IOD that structures all image related dicom tags. When loading multiple images, be aware that all images are loaded into the main memory at once. Therefore, it can be more efficient to load individual series with separate DicomLoader objects. A single series can be loaded by setting a series UID filter. However, this still needs to load all files first.

Example:

DicomLoader io("test.dcm");
// load all series:
auto images = io.loadImages();
// load only specific UID
io.setSeriesUIDFilter("1.2.392.200036.9116.2.5.1.48.1216111735.1427333783.608709");
images = io.loadImages();
DicomLoader(const std::string &path, Progress *progress=nullptr, Dicom::SharedDatasetCache cache=nullptr, std::shared_ptr< Dicom::IOD_Registry > registry=nullptr)
Creates a DicomLoader instance from a single file.

Paths passed to the constructor can be either local paths or URLs. Only the schemes "file:" and "pacs:" are supported. All others are handled as "file:". Paths to folders will be ignored.

If all frames in a series have the same SeriesInstanceUID, ImageType and SOP class, they are loaded as a single SharedImageSet. Otherwise a single series might be split into multiple SharedImageSets. A DICOM file that contains a NumberOfFrames value larger than 1, is always loaded as an individual SharedImageSet.

The DicomLoader uses Dicom::IOD_Registry to generate the Dicom::IOD instance(s) used for loading the image data. It also runs any enabled Extension that are part of the Dicom::IOD_Registry.

Error handling
Errors are generated via the Dicom::ErrorRecorder interface. To retrieve errors that are generated during loading, register one or multiple custom handlers with registerErrorHandler. By default no handler is registered.

Example:

DicomLoader io("test.dcm");
io.registerErrorHandler([](const Dicom::Error& e) { LOG_INFO(e.details); }
auto images = io.loadImages();
#define LOG_INFO(...)
Emits a log message of Log::Level::Info, optionally with a category.
Definition Log.h:247
Structure for storing errors occurring during loading/saving DICOM data.
Definition DicomError.h:50
std::string details
Additional information on the error.
Definition DicomError.h:100

Classes

struct  RawBuffer
 

Public Types

using SharedImageSetDescriptor = std::vector<ImageDescriptor>
 
- Public Types inherited from ErrorRecorder
using ErrorCallback = std::function<void(const Error&)>
 Alias for a function to call for each error recorded.
 

Public Member Functions

 DicomLoader (const std::string &path, Progress *progress=nullptr, Dicom::SharedDatasetCache cache=nullptr, std::shared_ptr< Dicom::IOD_Registry > registry=nullptr)
 Creates a DicomLoader instance from a single file.
 
 DicomLoader (const std::vector< std::string > &paths, Progress *progress=nullptr, Dicom::SharedDatasetCache cache=nullptr, std::shared_ptr< Dicom::IOD_Registry > registry=nullptr)
 Creates a DicomLoader instance from multiple files.
 
 DicomLoader (const std::vector< std::shared_ptr< DcmDataset > > &datasets, Progress *progress=nullptr, const std::vector< std::string > &paths=std::vector< std::string >(), std::shared_ptr< Dicom::IOD_Registry > registry=nullptr)
 Creates a DicomLoader instance from existing DcmDatasets.
 
 DicomLoader (std::shared_ptr< DcmDataset > dataset, Progress *progress=nullptr, std::shared_ptr< Dicom::IOD_Registry > registry={})
 Creates a DicomLoader instance from an existing DcmDataset.
 
 DicomLoader (const std::vector< RawBuffer > &buffers, Progress *progress=nullptr, const std::vector< std::string > &paths=std::vector< std::string >(), std::shared_ptr< Dicom::IOD_Registry > registry=nullptr)
 Creates a DicomLoader instance from buffers of DcmDatasets.
 
std::vector< std::unique_ptr< SharedImageSet > > loadImages ()
 Loads all images of all series.
 
std::vector< std::pair< std::unique_ptr< ImFusion::SharedImageSet >, OwningDataList > > loadImagesWithAdditionalData ()
 Loads all images of all series plus additional data (such as segmentations).
 
std::vector< SharedImageSetDescriptorloadDescriptors ()
 Similar to loadImages but does not load any pixel data but only the ImageDescriptors.
 
void setSeriesUidFilter (const std::string &filter)
 Only loads series that contain the given series UID.
 
void setSplitVolumes (bool enable)
 Sets the flag whether loaded data should be split up for best support in the ImFusionSuite.
 
bool splitsVolumes () const
 Returns the flag weather loaded data is prepared for best support in the ImFusionSuite.
 
void setReconstructVolumes (bool enable)
 Sets the flag whether loaded data should be reconstructed to volumes if possible.
 
bool reconstructionVolumes () const
 Returns whether loaded data will be reconstructed to volumes if possible.
 
void setIgnoreDuplicateFrames (bool enable)
 Sets the flag whether frames that are consider duplicates of other frames are ignored.
 
bool ignoreDuplicateFrames () const
 Returns whether duplicated frames are ignored.
 
const std::vector< Dicom::DatasetIodPair > & datasets () const
 List of DcmDatasets and corresponding IODs for each loaded file.
 
- Public Member Functions inherited from ErrorRecorder
virtual void * registerErrorHandler (ErrorCallback handler)
 Registers a new handler callback function.
 
virtual void unregisterErrorHandler (void *handler)
 Removes a previously registered handler again.
 
void * forwardErrors (const ErrorRecorder *otherRecorder)
 Convenient function to forward all errors registered to this recorder to another recorder.
 
virtual void registerError (const Error &error) const
 Sends the given error to all error handler callbacks.
 
void registerError (Error::Code code, Error::Type type, const std::string &details, TagProxy tag=TagProxy()) const
 

Static Public Member Functions

static std::multimap< std::string, std::vector< Dicom::IOD * > > groupSeries (const std::vector< Dicom::DatasetIodPair > &datasets, const Dicom::ErrorRecorder &recorder)
 Groups datasets by series instance UID.
 
static std::vector< std::vector< Dicom::IOD * > > splitDuplicatedFrames (const std::vector< Dicom::IOD * > &series, const Dicom::ErrorRecorder &recorder)
 Splits duplicated IODs from the list of series into separate lists.
 

Constructor & Destructor Documentation

◆ DicomLoader() [1/2]

DicomLoader ( const std::vector< std::shared_ptr< DcmDataset > > & datasets,
Progress * progress = nullptr,
const std::vector< std::string > & paths = std::vectorstd::string >(),
std::shared_ptr< Dicom::IOD_Registry > registry = nullptr )

Creates a DicomLoader instance from existing DcmDatasets.

If paths has the same size as datasets, they will be used as DicomIOD::pathInfo.

◆ DicomLoader() [2/2]

DicomLoader ( const std::vector< RawBuffer > & buffers,
Progress * progress = nullptr,
const std::vector< std::string > & paths = std::vectorstd::string >(),
std::shared_ptr< Dicom::IOD_Registry > registry = nullptr )

Creates a DicomLoader instance from buffers of DcmDatasets.

The buffers are assumed to be directly retrieved from DICOM files. The loader does not take ownership and the buffers can be safely deleted after the constructor is executed. If paths has the same size as datasets, they will be used as DicomIOD::pathInfo.

Member Function Documentation

◆ loadImages()

Loads all images of all series.

Usually one image corresponds to one series but there are exceptions such as series that contain both 2D and 3D data or Ultrasound Series.

◆ loadDescriptors()

std::vector< SharedImageSetDescriptor > loadDescriptors ( )

Similar to loadImages but does not load any pixel data but only the ImageDescriptors.

So a SharedImage is represented by a ImageDescriptor and a SharedImageSet (i.e. a list of SharedImage) therefore by a list of ImageDescriptors.

◆ setSplitVolumes()

void setSplitVolumes ( bool enable)

Sets the flag whether loaded data should be split up for best support in the ImFusionSuite.

If enabled, splits SharedImageSets that contain both 2D and 3D images into a single 2D image set. This usually happens when a volume could not be reconstructed correctly e.g. due to missing slices. Enabled by default.

◆ setReconstructVolumes()

void setReconstructVolumes ( bool enable)

Sets the flag whether loaded data should be reconstructed to volumes if possible.

Disabling this will load all series as image sets. Enabled by default.

◆ setIgnoreDuplicateFrames()

void setIgnoreDuplicateFrames ( bool enable)

Sets the flag whether frames that are consider duplicates of other frames are ignored.

Frames are considered the equal if they have the same SOP Instance UID, patient ID and position/orientation. This can happen if a dataset was copied and a folder containing both copies is loaded. When this option is disabled, duplicated frames will be loaded as separate images. E.g. if a folder contains every file twice, one image will be loaded is this option is enabled, but two images when this option is disabled. Enabled by default.

◆ groupSeries()

static std::multimap< std::string, std::vector< Dicom::IOD * > > groupSeries ( const std::vector< Dicom::DatasetIodPair > & datasets,
const Dicom::ErrorRecorder & recorder )
static

Groups datasets by series instance UID.

All IODs in one list will be of the same class. In case a series would end up with mixed IODs, it will be split according to their class types. Therefore, a single series instance UID can consist of multiple grouped dataset (hence the std::multimap).

◆ splitDuplicatedFrames()

static std::vector< std::vector< Dicom::IOD * > > splitDuplicatedFrames ( const std::vector< Dicom::IOD * > & series,
const Dicom::ErrorRecorder & recorder )
static

Splits duplicated IODs from the list of series into separate lists.

If no duplicated IODs have been detected, the returned list will only have one element. If a IOD has duplicates, the first found duplicate will be placed into the second list, the second found duplicate in the third list and so on. The order of IODs is retained. IODs are considered duplicates if certain tag values contain identical values (e.g. SOP Instance UID or Patient ID among others).


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close