Skip to content

Commit

Permalink
feat(dicomImageLoader types): Add types to the dicom image loader (#441)
Browse files Browse the repository at this point in the history
* initial effort

* internal options

* wip

* add wadors metadata types

* wip

* finish wadors

* wadouri metadata

* image loader wip

* finish image loader

* shared

* added all types

* updated package json

* rename

* rename

* finish rename

* fix missing types

* rename wado

* fix build

* update yarn lock

* Improve WARORS types as per PR comments (#449)

Co-authored-by: James Manners <james@binary.com.au>

* add types for wasm codec modules (#450)

* Improve WARORS types as per PR comments

* [dicom-image-loader] add types for wasm codec modules

* [dicom-image-loader] relocate WASM types

---------

Co-authored-by: James Manners <james@binary.com.au>

* apply review comments - working dynamic import

* rename dicom image loader to cornerstone image loader

* replace cswado with csdicom loader

* bring back cs wado for now

---------

Co-authored-by: James Manners <james@manners.net.au>
Co-authored-by: James Manners <james@binary.com.au>
  • Loading branch information
3 people authored Mar 3, 2023
1 parent a30c081 commit 10a3370
Show file tree
Hide file tree
Showing 155 changed files with 2,269 additions and 1,569 deletions.
6 changes: 5 additions & 1 deletion .webpack/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ module.exports = (env, argv, { DIST_DIR }) => {
envName: mode,
},
},
{
test: /\.wasm/,
type: 'asset/resource',
},
],
},
resolve: {
Expand Down Expand Up @@ -70,7 +74,7 @@ module.exports = (env, argv, { DIST_DIR }) => {
// Show build progress
new webpack.ProgressPlugin(),
// Clear dist between builds
new CleanWebpackPlugin()
new CleanWebpackPlugin(),
],
};

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@
"css-loader": "^5.2.7",
"cssnano": "^4.1.11",
"eslint": "^8.17.0",
"eslint-loader": "4.0.2",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "6.x",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-tsdoc": "^0.2.14",
"eslint-webpack-plugin": "^2.6.0",
"eslint-webpack-plugin": "^4.0.0",
"file-loader": "^6.2.0",
"follow-redirects": "^1.10.0",
"html-webpack-plugin": "^5.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/examples/cornerstoneDICOMSR/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h1>
<script src="https://unpkg.com/cornerstone-tools@4.16.1/dist/cornerstoneTools.js"></script>

<script src="https://unpkg.com/dicom-parser/dist/dicomParser.js"></script>
<script src="https://unpkg.com/cornerstone-wado-image-loader@3.0.2/dist/cornerstoneWADOImageLoader.min.js"></script>
<script src="https://unpkg.com/@cornerstonejs/dicom-image-loader@3.0.2/dist/cornerstoneDICOMImageLoader.min.js"></script>
<script src="https://unpkg.com/hammerjs/hammer.min.js"></script>

<script src="/js/initCornerstone.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ function getImageIdOfReferencedFrame(
const imageIdFrameNumber = Number(imageId.split("frame=")[1]);

return (
//frameNumber is zero indexed for cornerstoneWADOImageLoader image Ids.
//frameNumber is zero indexed for cornerstoneDICOMImageLoader image Ids.
sopCommonModule.sopInstanceUID === sopInstanceUid &&
imageIdFrameNumber === frameNumber - 1
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ function getImageIdOfReferencedFrame(
const imageIdFrameNumber = Number(imageId.split("frame=")[1]);

return (
//frameNumber is zero indexed for cornerstoneWADOImageLoader image Ids.
//frameNumber is zero indexed for cornerstoneDICOMImageLoader image Ids.
sopCommonModule.sopInstanceUID === sopInstanceUid &&
imageIdFrameNumber === frameNumber - 1
);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/examples/wadouri/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
setTitleAndDescription,
ctVoiRange,
} from '../../../../utils/demo/helpers';
import initCornerstoneWADOImageLoader from '../../../../utils/demo/helpers/initCornerstoneWADOImageLoader';
import initCornerstoneDICOMImageLoader from '../../../../utils/demo/helpers/initCornerstoneDICOMImageLoader';
import { init as csRenderInit } from '@cornerstonejs/core';

// This is for debugging purposes
Expand Down Expand Up @@ -99,7 +99,7 @@ addButtonToToolbar({
*/
async function run() {
// Init Cornerstone and related libraries
initCornerstoneWADOImageLoader();
initCornerstoneDICOMImageLoader();
await csRenderInit();

const renderingEngine = new RenderingEngine(renderingEngineId);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/webLoader/registerWebImageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function registerWebImageLoader(imageLoader): void {
}

/**
* Small stripped down loader from cornerstoneWADOImageLoader
* Small stripped down loader from cornerstoneDICOMImageLoader
* Which doesn't create cornerstone images that we don't need
*/
function _loadImageIntoBuffer(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class StackViewport extends Viewport implements IStackViewport {
windowCenter = windowCenter[0];
}

// when cornerstoneWADOImageLoader uses cornerstonejs/core types
// when cornerstoneDICOMImageLoader uses cornerstonejs/core types
// this marshalling step can be removed.
if (Object.values(VOILUTFunctionType).indexOf(voiLUTFunction) === -1) {
voiLUTFunction = VOILUTFunctionType.LINEAR;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/enums/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum Events {
IMAGE_SPACING_CALIBRATED = 'CORNERSTONE_IMAGE_SPACING_CALIBRATED',
/**
* Triggers on the eventTarget when there is a progress in the image load process. Note: this event
* is being used in the Cornerstone-WADO-Image-Loader repository. See {@link https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/master/src/imageLoader/internal/xhrRequest.js | here}
* is being used in the dicom-image-loader repository. See {@link https://github.com/cornerstonejs/cornerstoneDICOMImageLoader/blob/master/src/imageLoader/internal/xhrRequest.js | here}
*
* Make use of {@link EventTypes.ImageLoadProgress | ImageLoadProgress Event Type } for typing your event listeners for IMAGE_LOAD_PROGRESS event,
* and see what event detail is included in {@link EventTypes.ImageLoadProgressEventDetail | ImageLoadProgress Event Detail }
Expand Down
21 changes: 0 additions & 21 deletions packages/dicomImageLoader/.jsdocrc

This file was deleted.

19 changes: 19 additions & 0 deletions packages/dicomImageLoader/.webpack/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const _ = require('lodash');

// Merge two objects
// Instead of merging array objects index by index (n-th source
// item with n-th object item) it concatenates both arrays
module.exports = function (object, source) {
const clone = _.cloneDeep(object);
const merged = _.mergeWith(
clone,
source,
function (objValue, srcValue, key, object, source, stack) {
if (objValue && srcValue && _.isArray(objValue) && _.isArray(srcValue)) {
return _.concat(objValue, srcValue);
}
}
);

return merged;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path');
const webpack = require('webpack');

const rootPath = process.cwd();
const context = path.join(rootPath, 'src');
const codecs = path.join(rootPath, 'codecs');
const outputPath = path.join(rootPath, 'dist');
const ESLintPlugin = require('eslint-webpack-plugin');

const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
Expand All @@ -13,7 +13,7 @@ module.exports = {
mode: 'development',
context,
entry: {
cornerstoneDICOMImageLoader: './imageLoader/index.js',
cornerstoneDICOMImageLoader: './imageLoader/index.ts',
},
target: 'web',
output: {
Expand All @@ -36,6 +36,7 @@ module.exports = {
},
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
fs: false,
path: false,
Expand All @@ -44,21 +45,12 @@ module.exports = {
module: {
noParse: [/(codecs)/],
rules: [
// {
// enforce: 'pre',
// test: /\.js$/,
// exclude: /(node_modules)|(codecs)/,
// loader: 'eslint-loader',
// options: {
// failOnError: false,
// },
// },
{
test: /\.wasm/,
type: 'asset/resource',
},
{
test: /\.worker\.js$/,
test: /\.worker\.(mjs|js|ts)$/,
use: [
{
loader: 'worker-loader',
Expand All @@ -69,7 +61,7 @@ module.exports = {
],
},
{
test: /\.js$/,
test: /\.(mjs|js|ts)$/,
exclude: [/(node_modules)/, /(codecs)/],
use: {
loader: 'babel-loader',
Expand All @@ -88,6 +80,6 @@ module.exports = {
// experiments: {
// asyncWebAssembly: true,
// },
plugins: [new webpack.ProgressPlugin()],
plugins: [new ESLintPlugin(), new webpack.ProgressPlugin()],
// plugins: [new webpack.ProgressPlugin(), new BundleAnalyzerPlugin()],
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const webpack = require('webpack');

const rootPath = process.cwd();
const context = path.join(rootPath, 'src');
const codecs = path.join(rootPath, 'codecs');
Expand All @@ -16,8 +15,8 @@ module.exports = {
mode: 'production',
context,
entry: {
cornerstoneDICOMImageLoader: './imageLoader/index.js',
cornerstoneDICOMImageLoaderNoWebWorkers: './imageLoader/index-noWorkers.js',
cornerstoneDICOMImageLoader: './imageLoader/index.ts',
cornerstoneDICOMImageLoaderNoWebWorkers: './imageLoader/index-noWorkers.ts',
},
target: 'web',
output: {
Expand All @@ -40,6 +39,7 @@ module.exports = {
},
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
fs: false,
path: false,
Expand All @@ -50,7 +50,7 @@ module.exports = {
rules: [
// {
// enforce: 'pre',
// test: /\.js$/,
// test: /\.(mjs|js|ts)$/,
// exclude: /(node_modules)|(codecs)/,
// loader: 'eslint-loader',
// options: {
Expand All @@ -62,7 +62,7 @@ module.exports = {
type: 'asset/inline',
},
{
test: /\.worker\.js$/,
test: /\.worker\.(mjs|js|ts)$/,
use: [
{
loader: 'worker-loader',
Expand All @@ -74,7 +74,7 @@ module.exports = {
],
},
{
test: /\.js$/,
test: /\.(mjs|js|ts)$/,
exclude: [/(node_modules)/, /(codecs)/],
use: {
loader: 'babel-loader',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const webpack = require('webpack');
const merge = require('./merge');
const merge = require('webpack-merge');
const baseConfig = require('./webpack-base');

const devConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const TerserPlugin = require('terser-webpack-plugin');
const outputPath = path.join(rootPath, 'dist', 'dynamic-import');

const prodConfig = {
mode: 'production',
mode: 'development',
stats: {
children: true,
},
Expand All @@ -20,12 +20,12 @@ const prodConfig = {
filename: '[name].min.js',
},
optimization: {
// minimize: false,
minimizer: [
new TerserPlugin({
parallel: true,
}),
],
minimize: false,
// minimizer: [
// new TerserPlugin({
// parallel: true,
// }),
// ],
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Not used for now due to issues with experimental output modules
const path = require('path');
const webpack = require('webpack');

const rootPath = process.cwd();
const context = path.join(rootPath, 'src');
const outputPath = path.join(rootPath, 'dist');
Expand All @@ -13,7 +12,7 @@ const config = {
mode: 'development',
context,
entry: {
cornerstoneDICOMImageLoader: './imageLoader/index.js',
cornerstoneDICOMImageLoader: './imageLoader/index.ts',
},
target: 'web',
output: {
Expand All @@ -36,6 +35,7 @@ const config = {
},
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
fs: false,
path: false,
Expand All @@ -58,7 +58,7 @@ const config = {
type: 'asset/resource',
},
{
test: /\.js$/,
test: /\.(mjs|js|ts)$/,
exclude: [/(node_modules)/, /(codecs)/],
use: {
loader: 'babel-loader',
Expand Down
Loading

0 comments on commit 10a3370

Please sign in to comment.