# HG changeset patch # User Sebastien Jodogne # Date 1575059069 -3600 # Node ID b519c1c878f178ad35026a7a709bb64ccb89580d # Parent f3bb9a6dd949edfc3ce8cdc5e341cebce331f819# Parent 9added0d371ea851aa5d973e2d83ff784b208d54 integration mainline->broker diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyAlphaLayer.cpp --- a/Framework/Radiography/RadiographyAlphaLayer.cpp Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyAlphaLayer.cpp Fri Nov 29 21:24:29 2019 +0100 @@ -79,15 +79,19 @@ Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); - t.Apply(tmp, cropped, interpolation, true /* clear */); + unsigned int x1, y1, x2, y2; - unsigned int x1, y1, x2, y2; - OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, - t.GetHomogeneousMatrix(), - cropped.GetWidth(), - cropped.GetHeight(), - buffer.GetWidth(), - buffer.GetHeight()); + if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, + t.GetHomogeneousMatrix(), + cropped.GetWidth(), + cropped.GetHeight(), + buffer.GetWidth(), + buffer.GetHeight())) + { + return; // layer is outside the buffer + } + + t.Apply(tmp, cropped, interpolation, true /* clear */); float value = foreground_; diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyDicomLayer.cpp --- a/Framework/Radiography/RadiographyDicomLayer.cpp Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyDicomLayer.cpp Fri Nov 29 21:24:29 2019 +0100 @@ -162,14 +162,18 @@ Orthanc::ImageAccessor cropped; converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); + unsigned int x1, y1, x2, y2; + if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, + t.GetHomogeneousMatrix(), + cropped.GetWidth(), + cropped.GetHeight(), + buffer.GetWidth(), + buffer.GetHeight())) + { + return; // layer is outside the buffer + } + t.Apply(buffer, cropped, interpolation, false); - unsigned int x1, y1, x2, y2; - OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, - t.GetHomogeneousMatrix(), - cropped.GetWidth(), - cropped.GetHeight(), - buffer.GetWidth(), - buffer.GetHeight()); if (applyWindowing) { diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyMaskLayer.cpp --- a/Framework/Radiography/RadiographyMaskLayer.cpp Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.cpp Fri Nov 29 21:24:29 2019 +0100 @@ -112,15 +112,19 @@ Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); - t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */); unsigned int x1, y1, x2, y2; - OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, - t.GetHomogeneousMatrix(), - cropped.GetWidth(), - cropped.GetHeight(), - buffer.GetWidth(), - buffer.GetHeight()); + if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, + t.GetHomogeneousMatrix(), + cropped.GetWidth(), + cropped.GetHeight(), + buffer.GetWidth(), + buffer.GetHeight())) + { + return; // layer is outside the buffer + } + + t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */); // we have observed vertical lines at the image border (probably due to bilinear filtering of the DICOM image when it is not aligned with the buffer pixels) // -> draw the mask one line further on each side diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyScene.cpp --- a/Framework/Radiography/RadiographyScene.cpp Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Fri Nov 29 21:24:29 2019 +0100 @@ -240,6 +240,21 @@ } } + RadiographyLayer& RadiographyScene::GetLayer(size_t layerIndex) + { + Layers::const_iterator found = layers_.find(layerIndex); + + if (found == layers_.end()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + else + { + assert(found->second != NULL); + return *found->second; + } + } + bool RadiographyScene::GetWindowing(float& center, float& width) const { @@ -278,13 +293,27 @@ } + RadiographyLayer& RadiographyScene::UpdateText(size_t layerIndex, + const std::string& utf8, + unsigned int fontSize, + uint8_t foreground) + { + RadiographyTextLayer& textLayer = dynamic_cast(GetLayer(layerIndex)); + textLayer.SetText(utf8, fontSize, foreground); + + BroadcastMessage(RadiographyScene::ContentChangedMessage(*this, textLayer)); + BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, textLayer)); + return textLayer; + } + + RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, unsigned int fontSize, uint8_t foreground, RadiographyLayer::Geometry* geometry) { std::auto_ptr alpha(new RadiographyTextLayer(*this)); - alpha->LoadText(utf8, fontSize, foreground); + alpha->SetText(utf8, fontSize, foreground); if (geometry != NULL) { alpha->SetGeometry(*geometry); diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyScene.h --- a/Framework/Radiography/RadiographyScene.h Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.h Fri Nov 29 21:24:29 2019 +0100 @@ -180,6 +180,7 @@ void OnDicomWebReceived(const Deprecated::IWebService::HttpRequestSuccessMessage& message); virtual void OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message); + public: RadiographyScene(); @@ -202,7 +203,12 @@ unsigned int fontSize, uint8_t foreground, RadiographyLayer::Geometry* geometry); - + + RadiographyLayer& UpdateText(size_t layerIndex, + const std::string& utf8, + unsigned int fontSize, + uint8_t foreground); + RadiographyLayer& LoadTestBlock(unsigned int width, unsigned int height, RadiographyLayer::Geometry* geometry); @@ -232,10 +238,12 @@ void RemoveLayer(size_t layerIndex); + RadiographyLayer& GetLayer(size_t layerIndex); + const RadiographyLayer& GetLayer(size_t layerIndex) const; template - TypeLayer* GetLayer(size_t index = 0) + TypeLayer* GetTypedLayer(size_t indexOfType = 0) { std::vector layerIndexes; GetLayersIndexes(layerIndexes); @@ -247,31 +255,7 @@ TypeLayer* typedLayer = dynamic_cast(layers_[layerIndexes[i]]); if (typedLayer != NULL) { - if (count == index) - { - return typedLayer; - } - count++; - } - } - - return NULL; - } - - template - const TypeLayer* GetLayer(size_t index = 0) const - { - std::vector layerIndexes; - GetLayersIndexes(layerIndexes); - - size_t count = 0; - - for (size_t i = 0; i < layerIndexes.size(); ++i) - { - const TypeLayer* typedLayer = dynamic_cast(layers_.at(layerIndexes[i])); - if (typedLayer != NULL) - { - if (count == index) + if (count == indexOfType) { return typedLayer; } @@ -352,6 +336,7 @@ ImageInterpolation interpolation, bool invert, int64_t maxValue /* for inversion */, - bool applyWindowing); // i.e.: when + bool applyWindowing); + }; } diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyTextLayer.cpp --- a/Framework/Radiography/RadiographyTextLayer.cpp Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.cpp Fri Nov 29 21:24:29 2019 +0100 @@ -29,7 +29,7 @@ bool RadiographyTextLayer::fontHasBeenConfigured_ = false; Orthanc::EmbeddedResources::FileResourceId RadiographyTextLayer::fontResourceId_; - void RadiographyTextLayer::LoadText(const std::string& utf8, + void RadiographyTextLayer::SetText(const std::string& utf8, unsigned int fontSize, uint8_t foreground) { @@ -45,6 +45,8 @@ SetAlpha(TextRenderer::Render(fontResourceId_, fontSize_, text_)); + SetForegroundValue(foreground * 256.0f); } + } diff -r f3bb9a6dd949 -r b519c1c878f1 Framework/Radiography/RadiographyTextLayer.h --- a/Framework/Radiography/RadiographyTextLayer.h Fri Nov 29 21:22:21 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.h Fri Nov 29 21:24:29 2019 +0100 @@ -42,7 +42,7 @@ { } - void LoadText(const std::string& utf8, unsigned int fontSize, uint8_t foreground); + void SetText(const std::string& utf8, unsigned int fontSize, uint8_t foreground); const std::string& GetText() const {