Skip to content

Commit

Permalink
MAIN: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naterichman committed Nov 17, 2023
1 parent 2622ba3 commit ca47a48
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 220 deletions.
33 changes: 12 additions & 21 deletions pixeldata/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ fn get_from_shared<D: DataDictionary + Clone>(
) -> Option<Vec<&InMemElement<D>>> {
obj.get(tags::SHARED_FUNCTIONAL_GROUPS_SEQUENCE)?.items()?
.get(0)?
.get(selector[0])?.items()?
.get(0)?
.get(selector[1])
.get(selector[0])
.and_then(|inner|inner.items()?
.get(0)?
.get(selector[1]))
// Sometimes the tag is not in the properly nested sequence, but just flat in the first
// element of the SharedFunctionalGroupsSequence
.or_else(|| obj.get(tags::SHARED_FUNCTIONAL_GROUPS_SEQUENCE)?.items()?
.get(0)?
.get(selector[1]))
.map(|inner| vec![inner])
}

Expand Down Expand Up @@ -235,7 +241,7 @@ pub fn rescale_intercept<D: DataDictionary + Clone>(
pub fn rescale_slope<D: DataDictionary + Clone>(
obj: &FileDicomObject<InMemDicomObject<D>>,
) -> Vec<f64> {
obj.element(tags::RESCALE_INTERCEPT)
obj.element(tags::RESCALE_SLOPE)
.ok()
.and_then(|e| {
vec![e.to_float64().ok()]
Expand All @@ -246,15 +252,15 @@ pub fn rescale_slope<D: DataDictionary + Clone>(
obj,
[
tags::PIXEL_VALUE_TRANSFORMATION_SEQUENCE,
tags::RESCALE_INTERCEPT,
tags::RESCALE_SLOPE,
],
)
.and_then(|v| v.into_iter().map(|el| el.to_float64().ok()).collect()))
.or(get_from_shared(
obj,
[
tags::PIXEL_VALUE_TRANSFORMATION_SEQUENCE,
tags::RESCALE_INTERCEPT,
tags::RESCALE_SLOPE,
],
)
.and_then(|v| v.into_iter().map(|el| el.to_float64().ok()).collect()))
Expand Down Expand Up @@ -351,21 +357,6 @@ where
.context(CastValueSnafu { name })
}

#[inline]
fn retrieve_optional_to_f64<D>(
obj: &FileDicomObject<InMemDicomObject<D>>,
tag: Tag,
name: AttributeName,
) -> Result<Option<f64>>
where
D: DataDictionary + Clone,
{
match obj.element_opt(tag).context(RetrieveSnafu { name })? {
Some(e) => e.to_float64().context(ConvertValueSnafu { name }).map(Some),
None => Ok(None),
}
}

/// A decoded representation of the DICOM _Pixel Representation_ attribute.
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
#[repr(u16)]
Expand Down
Loading

0 comments on commit ca47a48

Please sign in to comment.