Struct dicom_object::mem::InMemDicomObject
source · pub struct InMemDicomObject<D = StandardDataDictionary> { /* private fields */ }Expand description
A DICOM object that is fully contained in memory.
See the module-level documentation for more details.
Implementations§
source§impl InMemDicomObject<StandardDataDictionary>
impl InMemDicomObject<StandardDataDictionary>
sourcepub fn create_empty() -> Self
👎Deprecated since 0.5.0: Use new_empty instead
pub fn create_empty() -> Self
new_empty insteadCreate a new empty DICOM object.
sourcepub fn from_element_source<I>(iter: I) -> Result<Self, AccessError>where
I: IntoIterator<Item = Result<InMemElement<StandardDataDictionary>, AccessError>>,
pub fn from_element_source<I>(iter: I) -> Result<Self, AccessError>where I: IntoIterator<Item = Result<InMemElement<StandardDataDictionary>, AccessError>>,
Construct a DICOM object from a fallible source of structured elements.
sourcepub fn from_element_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = InMemElement<StandardDataDictionary>>,
pub fn from_element_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = InMemElement<StandardDataDictionary>>,
Construct a DICOM object from a non-fallible source of structured elements.
sourcepub fn command_from_element_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = InMemElement<StandardDataDictionary>>,
pub fn command_from_element_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = InMemElement<StandardDataDictionary>>,
Construct a DICOM object representing a command set, from a non-fallible iterator of structured elements.
This method will automatically insert a Command Group Length (0000,0000) element based on the command elements found in the sequence.
sourcepub fn read_dataset<S>(decoder: S) -> Result<Self, ReadError>where
S: StatefulDecode,
pub fn read_dataset<S>(decoder: S) -> Result<Self, ReadError>where S: StatefulDecode,
Read an object from a source using the given decoder.
Note: read_dataset_with_ts and read_dataset_with_ts_cs
may be easier to use.
sourcepub fn read_dataset_with_ts_cs<S>(
from: S,
ts: &TransferSyntax,
cs: SpecificCharacterSet
) -> Result<Self, ReadError>where
S: Read,
pub fn read_dataset_with_ts_cs<S>( from: S, ts: &TransferSyntax, cs: SpecificCharacterSet ) -> Result<Self, ReadError>where S: Read,
Read an object from a source, using the given transfer syntax and default character set.
If the attribute Specific Character Set is found in the encoded data, this will override the given character set.
sourcepub fn read_dataset_with_ts<S>(
from: S,
ts: &TransferSyntax
) -> Result<Self, ReadError>where
S: Read,
pub fn read_dataset_with_ts<S>( from: S, ts: &TransferSyntax ) -> Result<Self, ReadError>where S: Read,
Read an object from a source, using the given transfer syntax.
The default character set is assumed until Specific Character Set is found in the encoded data, after which the text decoder will be overriden accordingly.
source§impl<D> InMemDicomObject<D>where
D: DataDictionary + Clone,
impl<D> InMemDicomObject<D>where D: DataDictionary + Clone,
sourcepub fn new_empty_with_dict(dict: D) -> Self
pub fn new_empty_with_dict(dict: D) -> Self
Create a new empty object, using the given dictionary for name lookup.
sourcepub fn from_element_source_with_dict<I>(
iter: I,
dict: D
) -> Result<Self, AccessError>where
I: IntoIterator<Item = Result<InMemElement<D>, AccessError>>,
pub fn from_element_source_with_dict<I>( iter: I, dict: D ) -> Result<Self, AccessError>where I: IntoIterator<Item = Result<InMemElement<D>, AccessError>>,
Construct a DICOM object from an iterator of structured elements.
sourcepub fn from_iter_with_dict<I>(iter: I, dict: D) -> Selfwhere
I: IntoIterator<Item = InMemElement<D>>,
pub fn from_iter_with_dict<I>(iter: I, dict: D) -> Selfwhere I: IntoIterator<Item = InMemElement<D>>,
Construct a DICOM object from a non-fallible iterator of structured elements.
sourcepub fn command_from_iter_with_dict<I>(iter: I, dict: D) -> Selfwhere
I: IntoIterator<Item = InMemElement<D>>,
pub fn command_from_iter_with_dict<I>(iter: I, dict: D) -> Selfwhere I: IntoIterator<Item = InMemElement<D>>,
Construct a DICOM object representing a command set, from a non-fallible iterator of structured elements.
This method will automatically insert a Command Group Length (0000,0000) element based on the command elements found in the sequence.
sourcepub fn read_dataset_with_dict<S>(decoder: S, dict: D) -> Result<Self, ReadError>where
S: StatefulDecode,
D: DataDictionary,
pub fn read_dataset_with_dict<S>(decoder: S, dict: D) -> Result<Self, ReadError>where S: StatefulDecode, D: DataDictionary,
Read an object from a source, using the given decoder and the given dictionary for name lookup.
sourcepub fn read_dataset_with_dict_ts<S>(
from: S,
dict: D,
ts: &TransferSyntax
) -> Result<Self, ReadError>where
S: Read,
D: DataDictionary,
pub fn read_dataset_with_dict_ts<S>( from: S, dict: D, ts: &TransferSyntax ) -> Result<Self, ReadError>where S: Read, D: DataDictionary,
Read an object from a source, using the given data dictionary and transfer syntax.
sourcepub fn read_dataset_with_dict_ts_cs<S>(
from: S,
dict: D,
ts: &TransferSyntax,
cs: SpecificCharacterSet
) -> Result<Self, ReadError>where
S: Read,
D: DataDictionary,
pub fn read_dataset_with_dict_ts_cs<S>( from: S, dict: D, ts: &TransferSyntax, cs: SpecificCharacterSet ) -> Result<Self, ReadError>where S: Read, D: DataDictionary,
Read an object from a source, using the given data dictionary, transfer syntax, and the given character set to assume by default.
If the attribute Specific Character Set is found in the encoded data, this will override the given character set.
sourcepub fn meta(&self) -> Option<&FileMetaTable>
👎Deprecated since 0.5.3: Always returns None, see FileDicomObject::meta instead
pub fn meta(&self) -> Option<&FileMetaTable>
FileDicomObject::meta insteadRetrieve the object’s meta table if available.
At the moment, this is sure to return None, because the meta
table is kept in a separate wrapper value.
sourcepub fn element(&self, tag: Tag) -> Result<&InMemElement<D>, AccessError>
pub fn element(&self, tag: Tag) -> Result<&InMemElement<D>, AccessError>
Retrieve a particular DICOM element by its tag.
An error is returned if the element does not exist.
For an alternative to this behavior,
see element_opt.
sourcepub fn element_by_name(
&self,
name: &str
) -> Result<&InMemElement<D>, AccessByNameError>
pub fn element_by_name( &self, name: &str ) -> Result<&InMemElement<D>, AccessByNameError>
Retrieve a particular DICOM element by its name.
This method translates the given attribute name into its tag
before retrieving the element.
If the attribute is known in advance,
using element
with a tag constant is preferred.
An error is returned if the element does not exist.
For an alternative to this behavior,
see element_by_name_opt.
sourcepub fn element_opt(
&self,
tag: Tag
) -> Result<Option<&InMemElement<D>>, AccessError>
pub fn element_opt( &self, tag: Tag ) -> Result<Option<&InMemElement<D>>, AccessError>
Retrieve a particular DICOM element that might not exist by its tag.
If the element does not exist,
None is returned.
sourcepub fn get(&self, tag: Tag) -> Option<&InMemElement<D>>
pub fn get(&self, tag: Tag) -> Option<&InMemElement<D>>
Get a particular DICOM attribute from this object by tag.
If the element does not exist,
None is returned.
sourcepub fn element_by_name_opt(
&self,
name: &str
) -> Result<Option<&InMemElement<D>>, AccessByNameError>
pub fn element_by_name_opt( &self, name: &str ) -> Result<Option<&InMemElement<D>>, AccessByNameError>
Retrieve a particular DICOM element that might not exist by its name.
If the element does not exist,
None is returned.
This method translates the given attribute name into its tag
before retrieving the element.
If the attribute is known in advance,
using element_opt
with a tag constant is preferred.
sourcepub fn put(&mut self, elt: InMemElement<D>) -> Option<InMemElement<D>>
pub fn put(&mut self, elt: InMemElement<D>) -> Option<InMemElement<D>>
Insert a data element to the object, replacing (and returning) any previous element of the same attribute.
sourcepub fn put_element(&mut self, elt: InMemElement<D>) -> Option<InMemElement<D>>
pub fn put_element(&mut self, elt: InMemElement<D>) -> Option<InMemElement<D>>
Insert a data element to the object, replacing (and returning) any previous element of the same attribute.
sourcepub fn put_str(
&mut self,
tag: Tag,
vr: VR,
string: impl Into<String>
) -> Option<InMemElement<D>>
pub fn put_str( &mut self, tag: Tag, vr: VR, string: impl Into<String> ) -> Option<InMemElement<D>>
Insert a new element with a string value to the object, replacing (and returning) any previous element of the same attribute.
sourcepub fn remove_element(&mut self, tag: Tag) -> bool
pub fn remove_element(&mut self, tag: Tag) -> bool
Remove a DICOM element by its tag, reporting whether it was present.
sourcepub fn remove_element_by_name(
&mut self,
name: &str
) -> Result<bool, AccessByNameError>
pub fn remove_element_by_name( &mut self, name: &str ) -> Result<bool, AccessByNameError>
Remove a DICOM element by its keyword, reporting whether it was present.
sourcepub fn take_element(&mut self, tag: Tag) -> Result<InMemElement<D>, AccessError>
pub fn take_element(&mut self, tag: Tag) -> Result<InMemElement<D>, AccessError>
Remove and return a particular DICOM element by its tag.
sourcepub fn take(&mut self, tag: Tag) -> Option<InMemElement<D>>
pub fn take(&mut self, tag: Tag) -> Option<InMemElement<D>>
Remove and return a particular DICOM element by its tag,
if it is present,
returns None otherwise.
sourcepub fn take_element_by_name(
&mut self,
name: &str
) -> Result<InMemElement<D>, AccessByNameError>
pub fn take_element_by_name( &mut self, name: &str ) -> Result<InMemElement<D>, AccessByNameError>
Remove and return a particular DICOM element by its name.
sourcepub fn retain(&mut self, f: impl FnMut(&InMemElement<D>) -> bool)
pub fn retain(&mut self, f: impl FnMut(&InMemElement<D>) -> bool)
Modify the object by retaining only the DICOM data elements specified by the predicate.
The elements are visited in ascending tag order,
and those for which f(&element) returns false are removed.
sourcepub fn update_value(
&mut self,
tag: Tag,
f: impl FnMut(&mut Value<InMemDicomObject<D>, InMemFragment>)
) -> bool
pub fn update_value( &mut self, tag: Tag, f: impl FnMut(&mut Value<InMemDicomObject<D>, InMemFragment>) ) -> bool
Obtain a temporary mutable reference to a DICOM value, so that mutations can be applied within.
If found, this method resets all related lengths recorded
and returns true.
Returns false otherwise.
Example
let mut obj = InMemDicomObject::from_element_iter([
DataElement::new(tags::LOSSY_IMAGE_COMPRESSION_RATIO, VR::DS, dicom_value!(Strs, ["25"])),
]);
// update lossy image compression ratio
obj.update_value(tags::LOSSY_IMAGE_COMPRESSION_RATIO, |e| {
e.primitive_mut().unwrap().extend_str(["2.56"]);
});
assert_eq!(
obj.get(tags::LOSSY_IMAGE_COMPRESSION_RATIO).unwrap().value().to_str().unwrap(),
"25\\2.56"
);sourcepub fn value_at(
&self,
selector: impl Into<AttributeSelector>
) -> Result<&Value<InMemDicomObject<D>, InMemFragment>, AtAccessError>
pub fn value_at( &self, selector: impl Into<AttributeSelector> ) -> Result<&Value<InMemDicomObject<D>, InMemFragment>, AtAccessError>
Obtain the DICOM value by finding the element that matches the given selector.
Returns an error if the respective element or any of its parents cannot be found.
See the documentation of AttributeSelector for more information
on how to write attribute selectors.
Example
let referenced_sop_instance_iod = obj.value_at(
(
tags::SHARED_FUNCTIONAL_GROUPS_SEQUENCE,
tags::REFERENCED_IMAGE_SEQUENCE,
tags::REFERENCED_SOP_INSTANCE_UID,
))?
.to_str()?;sourcepub fn write_dataset<W, E>(&self, to: W, encoder: E) -> Result<(), WriteError>where
W: Write,
E: EncodeTo<W>,
pub fn write_dataset<W, E>(&self, to: W, encoder: E) -> Result<(), WriteError>where W: Write, E: EncodeTo<W>,
Write this object’s data set into the given writer, with the given encoder specifications, without preamble, magic code, nor file meta group.
The text encoding to use will be the default character set until Specific Character Set is found in the data set, in which then that character set will be used.
Note: write_dataset_with_ts and write_dataset_with_ts_cs
may be easier to use.
sourcepub fn write_dataset_with_ts_cs<W>(
&self,
to: W,
ts: &TransferSyntax,
cs: SpecificCharacterSet
) -> Result<(), WriteError>where
W: Write,
pub fn write_dataset_with_ts_cs<W>( &self, to: W, ts: &TransferSyntax, cs: SpecificCharacterSet ) -> Result<(), WriteError>where W: Write,
Write this object’s data set into the given printer, with the specified transfer syntax and character set, without preamble, magic code, nor file meta group.
If the attribute Specific Character Set is found in the data set, the last parameter is overridden accordingly.
sourcepub fn write_dataset_with_ts<W>(
&self,
to: W,
ts: &TransferSyntax
) -> Result<(), WriteError>where
W: Write,
pub fn write_dataset_with_ts<W>( &self, to: W, ts: &TransferSyntax ) -> Result<(), WriteError>where W: Write,
Write this object’s data set into the given writer, with the specified transfer syntax, without preamble, magic code, nor file meta group.
The default character set is assumed until the Specific Character Set is found in the data set, after which the text encoder is overridden accordingly.
sourcepub fn with_exact_meta(self, meta: FileMetaTable) -> FileDicomObject<Self>
pub fn with_exact_meta(self, meta: FileMetaTable) -> FileDicomObject<Self>
Encapsulate this object to contain a file meta group as described exactly by the given table.
Note: this method will not adjust the file meta group to be semantically valid for the object.
sourcepub fn with_meta(
self,
meta: FileMetaTableBuilder
) -> Result<FileDicomObject<Self>, WithMetaError>
pub fn with_meta( self, meta: FileMetaTableBuilder ) -> Result<FileDicomObject<Self>, WithMetaError>
Encapsulate this object to contain a file meta group, created through the given file meta table builder.
A complete file meta group should provide the Transfer Syntax UID, the Media Storage SOP Instance UID, and the Media Storage SOP Class UID. The last two will be filled with the values of SOP Instance UID and SOP Class UID if they are present in this object.
Example
use dicom_object::{InMemDicomObject, meta::FileMetaTableBuilder};
let obj = InMemDicomObject::from_element_iter([
DataElement::new(tags::SOP_CLASS_UID, VR::UI, uids::COMPUTED_RADIOGRAPHY_IMAGE_STORAGE),
DataElement::new(tags::SOP_INSTANCE_UID, VR::UI, "2.25.60156688944589400766024286894543900794"),
// ...
]);
let obj = obj.with_meta(FileMetaTableBuilder::new()
.transfer_syntax(uids::EXPLICIT_VR_LITTLE_ENDIAN))?;
// can now save everything to a file
let meta = obj.write_to_file("out.dcm")?;sourcepub fn iter(&self) -> impl Iterator<Item = &InMemElement<D>> + '_
pub fn iter(&self) -> impl Iterator<Item = &InMemElement<D>> + '_
Obtain an iterator over the elements of this object.
Obtain an iteartor over the tags of the object’s elements.
Trait Implementations§
source§impl<D> ApplyOp for InMemDicomObject<D>where
D: DataDictionary + Clone,
impl<D> ApplyOp for InMemDicomObject<D>where D: DataDictionary + Clone,
§type Err = ApplyError
type Err = ApplyError
source§fn apply(&mut self, op: AttributeOp) -> ApplyResult
fn apply(&mut self, op: AttributeOp) -> ApplyResult
source§impl<D: Clone> Clone for InMemDicomObject<D>
impl<D: Clone> Clone for InMemDicomObject<D>
source§fn clone(&self) -> InMemDicomObject<D>
fn clone(&self) -> InMemDicomObject<D>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<D: Debug> Debug for InMemDicomObject<D>
impl<D: Debug> Debug for InMemDicomObject<D>
source§impl<'s, D> DicomObject for &'s InMemDicomObject<D>where
D: DataDictionary + Clone + 's,
impl<'s, D> DicomObject for &'s InMemDicomObject<D>where D: DataDictionary + Clone + 's,
type Element = &'s DataElement<InMemDicomObject<D>>
source§fn element(&self, tag: Tag) -> Result<Self::Element, AccessError>
fn element(&self, tag: Tag) -> Result<Self::Element, AccessError>
source§fn element_by_name(
&self,
name: &str
) -> Result<Self::Element, AccessByNameError>
fn element_by_name( &self, name: &str ) -> Result<Self::Element, AccessByNameError>
source§impl<D> Extend<DataElement<InMemDicomObject<D>>> for InMemDicomObject<D>
impl<D> Extend<DataElement<InMemDicomObject<D>>> for InMemDicomObject<D>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = InMemElement<D>>,
fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = InMemElement<D>>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)