Mercurial > hg > orthanc-stone
changeset 1195:bdc6837d5917 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 27 Nov 2019 14:34:34 +0100 |
parents | 09fc591d8ff9 (current diff) a0731faeafd3 (diff) |
children | 4cc997207d8a |
files | Applications/Samples/SingleFrameEditorApplication.h Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographySceneReader.cpp Framework/Radiography/RadiographySceneReader.h Framework/Radiography/RadiographyTextLayer.h Framework/Toolbox/GenericToolbox.h |
diffstat | 11 files changed, 77 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/CMakeLists.txt Sat Nov 23 11:57:03 2019 +0100 +++ b/Applications/Samples/CMakeLists.txt Wed Nov 27 14:34:34 2019 +0100 @@ -9,6 +9,7 @@ include(../../Resources/CMake/OrthancStoneParameters.cmake) set(ENABLE_STONE_DEPRECATED ON) # Need deprecated classes for these samples +set(EMSCRIPTEN_SET_LLVM_WASM_BACKEND ON) include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) DownloadPackage( @@ -53,7 +54,7 @@ set(WASM_FLAGS "${WASM_FLAGS} -s FILESYSTEM=1") # if we don't include it, gen_uuid.c fails to build because srand, getpid(), ... are not defined set(WASM_FLAGS "${WASM_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0") # actually enable exception catching set(WASM_FLAGS "${WASM_FLAGS} -s ERROR_ON_MISSING_LIBRARIES=1") - + if (CMAKE_BUILD_TYPE MATCHES DEBUG) set(WASM_FLAGS "${WASM_FLAGS} -g4") # generate debug information set(WASM_FLAGS "${WASM_FLAGS} -s ASSERTIONS=2") # more runtime checks @@ -238,6 +239,8 @@ ${SIMPLE_VIEWER_APPLICATION_SOURCES} ) target_link_libraries(OrthancStoneSimpleViewer OrthancStone) + + BuildSingleFileSample(OrthancStoneSingleFrameEditor SingleFrameEditorApplication.h 9) endif() #####################################################################
--- a/Applications/Samples/SingleFrameEditorApplication.h Sat Nov 23 11:57:03 2019 +0100 +++ b/Applications/Samples/SingleFrameEditorApplication.h Wed Nov 27 14:34:34 2019 +0100 @@ -38,7 +38,6 @@ #include "../../Framework/Toolbox/TextRenderer.h" #include <Core/HttpClient.h> -#include <Core/Images/FontRegistry.h> #include <Core/Logging.h> #include <Core/OrthancException.h> #include <Core/Images/PngWriter.h> @@ -317,11 +316,6 @@ boost::shared_ptr<RadiographyScene> scene(new RadiographyScene); RadiographySceneReader reader(*scene, context_->GetOrthancApiClient()); - - Orthanc::FontRegistry fontRegistry; - fontRegistry.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); - - reader.SetFontRegistry(fontRegistry); reader.Read(snapshot); widget.SetScene(scene); @@ -517,7 +511,7 @@ } { - RadiographyLayer& layer = scene_->LoadText(fontRegistry_.GetFont(0), "Hello\nworld", NULL); + RadiographyLayer& layer = scene_->LoadText("Hello\nworld", 20, 128, NULL); layer.SetResizeable(true); }
--- a/Applications/Samples/build-wasm.sh Sat Nov 23 11:57:03 2019 +0100 +++ b/Applications/Samples/build-wasm.sh Wed Nov 27 14:34:34 2019 +0100 @@ -19,7 +19,7 @@ cd $samplesRootDir/build-wasm source ~/apps/emsdk/emsdk_env.sh -cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=$buildType -DSTONE_SOURCES_DIR=$currentDir/../../../orthanc-stone -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT=$currentDir/../../../orthanc -DALLOW_DOWNLOADS=ON .. -DENABLE_WASM=ON +cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=~/apps/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=$buildType -DSTONE_SOURCES_DIR=$currentDir/../../../orthanc-stone -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT=$currentDir/../../../orthanc -DALLOW_DOWNLOADS=ON .. -DENABLE_WASM=ON ninja $target echo "-- building the web application -- "
--- a/Applications/Samples/build-web.sh Sat Nov 23 11:57:03 2019 +0100 +++ b/Applications/Samples/build-web.sh Wed Nov 27 14:34:34 2019 +0100 @@ -19,29 +19,29 @@ cp "$samplesRootDir/Web/index.html" "$outputDir" cp "$samplesRootDir/Web/samples-styles.css" "$outputDir" -# build simple-viewer-single-file (obsolete project) -if [[ $target == "all" || $target == "OrthancStoneSimpleViewerSingleFile" ]]; then - cp $samplesRootDir/Web/simple-viewer-single-file.html $outputDir - tsc --project $samplesRootDir/Web/simple-viewer-single-file.tsconfig.json --outDir "$outputDir" - browserify \ - "$outputDir/Platforms/Wasm/wasm-application-runner.js" \ - "$outputDir/Applications/Samples/Web/simple-viewer-single-file.js" \ - -o "$outputDir/app-simple-viewer-single-file.js" - cp "$currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.js" $outputDir - cp "$currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.wasm" $outputDir -fi +# # build simple-viewer-single-file (obsolete project) +# if [[ $target == "all" || $target == "OrthancStoneSimpleViewerSingleFile" ]]; then +# cp $samplesRootDir/Web/simple-viewer-single-file.html $outputDir +# tsc --project $samplesRootDir/Web/simple-viewer-single-file.tsconfig.json --outDir "$outputDir" +# browserify \ +# "$outputDir/Platforms/Wasm/wasm-application-runner.js" \ +# "$outputDir/Applications/Samples/Web/simple-viewer-single-file.js" \ +# -o "$outputDir/app-simple-viewer-single-file.js" +# cp "$currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.js" $outputDir +# cp "$currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.wasm" $outputDir +# fi -# build single-frame -if [[ $target == "all" || $target == "OrthancStoneSingleFrame" ]]; then - cp $samplesRootDir/Web/single-frame.html $outputDir - tsc --project $samplesRootDir/Web/single-frame.tsconfig.json --outDir "$outputDir" - browserify \ - "$outputDir/Platforms/Wasm/wasm-application-runner.js" \ - "$outputDir/Applications/Samples/Web/single-frame.js" \ - -o "$outputDir/app-single-frame.js" - cp "$currentDir/build-wasm/OrthancStoneSingleFrame.js" $outputDir - cp "$currentDir/build-wasm/OrthancStoneSingleFrame.wasm" $outputDir -fi +# # build single-frame +# if [[ $target == "all" || $target == "OrthancStoneSingleFrame" ]]; then +# cp $samplesRootDir/Web/single-frame.html $outputDir +# tsc --project $samplesRootDir/Web/single-frame.tsconfig.json --outDir "$outputDir" +# browserify \ +# "$outputDir/Platforms/Wasm/wasm-application-runner.js" \ +# "$outputDir/Applications/Samples/Web/single-frame.js" \ +# -o "$outputDir/app-single-frame.js" +# cp "$currentDir/build-wasm/OrthancStoneSingleFrame.js" $outputDir +# cp "$currentDir/build-wasm/OrthancStoneSingleFrame.wasm" $outputDir +# fi # build single-frame-editor if [[ $target == "all" || $target == "OrthancStoneSingleFrameEditor" ]]; then
--- a/Framework/Radiography/RadiographyScene.cpp Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Wed Nov 27 14:34:34 2019 +0100 @@ -280,12 +280,13 @@ } - RadiographyLayer& RadiographyScene::LoadText(const Orthanc::Font& font, - const std::string& utf8, + RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, + size_t fontSize, + uint8_t foreground, RadiographyLayer::Geometry* geometry) { std::auto_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(*this)); - alpha->LoadText(font, utf8); + alpha->LoadText(utf8, fontSize, foreground); if (geometry != NULL) { alpha->SetGeometry(*geometry);
--- a/Framework/Radiography/RadiographyScene.h Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.h Wed Nov 27 14:34:34 2019 +0100 @@ -198,8 +198,9 @@ RadiographyPhotometricDisplayMode GetPreferredPhotomotricDisplayMode() const; - RadiographyLayer& LoadText(const Orthanc::Font& font, - const std::string& utf8, + RadiographyLayer& LoadText(const std::string& utf8, + size_t fontSize, + uint8_t foreground, RadiographyLayer::Geometry* geometry); RadiographyLayer& LoadTestBlock(unsigned int width,
--- a/Framework/Radiography/RadiographySceneReader.cpp Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographySceneReader.cpp Wed Nov 27 14:34:34 2019 +0100 @@ -97,18 +97,8 @@ } else if (jsonLayer["type"].asString() == "text") { - if (fontRegistry_ == NULL || fontRegistry_->GetSize() == 0) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you must provide a FontRegistry if you need to re-create text layers. - } - ReadLayerGeometry(geometry, jsonLayer); - const Orthanc::Font* font = fontRegistry_->FindFont(jsonLayer["fontName"].asString()); - if (font == NULL) // if not found, take the first font in the registry - { - font = &(fontRegistry_->GetFont(0)); - } - scene_.LoadText(*font, jsonLayer["text"].asString(), &geometry); + scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["fontSize"].asUInt(), static_cast<uint8_t>(jsonLayer["foreground"].asUInt()), &geometry); } else if (jsonLayer["type"].asString() == "alpha") { @@ -184,18 +174,8 @@ } else if (jsonLayer["type"].asString() == "text") { - if (fontRegistry_ == NULL || fontRegistry_->GetSize() == 0) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you must provide a FontRegistry if you need to re-create text layers. - } - ReadLayerGeometry(geometry, jsonLayer); - const Orthanc::Font* font = fontRegistry_->FindFont(jsonLayer["fontName"].asString()); - if (font == NULL) // if not found, take the first font in the registry - { - font = &(fontRegistry_->GetFont(0)); - } - scene_.LoadText(*font, jsonLayer["text"].asString(), &geometry); + scene_.LoadText(jsonLayer["text"].asString(), jsonLayer["fontSize"].asUInt(), static_cast<uint8_t>(jsonLayer["foreground"].asUInt()), &geometry); } else if (jsonLayer["type"].asString() == "alpha") {
--- a/Framework/Radiography/RadiographySceneReader.h Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographySceneReader.h Wed Nov 27 14:34:34 2019 +0100 @@ -40,15 +40,13 @@ { protected: RadiographyScene& scene_; - const Orthanc::FontRegistry* fontRegistry_; std::auto_ptr<Orthanc::ImageAccessor> dicomImage_; std::auto_ptr<Deprecated::DicomFrameConverter> dicomFrameConverter_; RadiographyPhotometricDisplayMode preferredPhotometricDisplayMode_; public: RadiographySceneBuilder(RadiographyScene& scene) : - scene_(scene), - fontRegistry_(NULL) + scene_(scene) { } @@ -59,11 +57,6 @@ RadiographyPhotometricDisplayMode preferredPhotometricDisplayMode ); - void SetFontRegistry(const Orthanc::FontRegistry& fontRegistry) - { - fontRegistry_ = &fontRegistry; - } - static void ReadLayerGeometry(RadiographyLayer::Geometry& geometry, const Json::Value& input); static void ReadDicomLayerGeometry(RadiographyLayer::Geometry& geometry, const Json::Value& input);
--- a/Framework/Radiography/RadiographySceneWriter.cpp Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographySceneWriter.cpp Wed Nov 27 14:34:34 2019 +0100 @@ -62,7 +62,8 @@ { output["type"] = "text"; output["text"] = layer.GetText(); - output["fontName"] = layer.GetFontName(); + output["fontSize"] = static_cast<unsigned int>(layer.GetFontSize()); + output["foreground"] = layer.GetForeground(); } void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyMaskLayer& layer)
--- a/Framework/Radiography/RadiographyTextLayer.cpp Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.cpp Wed Nov 27 14:34:34 2019 +0100 @@ -18,19 +18,32 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. **/ - #include "RadiographyTextLayer.h" +#include "Core/OrthancException.h" #include "RadiographyScene.h" +#include "Framework/Toolbox/TextRenderer.h" namespace OrthancStone { - void RadiographyTextLayer::LoadText(const Orthanc::Font& font, - const std::string& utf8) + bool RadiographyTextLayer::fontHasBeenConfigured_ = false; + Orthanc::EmbeddedResources::FileResourceId RadiographyTextLayer::fontResourceId_; + + void RadiographyTextLayer::LoadText(const std::string& utf8, + size_t fontSize, + uint8_t foreground) { + if (!fontHasBeenConfigured_) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "No font has been loaded"); + } + text_ = utf8; - fontName_ = font.GetName(); + fontSize_ = fontSize; + foreground_ = foreground; - SetAlpha(font.RenderAlpha(utf8)); + SetAlpha(TextRenderer::Render(fontResourceId_, + fontSize_, + text_)); } }
--- a/Framework/Radiography/RadiographyTextLayer.h Sat Nov 23 11:57:03 2019 +0100 +++ b/Framework/Radiography/RadiographyTextLayer.h Wed Nov 27 14:34:34 2019 +0100 @@ -30,26 +30,39 @@ class RadiographyTextLayer : public RadiographyAlphaLayer { private: - std::string text_; - std::string fontName_; + std::string text_; + size_t fontSize_; + uint8_t foreground_; + static bool fontHasBeenConfigured_; + static Orthanc::EmbeddedResources::FileResourceId fontResourceId_; public: RadiographyTextLayer(const RadiographyScene& scene) : RadiographyAlphaLayer(scene) { } - void LoadText(const Orthanc::Font& font, - const std::string& utf8); + void LoadText(const std::string& utf8, size_t fontSize, uint8_t foreground); const std::string& GetText() const { return text_; } - const std::string& GetFontName() const + size_t GetFontSize() const + { + return fontSize_; + } + + uint8_t GetForeground() const { - return fontName_; + return foreground_; + } + + static void SetFont(Orthanc::EmbeddedResources::FileResourceId fontResourceId) + { + fontResourceId_ = fontResourceId; + fontHasBeenConfigured_ = true; } }; }