DicomObject

Trait DicomObject 

Source
pub trait DicomObject {
    type Attribute<'a>: DicomAttribute
       where Self: 'a;
    type LeafAttribute<'a>: DicomAttribute
       where Self: 'a;

    // Required methods
    fn attr_opt(
        &self,
        tag: Tag,
    ) -> Result<Option<Self::Attribute<'_>>, AccessError>;
    fn attr_by_name_opt(
        &self,
        name: &str,
    ) -> Result<Option<Self::Attribute<'_>>, AccessByNameError>;
    fn at(
        &self,
        selector: impl Into<AttributeSelector>,
    ) -> Result<Self::LeafAttribute<'_>, AtAccessError>;

    // Provided methods
    fn attr(&self, tag: Tag) -> Result<Self::Attribute<'_>, AccessError> { ... }
    fn attr_by_name(
        &self,
        name: &str,
    ) -> Result<Self::Attribute<'_>, AccessByNameError> { ... }
}
Expand description

Trait type for a generalized interpretation of a DICOM object.

This is a high-level abstraction where an object is accessed and manipulated as a dictionary of entries indexed by tags, which in turn may contain a DICOM object.

§Examples

You can use this trait to operate on DICOM data sets when the exact DICOM object type is not known.

use dicom_object::DicomObject;
use dicom_object::DicomAttribute as _;

fn my_data() -> impl DicomObject {
    InMemDicomObject::from_element_iter([
        DataElement::new(
            tags::SOP_INSTANCE_UID,
            VR::UI,
            "2.25.60131396312732822704775296119377475501",
        ),
    ])
}

let obj = my_data();
assert_eq!(
    obj.attr(tags::SOP_INSTANCE_UID)?.to_str()?,
   "2.25.60131396312732822704775296119377475501"
);

It works for in-memory data sets, file meta groups, and other similar structures. When operating on DICOM file objects, the look-up will be directed to the right group depending on the attribute requested.

use dicom_object::{DicomObject as _, open_file};

let file = open_file("00001.dcm")?;

let Some(media_storage_sop_class_uid) = file.attr_opt(tags::MEDIA_STORAGE_SOP_CLASS_UID)? else {
    panic!("DICOM file should have a Media Storage SOP Class UID");
};

Types implementing this trait will likely also implement ApplyOp, enabling more operations on DICOM objects.

Required Associated Types§

Source

type Attribute<'a>: DicomAttribute where Self: 'a

The type representing a DICOM attribute in the object and/or the necessary means to retrieve the value from it.

This is the outcome of a shallow look-up using the methods attr or attr_opt.

Source

type LeafAttribute<'a>: DicomAttribute where Self: 'a

The type representing a DICOM leaf attribute in the object and/or the necessary means to retrieve the value from it.

This is the outcome of a potentially deep look-up using the method at.

Required Methods§

Source

fn attr_opt(&self, tag: Tag) -> Result<Option<Self::Attribute<'_>>, AccessError>

Retrieve a particular DICOM attribute by looking up the given tag at the object’s root.

Ok(None) is returned when the object was successfully looked up but the element is not present. This is not a recursive search.

Source

fn attr_by_name_opt( &self, name: &str, ) -> Result<Option<Self::Attribute<'_>>, AccessByNameError>

Retrieve a particular DICOM element by its name (keyword).

Ok(None) is returned when the object was successfully looked up but the element is not present.

If the DICOM tag is already known, prefer calling attr_opt with one of the constants from the DICOM dictionary.

Source

fn at( &self, selector: impl Into<AttributeSelector>, ) -> Result<Self::LeafAttribute<'_>, AtAccessError>

Retrieve a particular DICOM attribute with a look-up by attribute selector.

This method returns an error if the element is not present.

Provided Methods§

Source

fn attr(&self, tag: Tag) -> Result<Self::Attribute<'_>, AccessError>

Retrieve a particular DICOM attribute by looking up the given tag at the object’s root.

Unlike attr_opt, this method returns an error if the element is not present.

Source

fn attr_by_name( &self, name: &str, ) -> Result<Self::Attribute<'_>, AccessByNameError>

Retrieve a particular DICOM element by its name (keyword).

Unlike attr_by_name_opt, this method returns an error if the element is not present.

If the DICOM tag is already known, prefer calling attr with one of the constants from the DICOM dictionary.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl DicomObject for FileMetaTable

Source§

type Attribute<'a> = FileMetaAttribute<'a> where Self: 'a

Source§

type LeafAttribute<'a> = FileMetaAttribute<'a> where Self: 'a

Source§

impl<'s, D> DicomObject for &'s InMemDicomObject<D>
where D: DataDictionary + Clone + 's,

Source§

type Attribute<'a> = &'a Value<InMemDicomObject<D>> where Self: 'a, 's: 'a

Source§

type LeafAttribute<'a> = &'a Value<InMemDicomObject<D>> where Self: 'a, 's: 'a

Source§

impl<'s, O> DicomObject for &'s FileDicomObject<O>
where O: DicomObject + 's,

Source§

type Attribute<'a> = Either<FileMetaAttribute<'a>, <O as DicomObject>::Attribute<'a>> where Self: 'a, O: 'a

Source§

type LeafAttribute<'a> = Either<FileMetaAttribute<'a>, <O as DicomObject>::LeafAttribute<'a>> where Self: 'a, O: 'a

Source§

impl<D> DicomObject for InMemDicomObject<D>
where D: DataDictionary + Clone,

Source§

type Attribute<'a> = &'a Value<InMemDicomObject<D>> where Self: 'a

Source§

type LeafAttribute<'a> = &'a Value<InMemDicomObject<D>> where Self: 'a

Source§

impl<O> DicomObject for FileDicomObject<O>
where O: DicomObject,

Source§

type Attribute<'a> = Either<FileMetaAttribute<'a>, <O as DicomObject>::Attribute<'a>> where Self: 'a, O: 'a

Source§

type LeafAttribute<'a> = Either<FileMetaAttribute<'a>, <O as DicomObject>::LeafAttribute<'a>> where Self: 'a, O: 'a