# HG changeset patch # User Sebastien Jodogne # Date 1480105126 -3600 # Node ID c619c8bd72ed633633353f1523a2aa7a433c361a # Parent 789885bd06aef2de2ced95591b81f5d56a5b5f07 DicomPyramidInstance::Deserialize diff -r 789885bd06ae -r c619c8bd72ed Framework/Inputs/DicomPyramidInstance.cpp --- 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(content["TileHeight"].asInt()); + tileWidth_ = static_cast(content["TileWidth"].asInt()); + totalHeight_ = static_cast(content["TotalHeight"].asInt()); + totalWidth_ = static_cast(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(); + } } } diff -r 789885bd06ae -r c619c8bd72ed Framework/Inputs/DicomPyramidInstance.h --- 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 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); diff -r 789885bd06ae -r c619c8bd72ed Framework/PrecompiledHeadersWSI.h --- 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