comparison Plugin/DecodedImageAdapter.cpp @ 99:46ec13a1177c refactoring

use of ordered-slices
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Nov 2015 21:39:41 +0100
parents ef1b27ba7dfc
children 2932473a9b19
comparison
equal deleted inserted replaced
98:745cc19aa32b 99:46ec13a1177c
28 #include "ViewerToolbox.h" 28 #include "ViewerToolbox.h"
29 29
30 #include <boost/lexical_cast.hpp> 30 #include <boost/lexical_cast.hpp>
31 #include <boost/algorithm/string/predicate.hpp> 31 #include <boost/algorithm/string/predicate.hpp>
32 #include <json/writer.h> 32 #include <json/writer.h>
33 #include <boost/regex.hpp>
33 34
34 namespace OrthancPlugins 35 namespace OrthancPlugins
35 { 36 {
36 bool DecodedImageAdapter::ParseUri(CompressionType& type, 37 bool DecodedImageAdapter::ParseUri(CompressionType& type,
37 uint8_t& compressionLevel, 38 uint8_t& compressionLevel,
38 std::string& instanceId, 39 std::string& instanceId,
40 unsigned int& frameIndex,
39 const std::string& uri) 41 const std::string& uri)
40 { 42 {
41 size_t separator = uri.find('-'); 43 boost::regex pattern("^([a-z0-9]+)-([a-z0-9-]+)_([0-9]+)$");
42 if (separator == std::string::npos && 44
43 separator >= 1) 45 boost::cmatch what;
44 { 46 if (!regex_match(uri.c_str(), what, pattern))
45 return false; 47 {
46 } 48 return false;
47 49 }
48 std::string compression = uri.substr(0, separator); 50
49 instanceId = uri.substr(separator + 1); 51 printf("[%s] [%s] [%s]\n", what[1].str().c_str(), what[2].str().c_str(), what[3].str().c_str());
52
53 std::string compression(what[1]);
54 instanceId = what[2];
55 frameIndex = boost::lexical_cast<unsigned int>(what[3]);
50 56
51 if (compression == "deflate") 57 if (compression == "deflate")
52 { 58 {
53 type = CompressionType_Deflate; 59 type = CompressionType_Deflate;
54 } 60 }
80 OrthancPluginLogInfo(context_, message.c_str()); 86 OrthancPluginLogInfo(context_, message.c_str());
81 87
82 CompressionType type; 88 CompressionType type;
83 uint8_t level; 89 uint8_t level;
84 std::string instanceId; 90 std::string instanceId;
91 unsigned int frameIndex;
85 92
86 if (!ParseUri(type, level, instanceId, uri)) 93 if (!ParseUri(type, level, instanceId, frameIndex, uri))
87 { 94 {
88 return false; 95 return false;
89 } 96 }
90 97
91 98
97 !GetJsonFromOrthanc(tags, context_, "/instances/" + instanceId + "/tags")) 104 !GetJsonFromOrthanc(tags, context_, "/instances/" + instanceId + "/tags"))
98 { 105 {
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); 106 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
100 } 107 }
101 108
102 std::auto_ptr<OrthancImageWrapper> image(decoderCache_.Decode(context_, dicom.c_str(), dicom.size(), 0 /* TODO Frame */)); 109 std::auto_ptr<OrthancImageWrapper> image(decoderCache_.Decode(context_, dicom.c_str(), dicom.size(), frameIndex));
103 110
104 Json::Value json; 111 Json::Value json;
105 if (GetCornerstoneMetadata(json, tags, *image)) 112 if (GetCornerstoneMetadata(json, tags, *image))
106 { 113 {
107 if (type == CompressionType_Deflate) 114 if (type == CompressionType_Deflate)