Skip to content

Commit

Permalink
fix: Revert "refactor: Reduce bundle size (#1575)" (#1622)
Browse files Browse the repository at this point in the history
This reverts commit 81dcbe2.
  • Loading branch information
dannyrb authored Apr 9, 2020
1 parent 70672ed commit d21af3f
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 174 deletions.
36 changes: 14 additions & 22 deletions extensions/vtk/src/OHIFVTKViewport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { getReactVtkjsViewport } from './utils/getReactVtkjsViewport';
import { getImageData, loadImageData } from 'react-vtkjs-viewport';
import ConnectedVTKViewport from './ConnectedVTKViewport';
import LoadingIndicator from './LoadingIndicator.js';
import OHIF from '@ohif/core';
Expand Down Expand Up @@ -69,7 +69,7 @@ class OHIFVTKViewport extends Component {
};

static defaultProps = {
onScroll: () => { },
onScroll: () => {},
};

static id = 'OHIFVTKViewport';
Expand Down Expand Up @@ -133,8 +133,7 @@ class OHIFVTKViewport extends Component {
displaySetInstanceUID,
SOPClassUID,
SOPInstanceUID,
frameIndex,
reactVtkjsViewport
frameIndex
) => {
const stack = OHIFVTKViewport.getCornerstoneStack(
studies,
Expand All @@ -145,10 +144,7 @@ class OHIFVTKViewport extends Component {
frameIndex
);

const imageDataObject = reactVtkjsViewport.getImageData(
stack.imageIds,
displaySetInstanceUID
);
const imageDataObject = getImageData(stack.imageIds, displaySetInstanceUID);
let labelmapDataObject;
let labelmapColorLUT;

Expand Down Expand Up @@ -261,9 +257,7 @@ class OHIFVTKViewport extends Component {
return volumeActor;
}

async setStateFromProps() {
const reactVtkjsViewport = await getReactVtkjsViewport();

setStateFromProps() {
const { studies, displaySet } = this.props.viewportData;
const {
StudyInstanceUID,
Expand Down Expand Up @@ -301,10 +295,8 @@ class OHIFVTKViewport extends Component {
studies,
StudyInstanceUID,
displaySetInstanceUID,
sopClassUIDs[0],
SOPInstanceUID,
frameIndex,
reactVtkjsViewport
frameIndex
);

this.imageDataObject = imageDataObject;
Expand All @@ -325,7 +317,7 @@ class OHIFVTKViewport extends Component {
dataDetails,
},
() => {
this.loadProgressively(imageDataObject, reactVtkjsViewport);
this.loadProgressively(imageDataObject);

// TODO: There must be a better way to do this.
// We do this so that if all the data is available the react-vtkjs-viewport
Expand All @@ -343,26 +335,26 @@ class OHIFVTKViewport extends Component {
);
}

async componentDidMount() {
await this.setStateFromProps();
componentDidMount() {
this.setStateFromProps();
}

async componentDidUpdate(prevProps) {
componentDidUpdate(prevProps) {
const { displaySet } = this.props.viewportData;
const prevDisplaySet = prevProps.viewportData.displaySet;

if (
displaySet.displaySetInstanceUID !==
prevDisplaySet.displaySetInstanceUID ||
prevDisplaySet.displaySetInstanceUID ||
displaySet.SOPInstanceUID !== prevDisplaySet.SOPInstanceUID ||
displaySet.frameIndex !== prevDisplaySet.frameIndex
) {
await this.setStateFromProps();
this.setStateFromProps();
}
}

loadProgressively(imageDataObject, reactVtkjsViewport) {
reactVtkjsViewport.loadImageData(imageDataObject);
loadProgressively(imageDataObject) {
loadImageData(imageDataObject);

const { isLoading, insertPixelDataPromises } = imageDataObject;

Expand Down
11 changes: 2 additions & 9 deletions extensions/vtk/src/VTKViewport.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import React, { useEffect, useCallback } from 'react';
// import { View2D } from 'react-vtkjs-viewport';
import { View2D } from 'react-vtkjs-viewport';
import PropTypes from 'prop-types';
import asyncComponent from './asyncComponent.js';
import { getReactVtkjsViewport } from './utils/getReactVtkjsViewport';

import './VTKViewport.css';

const View2D = asyncComponent(async () => {
const reactVtkjsViewport = await getReactVtkjsViewport();
return { default: reactVtkjsViewport.View2D };
});

const VTKViewport = props => {
const style = { width: '100%', height: '100%', position: 'relative' };

Expand Down Expand Up @@ -59,7 +52,7 @@ VTKViewport.propTypes = {
};

VTKViewport.defaultProps = {
onScroll: () => { },
onScroll: () => {},
};

export default VTKViewport;
27 changes: 14 additions & 13 deletions extensions/vtk/src/commandsModule.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import throttle from 'lodash.throttle';
import { getReactVtkjsViewport } from './utils/getReactVtkjsViewport';
import {
vtkInteractorStyleMPRCrosshairs,
vtkInteractorStyleMPRWindowLevel,
vtkInteractorStyleMPRRotate,
vtkSVGCrosshairsWidget,
} from 'react-vtkjs-viewport';

import setMPRLayout from './utils/setMPRLayout.js';
import setViewportToVTK from './utils/setViewportToVTK.js';
Expand Down Expand Up @@ -119,26 +124,24 @@ const commandsModule = ({ commandsManager }) => {

_setView(api, [0, 1, 0], [0, 0, 1]);
},
enableRotateTool: async () => {
const reactVtkjsViewport = await getReactVtkjsViewport();
enableRotateTool: () => {
apis.forEach(api => {
const istyle = reactVtkjsViewport.vtkInteractorStyleMPRRotate.newInstance();
const istyle = vtkInteractorStyleMPRRotate.newInstance();

api.setInteractorStyle({ istyle });
});
},
enableCrosshairsTool: async () => {
const reactVtkjsViewport = await getReactVtkjsViewport();
enableCrosshairsTool: () => {
apis.forEach((api, apiIndex) => {
const istyle = reactVtkjsViewport.vtkInteractorStyleMPRCrosshairs.newInstance();
const istyle = vtkInteractorStyleMPRCrosshairs.newInstance();

api.setInteractorStyle({
istyle,
configuration: { apis, apiIndex },
});
});
},
enableLevelTool: async () => {
enableLevelTool: () => {
function updateVOI(apis, windowWidth, windowCenter) {
apis.forEach(api => {
api.updateVOI(windowWidth, windowCenter);
Expand All @@ -159,9 +162,8 @@ const commandsModule = ({ commandsManager }) => {
},
};

const reactVtkjsViewport = await getReactVtkjsViewport();
apis.forEach(api => {
const istyle = reactVtkjsViewport.vtkInteractorStyleMPRWindowLevel.newInstance();
const istyle = vtkInteractorStyleMPRWindowLevel.newInstance();

api.setInteractorStyle({ istyle, callbacks });
});
Expand Down Expand Up @@ -258,15 +260,14 @@ const commandsModule = ({ commandsManager }) => {
}

// Add widgets and set default interactorStyle of each viewport.
const reactVtkjsViewport = await getReactVtkjsViewport();
apis.forEach((api, apiIndex) => {
api.addSVGWidget(
reactVtkjsViewport.vtkSVGCrosshairsWidget.newInstance(),
vtkSVGCrosshairsWidget.newInstance(),
'crosshairsWidget'
);

const uid = api.uid;
const istyle = reactVtkjsViewport.vtkInteractorStyleMPRCrosshairs.newInstance();
const istyle = vtkInteractorStyleMPRCrosshairs.newInstance();

api.setInteractorStyle({
istyle,
Expand Down
5 changes: 0 additions & 5 deletions extensions/vtk/src/utils/getReactVtkjsViewport.js

This file was deleted.

5 changes: 2 additions & 3 deletions platform/core/src/classes/StudyLoadingListener.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import cornerstone from 'cornerstone-core';
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import {
clearStudyLoadingProgress,
setStudyLoadingProgress,
} from '../redux/actions';
import StackManager from '../utils/StackManager';
import { getCornerstoneWADOImageLoader } from '../utils/cornerstoneWADOImageLoader';

class BaseLoadingListener {
constructor(stack, options = {}) {
Expand Down Expand Up @@ -103,8 +103,7 @@ class DICOMFileLoadingListener extends BaseLoadingListener {
this._checkCachedData();
}

async _checkCachedData() {
const cornerstoneWADOImageLoader = await getCornerstoneWADOImageLoader();
_checkCachedData() {
const dataSet = cornerstoneWADOImageLoader.wadouri.dataSetCacheManager.get(
this._dataSetUrl
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import DICOMWeb from '../../../DICOMWeb';
import metadataProvider from '../../../classes/MetadataProvider';
import getWADORSImageId from '../../../utils/getWADORSImageId';
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import getReferencedSeriesSequence from './getReferencedSeriesSequence';
import { getCornerstoneWADOImageLoader } from '../../../utils/cornerstoneWADOImageLoader';

/**
* Create a plain JS object that describes a study (a study descriptor object)
Expand Down Expand Up @@ -160,7 +160,6 @@ async function makeSOPInstance(server, study, instance) {

const wadoRSMetadata = Object.assign(instance);

const cornerstoneWADOImageLoader = await getCornerstoneWADOImageLoader();
if (sopInstance.NumberOfFrames) {
for (let i = 0; i < sopInstance.NumberOfFrames; i++) {
const wadorsImageId = getWADORSImageId(sopInstance, i);
Expand Down
5 changes: 0 additions & 5 deletions platform/core/src/utils/cornerstoneWADOImageLoader.js

This file was deleted.

13 changes: 6 additions & 7 deletions platform/core/src/utils/dicomLoaderService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cornerstone from 'cornerstone-core';
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import { api } from 'dicomweb-client';
import DICOMWeb from '../DICOMWeb';
import { getCornerstoneWADOImageLoader } from './cornerstoneWADOImageLoader';

const getImageId = imageObj => {
if (!imageObj) {
Expand Down Expand Up @@ -86,7 +86,7 @@ const getImageLoaderType = imageId => {
};

class DicomLoaderService {
async getLocalData(dataset, studies) {
getLocalData(dataset, studies) {
if (dataset && dataset.localFile) {
// Use referenced imageInstance
const imageInstance = getImageInstance(dataset);
Expand All @@ -98,7 +98,6 @@ class DicomLoaderService {
}

if (!someInvalidStrings(imageId)) {
const cornerstoneWADOImageLoader = await getCornerstoneWADOImageLoader();
return cornerstoneWADOImageLoader.wadouri.loadFileRequest(imageId);
}
}
Expand Down Expand Up @@ -177,16 +176,16 @@ class DicomLoaderService {
}
}

async *getLoaderIterator(dataset, studies) {
yield await this.getLocalData(dataset, studies);
*getLoaderIterator(dataset, studies) {
yield this.getLocalData(dataset, studies);
yield this.getDataByImageType(dataset);
yield this.getDataByDatasetType(dataset);
}

async findDicomDataPromise(dataset, studies) {
findDicomDataPromise(dataset, studies) {
const loaderIterator = this.getLoaderIterator(dataset, studies);
// it returns first valid retriever method.
for await (const loader of loaderIterator) {
for (const loader of loaderIterator) {
if (loader) {
return loader;
}
Expand Down
6 changes: 5 additions & 1 deletion platform/viewer/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import i18n from '@ohif/i18n';
import './config';

/** Utils */
import { getUserManagerForOpenIdConnectClient } from './utils/index.js';
import {
getUserManagerForOpenIdConnectClient,
initWebWorkers,
} from './utils/index.js';

/** Extensions */
import { GenericViewerCommands, MeasurementsPanel } from './appExtensions';
Expand Down Expand Up @@ -137,6 +140,7 @@ class App extends Component {
*/
_initHotkeys(appConfigHotkeys);
_initServers(servers);
initWebWorkers();
}

render() {
Expand Down
30 changes: 30 additions & 0 deletions platform/viewer/src/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OHIF from '@ohif/core';
import cornerstone from 'cornerstone-core';
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import dicomParser from 'dicom-parser';
import version from './version.js';

let homepage;
Expand All @@ -12,4 +15,31 @@ window.info = {
homepage,
};

// For debugging
//if (process.env.node_env === 'development') {
window.cornerstone = cornerstone;
window.cornerstoneWADOImageLoader = cornerstoneWADOImageLoader;
//}

cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
cornerstoneWADOImageLoader.external.dicomParser = dicomParser;

OHIF.user.getAccessToken = () => {
// TODO: Get the Redux store from somewhere else
const state = window.store.getState();
if (!state.oidc || !state.oidc.user) {
return;
}

return state.oidc.user.access_token;
};

cornerstoneWADOImageLoader.configure({
beforeSend: function(xhr) {
const headers = OHIF.DICOMWeb.getAuthorizationHeader();

if (headers.Authorization) {
xhr.setRequestHeader('Authorization', headers.Authorization);
}
},
});
2 changes: 1 addition & 1 deletion platform/viewer/src/lib/filesToStudies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FileLoaderService from './localFileLoaders/fileLoaderService';
const processFile = async file => {
try {
const fileLoaderService = new FileLoaderService(file);
const imageId = await fileLoaderService.addFile(file);
const imageId = fileLoaderService.addFile(file);
const image = await fileLoaderService.loadFile(file, imageId);
const dataset = await fileLoaderService.getDataset(image, imageId);
const studies = await fileLoaderService.getStudies(dataset, imageId);
Expand Down
5 changes: 2 additions & 3 deletions platform/viewer/src/lib/localFileLoaders/dicomFileLoader.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as dcmjs from 'dcmjs';
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import FileLoader from './fileLoader';
import OHIF from '@ohif/core';
import { getCornerstoneWADOImageLoader } from '../../utils/cornerstoneWADOImageLoader';

const metadataProvider = OHIF.cornerstone.metadataProvider;

const DICOMFileLoader = new (class extends FileLoader {
fileType = 'application/dicom';
async loadFile(file, imageId) {
const cornerstoneWADOImageLoader = await getCornerstoneWADOImageLoader();
loadFile(file, imageId) {
return cornerstoneWADOImageLoader.wadouri.loadFileRequest(imageId);
}

Expand Down
Loading

0 comments on commit d21af3f

Please sign in to comment.