ImFusion SDK 4.3
ImFusion::Dicom::Utils Namespace Reference

Collection of utility functions to handle DICOM data. More...

Detailed Description

Collection of utility functions to handle DICOM data.

Classes

struct  DcmTagKeyStlComp
 
struct  UrlQueries
 

Typedefs

using Url = Filesystem::Url
 

Functions

void anonymize (DcmDataset &dataset, const std::map< TagProxy, std::string > &profile, bool keepPrivateTags=false)
 Removes patient related information from the dataset as using a custom confidentiality profile.
 
void anonymize (DcmDataset &dataset, AnonymizationProfile profile, bool keepPrivateTags=false)
 Calls anonymize with the appropriate profile map.
 
bool computeTransformation (const Element< std::vector< double > > &imagePositionPatient, const Element< std::vector< double > > &imageOrientationPatient, const ImageDescriptor &desc, mat4 &matrixOut, const ErrorRecorder *errorRecorder=nullptr)
 Computes the image matrix according to imagePositionPatient and imageOrientationPatient.
 
bool saveTransformation (std::vector< double > &imagePositionPatient, std::vector< double > &imageOrientationPatient, const ImageDescriptor &desc, const mat4 &matrix, int sliceIndex)
 Saves the image matrix for the given slice in imagePositionPatient and imageOrientationPatient.
 
bool saveTransformation (Element< std::vector< double > > &imagePositionPatient, Element< std::vector< double > > &imageOrientationPatient, const ImageDescriptor &desc, const mat4 &matrix, int sliceIndex)
 Saves the image matrix for the given slice in imagePositionPatient and imageOrientationPatient.
 
bool assignToSequence (DcmItem &dataset, ElementList &elementList, DcmTagKey sequenceTag, ErrorRecorder *errorRecorder=nullptr)
 Assigns the given sequence as ElementBase::setTargetSequence to all elements of the given list.
 
template<typename T>
std::vector< T > splitString (const std::string &valuesString)
 
std::shared_ptr< DcmDataset > datasetFromBuffer (const void *buf, size_t size)
 
bool hasDicomHeader (const std::string &path)
 Checks if the file contains a DICOM header.
 
bool hasDicomHeader (const std::vector< char > &data)
 
bool hasDicomHeader (const char *data, size_t size)
 
std::string generateUID (const std::string &prefix="")
 Generates a new UID.
 
std::tuple< std::optional< date::year_month_day >, std::optional< Dicom::Error > > parseDICOMDate (std::string str)
 Converts the string to a date.
 
std::tuple< std::optional< std::chrono::microseconds >, std::optional< Dicom::Error > > parseDICOMTime (std::string str)
 Converts the string to a point in time.
 
std::tuple< std::optional< std::chrono::system_clock::time_point >, std::optional< Dicom::Error > > parseDICOMDateTime (std::string str)
 Converts the string to a date time.
 
std::string parseDICOMSex (const std::string &str)
 Converts the DICOM sex string M, F or O to male, female or other.
 
std::string formatDICOMDate (const date::year_month_day &date)
 Converts a date to a DICOM DA value.
 
std::string formatDICOMTime (std::chrono::microseconds time)
 Converts a point in time to a DICOM TM value.
 
std::string formatStr (const std::string &str)
 Replaces all ^ with spaces and trims surround whitespaces.
 
void convertPropertiesToDataset (const Properties &pr, DcmItem &parent)
 Recursively writes the DICOM tags specified in a Property into a DcmItem Params are converted into tags, by looking up their name as keyword; their content is dumped as-is into the tag.
 
std::unique_ptr< MemImagegeneratePreview (DcmDataset &dataset, bool copyDataset=false, std::optional< int > frameIndex=std::nullopt)
 Generates a preview of the given DICOM.
 
void anonymize (DcmDataset &dataset, bool keepPrivateTags=false)
 Removes all patient related information from the dataset as specified in the DICOM Basic Confidentiality Profile with the Retain UIDs Option.
 
Filesystem::Url parseUserInput (const std::string &path)
 Parses the given path and converts it to the best matching Url.
 
std::string checkDicomWebUrlWarnings (const std::string &url)
 Checks whether the given url has potential issues when used with DICOMweb.
 
UrlQueries parseUrlQueries (const Filesystem::Url &url)
 Extracts supported queries from the given url.
 
std::optional< std::stringqueryElement (DcmItem &item, TagProxy tag)
 Helper function to query the string representation of any Dicom Tag.
 
std::optional< std::stringqueryElement (DcmDataset &dataset, TagProxy tag)
 Helper function to query the string representation of any Dicom Tag.
 
void setDcmLogLevel (ImFusion::Log::Level level)
 Set the log level of the DCMTK library.
 

Variables

const std::set< DcmTagKey, DcmTagKeyStlCompreadOnlyTags
 List of all tags that should be considered read only when modifying a DcmDataset from outside an IOD (like Rows, Columns, SOPClassUID...)
 

Function Documentation

◆ anonymize() [1/2]

void anonymize ( DcmDataset & dataset,
const std::map< TagProxy, std::string > & profile,
bool keepPrivateTags = false )

Removes patient related information from the dataset as using a custom confidentiality profile.

Note
This method is threadsafe but not reentrant.

◆ assignToSequence()

bool assignToSequence ( DcmItem & dataset,
ElementList & elementList,
DcmTagKey sequenceTag,
ErrorRecorder * errorRecorder = nullptr )

Assigns the given sequence as ElementBase::setTargetSequence to all elements of the given list.

If the sequence does not exist yet, it is created. Always uses the first item in the sequence.

◆ generateUID()

std::string generateUID ( const std::string & prefix = "")

Generates a new UID.

See dcmGenerateUniqueIdentifier for details. If the prefix is empty, IMFUSION_INSTANCE_UID_ROOT is used.

◆ parseDICOMDate()

std::tuple< std::optional< date::year_month_day >, std::optional< Dicom::Error > > parseDICOMDate ( std::string str)

Converts the string to a date.

Aside from the standard DICOM format yyyyMMdd, it will also try the following formats (in that order): yyMMdd, ddMMyyyy, ddMMyy The first format producing a valid date is used. If no format is working, no date and an error is returned. A warning will be returned if a non-standard format is found.

http://dicom.nema.org/dicom/2013/output/chtml/part05/sect_6.2.html

◆ parseDICOMTime()

Converts the string to a point in time.

If a non-standardised time is parsed, an InvalidElementValue warning will be added to errorOut. If a time cannot be parsed at all, an InvalidElementValue error will be added to errorOut and an empty value is returned. http://dicom.nema.org/dicom/2013/output/chtml/part05/sect_6.2.html

◆ parseDICOMDateTime()

std::tuple< std::optional< std::chrono::system_clock::time_point >, std::optional< Dicom::Error > > parseDICOMDateTime ( std::string str)

Converts the string to a date time.

We currently don't support all allowed combinations. Especially omitting parts but still specify a timezone is not well supported. The timezone is always converted to UTC. http://dicom.nema.org/dicom/2013/output/chtml/part05/sect_6.2.html

◆ parseDICOMSex()

std::string parseDICOMSex ( const std::string & str)

Converts the DICOM sex string M, F or O to male, female or other.

Any other string is returned unchanged.

◆ formatDICOMDate()

std::string formatDICOMDate ( const date::year_month_day & date)

Converts a date to a DICOM DA value.

The format is always YYYYMMDD. If the given date is invalid, an empty string is returned.

◆ formatDICOMTime()

std::string formatDICOMTime ( std::chrono::microseconds time)

Converts a point in time to a DICOM TM value.

The format is always HHMMSS.FFFFFF or HHMMSS in case the second part is only zeros.

◆ convertPropertiesToDataset()

void convertPropertiesToDataset ( const Properties & pr,
DcmItem & parent )

Recursively writes the DICOM tags specified in a Property into a DcmItem Params are converted into tags, by looking up their name as keyword; their content is dumped as-is into the tag.

No validity control is performed. Nested subproperties are converted into DICOM sequences. Their name should also be a valid DICOM tag with SQ representation. Each contained param is converted into a tag, and each contained subproperty is converted into a nested sequence.

◆ generatePreview()

std::unique_ptr< MemImage > generatePreview ( DcmDataset & dataset,
bool copyDataset = false,
std::optional< int > frameIndex = std::nullopt )

Generates a preview of the given DICOM.

Returns nullptr if the thumbnail could not be generated.

If the DICOM contains multiple frames will either use the frame indicated by RepresentativeFrameNumber or the middle frame as a fallback (the middle frame is not necessary the middle frame of the final volume!).

The returned image is always 8bit grayscale or RGB. The width and height is always the original columns and rows of the DICOM.

Optionally clones the given dataset. This is recommended when this function is called from another thread since DcmDataset isn't entirely thread-safe. For multi-frame dicom a specific frameIndex can be optionally selected

◆ anonymize() [2/2]

void anonymize ( DcmDataset & dataset,
bool keepPrivateTags = false )

Removes all patient related information from the dataset as specified in the DICOM Basic Confidentiality Profile with the Retain UIDs Option.

This may not remove all information e.g. from private tags! If keepPrivateTags is set, no private tags are removed.

Note
This method is threadsafe but not reentrant.
See also
PS3.15 Annex E Table E.1-1 (http://dicom.nema.org/medical/dicom/current/output/chtml/part15/chapter_E.html)

◆ parseUserInput()

Filesystem::Url parseUserInput ( const std::string & path)

Parses the given path and converts it to the best matching Url.

If path is already a valid URL including a scheme of either file:// or pacs://, it will be returned unchanged. If path does not contain a valid URL scheme, it will be interpreted as file path and converted into a file:// URL interpreting an optional ? as query delimiter. Both absolute and relative paths are supported.

◆ checkDicomWebUrlWarnings()

std::string checkDicomWebUrlWarnings ( const std::string & url)

Checks whether the given url has potential issues when used with DICOMweb.

This includes the scheme not being http(s) or the path containing already the /studies endpoint which is added automatically. Returns an empty string if there is no warning.

◆ parseUrlQueries()

UrlQueries parseUrlQueries ( const Filesystem::Url & url)

Extracts supported queries from the given url.

If the query is not using a key-value format, it is parsed as a single seriesUID and no studyUID. Otherwise, the 'series' and 'study' keys are parsed. All other keys are ignored. The sopInstanceUID is parsed from the fragment part of the URL.

Search Tab / S to search, Esc to close