# HG changeset patch # User Sebastien Jodogne # Date 1642524763 -3600 # Node ID fe4befc9c2b0f9434791c0a0a0985be40e2dcdb7 # Parent 9bdce2c9162095b6c140e881bcfc6bd6622cdc60 rendering of rt-struct in plugin diff -r 9bdce2c91620 -r fe4befc9c2b0 RenderingPlugin/Sources/Plugin.cpp --- a/RenderingPlugin/Sources/Plugin.cpp Mon Jan 17 21:20:56 2022 +0100 +++ b/RenderingPlugin/Sources/Plugin.cpp Tue Jan 18 17:52:43 2022 +0100 @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -658,32 +659,34 @@ const char* url, const OrthancPluginHttpRequest* request) { - DicomStructureCache::Accessor accessor(DicomStructureCache::GetSingleton(), request->groups[0]); - - if (!accessor.IsValid()) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); - } - + DataAugmentationParameters dataAugmentation; std::string structureName; std::string instanceId; + 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 == "structure") - { - structureName = value; - } - else if (key == "instance") + if (!dataAugmentation.ParseParameter(key, value)) { - instanceId = value; - } - else - { - LOG(WARNING) << "Unsupported option: " << key; + if (key == "structure") + { + structureName = value; + } + else if (key == "instance") + { + instanceId = value; + } + else if (key == "compress") + { + compress = ParseBoolean(key, value); + } + else + { + LOG(WARNING) << "Unsupported option: " << key; + } } } @@ -698,33 +701,45 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, "Missing option \"instance\" to provide the Orthanc identifier of the instance of interest"); } - + std::unique_ptr parameters(GetInstanceParameters(instanceId)); - size_t structureIndex; - bool found = false; - for (size_t i = 0; i < accessor.GetRtStruct().GetStructuresCount(); i++) + std::list< std::vector > polygons; + { - if (accessor.GetRtStruct().GetStructureName(i) == structureName) + DicomStructureCache::Accessor accessor(DicomStructureCache::GetSingleton(), request->groups[0]); + + if (!accessor.IsValid()) { - structureIndex = i; - found = true; - break; + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); } - } - if (!found) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem, - "Unknown structure name: " + structureName); + size_t structureIndex; + bool found = false; + for (size_t i = 0; i < accessor.GetRtStruct().GetStructuresCount(); i++) + { + if (accessor.GetRtStruct().GetStructureName(i) == structureName) + { + structureIndex = i; + found = true; + break; + } + } + + if (!found) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem, + "Unknown structure name: " + structureName); + } + + accessor.GetRtStruct().GetStructurePoints(polygons, structureIndex, parameters->GetSopInstanceUid()); } - std::list< std::vector > polygons; - accessor.GetRtStruct().GetStructurePoints(polygons, structureIndex, parameters->GetSopInstanceUid()); - Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, parameters->GetWidth(), parameters->GetHeight(), false); Orthanc::ImageProcessing::Set(tmp, 0); - + + OrthancStone::AffineTransform2D transform = dataAugmentation.ComputeTransform(parameters->GetWidth(), parameters->GetHeight()); + for (std::list< std::vector >::const_iterator it = polygons.begin(); it != polygons.end(); ++it) { @@ -735,13 +750,18 @@ { double x, y; parameters->GetGeometry().ProjectPoint(x, y, (*it) [i]); + x /= parameters->GetPixelSpacingX(); + y /= parameters->GetPixelSpacingY(); + + transform.Apply(x, y); + points.push_back(Orthanc::ImageProcessing::ImagePoint(x, y)); } Orthanc::ImageProcessing::FillPolygon(tmp, points, 255); } - AnswerNumpyImage(output, tmp, true); + AnswerNumpyImage(output, tmp, compress); }