Skip to content

Commit

Permalink
Update binary VRs
Browse files Browse the repository at this point in the history
  • Loading branch information
lamyj committed Jul 8, 2016
1 parent 661b2e0 commit 524763d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
37 changes: 34 additions & 3 deletions src/odil/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ::read_element(Tag const & tag, DataSet const & data_set) const
{
value = Value(Value::DataSets());
}
else if(vr == VR::OB || vr == VR::OF || vr == VR::OW || vr == VR::UN)
else if(is_binary(vr))
{
value = Value(Value::Binary());
}
Expand Down Expand Up @@ -525,6 +525,21 @@ ::operator()(Value::Binary & value) const
this->stream.read(
reinterpret_cast<char*>(&value[0][0]), value[0].size());
}
else if(this->vr == VR::OD)
{
if(vl%8 != 0)
{
throw Exception("Cannot read OD for odd-sized array");
}

value[0].resize(vl);
for(unsigned int i=0; i<value[0].size(); i+=8)
{
auto const item = Reader::read_binary<double>(
this->stream, this->byte_ordering);
*reinterpret_cast<double*>(&value[0][i]) = item;
}
}
else if(this->vr == VR::OF)
{
if(vl%4 != 0)
Expand All @@ -540,6 +555,21 @@ ::operator()(Value::Binary & value) const
*reinterpret_cast<float*>(&value[0][i]) = item;
}
}
else if(this->vr == VR::OL)
{
if(vl%4 != 0)
{
throw Exception("Cannot read OL for odd-sized array");
}

value[0].resize(vl);
for(unsigned int i=0; i<value[0].size(); i+=4)
{
auto const item = Reader::read_binary<uint32_t>(
this->stream, this->byte_ordering);
*reinterpret_cast<uint32_t*>(&value[0][i]) = item;
}
}
else if(this->vr == VR::OW)
{
if(vl%2 != 0)
Expand Down Expand Up @@ -569,8 +599,9 @@ ::read_length() const
uint32_t length;
if(this->explicit_vr)
{
if(vr == VR::OB || vr == VR::OW || vr == VR::OF || vr == VR::SQ ||
vr == VR::UC || vr == VR::UR || vr == VR::UT || vr == VR::UN)
if(vr == VR::OB || vr == VR::OD || vr == VR::OF || vr == VR::OL ||
vr == VR::OW || vr == VR::OF || vr == VR::SQ || vr == VR::UC ||

This comment has been minimized.

Copy link
@cguebert

cguebert Jul 12, 2016

Contributor

You test twice for VR::OF.

vr == VR::UR || vr == VR::UT || vr == VR::UN)
{
Reader::ignore(this->stream, 2);
auto const vl = Reader::read_binary<uint32_t>(
Expand Down
4 changes: 3 additions & 1 deletion src/odil/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ bool is_string(VR vr)

bool is_binary(VR vr)
{
return (vr == VR::OB || vr == VR::OF || vr == VR::OW || vr == VR::UN);
return (
vr == VR::OB || vr == VR::OD || vr == VR::OF || vr == VR::OL ||
vr == VR::OW || vr == VR::UN);
}


Expand Down
7 changes: 4 additions & 3 deletions src/odil/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ ::write_element(Element const & element) const
// Write VL
if(this->explicit_vr)
{
if(vr == VR::OB || vr == VR::OW || vr == VR::OF || vr == VR::SQ ||
vr == VR::UC || vr == VR::UR || vr == VR::UT || vr == VR::UN)
if(vr == VR::OB || vr == VR::OD || vr == VR::OF || vr == VR::OL ||
vr == VR::OW || vr == VR::OF || vr == VR::SQ || vr == VR::UC ||

This comment has been minimized.

Copy link
@cguebert

cguebert Jul 12, 2016

Contributor

And here too (twice VR::OF).

vr == VR::UR || vr == VR::UT || vr == VR::UN)
{
this->write_binary(uint16_t(0), this->stream, this->byte_ordering);

Expand All @@ -185,7 +186,7 @@ ::write_element(Element const & element) const
{
vl = 0xffffffff;
}
else if((vr == VR::OB || vr == VR::OW) && element.size() > 1)
else if(is_binary(vr) && element.size() > 1)
{
vl = 0xffffffff;
}
Expand Down
2 changes: 1 addition & 1 deletion src/odil/json_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ DataSet as_dataset(Json::Value const & json)
element.as_data_set().push_back(dicom_item);
}
}
else if(vr == VR::OB || vr == VR::OF || vr == VR::OW || vr == VR::UN)
else if(is_binary(vr))
{
element = Element(Value::Binary(), vr);

Expand Down
2 changes: 1 addition & 1 deletion src/odil/xml_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ DataSet as_dataset(boost::property_tree::ptree const & xml)
element.as_data_set().push_back(it->second);
}
}
else if(vr == VR::OB || vr == VR::OF || vr == VR::OW || vr == VR::UN)
else if(is_binary(vr))
{
element = Element(Value::Binary(), vr);

Expand Down

0 comments on commit 524763d

Please sign in to comment.