changeset 1419:f5493e5a51a3

single CMakeLists.txt for all SDL samples & unit tests + another one for all Wasm samples
author Alain Mazy <alain@mazy.be>
date Wed, 13 May 2020 12:42:52 +0200
parents 998697c5ec74
children 7d6455a306ab
files .hgignore Samples/README.md Samples/Sdl/CMakeLists.txt Samples/WebAssembly/CMakeLists.txt Samples/build-wasm-samples.sh
diffstat 5 files changed, 335 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon May 11 09:50:02 2020 +0200
+++ b/.hgignore	Wed May 13 12:42:52 2020 +0200
@@ -6,23 +6,21 @@
 .vscode/
 build*/
 CMakeLists.txt.user
-Resources/CodeGeneration/.env
-Resources/CodeGeneration/.idea
-Resources/CodeGeneration/__pycache__
-Resources/CodeGeneration/build/
-Resources/CodeGeneration/build_browser/
-Resources/CodeGeneration/testCppHandler/build/
-Resources/CodeGeneration/testCppHandler/build_msbuild/
-Resources/CodeGeneration/testWasmIntegrated/build-final/
-Resources/CodeGeneration/testWasmIntegrated/build-tsc/
-Resources/CodeGeneration/testWasmIntegrated/build-wasm/
-Resources/CommandTool/flatc-tests/basic/build/
-Resources/CommandTool/protoc-tests/generated_js/
-Resources/CommandTool/protoc-tests/generated_ts/
-Resources/CommandTool/protoc-tests/node_modules/
+Deprecated/Resources/CodeGeneration/.env
+Deprecated/Resources/CodeGeneration/.idea
+Deprecated/Resources/CodeGeneration/__pycache__
+Deprecated/Resources/CodeGeneration/build/
+Deprecated/Resources/CodeGeneration/build_browser/
+Deprecated/Resources/CodeGeneration/testCppHandler/build/
+Deprecated/Resources/CodeGeneration/testCppHandler/build_msbuild/
+Deprecated/Resources/CodeGeneration/testWasmIntegrated/build-final/
+Deprecated/Resources/CodeGeneration/testWasmIntegrated/build-tsc/
+Deprecated/Resources/CodeGeneration/testWasmIntegrated/build-wasm/
 Samples/WebAssembly/*/ThirdPartyDownloads/
+Samples/WebAssembly/ThirdPartyDownloads/
 Samples/WebAssembly/*/out
 Samples/Sdl/*/ThirdPartyDownloads/
+Samples/Sdl/ThirdPartyDownloads/
 Samples/Sdl/*/out
 Samples/Sdl/build*/
 Samples/Deprecated/Sdl/ThirdPartyDownloads/
--- a/Samples/README.md	Mon May 11 09:50:02 2020 +0200
+++ b/Samples/README.md	Wed May 13 12:42:52 2020 +0200
@@ -29,6 +29,27 @@
 various ways suitable for the platform (command-line arguments, URL parameters
 or through the GUI)
 
+
+This repo contains two sample projects:
+
+SingleFrameViewer
+-----------------
+
+This sample application displays a single frame of a Dicom instance that can
+be loaded from Orthanc, either by using the Orthanc REST API or through the 
+Dicomweb server functionality of Orthanc.
+
+RtViewer
+--------
+
+This sample application displays set of Radiotherapy data:
+- a CT scan
+- an RT-Dose
+- an RT-Struct
+
+The WebAssembly version displays 3 viewports with MPR data
+while the SDL sample displays a single viewport.
+
  
 WebAssembly samples
 ===================
@@ -58,17 +79,7 @@
 sudo apt-get install -y mercurial unzip npm ninja-build p7zip-full gettext-base 
 ```
 
-SingleFrameViewer
------------------
-
-This sample application displays a single frame of a Dicom instance that can
-be loaded from Orthanc, either by using the Orthanc REST API or through the 
-Dicomweb server functionality of Orthanc.
-
-This barebones sample uses plain Javascript and requires the 
-Emscripten toolchain and cmake, in addition to a few standard packages.
-
-To build it, just launch the `build-wasm-SingleFrameViewer.sh` script from
+To build the Wasm samples, just launch the `build-wasm-samples.sh` script from
 this folder.  Optionaly, you can pass the build type as an argument.
 We suggest that you do *not* use the `Debug` configuration unless you really 
 need it, for the additional checks that are made will lead to a very long 
@@ -82,12 +93,20 @@
 {
   "Plugins" : ["LibServeFolders.so],
   "ServeFolders" : {
-    "/single-frame-viewer" : "..../out/install-stone-wasm-SingleFrameViewer-RelWithDebInfo"
+    "/single-frame-viewer" : "..../out/install-stone-wasm-samples-RelWithDebInfo/SingleFrameViewer",
+    "/rt-viewer": "..../out/install-stone-wasm-samples-RelWithDebInfo/RtViewer"
   }
 }
 ```
 
-You'll then be able to open the demo at `http://localhost:8042/single-frame-viewer/index.html`
+You'll then be able to open the single-frame-viewer demo at `http://localhost:8042/single-frame-viewer/index.html` 
+
+The rt-viewer demo at
+`http://localhost:8044/rt-viewer/index.html?ctseries=a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa&rtdose=eac822ef-a395f94e-e8121fe0-8411fef8-1f7bffad&rtstruct=54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9`.  Note that you must provide 3 ids in the url:
+
+- the CT series Orthanc ID
+- the RT-Dose instance Orthanc ID
+- the RT-Struct instance Orthanc ID
 
 
 RtViewer
@@ -129,9 +148,6 @@
 Native samples
 =================
 
-SdlSimpleViewer
----------------
-
 ### Windows build 
 
 Here's how to build the SdlSimpleViewer example using Visual Studio 2019
@@ -155,7 +171,7 @@
     -DALLOW_DOWNLOADS=ON `
     -DSTATIC_BUILD=ON `
     -DOPENSSL_NO_CAPIENG=ON `
-    ../orthanc-stone/Samples/Sdl/SimpleViewer
+    ../orthanc-stone/Samples/Sdl
   
   $solutionPath = ls -filter *.sln
   Write-Host "Solution file(s) available at: $solutionPath"
@@ -176,7 +192,9 @@
 port 8042 and launch:
 
 ```
-./SingleFrameViewer --orthanc http://localhost:8042 --instance 7fc84013-abef174e-3354ca83-b9cdb2a4-f1a74368
+./SdlSimpleViewer --orthanc http://localhost:8042 --instance 7fc84013-abef174e-3354ca83-b9cdb2a4-f1a74368
+
+./RtViewerSdl --orthanc http://localhost:8042 --ctseries a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa --rtdose 830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb --rtstruct 54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9
 ```
 
 RtViewer
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/Sdl/CMakeLists.txt	Wed May 13 12:42:52 2020 +0200
@@ -0,0 +1,103 @@
+cmake_minimum_required(VERSION 2.8.10)
+
+project(OrthancStone)
+
+set(ORTHANC_FRAMEWORK_SOURCE "path")
+set(ORTHANC_FRAMEWORK_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../orthanc)
+set(STONE_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../)
+
+include(${STONE_ROOT}/Resources/CMake/OrthancStoneParameters.cmake)
+include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
+
+set(ALLOW_DOWNLOADS ON)
+if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+  set(STATIC_BUILD ON)
+endif()
+set(ENABLE_GOOGLE_TEST ON)
+set(ENABLE_LOCALE ON)  # Necessary for text rendering
+set(ENABLE_SDL ON)
+set(ENABLE_DCMTK ON)  # <==
+set(ENABLE_OPENGL ON)  #  <==
+set(ENABLE_WEB_CLIENT ON)
+set(ORTHANC_SANDBOXED OFF)
+
+DownloadPackage(
+  "a24b8136b8f3bb93f166baf97d9328de"
+  "http://orthanc.osimis.io/ThirdPartyDownloads/ubuntu-font-family-0.83.zip"
+  "${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83")
+
+set(ORTHANC_STONE_APPLICATION_RESOURCES
+  UBUNTU_FONT  ${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83/Ubuntu-R.ttf
+  )
+
+include(${STONE_ROOT}/Resources/CMake/OrthancStoneConfiguration.cmake)
+include(${STONE_ROOT}/Resources/CMake/Utilities.cmake)
+
+include_directories(${STONE_ROOT})
+include_directories(../Common)
+
+add_definitions(
+  -DORTHANC_ENABLE_LOGGING=1
+  -DORTHANC_ENABLE_LOGGING_PLUGIN=0
+  -DORTHANC_ENABLE_PUGIXML=0
+  -DORTHANC_DEFAULT_DICOM_ENCODING=Encoding_Latin1
+  )
+
+SortFilesInSourceGroups()
+
+add_library(OrthancStone STATIC
+  ${ORTHANC_STONE_SOURCES}
+  )
+
+
+#############################
+project(RtViewerSdl)
+
+add_executable(RtViewerSdl
+  RtViewer/RtViewerSdl.cpp
+  SdlHelpers.h
+  ../Common/RtViewer.cpp
+  ../Common/RtViewer.h
+  ../Common/SampleHelpers.h
+  )
+
+target_link_libraries(RtViewerSdl ${DCMTK_LIBRARIES} OrthancStone)
+
+#############################
+project(SdlSimpleViewer)
+
+add_executable(SdlSimpleViewer
+  SdlHelpers.h
+  ../Common/SampleHelpers.h
+  SingleFrameViewer/SdlSimpleViewerApplication.h
+  SingleFrameViewer/SdlSimpleViewer.cpp
+  )
+
+target_link_libraries(SdlSimpleViewer ${DCMTK_LIBRARIES} OrthancStone)
+
+#############################
+project(UnitTests)
+
+add_executable(UnitTests
+  ${GOOGLE_TEST_SOURCES}
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/GenericToolboxTests.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/ImageToolboxTests.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/PixelTestPatternsTests.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestCommands.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestMessageBroker.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestStrategy.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestStructureSet.cpp
+  ${ORTHANC_STONE_ROOT}/UnitTestsSources/UnitTestsMain.cpp
+)
+
+target_link_libraries(UnitTests OrthancStone)
+
+add_custom_command(
+  TARGET UnitTests
+  POST_BUILD
+  COMMAND ${CMAKE_COMMAND} -E copy
+    "${ORTHANC_STONE_ROOT}/UnitTestsSources/72c773ac-5059f2c4-2e6a9120-4fd4bca1-45701661.json" 
+    "$<TARGET_FILE_DIR:UnitTests>/72c773ac-5059f2c4-2e6a9120-4fd4bca1-45701661.json"
+)
+
+target_link_libraries(UnitTests ${DCMTK_LIBRARIES} OrthancStone)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/WebAssembly/CMakeLists.txt	Wed May 13 12:42:52 2020 +0200
@@ -0,0 +1,136 @@
+cmake_minimum_required(VERSION 2.8.3)
+
+project(OrthancStone)
+
+# Configuration of the Emscripten compiler for WebAssembly target
+# ---------------------------------------------------------------
+set(USE_WASM ON CACHE BOOL "")
+set(ORTHANC_FRAMEWORK_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../orthanc CACHE STRING "")
+set(STONE_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../)
+
+set(EMSCRIPTEN_SET_LLVM_WASM_BACKEND ON CACHE BOOL "")
+
+set(WASM_FLAGS "-s WASM=1 -s FETCH=1")
+if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1")
+endif()
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WASM_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WASM_FLAGS}")
+
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456")  # 256MB + resize
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1")
+add_definitions(
+  -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
+)
+
+# Stone of Orthanc configuration
+# ---------------------------------------------------------------
+set(ALLOW_DOWNLOADS ON)
+set(ORTHANC_FRAMEWORK_SOURCE "path")
+
+include(${STONE_ROOT}/Resources/CMake/OrthancStoneParameters.cmake)
+include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
+
+SET(ENABLE_DCMTK ON)
+SET(ENABLE_GOOGLE_TEST OFF)
+SET(ENABLE_LOCALE ON)  # Necessary for text rendering
+SET(ENABLE_WASM ON)
+SET(ORTHANC_SANDBOXED ON)
+
+
+# We embed a font to be used for on-screen overlays
+# ---------------------------------------------------------------
+
+DownloadPackage(
+  "a24b8136b8f3bb93f166baf97d9328de"
+  "http://orthanc.osimis.io/ThirdPartyDownloads/ubuntu-font-family-0.83.zip"
+  "${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83")
+
+set(ORTHANC_STONE_APPLICATION_RESOURCES
+  UBUNTU_FONT  ${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83/Ubuntu-R.ttf
+  )
+
+# this will set up the build system for Stone of Orthanc and will
+# populate the ORTHANC_STONE_SOURCES CMake variable
+include(${STONE_ROOT}/Resources/CMake/OrthancStoneConfiguration.cmake)
+
+include_directories(${STONE_ROOT})
+include_directories(../Common)
+
+add_library(OrthancStone STATIC
+  ${ORTHANC_STONE_SOURCES}
+  )
+
+################################################################################
+
+# Define the WASM module
+# ---------------------------------------------------------------
+
+project(RtViewerWasm)
+
+add_executable(RtViewerWasm
+  RtViewer/RtViewerWasm.cpp
+  ../Common/RtViewer.cpp
+  ../Common/RtViewer.h
+  )
+
+target_link_libraries(RtViewerWasm OrthancStone)
+
+# Declare installation files for the module
+# ---------------------------------------------------------------
+install(
+  TARGETS RtViewerWasm
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/RtViewer/
+  )
+
+# Declare installation files for the companion files (web scaffolding)
+# please note that ${CMAKE_CURRENT_BINARY_DIR}/RtViewerWasm.js
+# (the generated JS loader for the WASM module) is handled by the `install1`
+# section above: it is considered to be the binary output of 
+# the linker.
+# ---------------------------------------------------------------
+install(
+  FILES
+  ${CMAKE_SOURCE_DIR}/RtViewer/RtViewerWasmApp.js
+  ${CMAKE_SOURCE_DIR}/RtViewer/index.html
+  ${CMAKE_CURRENT_BINARY_DIR}/RtViewerWasm.wasm
+  DESTINATION ${CMAKE_INSTALL_PREFIX}/RtViewer/
+  )
+
+################################################################################
+
+# Define the WASM module
+# ---------------------------------------------------------------
+
+project(SingleFrameViewerWasm)
+
+add_executable(SingleFrameViewerWasm
+  SingleFrameViewer/SingleFrameViewer.cpp
+  )
+
+target_link_libraries(SingleFrameViewerWasm OrthancStone)
+
+# Declare installation files for the module
+# ---------------------------------------------------------------
+install(
+  TARGETS SingleFrameViewerWasm
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/SingleFrameViewer/
+  )
+
+# Declare installation files for the companion files (web scaffolding)
+# please note that ${CMAKE_CURRENT_BINARY_DIR}/RtViewerWasm.js
+# (the generated JS loader for the WASM module) is handled by the `install1`
+# section above: it is considered to be the binary output of 
+# the linker.
+# ---------------------------------------------------------------
+install(
+  FILES
+  ${CMAKE_SOURCE_DIR}/SingleFrameViewer/SingleFrameViewerApp.js
+  ${CMAKE_SOURCE_DIR}/SingleFrameViewer/index.html
+  ${CMAKE_CURRENT_BINARY_DIR}/SingleFrameViewerWasm.wasm
+  DESTINATION ${CMAKE_INSTALL_PREFIX}/SingleFrameViewer/
+  )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/build-wasm-samples.sh	Wed May 13 12:42:52 2020 +0200
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# usage:
+# to build the samples in RelWithDebInfo:
+# ./build-wasm-samples.sh
+#
+# to build the samples in Release:
+# ./build-wasm-samples.sh Release
+
+set -e
+
+if [ ! -d "WebAssembly" ]; then
+  echo "This script must be run from the Samples folder one level below orthanc-stone"
+  exit 1
+fi
+
+
+currentDir=$(pwd)
+samplesRootDir=$(pwd)
+devrootDir=$(pwd)/../../
+
+buildType=${1:-RelWithDebInfo}
+buildFolderName="$devrootDir/out/build-stone-wasm-samples-$buildType"
+installFolderName="$devrootDir/out/install-stone-wasm-samples-$buildType"
+
+mkdir -p $buildFolderName
+# change current folder to the build folder
+pushd $buildFolderName
+
+# configure the environment to use Emscripten
+source ~/apps/emsdk/emsdk_env.sh
+
+emcmake cmake -G "Ninja" \
+  -DCMAKE_BUILD_TYPE=$buildType \
+  -DCMAKE_INSTALL_PREFIX=$installFolderName \
+  -DSTATIC_BUILD=ON -DALLOW_DOWNLOADS=ON \
+  $samplesRootDir/WebAssembly
+
+# perform build + installation
+ninja
+ninja install
+
+# restore the original working folder
+popd
+
+echo "If all went well, the output files can be found in $installFolderName:"
+
+ls $installFolderName
\ No newline at end of file