Mercurial > hg > orthanc-wsi
changeset 68:c619c8bd72ed
DicomPyramidInstance::Deserialize
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Nov 2016 21:18:46 +0100 |
parents | 789885bd06ae |
children | d529d9ce3c7e |
files | Framework/Inputs/DicomPyramidInstance.cpp Framework/Inputs/DicomPyramidInstance.h Framework/PrecompiledHeadersWSI.h |
diffstat | 3 files changed, 106 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Inputs/DicomPyramidInstance.cpp Fri Nov 25 21:04:12 2016 +0100 +++ b/Framework/Inputs/DicomPyramidInstance.cpp Fri Nov 25 21:18:46 2016 +0100 @@ -124,10 +124,8 @@ } - DicomPyramidInstance::DicomPyramidInstance(OrthancPlugins::IOrthancConnection& orthanc, - const std::string& instanceId) : - instanceId_(instanceId), - hasCompression_(false) + void DicomPyramidInstance::Load(OrthancPlugins::IOrthancConnection& orthanc, + const std::string& instanceId) { using namespace OrthancPlugins; @@ -194,6 +192,15 @@ } + DicomPyramidInstance::DicomPyramidInstance(OrthancPlugins::IOrthancConnection& orthanc, + const std::string& instanceId) : + instanceId_(instanceId), + hasCompression_(false) + { + Load(orthanc, instanceId); + } + + unsigned int DicomPyramidInstance::GetFrameLocationX(size_t frame) const { assert(frame < frames_.size()); @@ -220,15 +227,96 @@ frames.append(frame); } - Json::Value value; - value["PixelFormat"] = Orthanc::EnumerationToString(format_); - value["TileHeight"] = tileHeight_; - value["TileWidth"] = tileWidth_; - value["TotalHeight"] = totalHeight_; - value["TotalWidth"] = totalWidth_; - value["Frames"] = frames; + Json::Value content; + content["Frames"] = frames; + content["TileHeight"] = tileHeight_; + content["TileWidth"] = tileWidth_; + content["TotalHeight"] = totalHeight_; + content["TotalWidth"] = totalWidth_; + + switch (format_) + { + case Orthanc::PixelFormat_RGB24: + content["PixelFormat"] = 0; + break; + + case Orthanc::PixelFormat_Grayscale8: + content["PixelFormat"] = 1; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } Json::FastWriter writer; - result = writer.write(value); + result = writer.write(content); + } + + + void DicomPyramidInstance::Deserialize(const std::string& s) + { + hasCompression_ = false; + + Json::Value content; + OrthancPlugins::IOrthancConnection::ParseJson(content, s); + + if (content.type() != Json::objectValue || + !content.isMember("Frames") || + !content.isMember("PixelFormat") || + !content.isMember("TileHeight") || + !content.isMember("TileWidth") || + !content.isMember("TotalHeight") || + !content.isMember("TotalWidth") || + content["Frames"].type() != Json::arrayValue || + content["PixelFormat"].type() != Json::intValue || + content["TileHeight"].type() != Json::intValue || + content["TileWidth"].type() != Json::intValue || + content["TotalHeight"].type() != Json::intValue || + content["TotalWidth"].type() != Json::intValue || + content["TileHeight"].asInt() < 0 || + content["TileWidth"].asInt() < 0 || + content["TotalHeight"].asInt() < 0 || + content["TotalWidth"].asInt() < 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } + + switch (content["Frames"].asInt()) + { + case 0: + format_ = Orthanc::PixelFormat_RGB24; + break; + + case 1: + format_ = Orthanc::PixelFormat_Grayscale8; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } + + tileHeight_ = static_cast<unsigned int>(content["TileHeight"].asInt()); + tileWidth_ = static_cast<unsigned int>(content["TileWidth"].asInt()); + totalHeight_ = static_cast<unsigned int>(content["TotalHeight"].asInt()); + totalWidth_ = static_cast<unsigned int>(content["TotalWidth"].asInt()); + + const Json::Value f = content["Frames"]; + frames_.resize(f.size()); + + for (Json::Value::ArrayIndex i = 0; i < f.size(); i++) + { + if (f[i].type() != Json::arrayValue || + f[i].size() != 2 || + f[i][0].type() != Json::intValue || + f[i][1].type() != Json::intValue || + f[i][0].asInt() < 0 || + f[i][1].asInt() < 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } + + frames_[i].first = f[i][0].asInt(); + frames_[i].second = f[i][1].asInt(); + } } }
--- a/Framework/Inputs/DicomPyramidInstance.h Fri Nov 25 21:04:12 2016 +0100 +++ b/Framework/Inputs/DicomPyramidInstance.h Fri Nov 25 21:18:46 2016 +0100 @@ -43,6 +43,11 @@ unsigned int totalHeight_; std::vector<FrameLocation> frames_; + void Load(OrthancPlugins::IOrthancConnection& orthanc, + const std::string& instanceId); + + void Deserialize(const std::string& content); + public: DicomPyramidInstance(OrthancPlugins::IOrthancConnection& orthanc, const std::string& instanceId);
--- a/Framework/PrecompiledHeadersWSI.h Fri Nov 25 21:04:12 2016 +0100 +++ b/Framework/PrecompiledHeadersWSI.h Fri Nov 25 21:18:46 2016 +0100 @@ -27,8 +27,7 @@ #include "DicomToolbox.h" #include "ImageToolbox.h" #include "Inputs/ITiledPyramid.h" -#include "Messaging/IFileTarget.h" -#include "Messaging/IOrthancConnection.h" +#include "Targets/IFileTarget.h" #include "Outputs/IPyramidWriter.h" #endif