# HG changeset patch # User Sebastien Jodogne # Date 1712728185 -7200 # Node ID 9b2a2fcc9878c09f7a3da5794fa39553be1c03ee # Parent 967f947014ac79fe57d25ce2194381840c7240f8 added option to disable Nexus support diff -r 967f947014ac -r 9b2a2fcc9878 CMakeLists.txt --- a/CMakeLists.txt Tue Apr 09 22:13:01 2024 +0200 +++ b/CMakeLists.txt Wed Apr 10 07:49:45 2024 +0200 @@ -58,6 +58,9 @@ set(ORTHANC_FRAMEWORK_ARCHIVE "" CACHE STRING "Path to the Orthanc archive, if ORTHANC_FRAMEWORK_SOURCE is \"archive\"") set(ORTHANC_FRAMEWORK_ROOT "" CACHE STRING "Path to the Orthanc source directory, if ORTHANC_FRAMEWORK_SOURCE is \"path\"") +# New in release 2.0 +set(ENABLE_NEXUS OFF CACHE BOOL "Include support for Nexus 3D models") + # Advanced parameters to fine-tune linking against system libraries SET(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK") @@ -168,31 +171,57 @@ ## Create the autogenerated files ##################################################################### -EmbedResources( +set(EMBEDDED_RESOURCES THREE_HTML ${CMAKE_SOURCE_DIR}/WebApplications/three.html THREE_JS ${CMAKE_SOURCE_DIR}/WebApplications/three.js O3DV_HTML ${CMAKE_SOURCE_DIR}/WebApplications/o3dv.html O3DV_JS ${CMAKE_SOURCE_DIR}/WebApplications/o3dv.js ORTHANC_EXPLORER ${CMAKE_SOURCE_DIR}/Sources/OrthancExplorer.js + ) - NEXUS_HTML ${CMAKE_SOURCE_DIR}/Resources/Nexus/threejs.html - NEXUS_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/nexus.js - NEXUS_MECO_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/meco.js - NEXUS_THREE_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/nexus_three.js - NEXUS_TRACKBALL_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/TrackballControls.js +set(STATIC_ASSETS + ${CMAKE_SOURCE_DIR}/JavaScriptLibraries/dist ) +if (ENABLE_NEXUS) + set(NEXUS_ASSETS_DIR ${AUTOGENERATED_DIR}/nexus) + file(MAKE_DIRECTORY ${NEXUS_ASSETS_DIR}) + + DownloadCompressedFile( + "df21a4a192c0952a1189125609cc76f9" + "https://orthanc.uclouvain.be/downloads/third-party-downloads/STL/three-84.js.gz" + "${NEXUS_ASSETS_DIR}/three-84.js") + + list(APPEND EMBEDDED_RESOURCES + NEXUS_HTML ${CMAKE_SOURCE_DIR}/Resources/Nexus/threejs.html + NEXUS_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/nexus.js + NEXUS_MECO_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/meco.js + NEXUS_THREE_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/nexus_three.js + NEXUS_TRACKBALL_JS ${CMAKE_SOURCE_DIR}/Resources/Nexus/js/TrackballControls.js + ) + + list(APPEND STATIC_ASSETS + ${NEXUS_ASSETS_DIR} + ) + + add_definitions(-DORTHANC_ENABLE_NEXUS=1) +else() + add_definitions(-DORTHANC_ENABLE_NEXUS=0) +endif() + +EmbedResources(${EMBEDDED_RESOURCES}) + add_custom_command( OUTPUT ${AUTOGENERATED_DIR}/StaticAssets.cpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Resources/EmbedStaticAssets.py - ${CMAKE_SOURCE_DIR}/JavaScriptLibraries/dist ${AUTOGENERATED_DIR}/StaticAssets.cpp + ${STATIC_ASSETS} DEPENDS - ${CMAKE_SOURCE_DIR}/JavaScriptLibraries/dist ${CMAKE_SOURCE_DIR}/Resources/EmbedStaticAssets.py + ${STATIC_ASSETS} ) list(APPEND AUTOGENERATED_SOURCES diff -r 967f947014ac -r 9b2a2fcc9878 Resources/EmbedStaticAssets.py --- a/Resources/EmbedStaticAssets.py Tue Apr 09 22:13:01 2024 +0200 +++ b/Resources/EmbedStaticAssets.py Wed Apr 10 07:49:45 2024 +0200 @@ -26,14 +26,15 @@ import os import sys -if len(sys.argv) != 3: - raise Exception('Usage: %s [source folder] [target C++]' % sys.argv[0]) +if len(sys.argv) <= 2: + raise Exception('Usage: %s [target C++] [source folders]' % sys.argv[0]) -SOURCE = sys.argv[1] -TARGET = sys.argv[2] +SOURCES = sys.argv[2:] +TARGET = sys.argv[1] -if not os.path.isdir(SOURCE): - raise Exception('Nonexistent source folder: %s' % SOURCE) +for source in SOURCES: + if not os.path.isdir(source): + raise Exception('Nonexistent source folder: %s' % source) def EncodeFileAsCString(f, variable, content): @@ -94,33 +95,34 @@ index = {} count = 0 - for root, dirs, files in os.walk(SOURCE): - files.sort() - dirs.sort() + for source in SOURCES: + for root, dirs, files in os.walk(source): + files.sort() + dirs.sort() - for f in files: - fullPath = os.path.join(root, f) - relativePath = os.path.relpath(os.path.join(root, f), SOURCE) - variable = 'data_%06d' % count + for f in files: + fullPath = os.path.join(root, f) + relativePath = os.path.relpath(os.path.join(root, f), source) + variable = 'data_%06d' % count - with open(fullPath, 'rb') as source: - content = source.read() + with open(fullPath, 'rb') as f: + content = f.read() - if sys.version_info < (3, 0): - # Python 2.7 - fileobj = io.BytesIO() - gzip.GzipFile(fileobj=fileobj, mode='w', mtime=0).write(content) - compressed = fileobj.getvalue() - else: - # Python 3.x - compressed = gzip.compress(content, mtime=0) + if sys.version_info < (3, 0): + # Python 2.7 + fileobj = io.BytesIO() + gzip.GzipFile(fileobj=fileobj, mode='w', mtime=0).write(content) + compressed = fileobj.getvalue() + else: + # Python 3.x + compressed = gzip.compress(content, mtime=0) - EncodeFileAsCString(g, variable, compressed) - WriteChecksum(g, variable + '_md5', content) + EncodeFileAsCString(g, variable, compressed) + WriteChecksum(g, variable + '_md5', content) - index[relativePath] = variable + index[relativePath] = variable - count += 1 + count += 1 g.write('void ReadStaticAsset(std::string& target, const std::string& path)\n') g.write('{\n') diff -r 967f947014ac -r 9b2a2fcc9878 Resources/Nexus.txt --- a/Resources/Nexus.txt Tue Apr 09 22:13:01 2024 +0200 +++ b/Resources/Nexus.txt Wed Apr 10 07:49:45 2024 +0200 @@ -2,6 +2,15 @@ GitHub: https://github.com/cnr-isti-vclab/nexus -The files in this folder come from folder "html" in release 4.2 (Nexus 2018). + +The files in folder "./Nexus" come from folder "html" in release 4.2 +(Nexus 2018), where the line: + + + +is replaced by the line: + + + WARNING: Releases 4.2.1, 4.2.2, and 4.3 do not seem to work anymore. diff -r 967f947014ac -r 9b2a2fcc9878 Resources/Nexus/threejs.html --- a/Resources/Nexus/threejs.html Tue Apr 09 22:13:01 2024 +0200 +++ b/Resources/Nexus/threejs.html Wed Apr 10 07:49:45 2024 +0200 @@ -5,7 +5,7 @@ - + diff -r 967f947014ac -r 9b2a2fcc9878 Sources/OrthancExplorer.js --- a/Sources/OrthancExplorer.js Tue Apr 09 22:13:01 2024 +0200 +++ b/Sources/OrthancExplorer.js Wed Apr 10 07:49:45 2024 +0200 @@ -395,27 +395,29 @@ function AddOpenStlNexusButton(instanceId, id, parent) { - $.ajax({ - url: '/instances/' + instanceId + '/content/0008,9123', - success: function(creatorVersionUid) { - if (creatorVersionUid == STL_PLUGIN_NEXUS_CREATOR_VERSION_UID) { - var b = $('') - .attr('id', id) - .attr('data-role', 'button') - .attr('href', '#') - .attr('data-icon', 'search') - .attr('data-theme', 'e') - .text('Nexus 3D viewer') - .button(); + if (${IS_NEXUS_ENABLED}) { + $.ajax({ + url: '/instances/' + instanceId + '/content/0008,9123', + success: function(creatorVersionUid) { + if (creatorVersionUid == STL_PLUGIN_NEXUS_CREATOR_VERSION_UID) { + var b = $('') + .attr('id', id) + .attr('data-role', 'button') + .attr('href', '#') + .attr('data-icon', 'search') + .attr('data-theme', 'e') + .text('Nexus 3D viewer') + .button(); - b.insertAfter($('#' + parent)); + b.insertAfter($('#' + parent)); - b.click(function() { - window.open('../stl/nexus/threejs.html?model=../../instances/' + instanceId + '/nexus'); - }); + b.click(function() { + window.open('../stl/nexus/threejs.html?model=../../instances/' + instanceId + '/nexus'); + }); + } } - } - }); + }); + } } diff -r 967f947014ac -r 9b2a2fcc9878 Sources/Plugin.cpp --- a/Sources/Plugin.cpp Tue Apr 09 22:13:01 2024 +0200 +++ b/Sources/Plugin.cpp Wed Apr 10 07:49:45 2024 +0200 @@ -22,6 +22,10 @@ **/ +#if !defined(ORTHANC_ENABLE_NEXUS) +# error Macro ORTHANC_ENABLE_NEXUS must be defined +#endif + #include "StructureSetGeometry.h" #include "STLToolbox.h" #include "VTKToolbox.h" @@ -30,7 +34,6 @@ #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" -#include #include #include #include @@ -42,6 +45,11 @@ #include #include + +#if ORTHANC_ENABLE_NEXUS == 1 +# include +#endif + #define ORTHANC_PLUGIN_NAME "stl" @@ -702,6 +710,8 @@ } +#if ORTHANC_ENABLE_NEXUS == 1 + void ServeNexusAssets(OrthancPluginRestOutput* output, const char* url, const OrthancPluginHttpRequest* request) @@ -868,6 +878,8 @@ OrthancPluginSendHttpStatus(context, output, 206 /* partial content */, part.c_str(), part.size()); } +#endif + extern "C" { @@ -916,9 +928,11 @@ OrthancPlugins::RegisterRestCallback("/stl/encode-nifti", true); } +#if ORTHANC_ENABLE_NEXUS == 1 nexusCache_.SetMaximumSize(512 * 1024 * 1024); // Cache of 512MB for Nexus OrthancPlugins::RegisterRestCallback("/instances/([0-9a-f-]+)/nexus", true); OrthancPlugins::RegisterRestCallback("/stl/nexus/(.*)", true); +#endif OrthancPlugins::OrthancConfiguration globalConfiguration; OrthancPlugins::OrthancConfiguration configuration; @@ -933,6 +947,7 @@ std::map dictionary; dictionary["HAS_CREATE_DICOM_STL"] = (hasCreateDicomStl_ ? "true" : "false"); dictionary["SHOW_NIFTI_BUTTON"] = (configuration.GetBooleanValue("EnableNIfTI", false) ? "true" : "false"); + dictionary["IS_NEXUS_ENABLED"] = (ORTHANC_ENABLE_NEXUS == 1 ? "true" : "false"); explorer = Orthanc::Toolbox::SubstituteVariables(explorer, dictionary); OrthancPlugins::ExtendOrthancExplorer(ORTHANC_PLUGIN_NAME, explorer);