I'm using post 3.6.0 trunk version bf1a1e13d24678c05d599cc16b942f83b02342c8. I was trying to save a StrutureSet to a file with write(dcmStrm, EXS_LittleEndianExplicit, EET_ExplicitLength, NULL); It fails with
After much debugging I tracked it down to dcobject.cc writeTagAndLength() routine, which throws an error because VR (DS in this case) is not set to use extended length, and the length is more than 16 bits. That check seems to come from the data dictionary. Does that seem correct? I had a quick look at part 5 and part 6 but couldn't find if DS should not return usesExtendedLengthEncoding().E: DcmObject: Length of element ContourData (3006,0050) exceeds maximum of 16-bit length field
The code is posted below for your quick reference:
Code: Select all
dcobject.cc:
OFCondition DcmObject::writeTagAndLength(DcmOutputStream &outStream,
const E_TransferSyntax oxfer,
Uint32 &writtenBytes) const
...
/* in case we are dealing with a transfer syntax with explicit VR (see if above) */
/* and the actual VR uses extended length encoding (see DICOM standard part 5, */
/* section 7.1.2) we have to add 2 reserved bytes (set to a value of 00H) to the */
/* data type field and the actual length field is 4 bytes wide. Write the */
/* corresponding information to the stream. */
if (outvr.usesExtendedLengthEncoding()) <-----------!!! Returns FALSE
{
Uint16 reserved = 0;
outStream.write(&reserved, 2); // write 2 reserved bytes to stream
Uint32 valueLength = Length; // determine length
swapIfNecessary(oByteOrder, gLocalByteOrder, &valueLength, 4, 4); // mind transfer syntax
outStream.write(&valueLength, 4); // write length, 4 bytes wide
writtenBytes += 6; // remember that 6 bytes were written in total
}
/* in case that we are dealing with a transfer syntax with explicit VR (see if above) and */
/* the actual VR does not use extended length encoding (see DICOM standard part 5, section */
/* 7.1.2) we do not have to add reserved bytes to the data type field and the actual length */
/* is 2 bytes wide. Write the corresponding information to the stream. But, make sure that */
/* the length really fits into the 2-byte field ... */
else if (Length <= 0xffff)
{
Uint16 valueLength = OFstatic_cast(Uint16, Length); // determine length (cast to 16 bit)
swapIfNecessary(oByteOrder, gLocalByteOrder, &valueLength, 2, 2); // mind transfer syntax
outStream.write(&valueLength, 2); // write length, 2 bytes wide
writtenBytes += 2; // remember that 2 bytes were written in total
}
/* ... if not, report an error message and return an error code. */
else {
DcmTag tag(Tag);
DCMDATA_ERROR("DcmObject: Length of element " << tag.getTagName() << " " << tag
<< " exceeds maximum of 16-bit length field");
l_error = EC_ElemLengthExceeds16BitField;
}
And dcvr.cc
OFBool
DcmVR::usesExtendedLengthEncoding() const
{
return (DcmVRDict[vr].propertyFlags & DCMVR_PROP_EXTENDEDLENGTHENCODING) ? OFTrue : OFFalse;
}