Mercurial > hg > orthanc
comparison OrthancServer/FromDcmtkBridge.cpp @ 2006:6301bbcbcaed
more generic support of value representations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 09 Jun 2016 14:48:40 +0200 |
parents | 9b61701c35f2 |
children | 655489d9165d |
comparison
equal
deleted
inserted
replaced
2005:9e021b2b348b | 2006:6301bbcbcaed |
---|---|
35 #ifndef NOMINMAX | 35 #ifndef NOMINMAX |
36 #define NOMINMAX | 36 #define NOMINMAX |
37 #endif | 37 #endif |
38 | 38 |
39 #include "FromDcmtkBridge.h" | 39 #include "FromDcmtkBridge.h" |
40 #include "ToDcmtkBridge.h" | |
40 #include "../Core/Logging.h" | 41 #include "../Core/Logging.h" |
41 #include "../Core/Toolbox.h" | 42 #include "../Core/Toolbox.h" |
42 #include "../Core/Uuid.h" | 43 #include "../Core/Uuid.h" |
43 #include "../Core/OrthancException.h" | 44 #include "../Core/OrthancException.h" |
44 | 45 |
230 } | 231 } |
231 } | 232 } |
232 | 233 |
233 | 234 |
234 void FromDcmtkBridge::RegisterDictionaryTag(const DicomTag& tag, | 235 void FromDcmtkBridge::RegisterDictionaryTag(const DicomTag& tag, |
235 const DcmEVR& vr, | 236 ValueRepresentation vr, |
236 const std::string& name, | 237 const std::string& name, |
237 unsigned int minMultiplicity, | 238 unsigned int minMultiplicity, |
238 unsigned int maxMultiplicity) | 239 unsigned int maxMultiplicity) |
239 { | 240 { |
240 if (minMultiplicity < 1) | 241 if (minMultiplicity < 1) |
251 else if (maxMultiplicity < minMultiplicity) | 252 else if (maxMultiplicity < minMultiplicity) |
252 { | 253 { |
253 throw OrthancException(ErrorCode_ParameterOutOfRange); | 254 throw OrthancException(ErrorCode_ParameterOutOfRange); |
254 } | 255 } |
255 | 256 |
256 LOG(INFO) << "Registering tag in dictionary: " << tag << " " << (DcmVR(vr).getValidVRName()) << " " | 257 DcmEVR evr = ToDcmtkBridge::Convert(vr); |
258 | |
259 LOG(INFO) << "Registering tag in dictionary: " << tag << " " << (DcmVR(evr).getValidVRName()) << " " | |
257 << name << " (multiplicity: " << minMultiplicity << "-" | 260 << name << " (multiplicity: " << minMultiplicity << "-" |
258 << (arbitrary ? "n" : boost::lexical_cast<std::string>(maxMultiplicity)) << ")"; | 261 << (arbitrary ? "n" : boost::lexical_cast<std::string>(maxMultiplicity)) << ")"; |
259 | 262 |
260 std::auto_ptr<DcmDictEntry> entry(new DcmDictEntry(tag.GetGroup(), | 263 std::auto_ptr<DcmDictEntry> entry(new DcmDictEntry(tag.GetGroup(), |
261 tag.GetElement(), | 264 tag.GetElement(), |
262 vr, name.c_str(), | 265 evr, name.c_str(), |
263 static_cast<int>(minMultiplicity), | 266 static_cast<int>(minMultiplicity), |
264 static_cast<int>(maxMultiplicity), | 267 static_cast<int>(maxMultiplicity), |
265 NULL /* version */, | 268 NULL /* version */, |
266 OFTrue /* doCopyString */, | 269 OFTrue /* doCopyString */, |
267 NULL /* private creator */)); | 270 NULL /* private creator */)); |
1067 return false; | 1070 return false; |
1068 } | 1071 } |
1069 } | 1072 } |
1070 | 1073 |
1071 | 1074 |
1072 ValueRepresentation FromDcmtkBridge::GetValueRepresentation(const DicomTag& tag) | 1075 ValueRepresentation FromDcmtkBridge::LookupValueRepresentation(const DicomTag& tag) |
1073 { | 1076 { |
1074 DcmTag t(tag.GetGroup(), tag.GetElement()); | 1077 DcmTag t(tag.GetGroup(), tag.GetElement()); |
1075 switch (t.getEVR()) | 1078 return Convert(t.getEVR()); |
1076 { | 1079 } |
1080 | |
1081 ValueRepresentation FromDcmtkBridge::Convert(const DcmEVR vr) | |
1082 { | |
1083 switch (vr) | |
1084 { | |
1085 case EVR_AE: | |
1086 return ValueRepresentation_ApplicationEntity; | |
1087 | |
1088 case EVR_AS: | |
1089 return ValueRepresentation_AgeString; | |
1090 | |
1091 case EVR_AT: | |
1092 return ValueRepresentation_AttributeTag; | |
1093 | |
1094 case EVR_CS: | |
1095 return ValueRepresentation_CodeString; | |
1096 | |
1097 case EVR_DA: | |
1098 return ValueRepresentation_Date; | |
1099 | |
1100 case EVR_DS: | |
1101 return ValueRepresentation_DecimalString; | |
1102 | |
1103 case EVR_DT: | |
1104 return ValueRepresentation_DateTime; | |
1105 | |
1106 case EVR_FL: | |
1107 return ValueRepresentation_FloatingPointSingle; | |
1108 | |
1109 case EVR_FD: | |
1110 return ValueRepresentation_FloatingPointDouble; | |
1111 | |
1112 case EVR_IS: | |
1113 return ValueRepresentation_IntegerString; | |
1114 | |
1115 case EVR_LO: | |
1116 return ValueRepresentation_LongString; | |
1117 | |
1118 case EVR_LT: | |
1119 return ValueRepresentation_LongText; | |
1120 | |
1121 case EVR_OB: | |
1122 return ValueRepresentation_OtherByte; | |
1123 | |
1124 // Not supported as of DCMTK 3.6.0 | |
1125 /*case EVR_OD: | |
1126 return ValueRepresentation_OtherDouble;*/ | |
1127 | |
1128 case EVR_OF: | |
1129 return ValueRepresentation_OtherFloat; | |
1130 | |
1131 // Not supported as of DCMTK 3.6.0 | |
1132 /*case EVR_OL: | |
1133 return ValueRepresentation_OtherLong;*/ | |
1134 | |
1135 case EVR_OW: | |
1136 return ValueRepresentation_OtherWord; | |
1137 | |
1077 case EVR_PN: | 1138 case EVR_PN: |
1078 return ValueRepresentation_PatientName; | 1139 return ValueRepresentation_PatientName; |
1079 | 1140 |
1080 case EVR_DA: | 1141 case EVR_SH: |
1081 return ValueRepresentation_Date; | 1142 return ValueRepresentation_ShortString; |
1082 | 1143 |
1083 case EVR_DT: | 1144 case EVR_SL: |
1084 return ValueRepresentation_DateTime; | 1145 return ValueRepresentation_SignedLong; |
1146 | |
1147 case EVR_SQ: | |
1148 return ValueRepresentation_Sequence; | |
1149 | |
1150 case EVR_SS: | |
1151 return ValueRepresentation_SignedShort; | |
1152 | |
1153 case EVR_ST: | |
1154 return ValueRepresentation_ShortText; | |
1085 | 1155 |
1086 case EVR_TM: | 1156 case EVR_TM: |
1087 return ValueRepresentation_Time; | 1157 return ValueRepresentation_Time; |
1088 | 1158 |
1089 case EVR_SQ: | 1159 // Not supported as of DCMTK 3.6.0 |
1090 return ValueRepresentation_Sequence; | 1160 /*case EVR_UC: |
1161 return ValueRepresentation_UnlimitedCharacters;*/ | |
1162 | |
1163 case EVR_UI: | |
1164 return ValueRepresentation_UniqueIdentifier; | |
1165 | |
1166 case EVR_UL: | |
1167 return ValueRepresentation_UnsignedLong; | |
1168 | |
1169 case EVR_UN: | |
1170 return ValueRepresentation_Unknown; | |
1171 | |
1172 // Not supported as of DCMTK 3.6.0 | |
1173 /*case EVR_UR: | |
1174 return ValueRepresentation_UniversalResource;*/ | |
1175 | |
1176 case EVR_US: | |
1177 return ValueRepresentation_UnsignedShort; | |
1178 | |
1179 case EVR_UT: | |
1180 return ValueRepresentation_UnlimitedText; | |
1091 | 1181 |
1092 default: | 1182 default: |
1093 return ValueRepresentation_Other; | 1183 return ValueRepresentation_NotSupported; |
1094 } | 1184 } |
1095 } | 1185 } |
1096 | 1186 |
1097 | 1187 |
1098 static bool IsBinaryTag(const DcmTag& key) | 1188 static bool IsBinaryTag(const DcmTag& key) |
1475 | 1565 |
1476 return element.release(); | 1566 return element.release(); |
1477 } | 1567 } |
1478 | 1568 |
1479 | 1569 |
1480 DcmEVR FromDcmtkBridge::ParseValueRepresentation(const std::string& s) | |
1481 { | |
1482 if (s == "AE") | |
1483 return EVR_AE; | |
1484 | |
1485 if (s == "AS") | |
1486 return EVR_AS; | |
1487 | |
1488 if (s == "AT") | |
1489 return EVR_AT; | |
1490 | |
1491 if (s == "CS") | |
1492 return EVR_CS; | |
1493 | |
1494 if (s == "DA") | |
1495 return EVR_DA; | |
1496 | |
1497 if (s == "DS") | |
1498 return EVR_DS; | |
1499 | |
1500 if (s == "DT") | |
1501 return EVR_DT; | |
1502 | |
1503 if (s == "FD") | |
1504 return EVR_FD; | |
1505 | |
1506 if (s == "FL") | |
1507 return EVR_FL; | |
1508 | |
1509 if (s == "IS") | |
1510 return EVR_IS; | |
1511 | |
1512 if (s == "LO") | |
1513 return EVR_LO; | |
1514 | |
1515 if (s == "LT") | |
1516 return EVR_LT; | |
1517 | |
1518 if (s == "OB") | |
1519 return EVR_OB; | |
1520 | |
1521 if (s == "OF") | |
1522 return EVR_OF; | |
1523 | |
1524 if (s == "OW") | |
1525 return EVR_OW; | |
1526 | |
1527 if (s == "PN") | |
1528 return EVR_PN; | |
1529 | |
1530 if (s == "SH") | |
1531 return EVR_SH; | |
1532 | |
1533 if (s == "SL") | |
1534 return EVR_SL; | |
1535 | |
1536 if (s == "SQ") | |
1537 return EVR_SQ; | |
1538 | |
1539 if (s == "SS") | |
1540 return EVR_SS; | |
1541 | |
1542 if (s == "ST") | |
1543 return EVR_ST; | |
1544 | |
1545 if (s == "TM") | |
1546 return EVR_TM; | |
1547 | |
1548 if (s == "UI") | |
1549 return EVR_UI; | |
1550 | |
1551 if (s == "UL") | |
1552 return EVR_UL; | |
1553 | |
1554 if (s == "UN") | |
1555 return EVR_UN; | |
1556 | |
1557 if (s == "US") | |
1558 return EVR_US; | |
1559 | |
1560 if (s == "UT") | |
1561 return EVR_UT; | |
1562 | |
1563 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1564 } | |
1565 | |
1566 | |
1567 DcmPixelSequence* FromDcmtkBridge::GetPixelSequence(DcmDataset& dataset) | 1570 DcmPixelSequence* FromDcmtkBridge::GetPixelSequence(DcmDataset& dataset) |
1568 { | 1571 { |
1569 DcmElement *element = NULL; | 1572 DcmElement *element = NULL; |
1570 if (!dataset.findAndGetElement(DCM_PixelData, element).good()) | 1573 if (!dataset.findAndGetElement(DCM_PixelData, element).good()) |
1571 { | 1574 { |