ImFusion Web SDK

@imfusion/sdk-react

ImFusion Web SDK React Bindings

React components and hooks for integrating the ImFusion Web SDK into React applications.

Getting Started

Wrap your app with ImFusionProvider, add a canvas, and use the lifecycle components:

tsx
import { ImFusionProvider, ImFusionCanvas, ImFusionReady, ImFusionLoading, ImFusionError } from '@imfusion/sdk-react';

function App() {
  return (
    <ImFusionProvider>
      <ImFusionCanvas style={{ width: '100%', height: '100%' }} />
      <ImFusionLoading>Initializing SDK...</ImFusionLoading>
      <ImFusionError>{(error) => <p>Failed: {error.message}</p>}</ImFusionError>
      <ImFusionReady>
        <Viewer />
      </ImFusionReady>
    </ImFusionProvider>
  );
}

Inside ImFusionReady, use hooks to interact with the SDK:

tsx
import { useImFusion, useDataLoader, useData } from '@imfusion/sdk-react';

function Viewer() {
  const imf = useImFusion();
  const { loadFileFromUrl, isLoading, progress } = useDataLoader();
  const datasets = useData();

  return (
    <div>
      <button onClick={() => loadFileFromUrl('/data/scan.nii.gz')} disabled={isLoading}>
        {isLoading ? 'Loading...' : 'Load'}
      </button>
      <p>{datasets.length} dataset(s) loaded</p>
    </div>
  );
}

License

Use of this package is governed by the ImFusion end user license agreement, included as LICENSE.txt in the package.

Interfaces

Functions

FunctionDescription
ImFusionErrorRenders children when SDK initialization has failed.
ImFusionLoadingRenders children while the SDK is initializing.
ImFusionProviderInitializes the ImFusion SDK and provides it to descendant components.
ImFusionReadyRenders children only after the SDK has successfully initialized.
useAnnotationsReturns a reactive list of annotations, optionally filtered by dataset.
useContextMenuRegisters a context menu handler that fires when the SDK produces a context menu from an input event.
useDataReturns a reactive list of all data in the data model.
useDataLoaderProvides data loading methods with reactive loading, progress, and error state.
useDisplayOptions2dReturns the reactive 2D display options for a dataset.
useDisplayOptions3dReturns the reactive 3D display options for a dataset.
useFrameSelectionReturns the reactive selection for a dataset.
useImFusionReturns the initialized ImFusion SDK instance.
useImFusionErrorReturns the SDK initialization error.
useImFusionStateReturns the SDK initialization state.
useLayoutModeReturns the reactive display layout mode.
useThumbnailReturns an object URL pointing at a PNG thumbnail of data. Returns null when: - Thumbnail is still being generated or - data is nullish, or if it does not support thumbnails.
useViewVisibilityReturns the reactive 'hidden' state of a view.
useVisibleDataReturns the reactive list of currently visible datasets.

Variables

VariableDescription
ImFusionCanvasRenders a canvas element and registers it with the ImFusionProvider.

On this page