Class DicomDataset
- Namespace
- FellowOakDicom
- Assembly
- fo-dicom.core.dll
A collection of DICOM items.
public class DicomDataset : IEnumerable<DicomItem>, IEnumerable, IEquatable<DicomDataset>
- Inheritance
-
DicomDataset
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
DicomDataset()
Initializes a new instance of the DicomDataset class with InternalTransferSyntax set to Explicit VR Little Endian (DICOM default transfer syntax).
public DicomDataset()
DicomDataset(params DicomItem[])
Initializes a new instance of the DicomDataset class.
public DicomDataset(params DicomItem[] items)
Parameters
items
DicomItem[]An array of DICOM items.
DicomDataset(DicomTransferSyntax)
Initializes a new instance of the DicomDataset class.
public DicomDataset(DicomTransferSyntax internalTransferSyntax)
Parameters
internalTransferSyntax
DicomTransferSyntaxInternal transfer syntax representation of the dataset.
DicomDataset(IEnumerable<DicomItem>)
Initializes a new instance of the DicomDataset class.
public DicomDataset(IEnumerable<DicomItem> items)
Parameters
items
IEnumerable<DicomItem>A collection of DICOM items.
Properties
AutoValidate
Gets or sets if the content of DicomItems shall be validated as soon as they are added to the DicomDataset
[Obsolete("Use this property with care. You can suppress validation, but be aware you might create invalid Datasets if you need to set this property.", false)]
public bool AutoValidate { get; set; }
Property Value
CompareInstancesByContent
Gets or sets how two DicomDatasets are compared if dataset1 == dataset2 is called If this property is true, then all items are iterated and the content is compared. Then two DicomDatasets are equal if the content is equal. If this property is false, then the equalitycheck tests if the DicomDatasets are the same instance.
public static bool CompareInstancesByContent { get; set; }
Property Value
InternalTransferSyntax
Gets the DICOM transfer syntax of this dataset.
public DicomTransferSyntax InternalTransferSyntax { get; }
Property Value
Methods
Add(DicomItem)
Adds a DICOM item to the dataset.
public DicomDataset Add(DicomItem item)
Parameters
item
DicomItemDICOM item to add.
Returns
- DicomDataset
The dataset instance.
Exceptions
- ArgumentException
If tag of added item already exists in dataset.
Add(params DicomItem[])
Add a collection of DICOM items to the dataset.
public DicomDataset Add(params DicomItem[] items)
Parameters
items
DicomItem[]Collection of DICOM items to add.
Returns
- DicomDataset
The dataset instance.
Exceptions
- ArgumentException
If tag of added item already exists in dataset.
Add(IEnumerable<DicomItem>)
Add a collection of DICOM items to the dataset.
public DicomDataset Add(IEnumerable<DicomItem> items)
Parameters
items
IEnumerable<DicomItem>Collection of DICOM items to add.
Returns
- DicomDataset
The dataset instance.
Exceptions
- ArgumentException
If tag of added item already exists in dataset.
AddOrUpdate(DicomItem)
Add a DICOM item to the dataset. Update existing items.
public DicomDataset AddOrUpdate(DicomItem item)
Parameters
item
DicomItemDICOM item to add.
Returns
- DicomDataset
The dataset instance.
AddOrUpdate(params DicomItem[])
Add a collection of DICOM items to the dataset. Update existing items.
public DicomDataset AddOrUpdate(params DicomItem[] items)
Parameters
items
DicomItem[]Collection of DICOM items to add.
Returns
- DicomDataset
The dataset instance.
AddOrUpdate(IEnumerable<DicomItem>)
Add a collection of DICOM items to the dataset. Update existing items.
public DicomDataset AddOrUpdate(IEnumerable<DicomItem> items)
Parameters
items
IEnumerable<DicomItem>Collection of DICOM items to add.
Returns
- DicomDataset
The dataset instance.
AddOrUpdate<T>(DicomTag, params T[])
Add or update a single DICOM item given by tag
and values
.
public DicomDataset AddOrUpdate<T>(DicomTag tag, params T[] values)
Parameters
tag
DicomTagDICOM tag of the added item.
values
T[]Values of the added item.
Returns
- DicomDataset
The dataset instance.
Type Parameters
T
Type of added values.
AddOrUpdate<T>(DicomVR, DicomTag, params T[])
Add or update a single DICOM item given by vr
, tag
and values
.
public DicomDataset AddOrUpdate<T>(DicomVR vr, DicomTag tag, params T[] values)
Parameters
vr
DicomVRDICOM vr of the added item. Use when setting a private element.
tag
DicomTagDICOM tag of the added item.
values
T[]Values of the added item.
Returns
- DicomDataset
The dataset instance.
Type Parameters
T
Type of added values.
Remarks
No validation is performed on the vr
matching the element tag
This method is useful when adding a private tag and need to explicitly set the VR of the created element.
Add<T>(DicomTag, params T[])
Add single DICOM item given by tag
and values
.
public DicomDataset Add<T>(DicomTag tag, params T[] values)
Parameters
tag
DicomTagDICOM tag of the added item.
values
T[]Values of the added item.
Returns
- DicomDataset
The dataset instance.
Type Parameters
T
Type of added values.
Exceptions
- ArgumentException
If tag already exists in dataset.
Add<T>(DicomVR, DicomTag, params T[])
Add single DICOM item given by vr
, tag
and values
.
public DicomDataset Add<T>(DicomVR vr, DicomTag tag, params T[] values)
Parameters
vr
DicomVRDICOM vr of the added item. Use when setting a private element.
tag
DicomTagDICOM tag of the added item.
values
T[]Values of the added item.
Returns
- DicomDataset
The dataset instance.
Type Parameters
T
Type of added values.
Remarks
No validation is performed on the vr
matching the element tag
This method is useful when adding a private tag and need to explicitly set the VR of the created element.
Exceptions
- ArgumentException
If tag already exists in dataset.
Clear()
Removes all items from the dataset.
public DicomDataset Clear()
Returns
- DicomDataset
Current Dataset
Contains(DicomTag)
Checks the DICOM dataset to determine if the dataset already contains an item with the specified tag.
public bool Contains(DicomTag tag)
Parameters
tag
DicomTagDICOM tag to test
Returns
- bool
True
if a DICOM item with the specified tag already exists.
CopyTo(DicomDataset)
Copies all items to the destination dataset.
public DicomDataset CopyTo(DicomDataset destination)
Parameters
destination
DicomDatasetDestination Dataset
Returns
- DicomDataset
Current Dataset
CopyTo(DicomDataset, DicomMaskedTag)
Copies tags matching mask to the destination dataset.
public DicomDataset CopyTo(DicomDataset destination, DicomMaskedTag mask)
Parameters
destination
DicomDatasetDestination Dataset
mask
DicomMaskedTagTags to copy
Returns
- DicomDataset
Current Dataset
CopyTo(DicomDataset, params DicomTag[])
Copies tags to the destination dataset.
public DicomDataset CopyTo(DicomDataset destination, params DicomTag[] tags)
Parameters
destination
DicomDatasetDestination Dataset
tags
DicomTag[]Tags to copy
Returns
- DicomDataset
Current Dataset
Equals(DicomDataset)
public bool Equals(DicomDataset other)
Parameters
other
DicomDataset
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
obj
object
Returns
FunctionalGroupValues(int)
Returns a DicomDataset, that contains all Tags accumulated from the Shared Functional Group Sequence and the Per-Frame Functional Group Sequence.
public DicomDataset FunctionalGroupValues(int frame)
Parameters
frame
intZero-based frame index.
Returns
Exceptions
GetCodeItem(DicomTag)
public DicomCodeItem GetCodeItem(DicomTag tag)
Parameters
tag
DicomTag
Returns
GetDicomItem<T>(DicomTag)
Gets the DicomItem of the specified tag
.
public T GetDicomItem<T>(DicomTag tag) where T : DicomItem
Parameters
tag
DicomTagRequested DICOM tag.
Returns
- T
Item corresponding to
tag
or
if thenull
tag
is not contained in the instance.
Type Parameters
T
Type of the return value. Must inherit from DicomItem.
GetEnumerator()
Enumerates all DICOM items.
public IEnumerator<DicomItem> GetEnumerator()
Returns
- IEnumerator<DicomItem>
Enumeration of DICOM items
GetHashCode()
public override int GetHashCode()
Returns
GetMeasuredValue(DicomTag)
public DicomMeasuredValue GetMeasuredValue(DicomTag tag)
Parameters
tag
DicomTag
Returns
GetPrivateTag(DicomTag)
Converts a dictionary tag to a valid private tag. Creates the private creator tag if needed.
public DicomTag GetPrivateTag(DicomTag tag)
Parameters
tag
DicomTagDictionary DICOM tag
Returns
- DicomTag
Private DICOM tag, or null if all groups are already used.
GetReferencedSOP(DicomTag)
public DicomReferencedSOP GetReferencedSOP(DicomTag tag)
Parameters
tag
DicomTag
Returns
GetSequence(DicomTag)
Gets the sequence of the specified tag
.
public DicomSequence GetSequence(DicomTag tag)
Parameters
tag
DicomTagRequested DICOM tag.
Returns
- DicomSequence
Sequence of datasets corresponding to
tag
.
Exceptions
- DicomDataException
If the dataset does not contain
tag
or this is not a sequence.
GetSingleValueOrDefault<T>(DicomTag, T)
Gets the element value of the specified tag
, whose value multiplicity has to be 1, or the provided defaultValue
if the element value does not exist.
public T GetSingleValueOrDefault<T>(DicomTag tag, T defaultValue)
Parameters
tag
DicomTagRequested DICOM tag.
defaultValue
TValue that is returned if the requested element value does not exist.
Returns
- T
Type Parameters
T
Type of the return value. This cannot be an array type.
GetSingleValue<T>(DicomTag)
Gets the element value of the specified tag
, whose value multiplicity has to be 1.
public T GetSingleValue<T>(DicomTag tag)
Parameters
tag
DicomTagRequested DICOM tag.
Returns
- T
Element values corresponding to
tag
.
Type Parameters
T
Type of the return value. This cannot be an array type.
Exceptions
- DicomDataException
If the dataset does not contain
tag
, is empty or is multi-valued.
GetString(DicomTag)
Gets a string representation of the value of the specified tag
.
public string GetString(DicomTag tag)
Parameters
tag
DicomTagRequested DICOM tag.
Returns
- string
String representing the element value corresponding to
tag
.
Exceptions
- DicomDataException
If the dataset does not contain
tag
.
GetValueCount(DicomTag)
Returns the number of values in the specified tag
.
public int GetValueCount(DicomTag tag)
Parameters
tag
DicomTagRequested DICOM tag.
Returns
Exceptions
- DicomDataException
If the dataset does not contain
tag
.
GetValueOrDefault<T>(DicomTag, int, T)
Gets the index
-th element value of the specified tag
or the provided defaultValue
if the requested value is not contained in the dataset.
public T GetValueOrDefault<T>(DicomTag tag, int index, T defaultValue)
Parameters
tag
DicomTagRequested DICOM tag.
index
intItem index (for multi-valued elements).
defaultValue
TValue that is returned if the requested element value does not exist.
Returns
- T
Type Parameters
T
Type of the return value. This cannot be an array type.
GetValue<T>(DicomTag, int)
Gets the index
-th element value of the specified tag
.
public T GetValue<T>(DicomTag tag, int index)
Parameters
Returns
- T
Element value corresponding to
tag
.
Type Parameters
T
Type of the return value. This cannot be an array type.
Exceptions
- DicomDataException
If the dataset does not contain
tag
or if the specifiedindex
is out-of-range.
GetValues<T>(DicomTag)
Gets the array of element values of the specified tag
.
public T[] GetValues<T>(DicomTag tag)
Parameters
tag
DicomTagRequested DICOM tag.
Returns
- T[]
Element values corresponding to
tag
.
Type Parameters
T
Type of the return value. This cannot be an array type.
Exceptions
- DicomDataException
If the dataset does not contain
tag
.
Remove(params DicomTag[])
Removes items for specified tags.
public DicomDataset Remove(params DicomTag[] tags)
Parameters
tags
DicomTag[]DICOM tags to remove
Returns
- DicomDataset
Current Dataset
Remove(Func<DicomItem, bool>)
Removes items where the selector function returns true.
public DicomDataset Remove(Func<DicomItem, bool> selector)
Parameters
Returns
- DicomDataset
Current Dataset
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
TryGetNonEmptySequence(DicomTag, out DicomSequence)
Gets the sequence of the specified tag
if it exists and is not empty.
public bool TryGetNonEmptySequence(DicomTag tag, out DicomSequence sequence)
Parameters
tag
DicomTagRequested DICOM tag.
sequence
DicomSequenceSequence of datasets corresponding to
tag
.
Returns
- bool
Returns
if thetrue
tag
exists and is not empty,
otherwise.false
TryGetSequence(DicomTag, out DicomSequence)
Gets the sequence of the specified tag
.
public bool TryGetSequence(DicomTag tag, out DicomSequence sequence)
Parameters
tag
DicomTagRequested DICOM tag.
sequence
DicomSequenceSequence of datasets corresponding to
tag
.
Returns
- bool
Returns
if thetrue
tag
could be returned as sequence,
otherwise.false
TryGetSingleValue<T>(DicomTag, out T)
Tries to get the element value of the specified tag
, whose value multiplicity has to be 1.
public bool TryGetSingleValue<T>(DicomTag tag, out T value)
Parameters
tag
DicomTagRequested DICOM tag.
value
T
Returns
- bool
Returns
if the element values could be exctracted, otherwisetrue
.false
Type Parameters
T
Type of the return value. This cannot be an array type.
TryGetString(DicomTag, out string)
Tries to get a string representation of the value of the specified tag
.
public bool TryGetString(DicomTag tag, out string stringValue)
Parameters
tag
DicomTagRequested DICOM tag.
stringValue
stringString representing the element value corresponding to
tag
.
Returns
- bool
Returns
if the dataset does not contain the tag.false
TryGetValue<T>(DicomTag, int, out T)
Tries to get the index
-th element value of the specified tag
.
public bool TryGetValue<T>(DicomTag tag, int index, out T elementValue)
Parameters
tag
DicomTagRequested DICOM tag.
index
intItem index (for multi-valued elements).
elementValue
TElement value corresponding to
tag
.
Returns
- bool
Returns
if the element value could be exctracted, otherwisetrue
.false
Type Parameters
T
Type of the return value. This cannot be an array type.
TryGetValues<T>(DicomTag, out T[])
Tries to get the array of element values of the specified tag
.
public bool TryGetValues<T>(DicomTag tag, out T[] values)
Parameters
tag
DicomTagRequested DICOM tag.
values
T[]Element values corresponding to
tag
.
Returns
- bool
Returns
if the element values could be extracted, otherwisetrue
.false
Type Parameters
T
Type of the return value. This cannot be an array type.
Validate()
Performs a validation of all DICOM items that are contained in this DicomDataset. This explicit call for validation ignores the gobal DicomValidation.AutoValidate and DicomDataset.AutoValidate property.
public void Validate()
Exceptions
- DicomValidationException
A exception is thrown if one of the items does not pass the valiation
ValidateTag(DicomTag)
Does nothing. Can be overwritten in derived classes to check if the tag is allowed.
protected virtual void ValidateTag(DicomTag tag)
Parameters
tag
DicomTag
Operators
operator ==(DicomDataset, DicomDataset)
public static bool operator ==(DicomDataset a, DicomDataset b)
Parameters
Returns
operator !=(DicomDataset, DicomDataset)
public static bool operator !=(DicomDataset a, DicomDataset b)