# HG changeset patch # User Sebastien Jodogne # Date 1642166065 -3600 # Node ID 0c6923982fdd90e68926505e679fc261c89d8d7c # Parent fba6e550e0ee76133920165b71c00bef84f7988c rendering options from GET args diff -r fba6e550e0ee -r 0c6923982fdd RenderingPlugin/Sources/Plugin.cpp --- a/RenderingPlugin/Sources/Plugin.cpp Wed Jan 12 18:26:05 2022 +0100 +++ b/RenderingPlugin/Sources/Plugin.cpp Fri Jan 14 14:14:25 2022 +0100 @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -57,11 +58,91 @@ } +static bool ParseBoolean(const std::string& key, + const std::string& value) +{ + bool result; + + if (Orthanc::SerializationToolbox::ParseBoolean(result, value)) + { + return result; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, + "Bad value for " + key + ": " + value); + } +} + + +static double ParseDouble(const std::string& key, + const std::string& value) +{ + double result; + + if (Orthanc::SerializationToolbox::ParseDouble(result, value)) + { + return result; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, + "Bad value for " + key + ": " + value); + } +} + + static void RenderNumpyFrame(OrthancPluginRestOutput* output, const char* url, const OrthancPluginHttpRequest* request) { - // TODO: Parameters in GET + double angleRadians = 0; + double scaling = 1; + double offsetX = 0; + double offsetY = 0; + bool flipX = false; + bool flipY = false; + bool compress = false; + + for (uint32_t i = 0; i < request->getCount; i++) + { + std::string key(request->getKeys[i]); + std::string value(request->getValues[i]); + + if (key == "angle") + { + double angle = ParseDouble(key, value); + angleRadians = angle / 180.0 * boost::math::constants::pi(); + } + else if (key == "scaling") + { + scaling = ParseDouble(key, value); + } + else if (key == "offset-x") + { + offsetX = ParseDouble(key, value); + } + else if (key == "offset-y") + { + offsetY = ParseDouble(key, value); + } + else if (key == "flip-x") + { + flipX = ParseBoolean(key, value); + } + else if (key == "flip-y") + { + flipY = ParseBoolean(key, value); + } + else if (key == "compress") + { + compress = ParseBoolean(key, value); + } + else + { + LOG(WARNING) << "Unsupported option: " << key; + } + } OrthancPlugins::MemoryBuffer tags; if (!tags.RestApiGet("/instances/" + std::string(request->groups[0]) + "/tags", false)) @@ -89,19 +170,12 @@ source.AssignReadOnly(Convert(image.GetPixelFormat()), image.GetWidth(), image.GetHeight(), image.GetPitch(), image.GetBuffer()); - double angle = 0; - double scaling = 1; - double offsetX = 0; - double offsetY = 0; - bool flipX = false; - bool flipY = false; - OrthancStone::AffineTransform2D t; t = OrthancStone::AffineTransform2D::Combine( OrthancStone::AffineTransform2D::CreateOffset(static_cast(image.GetWidth()) / 2.0 + offsetX, static_cast(image.GetHeight()) / 2.0 + offsetY), OrthancStone::AffineTransform2D::CreateScaling(scaling, scaling), - OrthancStone::AffineTransform2D::CreateRotation(angle / 180.0 * boost::math::constants::pi()), + OrthancStone::AffineTransform2D::CreateRotation(angleRadians), OrthancStone::AffineTransform2D::CreateOffset(-static_cast(image.GetWidth()) / 2.0, -static_cast(image.GetHeight()) / 2.0), OrthancStone::AffineTransform2D::CreateFlip(flipX, flipY, image.GetWidth(), image.GetHeight())); @@ -128,8 +202,9 @@ std::string answer; Orthanc::NumpyWriter writer; + writer.SetCompressed(compress); Orthanc::IImageWriter::WriteToMemory(writer, answer, *modified); - + OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, answer.c_str(), answer.size(), "text/plain"); }