Mercurial > hg > orthanc
comparison Core/DicomParsing/FromDcmtkBridge.cpp @ 3198:7724ed267b5c
unit testing dicomweb conversion
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Feb 2019 07:28:58 +0100 |
parents | 880e4161c312 |
children | 9316f341e40f |
comparison
equal
deleted
inserted
replaced
3197:24a76ed0d8a3 | 3198:7724ed267b5c |
---|---|
1287 return ValueRepresentation_LongText; | 1287 return ValueRepresentation_LongText; |
1288 | 1288 |
1289 case EVR_OB: | 1289 case EVR_OB: |
1290 return ValueRepresentation_OtherByte; | 1290 return ValueRepresentation_OtherByte; |
1291 | 1291 |
1292 // Not supported as of DCMTK 3.6.0 | 1292 #if DCMTK_VERSION_NUMBER >= 362 |
1293 /*case EVR_OD: | 1293 case EVR_OD: |
1294 return ValueRepresentation_OtherDouble;*/ | 1294 return ValueRepresentation_OtherDouble; |
1295 #endif | |
1295 | 1296 |
1296 case EVR_OF: | 1297 case EVR_OF: |
1297 return ValueRepresentation_OtherFloat; | 1298 return ValueRepresentation_OtherFloat; |
1298 | 1299 |
1299 // Not supported as of DCMTK 3.6.0 | 1300 #if DCMTK_VERSION_NUMBER >= 362 |
1300 /*case EVR_OL: | 1301 case EVR_OL: |
1301 return ValueRepresentation_OtherLong;*/ | 1302 return ValueRepresentation_OtherLong; |
1303 #endif | |
1302 | 1304 |
1303 case EVR_OW: | 1305 case EVR_OW: |
1304 return ValueRepresentation_OtherWord; | 1306 return ValueRepresentation_OtherWord; |
1305 | 1307 |
1306 case EVR_PN: | 1308 case EVR_PN: |
1322 return ValueRepresentation_ShortText; | 1324 return ValueRepresentation_ShortText; |
1323 | 1325 |
1324 case EVR_TM: | 1326 case EVR_TM: |
1325 return ValueRepresentation_Time; | 1327 return ValueRepresentation_Time; |
1326 | 1328 |
1327 // Not supported as of DCMTK 3.6.0 | 1329 #if DCMTK_VERSION_NUMBER >= 362 |
1328 /*case EVR_UC: | 1330 case EVR_UC: |
1329 return ValueRepresentation_UnlimitedCharacters;*/ | 1331 return ValueRepresentation_UnlimitedCharacters; |
1332 #endif | |
1330 | 1333 |
1331 case EVR_UI: | 1334 case EVR_UI: |
1332 return ValueRepresentation_UniqueIdentifier; | 1335 return ValueRepresentation_UniqueIdentifier; |
1333 | 1336 |
1334 case EVR_UL: | 1337 case EVR_UL: |
1335 return ValueRepresentation_UnsignedLong; | 1338 return ValueRepresentation_UnsignedLong; |
1336 | 1339 |
1337 case EVR_UN: | 1340 case EVR_UN: |
1338 return ValueRepresentation_Unknown; | 1341 return ValueRepresentation_Unknown; |
1339 | 1342 |
1340 // Not supported as of DCMTK 3.6.0 | 1343 #if DCMTK_VERSION_NUMBER >= 362 |
1341 /*case EVR_UR: | 1344 case EVR_UR: |
1342 return ValueRepresentation_UniversalResource;*/ | 1345 return ValueRepresentation_UniversalResource; |
1346 #endif | |
1343 | 1347 |
1344 case EVR_US: | 1348 case EVR_US: |
1345 return ValueRepresentation_UnsignedShort; | 1349 return ValueRepresentation_UnsignedShort; |
1346 | 1350 |
1347 case EVR_UT: | 1351 case EVR_UT: |
2162 const std::vector<DicomTag>& parentTags, | 2166 const std::vector<DicomTag>& parentTags, |
2163 const std::vector<size_t>& parentIndexes, | 2167 const std::vector<size_t>& parentIndexes, |
2164 const DicomTag& tag, | 2168 const DicomTag& tag, |
2165 Encoding encoding) | 2169 Encoding encoding) |
2166 { | 2170 { |
2167 // TODO - Merge this function with ConvertLeafElement() | 2171 // TODO - Merge this function, that is more recent, with ConvertLeafElement() |
2168 | 2172 |
2169 assert(element.isLeaf()); | 2173 assert(element.isLeaf()); |
2170 | 2174 |
2171 DcmEVR evr = element.getTag().getEVR(); | 2175 DcmEVR evr = element.getTag().getEVR(); |
2172 ValueRepresentation vr = FromDcmtkBridge::Convert(evr); | 2176 |
2177 | |
2178 /** | |
2179 * Fix the EVR for types internal to DCMTK | |
2180 **/ | |
2181 | |
2182 if (evr == EVR_ox) // OB or OW depending on context | |
2183 { | |
2184 evr = EVR_OB; | |
2185 } | |
2186 | |
2187 if (evr == EVR_UNKNOWN || // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | |
2188 evr == EVR_UNKNOWN2B) // used internally for elements with unknown VR with 2-byte length field in explicit VR | |
2189 { | |
2190 evr = EVR_UN; | |
2191 } | |
2192 | |
2193 const ValueRepresentation vr = FromDcmtkBridge::Convert(evr); | |
2194 | |
2195 | |
2196 /** | |
2197 * Deal with binary data (including PixelData). | |
2198 **/ | |
2199 | |
2200 if (evr == EVR_OB || // other byte | |
2201 evr == EVR_OF || // other float | |
2202 #if DCMTK_VERSION_NUMBER >= 362 | |
2203 evr == EVR_OD || // other double | |
2204 evr == EVR_OL || // other long | |
2205 #endif | |
2206 evr == EVR_OW || // other word | |
2207 evr == EVR_UN) // unknown value representation | |
2208 { | |
2209 Uint8* data = NULL; | |
2210 | |
2211 if (element.getUint8Array(data) == EC_Normal) | |
2212 { | |
2213 visitor.VisitBinary(parentTags, parentIndexes, tag, vr, data, element.getLength()); | |
2214 } | |
2215 else | |
2216 { | |
2217 visitor.VisitNotSupported(parentTags, parentIndexes, tag, vr); | |
2218 } | |
2219 | |
2220 return; // We're done | |
2221 } | |
2222 | |
2223 | |
2224 /** | |
2225 * Deal with plain strings (and convert them to UTF-8) | |
2226 **/ | |
2173 | 2227 |
2174 char *c = NULL; | 2228 char *c = NULL; |
2175 if (element.isaString() && | 2229 if (element.isaString() && |
2176 element.getString(c).good()) | 2230 element.getString(c).good()) |
2177 { | 2231 { |
2213 | 2267 |
2214 | 2268 |
2215 try | 2269 try |
2216 { | 2270 { |
2217 // http://support.dcmtk.org/docs/dcvr_8h-source.html | 2271 // http://support.dcmtk.org/docs/dcvr_8h-source.html |
2218 switch (element.getVR()) | 2272 switch (evr) |
2219 { | 2273 { |
2220 | 2274 |
2221 /** | 2275 /** |
2222 * Deal with binary data (including PixelData). | 2276 * Plain string values. |
2223 **/ | 2277 **/ |
2224 | 2278 |
2225 case EVR_OB: // other byte | |
2226 case EVR_OF: // other float | |
2227 case EVR_OW: // other word | |
2228 case EVR_UN: // unknown value representation | |
2229 case EVR_ox: // OB or OW depending on context | |
2230 case EVR_DS: // decimal string | 2279 case EVR_DS: // decimal string |
2231 case EVR_IS: // integer string | 2280 case EVR_IS: // integer string |
2232 case EVR_AS: // age string | 2281 case EVR_AS: // age string |
2233 case EVR_DA: // date string | 2282 case EVR_DA: // date string |
2234 case EVR_DT: // date time string | 2283 case EVR_DT: // date time string |
2240 case EVR_ST: // short text | 2289 case EVR_ST: // short text |
2241 case EVR_LT: // long text | 2290 case EVR_LT: // long text |
2242 case EVR_UT: // unlimited text | 2291 case EVR_UT: // unlimited text |
2243 case EVR_PN: // person name | 2292 case EVR_PN: // person name |
2244 case EVR_UI: // unique identifier | 2293 case EVR_UI: // unique identifier |
2245 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | |
2246 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR | |
2247 { | 2294 { |
2248 Uint8* data = NULL; | 2295 Uint8* data = NULL; |
2249 | 2296 |
2250 if (element.getUint8Array(data) == EC_Normal) | 2297 if (element.getUint8Array(data) == EC_Normal) |
2251 { | 2298 { |
2252 visitor.VisitBinary(parentTags, parentIndexes, tag, vr, data, element.getLength()); | 2299 const Uint32 length = element.getLength(); |
2300 Uint32 l = 0; | |
2301 while (l < length && | |
2302 data[l] != 0) | |
2303 { | |
2304 l++; | |
2305 } | |
2306 | |
2307 if (l == length) | |
2308 { | |
2309 // Not a null-terminated plain string | |
2310 visitor.VisitNotSupported(parentTags, parentIndexes, tag, vr); | |
2311 } | |
2312 else | |
2313 { | |
2314 std::string ignored; | |
2315 std::string s(reinterpret_cast<const char*>(data), l); | |
2316 ITagVisitor::Action action = visitor.VisitString | |
2317 (ignored, parentTags, parentIndexes, tag, vr, | |
2318 Toolbox::ConvertToUtf8(s, encoding)); | |
2319 | |
2320 if (action != ITagVisitor::Action_None) | |
2321 { | |
2322 LOG(WARNING) << "Cannot replace this string tag: " | |
2323 << FromDcmtkBridge::GetTagName(element) | |
2324 << " (" << tag.Format() << ")"; | |
2325 } | |
2326 } | |
2253 } | 2327 } |
2254 else | 2328 else |
2255 { | 2329 { |
2256 visitor.VisitNotSupported(parentTags, parentIndexes, tag, vr); | 2330 visitor.VisitNotSupported(parentTags, parentIndexes, tag, vr); |
2257 } | 2331 } |
2258 | 2332 |
2259 break; | 2333 return; |
2260 } | 2334 } |
2261 | 2335 |
2262 /** | 2336 /** |
2263 * Numeric types | 2337 * Numeric types |
2264 **/ | 2338 **/ |
2415 * Sequence types, should never occur at this point because of | 2489 * Sequence types, should never occur at this point because of |
2416 * "element.isLeaf()". | 2490 * "element.isLeaf()". |
2417 **/ | 2491 **/ |
2418 | 2492 |
2419 case EVR_SQ: // sequence of items | 2493 case EVR_SQ: // sequence of items |
2494 { | |
2420 return; | 2495 return; |
2421 | 2496 } |
2422 | 2497 |
2423 /** | 2498 |
2424 * Internal to DCMTK. | 2499 /** |
2425 **/ | 2500 * Internal to DCMTK. |
2501 **/ | |
2426 | 2502 |
2427 case EVR_xs: // SS or US depending on context | 2503 case EVR_xs: // SS or US depending on context |
2428 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) | 2504 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) |
2429 case EVR_na: // na="not applicable", for data which has no VR | 2505 case EVR_na: // na="not applicable", for data which has no VR |
2430 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor | 2506 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor |
2436 case EVR_dirRecord: // used internally for DICOMDIR records | 2512 case EVR_dirRecord: // used internally for DICOMDIR records |
2437 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image | 2513 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image |
2438 case EVR_pixelItem: // used internally for pixel items in a compressed image | 2514 case EVR_pixelItem: // used internally for pixel items in a compressed image |
2439 case EVR_PixelData: // used internally for uncompressed pixeld data | 2515 case EVR_PixelData: // used internally for uncompressed pixeld data |
2440 case EVR_OverlayData: // used internally for overlay data | 2516 case EVR_OverlayData: // used internally for overlay data |
2517 { | |
2441 visitor.VisitNotSupported(parentTags, parentIndexes, tag, vr); | 2518 visitor.VisitNotSupported(parentTags, parentIndexes, tag, vr); |
2442 return; | 2519 return; |
2443 | 2520 } |
2444 | 2521 |
2445 /** | 2522 |
2446 * Default case. | 2523 /** |
2447 **/ | 2524 * Default case. |
2525 **/ | |
2448 | 2526 |
2449 default: | 2527 default: |
2450 return; | 2528 return; |
2451 } | 2529 } |
2452 } | 2530 } |