ivmartel / dwv

DICOM Web Viewer: open source zero footprint medical image library.
https://ivmartel.github.io/dwv/
GNU General Public License v3.0
1.68k stars 593 forks source link

How can I create a ViewFactory in v0.32? #1425

Closed LeoReubelt closed 1 year ago

LeoReubelt commented 1 year ago

I have a function to that uses ViewFactory.

i used to do the following...

const dwv = require(`dwv`);
const viewFactory = new dwv.image.ViewFactory();

After upgrading to 0.32, I get the following... TypeError: Cannot read properties of undefined (reading 'ViewFactory')

And I can't seem to figure out how to get it now.

ivmartel commented 1 year ago

Instead of creating an instance of a factory, you now can just call createView(elements, image) to create a View (see createView in the doc).

LeoReubelt commented 1 year ago

Thanks @ivmartel.

LeoReubelt commented 1 year ago

@ivmartel - do i have to be on 0.32.1 for this to work? Because i still can't seem to get it to work. I can not seem to import it.

ivmartel commented 1 year ago

Yes, it's on 0.32.1 (#1410).

LeoReubelt commented 1 year ago

ok. thanks.

LeoReubelt commented 1 year ago

@ivmartel - sorry for the continuous questions. but when i upgrade to 0.32.1, i get dozens of the following error. Index already used in storage: 0

ivmartel commented 1 year ago

In what context? Are you trying to load a data?

LeoReubelt commented 1 year ago

yep. that is the error i get back in the loaderror event listener.

dwvAppRef.current?.addEventListener(`loaderror`, (event: any) => {
    console.log(`ERROR  &&&&& `, event);
    message.error(event.error.message);
});
message: "Index already used in storage: 0"
Error: Index already used in storage: 0
    at nn.addNew (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:379049)
    at #Wr (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:455077)
    at eval (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:378658)
    at t.onloaditem (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:378208)
    at #Hn (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:362132)
    at #Wn (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:363037)
    at #Qn.#Qn.ondecodeditem [as onworkitem] (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:364217)
    at Worker.onmessage (webpack-internal:///./node_modules/dwv/dist/dwv.min.js:1:359079)
ivmartel commented 1 year ago

This error is when the app tries to use an already assigned index. Are you loading with loadURLs?

LeoReubelt commented 1 year ago

no, i am using App.loadFiles. we get zip files that sometimes contain multiple series mixed together, subfolders, non-dicom files, and rtstruct or rtplan modalities. so first i open the zip, separate everything by file type, series, and modality. and then i use App.loadFiles and pass it files: File[].

LeoReubelt commented 1 year ago

but if if i make urls from the files and use loadURLs, i get the same errors.

const urls = props.files.map((file) => URL.createObjectURL(file));
app.loadURLs(urls);
ivmartel commented 1 year ago

Did you find a solution to your problem?

LeoReubelt commented 1 year ago

@ivmartel yes thanks. i don't actually know what fixed it. otherwise i would have put it here. but i had a remaining require('dwv'). and when i changed it to import some of the functions changed. so i am assuming that is what fixed it.

ivmartel commented 1 year ago

dwv 0.32 allows to do individual imports such as import {App} from 'dwv'. I would recommend it if your environment supports it instead of a global import or require. That way you know exactly what you depend upon.