Mercurial > hg > orthanc-wsi
comparison Framework/Inputs/DicomPyramidInstance.cpp @ 69:d529d9ce3c7e
cache for DicomPyramidInstance
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Nov 2016 21:56:07 +0100 |
parents | c619c8bd72ed |
children | f2c179294382 |
comparison
equal
deleted
inserted
replaced
68:c619c8bd72ed | 69:d529d9ce3c7e |
---|---|
29 #include "../DicomToolbox.h" | 29 #include "../DicomToolbox.h" |
30 | 30 |
31 #include <cassert> | 31 #include <cassert> |
32 #include <json/writer.h> | 32 #include <json/writer.h> |
33 | 33 |
34 #define SERIALIZED_METADATA "4200" | |
35 | |
34 namespace OrthancWSI | 36 namespace OrthancWSI |
35 { | 37 { |
36 static ImageCompression DetectImageCompression(OrthancPlugins::IOrthancConnection& orthanc, | 38 static ImageCompression DetectImageCompression(OrthancPlugins::IOrthancConnection& orthanc, |
37 const std::string& instanceId) | 39 const std::string& instanceId) |
38 { | 40 { |
135 reader.GetMandatoryStringValue(DICOM_TAG_MODALITY) != "SM") | 137 reader.GetMandatoryStringValue(DICOM_TAG_MODALITY) != "SM") |
136 { | 138 { |
137 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 139 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
138 } | 140 } |
139 | 141 |
142 hasCompression_ = false; | |
140 format_ = DetectPixelFormat(reader); | 143 format_ = DetectPixelFormat(reader); |
141 tileWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_COLUMNS); | 144 tileWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_COLUMNS); |
142 tileHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_ROWS); | 145 tileHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_ROWS); |
143 totalWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS); | 146 totalWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS); |
144 totalHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS); | 147 totalHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS); |
191 } | 194 } |
192 } | 195 } |
193 | 196 |
194 | 197 |
195 DicomPyramidInstance::DicomPyramidInstance(OrthancPlugins::IOrthancConnection& orthanc, | 198 DicomPyramidInstance::DicomPyramidInstance(OrthancPlugins::IOrthancConnection& orthanc, |
196 const std::string& instanceId) : | 199 const std::string& instanceId, |
200 bool useCache) : | |
197 instanceId_(instanceId), | 201 instanceId_(instanceId), |
198 hasCompression_(false) | 202 hasCompression_(false) |
199 { | 203 { |
204 if (useCache) | |
205 { | |
206 try | |
207 { | |
208 // Try and deserialized the cached information about this instance | |
209 std::string serialized; | |
210 orthanc.RestApiGet(serialized, "/instances/" + instanceId + "/metadata/" + SERIALIZED_METADATA); | |
211 Deserialize(serialized); | |
212 return; // Success | |
213 } | |
214 catch (Orthanc::OrthancException&) | |
215 { | |
216 } | |
217 } | |
218 | |
219 // No cached information, compute it from scratch | |
200 Load(orthanc, instanceId); | 220 Load(orthanc, instanceId); |
221 | |
222 // Serialize the computed information and cache it as a metadata | |
223 std::string serialized, tmp; | |
224 Serialize(serialized); | |
225 orthanc.RestApiPut(tmp, "/instances/" + instanceId + "/metadata/" + SERIALIZED_METADATA, serialized); | |
201 } | 226 } |
202 | 227 |
203 | 228 |
204 unsigned int DicomPyramidInstance::GetFrameLocationX(size_t frame) const | 229 unsigned int DicomPyramidInstance::GetFrameLocationX(size_t frame) const |
205 { | 230 { |
279 content["TotalWidth"].asInt() < 0) | 304 content["TotalWidth"].asInt() < 0) |
280 { | 305 { |
281 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 306 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
282 } | 307 } |
283 | 308 |
284 switch (content["Frames"].asInt()) | 309 switch (content["PixelFormat"].asInt()) |
285 { | 310 { |
286 case 0: | 311 case 0: |
287 format_ = Orthanc::PixelFormat_RGB24; | 312 format_ = Orthanc::PixelFormat_RGB24; |
288 break; | 313 break; |
289 | 314 |
293 | 318 |
294 default: | 319 default: |
295 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 320 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
296 } | 321 } |
297 | 322 |
323 hasCompression_ = false; | |
298 tileHeight_ = static_cast<unsigned int>(content["TileHeight"].asInt()); | 324 tileHeight_ = static_cast<unsigned int>(content["TileHeight"].asInt()); |
299 tileWidth_ = static_cast<unsigned int>(content["TileWidth"].asInt()); | 325 tileWidth_ = static_cast<unsigned int>(content["TileWidth"].asInt()); |
300 totalHeight_ = static_cast<unsigned int>(content["TotalHeight"].asInt()); | 326 totalHeight_ = static_cast<unsigned int>(content["TotalHeight"].asInt()); |
301 totalWidth_ = static_cast<unsigned int>(content["TotalWidth"].asInt()); | 327 totalWidth_ = static_cast<unsigned int>(content["TotalWidth"].asInt()); |
302 | 328 |