![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Dicom/DicomDatasetCache.h>
The DatasetCache class provides caching of DcmDataset loaded from different locations. More...
The DatasetCache class provides caching of DcmDataset loaded from different locations.
The cache has a certain maximum size and will automatically remove datasets from the cache if the maximum size is exceeded. The least recent accessed datasets will be removed first.
When loading a DcmDataset, all data is loaded into memory right away (see DcmItem::loadAllDataIntoMemory).
Public Member Functions | |
DatasetCache (int maxCost=2048) | |
std::shared_ptr< DcmDataset > | loadFromFile (const std::string &filepath, Progress *progress=nullptr, bool loadIntoMemory=true) |
Loads the local file (see load(Url)) | |
std::vector< std::shared_ptr< DcmDataset > > | loadFromFolder (const std::string &folderpath, bool recursive=false, std::vector< std::string > *filepathsOut=nullptr, Progress *progress=nullptr, bool loadIntoMemory=true, bool ignoreNonDicomFiles=true) |
Loads and returns all dicom files from the given folder. | |
std::vector< std::shared_ptr< DcmDataset > > | loadFromPacs (const Url &url, std::vector< std::string > *filepathsOut=nullptr, Progress *progress=nullptr) |
Loads and returns all dicom files from a pacs series URL The method will first issue a find request for the given series url . | |
std::vector< std::shared_ptr< DcmDataset > > | loadFromHttp (const Url &url, std::vector< std::string > *filepathsOut=nullptr, Progress *progress=nullptr) |
Loads and returns all dicom files from the given URL. | |
std::vector< std::shared_ptr< DcmDataset > > | load (const Url &url, std::vector< std::string > *filepathsOut=nullptr, Progress *progress=nullptr, bool loadIntoMemory=true) |
Loads and returns the dataset at the given url. | |
void | addDataset (std::shared_ptr< DcmDataset > dataset, const Url &url) |
Adds an external dataset to the cache. | |
bool | contains (const Url &url) const |
Returns true if the given url is available in the cache. | |
void | remove (const Url &url) |
Removes the given url from the cache. Does nothing if cache does not contain the url. | |
void | clear () |
Removes all items from the cache. | |
double | totalCost () const |
Returns the total cost of all datasets in the cache. | |
size_t | size () const |
Returns the number of datasets in the cache. | |
void | setAuthorizationProvider (std::shared_ptr< Network::AuthorizationProvider > provider) |
Sets the AuthorizationProvider for the internal Dicom::WebClient object. | |
std::shared_ptr< Network::AuthorizationProvider > | authorizationProvider () const |
Reteurns the AuthorizationProvider for the internal Dicom::WebClient object. | |
void | setMaxCost (int maxCost) |
Sets the maximum allowed total cost of cache in MB. | |
int | maxCost () const |
void | registerError (const Error &error) const override |
Sends the given error to all error handler callbacks. | |
void | registerHttpError (const Network::HttpError &error) |
![]() | |
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. | |
void | registerError (Error::Code code, Error::Type type, const std::string &details, TagProxy tag=TagProxy()) const |
Additional Inherited Members | |
![]() | |
using | ErrorCallback = std::function<void(const Error&)> |
Alias for a function to call for each error recorded. | |
std::vector< std::shared_ptr< DcmDataset > > loadFromFolder | ( | const std::string & | folderpath, |
bool | recursive = false, | ||
std::vector< std::string > * | filepathsOut = nullptr, | ||
Progress * | progress = nullptr, | ||
bool | loadIntoMemory = true, | ||
bool | ignoreNonDicomFiles = true ) |
Loads and returns all dicom files from the given folder.
Files are always returned in a naturally sorted order (e.g. 10.dcm after 1.dcm). The optional filepathsOut contains the paths to each of the return datasets. If the files in the folder are larger than the maximum cost, the alphabetical first files will be cached before the last ones. All files of the folder are always loaded and returned, independend of the caching behaviour. See load(QUrl) for details about loadIntoMemory
.
std::vector< std::shared_ptr< DcmDataset > > loadFromPacs | ( | const Url & | url, |
std::vector< std::string > * | filepathsOut = nullptr, | ||
Progress * | progress = nullptr ) |
Loads and returns all dicom files from a pacs series URL The method will first issue a find request for the given series url
.
For any listed dataset the method first checks if the dataset is already cached. If this is the case the cached instance will be used. Otherwise a move request will be send to the PACS server. Caching happens in the order in which the data is returned by the PACS server. All files of the series are always loaded and returned, independend of the caching behaviour. I.e. for files which are currently not cached a move request will be send to the PACS server.
std::vector< std::shared_ptr< DcmDataset > > loadFromHttp | ( | const Url & | url, |
std::vector< std::string > * | filepathsOut = nullptr, | ||
Progress * | progress = nullptr ) |
Loads and returns all dicom files from the given URL.
The URL can be for two DICOMweb endpoints:
std::vector< std::shared_ptr< DcmDataset > > load | ( | const Url & | url, |
std::vector< std::string > * | filepathsOut = nullptr, | ||
Progress * | progress = nullptr, | ||
bool | loadIntoMemory = true ) |
Loads and returns the dataset at the given url.
If the cache already contains the dataset for the given url, the cached dataset is returned. Otherwise the dataset is loaded from the url and added to the cache. Returns nullptr if the dataset could not be loaded.
If the loaded dataset is larger than the maximum cost of the cache, the dataset will not be cached but still returned normally.
If the url is a folder and the query contains a key 'recursive' with a value of 1, the folder is loaded recursive.
If the url is a folder and the query contains a key 'ignoreNonDicom' with a value of 0, then all files will be loaded as DICOMs. Without this option or with a value of 1, files without a valid DICOM header or with certain non-DICOM extensions (.pdf, .txt, .png...) are ignored.
By default, the dataset is loaded completely into memory (and stored like this in the cache if applicable). This can use a lot of memory especially when the pixel data is not going to be used. In those cases loadIntoMemory should be set to false. The pixel data and all other tags will still be available through the DcmDataset but will be loaded on demand.
void setMaxCost | ( | int | maxCost | ) |
Sets the maximum allowed total cost of cache in MB.
If the cache exceeds the maximum cost, it will start to remove datasets until the total cost is below the maximum again. The actual memory requirements might still exceed the maximum cost because a dataset can grow in size (e.g. when it gets uncompressed). The cache has no means of detecting this and might therefore use the wrong cost. If the cache is too small, it might not be possible to cache big datasets. Passing a cost of 0 disables caching completely.
|
overridevirtual |
Sends the given error to all error handler callbacks.
If there is no handler registered yet, the error will be stored until the first registration of one.
Reimplemented from ErrorRecorder.