forked from Kitware/VolView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportSingleFile.ts
More file actions
51 lines (42 loc) · 1.52 KB
/
Copy pathimportSingleFile.ts
File metadata and controls
51 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
import { useImageStore } from '@/src/store/datasets-images';
import { useModelStore } from '@/src/store/datasets-models';
import { FILE_READERS } from '@/src/io';
import { ImportHandler, asLoadableResult } from '@/src/io/import/common';
import { useMessageStore } from '@/src/store/messages';
import { Skip } from '@/src/utils/evaluateChain';
/**
* Reads and imports a file DataSource.
* @param dataSource
* @returns
*/
const importSingleFile: ImportHandler = async (dataSource) => {
if (dataSource.type !== 'file') {
return Skip;
}
if (!FILE_READERS.has(dataSource.fileType)) {
return Skip;
}
const reader = FILE_READERS.get(dataSource.fileType)!;
const dataObject = await reader(dataSource.file);
if (dataObject.isA('vtkImageData')) {
const dataID = useImageStore().addVTKImageData(
dataSource.file.name,
dataObject as vtkImageData
);
return asLoadableResult(dataID, dataSource, 'image');
}
if (dataObject.isA('vtkPolyData')) {
useMessageStore().addWarning('Meshes are currently not viewable');
const dataID = useModelStore().addVTKPolyData(
dataSource.file.name,
dataObject as vtkPolyData
);
return asLoadableResult(dataID, dataSource, 'model');
}
throw new Error(
`Failed to import "${dataSource.file.name}". The file may be corrupted or in an unsupported format variant.`
);
};
export default importSingleFile;