Mercurial > hg > orthanc
comparison OrthancServer/DicomInstanceToStore.cpp @ 1004:a226e0959d8b lua-scripting
DicomInstanceToStore
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Jul 2014 14:06:05 +0200 |
parents | 1d35281d967c |
children | 84b6d7bca6db |
comparison
equal
deleted
inserted
replaced
1003:1d35281d967c | 1004:a226e0959d8b |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "DicomInstanceToStore.h" | 33 #include "DicomInstanceToStore.h" |
34 | 34 |
35 #include "FromDcmtkBridge.h" | |
36 | |
37 #include <dcmtk/dcmdata/dcfilefo.h> | |
38 #include <glog/logging.h> | |
39 | |
40 | |
35 namespace Orthanc | 41 namespace Orthanc |
36 { | 42 { |
37 DicomInstanceToStore::DicomInstanceToStore() : | 43 static DcmDataset& GetDataset(ParsedDicomFile& file) |
38 hasBuffer_(false), | |
39 parsed_(NULL), | |
40 summary_(NULL), | |
41 json_(NULL) | |
42 { | 44 { |
43 } | 45 return *reinterpret_cast<DcmFileFormat*>(file.GetDcmtkObject())->getDataset(); |
44 | |
45 void DicomInstanceToStore::SetBuffer(const std::string& dicom) | |
46 { | |
47 hasBuffer_ = true; | |
48 bufferSize_ = dicom.size(); | |
49 | |
50 if (dicom.size() == 0) | |
51 { | |
52 buffer_ = NULL; | |
53 } | |
54 else | |
55 { | |
56 buffer_ = &dicom[0]; | |
57 } | |
58 } | 46 } |
59 | 47 |
60 | 48 |
61 void DicomInstanceToStore::SetBuffer(const char* buffer, | 49 void DicomInstanceToStore::AddMetadata(ResourceType level, |
62 size_t size) | |
63 { | |
64 hasBuffer_ = true; | |
65 buffer_ = buffer; | |
66 bufferSize_ = size; | |
67 } | |
68 | |
69 | |
70 void DicomInstanceToStore::SetMetadata(ResourceType level, | |
71 MetadataType metadata, | 50 MetadataType metadata, |
72 const std::string& value) | 51 const std::string& value) |
73 { | 52 { |
74 metadata_[std::make_pair(level, metadata)] = value; | 53 metadata_[std::make_pair(level, metadata)] = value; |
75 } | 54 } |
76 | 55 |
77 | 56 |
78 void DicomInstanceToStore::ComputeMissingInformation() | 57 void DicomInstanceToStore::ComputeMissingInformation() |
79 { | 58 { |
80 // TODO | 59 if (buffer_.HasContent() && |
60 summary_.HasContent() && | |
61 json_.HasContent()) | |
62 { | |
63 // Fine, everything is available | |
64 return; | |
65 } | |
66 | |
67 if (!buffer_.HasContent()) | |
68 { | |
69 if (!parsed_.HasContent()) | |
70 { | |
71 throw OrthancException(ErrorCode_NotImplemented); | |
72 } | |
73 else | |
74 { | |
75 // Serialize the parsed DICOM file | |
76 buffer_.Allocate(); | |
77 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer_.GetContent(), GetDataset(parsed_.GetContent()))) | |
78 { | |
79 LOG(ERROR) << "Unable to serialize a DICOM file to a memory buffer"; | |
80 throw OrthancException(ErrorCode_InternalError); | |
81 } | |
82 } | |
83 } | |
81 | 84 |
82 assert(hasBuffer_ && (buffer_ != NULL || bufferSize_ == 0)); | 85 if (summary_.HasContent() && |
86 json_.HasContent()) | |
87 { | |
88 return; | |
89 } | |
90 | |
91 // At this point, we know that the DICOM file is available as a | |
92 // memory buffer, but that its summary or its JSON version is | |
93 // missing | |
94 | |
95 if (!parsed_.HasContent()) | |
96 { | |
97 parsed_.TakeOwnership(new ParsedDicomFile(buffer_.GetContent())); | |
98 } | |
99 | |
100 // At this point, we have parsed the DICOM file | |
101 | |
102 if (!summary_.HasContent()) | |
103 { | |
104 summary_.Allocate(); | |
105 FromDcmtkBridge::Convert(summary_.GetContent(), GetDataset(parsed_.GetContent())); | |
106 } | |
107 | |
108 if (!json_.HasContent()) | |
109 { | |
110 json_.Allocate(); | |
111 FromDcmtkBridge::ToJson(json_.GetContent(), GetDataset(parsed_.GetContent())); | |
112 } | |
83 } | 113 } |
84 | 114 |
85 | 115 |
86 | 116 |
87 const char* DicomInstanceToStore::GetBuffer() | 117 const char* DicomInstanceToStore::GetBufferData() |
88 { | 118 { |
89 ComputeMissingInformation(); | 119 ComputeMissingInformation(); |
90 return buffer_; | 120 |
121 if (!buffer_.HasContent()) | |
122 { | |
123 throw OrthancException(ErrorCode_InternalError); | |
124 } | |
125 | |
126 if (buffer_.GetConstContent().size() == 0) | |
127 { | |
128 return NULL; | |
129 } | |
130 else | |
131 { | |
132 return buffer_.GetConstContent().c_str(); | |
133 } | |
91 } | 134 } |
92 | 135 |
93 | 136 |
94 size_t DicomInstanceToStore::GetBufferSize() | 137 size_t DicomInstanceToStore::GetBufferSize() |
95 { | 138 { |
96 ComputeMissingInformation(); | 139 ComputeMissingInformation(); |
97 return bufferSize_; | 140 |
141 if (!buffer_.HasContent()) | |
142 { | |
143 throw OrthancException(ErrorCode_InternalError); | |
144 } | |
145 | |
146 return buffer_.GetConstContent().size(); | |
147 } | |
148 | |
149 | |
150 const DicomMap& DicomInstanceToStore::GetSummary() | |
151 { | |
152 ComputeMissingInformation(); | |
153 | |
154 if (!summary_.HasContent()) | |
155 { | |
156 throw OrthancException(ErrorCode_InternalError); | |
157 } | |
158 | |
159 return summary_.GetConstContent(); | |
160 } | |
161 | |
162 | |
163 const Json::Value& DicomInstanceToStore::GetJson() | |
164 { | |
165 ComputeMissingInformation(); | |
166 | |
167 if (!json_.HasContent()) | |
168 { | |
169 throw OrthancException(ErrorCode_InternalError); | |
170 } | |
171 | |
172 return json_.GetConstContent(); | |
98 } | 173 } |
99 } | 174 } |