Mercurial > hg > orthanc
changeset 1739:df331354cea2
include binary in ToJson
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 22 Oct 2015 19:00:32 +0200 |
parents | 15a788a63846 |
children | 5e99a70b0635 |
files | OrthancServer/FromDcmtkBridge.cpp OrthancServer/ServerEnumerations.h UnitTestsSources/FromDcmtkTests.cpp |
diffstat | 3 files changed, 120 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/FromDcmtkBridge.cpp Thu Oct 22 09:28:08 2015 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Thu Oct 22 19:00:32 2015 +0200 @@ -407,17 +407,15 @@ case EVR_OF: // other float case EVR_OW: // other word case EVR_UN: // unknown value representation + case EVR_ox: // OB or OW depending on context { - DicomTag tag(Convert(element.getTag())); - - if ((tag == DICOM_TAG_PIXEL_DATA && flags & DicomToJsonFlags_IncludePixelData) || - (tag != DICOM_TAG_PIXEL_DATA && flags & DicomToJsonFlags_IncludeBinary)) + if (!(flags & DicomToJsonFlags_ConvertBinaryToNull)) { Uint8* data = NULL; if (element.getUint8Array(data) == EC_Normal) { return new DicomValue(reinterpret_cast<const char*>(data), element.getLength(), true); - } + } } return new DicomValue; @@ -537,7 +535,6 @@ * Internal to DCMTK. **/ - case EVR_ox: // OB or OW depending on context case EVR_xs: // SS or US depending on context case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) case EVR_na: // na="not applicable", for data which has no VR @@ -794,6 +791,23 @@ } } + DcmEVR evr = element->getTag().getEVR(); + if (evr == EVR_OB || + evr == EVR_OF || + evr == EVR_OW || + evr == EVR_UN || + evr == EVR_ox) + { + // This is a binary tag + DicomTag tag(FromDcmtkBridge::Convert(element->getTag())); + + if ((tag == DICOM_TAG_PIXEL_DATA && !(flags & DicomToJsonFlags_IncludePixelData)) || + (tag != DICOM_TAG_PIXEL_DATA && !(flags & DicomToJsonFlags_IncludeBinary))) + { + continue; + } + } + FromDcmtkBridge::ToJson(parent, *element, format, flags, maxStringLength, encoding); } } @@ -1061,7 +1075,13 @@ static bool IsBinaryTag(const DcmTag& key) { - return key.isPrivate() || key.isUnknownVR(); + return (key.isPrivate() || + key.isUnknownVR() || + key.getEVR() == EVR_OB || + key.getEVR() == EVR_OF || + key.getEVR() == EVR_OW || + key.getEVR() == EVR_UN || + key.getEVR() == EVR_ox); } @@ -1079,17 +1099,15 @@ // http://support.dcmtk.org/docs/dcvr_8h-source.html /** - * TODO. + * Binary types, handled above **/ case EVR_OB: // other byte case EVR_OF: // other float case EVR_OW: // other word - case EVR_AT: // attribute tag - throw OrthancException(ErrorCode_NotImplemented); - case EVR_UN: // unknown value representation - throw OrthancException(ErrorCode_ParameterOutOfRange); + case EVR_ox: // OB or OW depending on context + throw OrthancException(ErrorCode_InternalError); /** @@ -1175,10 +1193,17 @@ /** + * TODO + **/ + + case EVR_AT: // attribute tag + throw OrthancException(ErrorCode_NotImplemented); + + + /** * Internal to DCMTK. **/ - case EVR_ox: // OB or OW depending on context case EVR_xs: // SS or US depending on context case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) case EVR_na: // na="not applicable", for data which has no VR
--- a/OrthancServer/ServerEnumerations.h Thu Oct 22 09:28:08 2015 +0200 +++ b/OrthancServer/ServerEnumerations.h Thu Oct 22 19:00:32 2015 +0200 @@ -115,10 +115,14 @@ DicomToJsonFlags_IncludeUnknownTags = (1 << 2), DicomToJsonFlags_IncludePixelData = (1 << 3), DicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), + DicomToJsonFlags_ConvertBinaryToNull = (1 << 5), // Some predefined combinations - DicomToJsonFlags_None = 0, - DicomToJsonFlags_Default = DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeUnknownTags + DicomToJsonFlags_None = 0, + DicomToJsonFlags_Default = (DicomToJsonFlags_IncludePrivateTags | + DicomToJsonFlags_IncludeUnknownTags | + DicomToJsonFlags_IncludePixelData | + DicomToJsonFlags_ConvertBinaryToNull) };
--- a/UnitTestsSources/FromDcmtkTests.cpp Thu Oct 22 09:28:08 2015 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Thu Oct 22 19:00:32 2015 +0200 @@ -521,53 +521,88 @@ } } -TEST(ParsedDicomFile, ToJsonFlags) + +TEST(ParsedDicomFile, ToJsonFlags1) { FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7053, 0x1000), EVR_PN, "MyPrivateTag", 1, 1); FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), EVR_PN, "Declared public tag", 1, 1); - { - ParsedDicomFile f; - f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false); // Even group => public tag - f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false); // Even group => public, unknown tag - f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false); // Odd group => private tag + ParsedDicomFile f; + f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false); // Even group => public tag + f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false); // Even group => public, unknown tag + f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false); // Odd group => private tag + + Json::Value v; + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(6, v.getMemberNames().size()); + ASSERT_FALSE(v.isMember("7052,1000")); + ASSERT_FALSE(v.isMember("7053,1000")); + ASSERT_TRUE(v.isMember("7050,1000")); + ASSERT_EQ(Json::stringValue, v["7050,1000"].type()); + ASSERT_EQ("Some public tag", v["7050,1000"].asString()); - Json::Value v; - f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); - ASSERT_EQ(Json::objectValue, v.type()); - ASSERT_EQ(6, v.getMemberNames().size()); - ASSERT_FALSE(v.isMember("7052,1000")); - ASSERT_FALSE(v.isMember("7053,1000")); - ASSERT_TRUE(v.isMember("7050,1000")); - ASSERT_EQ(Json::stringValue, v["7050,1000"].type()); - ASSERT_EQ("Some public tag", v["7050,1000"].asString()); + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(7, v.getMemberNames().size()); + ASSERT_FALSE(v.isMember("7052,1000")); + ASSERT_TRUE(v.isMember("7050,1000")); + ASSERT_TRUE(v.isMember("7053,1000")); + ASSERT_EQ("Some public tag", v["7050,1000"].asString()); + ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); // TODO SHOULD BE STRING + + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludeUnknownTags, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(7, v.getMemberNames().size()); + ASSERT_TRUE(v.isMember("7050,1000")); + ASSERT_TRUE(v.isMember("7052,1000")); + ASSERT_FALSE(v.isMember("7053,1000")); + ASSERT_EQ("Some public tag", v["7050,1000"].asString()); + ASSERT_EQ(Json::nullValue, v["7052,1000"].type()); // TODO SHOULD BE STRING - f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0); - ASSERT_EQ(Json::objectValue, v.type()); - ASSERT_EQ(7, v.getMemberNames().size()); - ASSERT_FALSE(v.isMember("7052,1000")); - ASSERT_TRUE(v.isMember("7050,1000")); - ASSERT_TRUE(v.isMember("7053,1000")); - ASSERT_EQ("Some public tag", v["7050,1000"].asString()); - ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); // TODO SHOULD BE STRING + f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags), 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(8, v.getMemberNames().size()); + ASSERT_TRUE(v.isMember("7050,1000")); + ASSERT_TRUE(v.isMember("7052,1000")); + ASSERT_TRUE(v.isMember("7053,1000")); + ASSERT_EQ("Some public tag", v["7050,1000"].asString()); + ASSERT_EQ(Json::nullValue, v["7052,1000"].type()); // TODO SHOULD BE STRING + ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); // TODO SHOULD BE STRING +} + + +TEST(ParsedDicomFile, ToJsonFlags2) +{ + ParsedDicomFile f; + f.Insert(DICOM_TAG_PIXEL_DATA, "Pixels", false); + + Json::Value v; + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(5, v.getMemberNames().size()); + ASSERT_FALSE(v.isMember("7fe0,0010")); - f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludeUnknownTags, 0); - ASSERT_EQ(Json::objectValue, v.type()); - ASSERT_EQ(7, v.getMemberNames().size()); - ASSERT_TRUE(v.isMember("7050,1000")); - ASSERT_TRUE(v.isMember("7052,1000")); - ASSERT_FALSE(v.isMember("7053,1000")); - ASSERT_EQ("Some public tag", v["7050,1000"].asString()); - ASSERT_EQ(Json::nullValue, v["7052,1000"].type()); // TODO SHOULD BE STRING + f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData | DicomToJsonFlags_ConvertBinaryToNull), 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(6, v.getMemberNames().size()); + ASSERT_TRUE(v.isMember("7fe0,0010")); + ASSERT_EQ(Json::nullValue, v["7fe0,0010"].type()); - f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags), 0); - ASSERT_EQ(Json::objectValue, v.type()); - ASSERT_EQ(8, v.getMemberNames().size()); - ASSERT_TRUE(v.isMember("7050,1000")); - ASSERT_TRUE(v.isMember("7052,1000")); - ASSERT_TRUE(v.isMember("7053,1000")); - ASSERT_EQ("Some public tag", v["7050,1000"].asString()); - ASSERT_EQ(Json::nullValue, v["7052,1000"].type()); // TODO SHOULD BE STRING - ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); // TODO SHOULD BE STRING - } + f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData | DicomToJsonFlags_ConvertBinaryToAscii), 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(6, v.getMemberNames().size()); + ASSERT_TRUE(v.isMember("7fe0,0010")); + ASSERT_EQ(Json::stringValue, v["7fe0,0010"].type()); + ASSERT_EQ("Pixels", v["7fe0,0010"].asString()); + + f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePixelData, 0); + ASSERT_EQ(Json::objectValue, v.type()); + ASSERT_EQ(6, v.getMemberNames().size()); + ASSERT_TRUE(v.isMember("7fe0,0010")); + ASSERT_EQ(Json::stringValue, v["7fe0,0010"].type()); + std::string mime, content; + Toolbox::DecodeDataUriScheme(mime, content, v["7fe0,0010"].asString()); + ASSERT_EQ("application/octet-stream", mime); + ASSERT_EQ("Pixels", content); }