Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/DicomMapTests.cpp @ 5316:03501a258d9e
added instance metadata "PixelDataVR"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 22 Jun 2023 08:48:38 +0200 |
parents | 887df8c45838 |
children | 48b8dae6dc77 |
comparison
equal
deleted
inserted
replaced
5315:592507a8e227 | 5316:03501a258d9e |
---|---|
40 #include "../Sources/DicomParsing/ToDcmtkBridge.h" | 40 #include "../Sources/DicomParsing/ToDcmtkBridge.h" |
41 #include "../Sources/DicomParsing/ParsedDicomFile.h" | 41 #include "../Sources/DicomParsing/ParsedDicomFile.h" |
42 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" | 42 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" |
43 | 43 |
44 #include <boost/lexical_cast.hpp> | 44 #include <boost/lexical_cast.hpp> |
45 #include <boost/tuple/tuple.hpp> | |
45 | 46 |
46 using namespace Orthanc; | 47 using namespace Orthanc; |
47 | 48 |
48 | 49 |
49 namespace Orthanc | 50 namespace Orthanc |
1286 | 1287 |
1287 TEST(DicomStreamReader, DISABLED_Tutu) | 1288 TEST(DicomStreamReader, DISABLED_Tutu) |
1288 { | 1289 { |
1289 static const std::string PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/"; | 1290 static const std::string PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/"; |
1290 | 1291 |
1291 typedef std::list< std::pair<std::string, uint64_t> > Sources; | 1292 typedef boost::tuple<std::string, uint64_t, ValueRepresentation> Source; |
1293 typedef std::list<Source> Sources; | |
1294 | |
1295 // $ ~/Subversion/orthanc-tests/Tests/GetPixelDataVR.py ~/Subversion/orthanc-tests/Database/ColorTestMalaterre.dcm ~/Subversion/orthanc-tests/Database/ColorTestImageJ.dcm ~/Subversion/orthanc-tests/Database/Knee/T1/IM-0001-0001.dcm ~/Subversion/orthanc-tests/Database/TransferSyntaxes/*.dcm | |
1292 | 1296 |
1293 Sources sources; | 1297 Sources sources; |
1294 sources.push_back(std::make_pair(PATH + "../ColorTestMalaterre.dcm", 0x03a0u)); | 1298 sources.push_back(Source(PATH + "../ColorTestMalaterre.dcm", 0x03a0u, ValueRepresentation_Unknown)); // This file has strange VR |
1295 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.1.dcm", 0x037cu)); | 1299 sources.push_back(Source(PATH + "../ColorTestImageJ.dcm", 0x00924, ValueRepresentation_OtherByte)); |
1296 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.2.dcm", 0x03e8u)); // Big Endian | 1300 sources.push_back(Source(PATH + "../Knee/T1/IM-0001-0001.dcm", 0x00c78, ValueRepresentation_OtherWord)); |
1297 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.50.dcm", 0x04acu)); | 1301 sources.push_back(Source(PATH + "1.2.840.10008.1.2.1.dcm", 0x037cu, ValueRepresentation_OtherByte)); |
1298 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.51.dcm", 0x072cu)); | 1302 sources.push_back(Source(PATH + "1.2.840.10008.1.2.2.dcm", 0x03e8u, ValueRepresentation_OtherByte)); // Big Endian |
1299 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.57.dcm", 0x0620u)); | 1303 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.50.dcm", 0x04acu, ValueRepresentation_OtherByte)); |
1300 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.70.dcm", 0x065au)); | 1304 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.51.dcm", 0x072cu, ValueRepresentation_OtherByte)); |
1301 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.80.dcm", 0x0b46u)); | 1305 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.57.dcm", 0x0620u, ValueRepresentation_OtherByte)); |
1302 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.81.dcm", 0x073eu)); | 1306 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.70.dcm", 0x065au, ValueRepresentation_OtherByte)); |
1303 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.90.dcm", 0x0b66u)); | 1307 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.80.dcm", 0x0b46u, ValueRepresentation_OtherByte)); |
1304 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.4.91.dcm", 0x19b8u)); | 1308 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.81.dcm", 0x073eu, ValueRepresentation_OtherByte)); |
1305 sources.push_back(std::make_pair(PATH + "1.2.840.10008.1.2.5.dcm", 0x0b0au)); | 1309 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.90.dcm", 0x0b66u, ValueRepresentation_OtherByte)); |
1310 sources.push_back(Source(PATH + "1.2.840.10008.1.2.4.91.dcm", 0x19b8u, ValueRepresentation_OtherByte)); | |
1311 sources.push_back(Source(PATH + "1.2.840.10008.1.2.5.dcm", 0x0b0au, ValueRepresentation_OtherByte)); | |
1306 | 1312 |
1307 { | 1313 { |
1308 std::string dicom; | 1314 std::string dicom; |
1309 | 1315 |
1310 uint64_t offset; | 1316 uint64_t offset; |
1317 ValueRepresentation vr; | |
1318 | |
1311 // Not a DICOM image | 1319 // Not a DICOM image |
1312 SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.50.png", false); | 1320 SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.4.50.png", false); |
1313 ASSERT_FALSE(DicomStreamReader::LookupPixelDataOffset(offset, dicom)); | 1321 ASSERT_FALSE(DicomStreamReader::LookupPixelDataOffset(offset, vr, dicom)); |
1314 | 1322 |
1315 // Image without valid DICOM preamble | 1323 // Image without valid DICOM preamble |
1316 SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.dcm", false); | 1324 SystemToolbox::ReadFile(dicom, PATH + "1.2.840.10008.1.2.dcm", false); |
1317 ASSERT_FALSE(DicomStreamReader::LookupPixelDataOffset(offset, dicom)); | 1325 ASSERT_FALSE(DicomStreamReader::LookupPixelDataOffset(offset, vr, dicom)); |
1318 } | 1326 } |
1319 | 1327 |
1320 for (Sources::const_iterator it = sources.begin(); it != sources.end(); ++it) | 1328 for (Sources::const_iterator it = sources.begin(); it != sources.end(); ++it) |
1321 { | 1329 { |
1322 std::string dicom; | 1330 std::string dicom; |
1323 SystemToolbox::ReadFile(dicom, it->first, false); | 1331 SystemToolbox::ReadFile(dicom, it->get<0>(), false); |
1324 | 1332 |
1325 { | 1333 { |
1326 uint64_t offset; | 1334 uint64_t offset; |
1327 ASSERT_TRUE(DicomStreamReader::LookupPixelDataOffset(offset, dicom)); | 1335 ValueRepresentation vr; |
1328 ASSERT_EQ(it->second, offset); | 1336 ASSERT_TRUE(DicomStreamReader::LookupPixelDataOffset(offset, vr, dicom)); |
1337 ASSERT_EQ(it->get<1>(), offset); | |
1338 ASSERT_EQ(it->get<2>(), vr); | |
1329 } | 1339 } |
1330 | 1340 |
1331 { | 1341 { |
1332 uint64_t offset; | 1342 uint64_t offset; |
1333 ASSERT_TRUE(DicomStreamReader::LookupPixelDataOffset(offset, dicom.c_str(), dicom.size())); | 1343 ValueRepresentation vr; |
1334 ASSERT_EQ(it->second, offset); | 1344 ASSERT_TRUE(DicomStreamReader::LookupPixelDataOffset(offset, vr, dicom.c_str(), dicom.size())); |
1345 ASSERT_EQ(it->get<1>(), offset); | |
1346 ASSERT_EQ(it->get<2>(), vr); | |
1335 } | 1347 } |
1336 | 1348 |
1337 ParsedDicomFile a(dicom); | 1349 ParsedDicomFile a(dicom); |
1338 Json::Value aa; | 1350 Json::Value aa; |
1339 a.DatasetToJson(aa, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0); | 1351 a.DatasetToJson(aa, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0); |
1353 stream.put(dicom[pos++]); | 1365 stream.put(dicom[pos++]); |
1354 } | 1366 } |
1355 | 1367 |
1356 r.Consume(visitor); | 1368 r.Consume(visitor); |
1357 | 1369 |
1358 ASSERT_EQ(it->second, visitor.GetPixelDataOffset()); | 1370 ASSERT_EQ(it->get<1>(), visitor.GetPixelDataOffset()); |
1359 | 1371 |
1360 // Truncate the original DICOM up to pixel data | 1372 // Truncate the original DICOM up to pixel data |
1361 dicom.resize(visitor.GetPixelDataOffset()); | 1373 dicom.resize(visitor.GetPixelDataOffset()); |
1362 | 1374 |
1363 ParsedDicomFile b(dicom); | 1375 ParsedDicomFile b(dicom); |