# HG changeset patch # User Alain Mazy # Date 1575040884 -3600 # Node ID ab958fd99b07ec65c5b8861f92d3706759857e8c # Parent 922d2e61aa5d74bb8be701a8b4520561f2085d38 RadiographyScene fixes diff -r 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyAlphaLayer.cpp --- a/Framework/Radiography/RadiographyAlphaLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyAlphaLayer.cpp Fri Nov 29 16:21:24 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 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyDicomLayer.cpp --- a/Framework/Radiography/RadiographyDicomLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyDicomLayer.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -161,14 +161,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 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyMaskLayer.cpp --- a/Framework/Radiography/RadiographyMaskLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyMaskLayer.cpp Fri Nov 29 16:21:24 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 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyScene.cpp --- a/Framework/Radiography/RadiographyScene.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Fri Nov 29 16:21:24 2019 +0100 @@ -243,6 +243,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 { @@ -281,13 +296,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(IObservable::GetBroker(), *this)); - alpha->LoadText(utf8, fontSize, foreground); + alpha->SetText(utf8, fontSize, foreground); if (geometry != NULL) { alpha->SetGeometry(*geometry); diff -r 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyScene.h --- a/Framework/Radiography/RadiographyScene.h Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.h Fri Nov 29 16:21:24 2019 +0100 @@ -179,6 +179,7 @@ void OnDicomWebReceived(const Deprecated::IWebService::HttpRequestSuccessMessage& message); virtual void OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message); + public: RadiographyScene(MessageBroker& broker); @@ -201,7 +202,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); @@ -231,10 +237,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); @@ -246,31 +254,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; } diff -r 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyTextLayer.cpp --- a/Framework/Radiography/RadiographyTextLayer.cpp Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.cpp Fri Nov 29 16:21:24 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 922d2e61aa5d -r ab958fd99b07 Framework/Radiography/RadiographyTextLayer.h --- a/Framework/Radiography/RadiographyTextLayer.h Thu Nov 28 18:28:15 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.h Fri Nov 29 16:21:24 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 {