Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 5807:8279eaab0d1d attach-custom-data tip
merged default -> attach-custom-data
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 24 Sep 2024 11:39:52 +0200 |
parents | dedbf019a707 |
children |
comparison
equal
deleted
inserted
replaced
5085:79f98ee4f04b | 5807:8279eaab0d1d |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | 6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | 8 * |
8 * This program is free software: you can redistribute it and/or | 9 * This program is free software: you can redistribute it and/or |
9 * modify it under the terms of the GNU Lesser General Public License | 10 * modify it under the terms of the GNU Lesser General Public License |
10 * as published by the Free Software Foundation, either version 3 of | 11 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | 12 * the License, or (at your option) any later version. |
35 #endif | 36 #endif |
36 | 37 |
37 #include <gtest/gtest.h> | 38 #include <gtest/gtest.h> |
38 | 39 |
39 #include "../Sources/Compatibility.h" | 40 #include "../Sources/Compatibility.h" |
41 #include "../Sources/DicomFormat/DicomImageInformation.h" | |
40 #include "../Sources/DicomFormat/DicomPath.h" | 42 #include "../Sources/DicomFormat/DicomPath.h" |
41 #include "../Sources/DicomNetworking/DicomFindAnswers.h" | 43 #include "../Sources/DicomNetworking/DicomFindAnswers.h" |
42 #include "../Sources/DicomParsing/DicomModification.h" | 44 #include "../Sources/DicomParsing/DicomModification.h" |
43 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" | 45 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" |
44 #include "../Sources/DicomParsing/FromDcmtkBridge.h" | 46 #include "../Sources/DicomParsing/FromDcmtkBridge.h" |
312 | 314 |
313 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-5 | 315 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-5 |
314 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 192")); ASSERT_EQ(Encoding_Utf8, e); | 316 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 192")); ASSERT_EQ(Encoding_Utf8, e); |
315 ASSERT_TRUE(GetDicomEncoding(e, "GB18030")); ASSERT_EQ(Encoding_Chinese, e); | 317 ASSERT_TRUE(GetDicomEncoding(e, "GB18030")); ASSERT_EQ(Encoding_Chinese, e); |
316 ASSERT_TRUE(GetDicomEncoding(e, "GBK")); ASSERT_EQ(Encoding_Chinese, e); | 318 ASSERT_TRUE(GetDicomEncoding(e, "GBK")); ASSERT_EQ(Encoding_Chinese, e); |
319 | |
320 // common spelling mistakes | |
321 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR_100")); ASSERT_EQ(Encoding_Latin1, e); | |
322 ASSERT_TRUE(GetDicomEncoding(e, "ISO_2022_IR_6")); ASSERT_EQ(Encoding_Ascii, e); | |
317 } | 323 } |
318 | 324 |
319 | 325 |
320 TEST(FromDcmtkBridge, Encodings3) | 326 TEST(FromDcmtkBridge, Encodings3) |
321 { | 327 { |
2765 std::unique_ptr<ParsedDicomFile> dicom1(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, "")); | 2771 std::unique_ptr<ParsedDicomFile> dicom1(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, "")); |
2766 std::unique_ptr<ParsedDicomFile> dicom2(dicom1->Clone(true)); | 2772 std::unique_ptr<ParsedDicomFile> dicom2(dicom1->Clone(true)); |
2767 | 2773 |
2768 { | 2774 { |
2769 DicomModification modif; | 2775 DicomModification modif; |
2770 modif.SetupAnonymization(DicomVersion_2021b); | 2776 modif.SetupAnonymization(DicomVersion_2023b); |
2771 modif.Apply(*dicom1); | 2777 modif.Apply(*dicom1); |
2772 modif.Apply(*dicom2); | 2778 modif.Apply(*dicom2); |
2773 } | 2779 } |
2774 | 2780 |
2775 // Same anonymization context and same input DICOM => hence, same output DICOM | 2781 // Same anonymization context and same input DICOM => hence, same output DICOM |
2792 { | 2798 { |
2793 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, "")); | 2799 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, "")); |
2794 | 2800 |
2795 { | 2801 { |
2796 DicomModification modif; | 2802 DicomModification modif; |
2797 modif.SetupAnonymization(DicomVersion_2021b); | 2803 modif.SetupAnonymization(DicomVersion_2023b); |
2798 modif.Keep(DicomPath::Parse("ReferencedImageSequence[1].ReferencedSOPInstanceUID")); | 2804 modif.Keep(DicomPath::Parse("ReferencedImageSequence[1].ReferencedSOPInstanceUID")); |
2799 modif.Keep(DicomPath::Parse("RelatedSeriesSequence")); | 2805 modif.Keep(DicomPath::Parse("RelatedSeriesSequence")); |
2800 modif.Apply(*dicom); | 2806 modif.Apply(*dicom); |
2801 } | 2807 } |
2802 | 2808 |
3083 ASSERT_EQ(Json::objectValue, b["0008,1140"][0].type()); | 3089 ASSERT_EQ(Json::objectValue, b["0008,1140"][0].type()); |
3084 ASSERT_EQ(0u, b["0008,1140"][0].size()); | 3090 ASSERT_EQ(0u, b["0008,1140"][0].size()); |
3085 } | 3091 } |
3086 } | 3092 } |
3087 | 3093 |
3094 | |
3095 TEST(ParsedDicomFile, MultipleFloatValue) | |
3096 { | |
3097 // from https://discourse.orthanc-server.org/t/qido-includefield-with-sequences/4746/6 | |
3098 Json::Value v = Json::objectValue; | |
3099 v["4010,1001"][0]["4010,1004"] = "30\\20\\10"; | |
3100 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, "")); | |
3101 ASSERT_TRUE(dicom->HasTag(Orthanc::DicomTag(0x4010, 0x1001))); | |
3102 | |
3103 DicomMap m; | |
3104 ASSERT_TRUE(dicom->LookupSequenceItem(m, DicomPath(DicomTag(0x4010, 0x1001)), 0)); | |
3105 ASSERT_EQ(1u, m.GetSize()); | |
3106 std::string value = m.GetStringValue(DicomTag(0x4010, 0x1004), "", false); | |
3107 ASSERT_EQ("30\\20\\10", value); | |
3108 } | |
3088 | 3109 |
3089 | 3110 |
3090 TEST(ParsedDicomFile, ImageInformation) | 3111 TEST(ParsedDicomFile, ImageInformation) |
3091 { | 3112 { |
3092 double wc, ww; | 3113 double wc, ww; |
3215 DicomMap m; | 3236 DicomMap m; |
3216 m.FromDicomWeb(v); | 3237 m.FromDicomWeb(v); |
3217 } | 3238 } |
3218 | 3239 |
3219 | 3240 |
3241 TEST(ParsedDicomFile, InjectEmptyPixelData) | |
3242 { | |
3243 static const char* PIXEL_DATA = "7FE00010"; | |
3244 | |
3245 { | |
3246 ParsedDicomFile dicom(true); | |
3247 | |
3248 DicomWebJsonVisitor visitor; | |
3249 dicom.Apply(visitor); | |
3250 | |
3251 ASSERT_FALSE(visitor.GetResult().isMember(PIXEL_DATA)); | |
3252 } | |
3253 | |
3254 { | |
3255 ParsedDicomFile dicom(true); | |
3256 dicom.InjectEmptyPixelData(ValueRepresentation_OtherByte); | |
3257 dicom.InjectEmptyPixelData(ValueRepresentation_OtherWord); // Must be ignored | |
3258 | |
3259 DicomWebJsonVisitor visitor; | |
3260 dicom.Apply(visitor); | |
3261 | |
3262 ASSERT_TRUE(visitor.GetResult().isMember(PIXEL_DATA)); | |
3263 ASSERT_EQ(2u, visitor.GetResult() [PIXEL_DATA].size()); | |
3264 ASSERT_EQ("", visitor.GetResult() [PIXEL_DATA]["InlineBinary"].asString()); | |
3265 ASSERT_EQ("OB", visitor.GetResult() [PIXEL_DATA]["vr"].asString()); | |
3266 } | |
3267 | |
3268 { | |
3269 ParsedDicomFile dicom(true); | |
3270 dicom.InjectEmptyPixelData(ValueRepresentation_OtherWord); | |
3271 dicom.InjectEmptyPixelData(ValueRepresentation_OtherByte); // Must be ignored | |
3272 | |
3273 DicomWebJsonVisitor visitor; | |
3274 dicom.Apply(visitor); | |
3275 | |
3276 ASSERT_TRUE(visitor.GetResult().isMember(PIXEL_DATA)); | |
3277 ASSERT_EQ(2u, visitor.GetResult() [PIXEL_DATA].size()); | |
3278 ASSERT_EQ("", visitor.GetResult() [PIXEL_DATA]["InlineBinary"].asString()); | |
3279 ASSERT_EQ("OW", visitor.GetResult() [PIXEL_DATA]["vr"].asString()); | |
3280 } | |
3281 } | |
3282 | |
3283 | |
3284 TEST(ParsedDicomFile, RemoveFromPixelData) | |
3285 { | |
3286 ParsedDicomFile dicom(true); | |
3287 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0000), "").good()); | |
3288 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0009), "").good()); | |
3289 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint8Array(DcmTag(0x7fe0, 0x0010), NULL, 0).good()); | |
3290 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0011), "").good()); | |
3291 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe1, 0x0000), "").good()); | |
3292 | |
3293 { | |
3294 DicomMap m; | |
3295 dicom.ExtractDicomSummary(m, 0); | |
3296 | |
3297 ASSERT_EQ(10u, m.GetSize()); | |
3298 ASSERT_TRUE(m.HasTag(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID)); | |
3299 ASSERT_TRUE(m.HasTag(DICOM_TAG_SOP_INSTANCE_UID)); | |
3300 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_ID)); | |
3301 ASSERT_TRUE(m.HasTag(DICOM_TAG_SERIES_INSTANCE_UID)); | |
3302 ASSERT_TRUE(m.HasTag(DICOM_TAG_STUDY_INSTANCE_UID)); | |
3303 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0000)); | |
3304 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0009)); | |
3305 ASSERT_TRUE(m.HasTag(DICOM_TAG_PIXEL_DATA)); | |
3306 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0011)); | |
3307 ASSERT_TRUE(m.HasTag(0x7fe1, 0x0000)); | |
3308 } | |
3309 | |
3310 dicom.RemoveFromPixelData(); | |
3311 | |
3312 { | |
3313 DicomMap m; | |
3314 dicom.ExtractDicomSummary(m, 0); | |
3315 | |
3316 ASSERT_EQ(7u, m.GetSize()); | |
3317 ASSERT_TRUE(m.HasTag(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID)); | |
3318 ASSERT_TRUE(m.HasTag(DICOM_TAG_SOP_INSTANCE_UID)); | |
3319 ASSERT_TRUE(m.HasTag(DICOM_TAG_PATIENT_ID)); | |
3320 ASSERT_TRUE(m.HasTag(DICOM_TAG_SERIES_INSTANCE_UID)); | |
3321 ASSERT_TRUE(m.HasTag(DICOM_TAG_STUDY_INSTANCE_UID)); | |
3322 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0000)); | |
3323 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0009)); | |
3324 ASSERT_FALSE(m.HasTag(DICOM_TAG_PIXEL_DATA)); | |
3325 ASSERT_FALSE(m.HasTag(0x7fe0, 0x0011)); | |
3326 ASSERT_FALSE(m.HasTag(0x7fe1, 0x0000)); | |
3327 } | |
3328 } | |
3329 | |
3330 | |
3331 TEST(ParsedDicomFile, GuessPixelDataValueRepresentation) | |
3332 { | |
3333 typedef std::list< std::pair<E_TransferSyntax, DicomTransferSyntax> > Syntaxes; | |
3334 | |
3335 // Create a list of the main non-retired transfer syntaxes, from: | |
3336 // https://www.dicomlibrary.com/dicom/transfer-syntax/ | |
3337 Syntaxes compressedSyntaxes; | |
3338 compressedSyntaxes.push_back(std::make_pair(EXS_DeflatedLittleEndianExplicit, DicomTransferSyntax_DeflatedLittleEndianExplicit)); | |
3339 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess1, DicomTransferSyntax_JPEGProcess1)); | |
3340 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess2_4, DicomTransferSyntax_JPEGProcess2_4)); | |
3341 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess14, DicomTransferSyntax_JPEGProcess14)); | |
3342 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess14SV1, DicomTransferSyntax_JPEGProcess14SV1)); | |
3343 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGLSLossless, DicomTransferSyntax_JPEGLSLossless)); | |
3344 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGLSLossy, DicomTransferSyntax_JPEGLSLossy)); | |
3345 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000LosslessOnly, DicomTransferSyntax_JPEG2000LosslessOnly)); | |
3346 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000, DicomTransferSyntax_JPEG2000)); | |
3347 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000MulticomponentLosslessOnly, DicomTransferSyntax_JPEG2000MulticomponentLosslessOnly)); | |
3348 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000Multicomponent, DicomTransferSyntax_JPEG2000Multicomponent)); | |
3349 compressedSyntaxes.push_back(std::make_pair(EXS_JPIPReferenced, DicomTransferSyntax_JPIPReferenced)); | |
3350 compressedSyntaxes.push_back(std::make_pair(EXS_JPIPReferencedDeflate, DicomTransferSyntax_JPIPReferencedDeflate)); | |
3351 compressedSyntaxes.push_back(std::make_pair(EXS_RLELossless, DicomTransferSyntax_RLELossless)); | |
3352 compressedSyntaxes.push_back(std::make_pair(EXS_MPEG2MainProfileAtMainLevel, DicomTransferSyntax_MPEG2MainProfileAtMainLevel)); | |
3353 compressedSyntaxes.push_back(std::make_pair(EXS_MPEG4HighProfileLevel4_1, DicomTransferSyntax_MPEG4HighProfileLevel4_1)); | |
3354 compressedSyntaxes.push_back(std::make_pair(EXS_MPEG4BDcompatibleHighProfileLevel4_1, DicomTransferSyntax_MPEG4BDcompatibleHighProfileLevel4_1)); | |
3355 | |
3356 for (unsigned int i = 0; i < 3; i++) | |
3357 { | |
3358 unsigned int bitsAllocated; | |
3359 switch (i) | |
3360 { | |
3361 case 0: bitsAllocated = 1; break; | |
3362 case 1: bitsAllocated = 8; break; | |
3363 case 2: bitsAllocated = 16; break; | |
3364 default: | |
3365 throw OrthancException(ErrorCode_InternalError); | |
3366 } | |
3367 | |
3368 for (Syntaxes::const_iterator it = compressedSyntaxes.begin(); it != compressedSyntaxes.end(); ++it) | |
3369 { | |
3370 // All the compressed transfer syntaxes must have "OB" pixel data | |
3371 ASSERT_EQ(ValueRepresentation_OtherByte, DicomImageInformation::GuessPixelDataValueRepresentation(it->second, bitsAllocated)); | |
3372 | |
3373 { | |
3374 DicomMap dicom; | |
3375 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, boost::lexical_cast<std::string>(bitsAllocated), false); | |
3376 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(it->second)); | |
3377 } | |
3378 | |
3379 { | |
3380 DicomMap dicom; | |
3381 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(it->second)); | |
3382 } | |
3383 | |
3384 { | |
3385 ParsedDicomFile dicom(true); | |
3386 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); | |
3387 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(it->first, NULL).good()); | |
3388 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); | |
3389 DicomTransferSyntax ts; | |
3390 ASSERT_TRUE(dicom.LookupTransferSyntax(ts)); | |
3391 ASSERT_EQ(ts, it->second); | |
3392 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation()); | |
3393 } | |
3394 } | |
3395 | |
3396 { | |
3397 // Little endian implicit is always OW | |
3398 ASSERT_EQ(ValueRepresentation_OtherWord, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianImplicit, bitsAllocated)); | |
3399 | |
3400 { | |
3401 DicomMap dicom; | |
3402 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, boost::lexical_cast<std::string>(bitsAllocated), false); | |
3403 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianImplicit)); | |
3404 } | |
3405 | |
3406 { | |
3407 DicomMap dicom; | |
3408 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianImplicit)); | |
3409 } | |
3410 | |
3411 { | |
3412 ParsedDicomFile dicom(true); | |
3413 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); | |
3414 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianImplicit, NULL).good()); | |
3415 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); | |
3416 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation()); | |
3417 } | |
3418 } | |
3419 | |
3420 } | |
3421 | |
3422 // Explicit little and big endian with <= 8 bpp is OB | |
3423 | |
3424 for (unsigned int i = 0; i < 2; i++) | |
3425 { | |
3426 unsigned int bitsAllocated; | |
3427 switch (i) | |
3428 { | |
3429 case 0: bitsAllocated = 1; break; | |
3430 case 1: bitsAllocated = 8; break; | |
3431 default: | |
3432 throw OrthancException(ErrorCode_InternalError); | |
3433 } | |
3434 | |
3435 ASSERT_EQ(ValueRepresentation_OtherByte, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit, bitsAllocated)); | |
3436 ASSERT_EQ(ValueRepresentation_OtherByte, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit, bitsAllocated)); | |
3437 | |
3438 { | |
3439 DicomMap dicom; | |
3440 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, boost::lexical_cast<std::string>(bitsAllocated), false); | |
3441 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit)); | |
3442 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit)); | |
3443 } | |
3444 | |
3445 { | |
3446 DicomMap dicom; | |
3447 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit)); | |
3448 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit)); | |
3449 } | |
3450 | |
3451 { | |
3452 ParsedDicomFile dicom(true); | |
3453 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); | |
3454 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianExplicit, NULL).good()); | |
3455 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); | |
3456 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation()); | |
3457 } | |
3458 | |
3459 { | |
3460 ParsedDicomFile dicom(true); | |
3461 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good()); | |
3462 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_BigEndianExplicit, NULL).good()); | |
3463 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); | |
3464 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation()); | |
3465 } | |
3466 } | |
3467 | |
3468 // Explicit little and big endian with > 8 bpp is OW | |
3469 | |
3470 ASSERT_EQ(ValueRepresentation_OtherWord, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit, 16)); | |
3471 ASSERT_EQ(ValueRepresentation_OtherWord, DicomImageInformation::GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit, 16)); | |
3472 | |
3473 { | |
3474 DicomMap dicom; | |
3475 dicom.SetValue(DICOM_TAG_BITS_ALLOCATED, "16", false); | |
3476 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_LittleEndianExplicit)); | |
3477 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation(DicomTransferSyntax_BigEndianExplicit)); | |
3478 } | |
3479 | |
3480 { | |
3481 ParsedDicomFile dicom(true); | |
3482 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, 16).good()); | |
3483 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianExplicit, NULL).good()); | |
3484 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); | |
3485 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation()); | |
3486 } | |
3487 | |
3488 { | |
3489 ParsedDicomFile dicom(true); | |
3490 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, 16).good()); | |
3491 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_BigEndianExplicit, NULL).good()); | |
3492 dicom.GetDcmtkObject().removeAllButCurrentRepresentations(); | |
3493 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation()); | |
3494 } | |
3495 } | |
3496 | |
3497 | |
3498 #if ORTHANC_SANDBOXED != 1 | |
3499 TEST(ParsedDicomFile, DISABLED_InjectEmptyPixelData2) | |
3500 { | |
3501 static const char* PIXEL_DATA = "7FE00010"; | |
3502 | |
3503 for (int i = 0; i <= DicomTransferSyntax_XML; i++) | |
3504 { | |
3505 DicomTransferSyntax a = (DicomTransferSyntax) i; | |
3506 | |
3507 std::string path = (std::string(getenv("HOME")) + | |
3508 "/Subversion/orthanc-tests/Database/TransferSyntaxes/" + | |
3509 std::string(GetTransferSyntaxUid(a)) + ".dcm"); | |
3510 if (Orthanc::SystemToolbox::IsRegularFile(path)) | |
3511 { | |
3512 printf("\n======= %s\n", GetTransferSyntaxUid(a)); | |
3513 | |
3514 std::string source; | |
3515 Orthanc::SystemToolbox::ReadFile(source, path); | |
3516 | |
3517 ParsedDicomFile dicom(source); | |
3518 std::unique_ptr<DcmElement> removal(dicom.GetDcmtkObject().getDataset()->remove(DCM_PixelData)); | |
3519 | |
3520 { | |
3521 DicomWebJsonVisitor visitor; | |
3522 dicom.Apply(visitor); | |
3523 ASSERT_FALSE(visitor.GetResult().isMember(PIXEL_DATA)); | |
3524 } | |
3525 | |
3526 { | |
3527 DicomWebJsonVisitor visitor; | |
3528 dicom.InjectEmptyPixelData(ValueRepresentation_OtherByte); | |
3529 dicom.Apply(visitor); | |
3530 ASSERT_TRUE(visitor.GetResult().isMember(PIXEL_DATA)); | |
3531 ASSERT_EQ("OB", visitor.GetResult() [PIXEL_DATA]["vr"].asString()); | |
3532 } | |
3533 | |
3534 removal.reset(dicom.GetDcmtkObject().getDataset()->remove(DCM_PixelData)); | |
3535 | |
3536 { | |
3537 DicomWebJsonVisitor visitor; | |
3538 dicom.InjectEmptyPixelData(ValueRepresentation_OtherWord); | |
3539 dicom.Apply(visitor); | |
3540 ASSERT_TRUE(visitor.GetResult().isMember(PIXEL_DATA)); | |
3541 ASSERT_EQ("OW", visitor.GetResult() [PIXEL_DATA]["vr"].asString()); | |
3542 } | |
3543 } | |
3544 } | |
3545 } | |
3546 #endif | |
3547 | |
3220 | 3548 |
3221 | 3549 |
3222 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 | 3550 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 |
3223 | 3551 |
3224 #include "../Sources/DicomNetworking/DicomStoreUserConnection.h" | 3552 #include "../Sources/DicomNetworking/DicomStoreUserConnection.h" |
3234 scu.SetRetiredBigEndianProposed(true); | 3562 scu.SetRetiredBigEndianProposed(true); |
3235 | 3563 |
3236 DcmtkTranscoder transcoder; | 3564 DcmtkTranscoder transcoder; |
3237 | 3565 |
3238 for (int j = 0; j < 2; j++) | 3566 for (int j = 0; j < 2; j++) |
3567 { | |
3239 for (int i = 0; i <= DicomTransferSyntax_XML; i++) | 3568 for (int i = 0; i <= DicomTransferSyntax_XML; i++) |
3240 { | 3569 { |
3241 DicomTransferSyntax a = (DicomTransferSyntax) i; | 3570 DicomTransferSyntax a = (DicomTransferSyntax) i; |
3242 | 3571 |
3243 std::string path = ("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/" + | 3572 std::string path = (std::string(getenv("HOME")) + |
3573 "/Subversion/orthanc-tests/Database/TransferSyntaxes/" + | |
3244 std::string(GetTransferSyntaxUid(a)) + ".dcm"); | 3574 std::string(GetTransferSyntaxUid(a)) + ".dcm"); |
3245 if (Orthanc::SystemToolbox::IsRegularFile(path)) | 3575 if (Orthanc::SystemToolbox::IsRegularFile(path)) |
3246 { | 3576 { |
3247 printf("\n======= %s\n", GetTransferSyntaxUid(a)); | 3577 printf("\n======= %s\n", GetTransferSyntaxUid(a)); |
3248 | 3578 |
3266 throw; | 3596 throw; |
3267 } | 3597 } |
3268 } | 3598 } |
3269 } | 3599 } |
3270 } | 3600 } |
3601 } | |
3271 } | 3602 } |
3272 | 3603 |
3273 | 3604 |
3274 TEST(Toto, DISABLED_Transcode4) | 3605 TEST(Toto, DISABLED_Transcode4) |
3275 { | 3606 { |
3276 std::unique_ptr<DcmFileFormat> toto; | 3607 std::unique_ptr<DcmFileFormat> toto; |
3277 | 3608 |
3278 { | 3609 { |
3279 std::string source; | 3610 std::string source; |
3280 Orthanc::SystemToolbox::ReadFile(source, "/home/jodogne/Subversion/orthanc-tests/Database/KarstenHilbertRF.dcm"); | 3611 Orthanc::SystemToolbox::ReadFile(source, std::string(getenv("HOME")) + |
3612 "/Subversion/orthanc-tests/Database/KarstenHilbertRF.dcm"); | |
3281 toto.reset(FromDcmtkBridge::LoadFromMemoryBuffer(source.c_str(), source.size())); | 3613 toto.reset(FromDcmtkBridge::LoadFromMemoryBuffer(source.c_str(), source.size())); |
3282 } | 3614 } |
3283 | 3615 |
3284 const std::string sourceUid = IDicomTranscoder::GetSopInstanceUid(*toto); | 3616 const std::string sourceUid = IDicomTranscoder::GetSopInstanceUid(*toto); |
3285 | 3617 |