-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce6c00e
commit 89e07ba
Showing
51 changed files
with
4,882 additions
and
4,299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { MRIFileReader, mriFileReader } from './core/readers'; | ||
import { MRIEventsService } from './services'; | ||
import mriEventsService from './services/EventsService'; | ||
|
||
export class MRIViwer { | ||
public fileReader: MRIFileReader; | ||
public events: MRIEventsService; | ||
|
||
constructor() { | ||
this.events = mriEventsService; | ||
this.fileReader = mriFileReader; | ||
} | ||
|
||
read(data: File[] | string): void { | ||
console.log('data = ', data); | ||
|
||
this.fileReader.read(data); | ||
} | ||
} | ||
|
||
// Create the singleton instance and freeze it | ||
const w3MriViwer = new MRIViwer(); | ||
Object.freeze(w3MriViwer); | ||
|
||
export default w3MriViwer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const volumeConfig: any = { | ||
setTextureSize4X: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MRIUrlReader } from './url/MRIUrlReader'; | ||
import { MRIFileReaderFactory } from './local/MRIFileReaderFactory'; | ||
|
||
export class MRIFileReader { | ||
private localFileReader: MRIFileReaderFactory; | ||
private urlFileReader: MRIUrlReader; | ||
|
||
constructor() { | ||
this.localFileReader = new MRIFileReaderFactory(); | ||
this.urlFileReader = new MRIUrlReader(); | ||
} | ||
|
||
read(data: File[] | string): void { | ||
if (data && data.length && data[0] instanceof File) { | ||
this.localFileReader.read(data as File[]); | ||
} else if (typeof data === 'string') { | ||
this.urlFileReader.read(data as string); | ||
} else { | ||
throw new Error('Invalid input. Expected a File or URL string.'); | ||
} | ||
} | ||
} | ||
|
||
// Create the singleton instance and freeze it | ||
const mriFileReader = new MRIFileReader(); | ||
Object.freeze(mriFileReader); | ||
|
||
export default mriFileReader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import LoadResult from '../../../../LoadResult'; | ||
import VolumeSet from '../../../../VolumeSet'; | ||
import LoaderDicom from '../../../../loaders/LoaderDicom'; | ||
import LoaderHdr from '../../../../loaders/LoaderHdr'; | ||
import { volumeConfig } from '../../../config/volume.config'; | ||
import { MriEvents } from '../../../enums'; | ||
import mriEventsService, { MRIEventsService } from '../../../services/EventsService'; | ||
import mriLocalStorageService, { MRILocalStorageService } from '../../../services/LocalStorageService'; | ||
import mriStoreService, { MRIStoreService } from '../../../services/StoreService'; | ||
|
||
export abstract class AbstractMRIReader { | ||
// VolumeData | ||
volumeSet: VolumeSet; | ||
volumeIndex: number = 0; | ||
// FileData | ||
fileName: string; | ||
fileExtension: string; | ||
// File Handlers | ||
loader: LoaderDicom | LoaderHdr | null; | ||
fileReader: FileReader; | ||
// Services | ||
store: MRIStoreService; | ||
events: MRIEventsService; | ||
localStorage: MRILocalStorageService; | ||
|
||
constructor() { | ||
this.loader = null; | ||
this.volumeSet = new VolumeSet(); | ||
this.fileReader = new FileReader(); | ||
|
||
this.fileName = ''; | ||
this.fileExtension = ''; | ||
|
||
this.store = mriStoreService; | ||
this.events = mriEventsService; | ||
this.localStorage = mriLocalStorageService; | ||
|
||
this.callbackReadProgress = this.callbackReadProgress.bind(this); | ||
this.callbackReadComplete = this.callbackReadComplete.bind(this); | ||
} | ||
|
||
public handleVolumeLoadSuccess() { | ||
const volume = this.volumeSet.getVolume(this.volumeIndex); | ||
|
||
if (!volume.m_dataArray) return; | ||
|
||
if (volumeConfig.setTextureSize4X) { | ||
volume.makeDimensions4x(); | ||
} | ||
|
||
this.callbackReadProgress(1); | ||
this.localStorage.saveRecentFiles(this.fileName); | ||
this.store.setVolume(this.volumeSet, this.volumeIndex, this.fileName); | ||
|
||
if (this.store.getState().graphics2d) { | ||
this.store.getState().graphics2d.forceUpdate(); | ||
} | ||
} | ||
|
||
public handleVolumeLoadFailed(error: string) { | ||
this.events.emit(MriEvents.FILE_READ_ERROR, { error }); | ||
this.store.setVolumeLoadFailed(this.fileName, [error]); | ||
} | ||
|
||
public callbackReadProgress(progress: number) { | ||
const progressPercentage: number = Math.floor(progress * 100); | ||
|
||
if (progressPercentage >= 99) { | ||
this.store.setLoadingProgress(0); | ||
} else { | ||
this.store.setLoadingProgress(progressPercentage); | ||
} | ||
} | ||
|
||
public callbackReadComplete(status: number) { | ||
if (status === LoadResult.SUCCESS) { | ||
this.handleVolumeLoadSuccess(); | ||
} else { | ||
const error = LoadResult.getResultString(status); | ||
this.handleVolumeLoadFailed(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import mriFileReader, { MRIFileReader } from './MRIFileReader'; | ||
|
||
export { mriFileReader, MRIFileReader }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import JSZip from 'jszip'; | ||
|
||
const IGNORED_FILE_PREFIXES = ['__MACOSX/', '._']; | ||
|
||
export class ArchiveReader { | ||
/** | ||
* Reads the provided ZIP file and returns the list of extracted files. | ||
* @param file - The ZIP file to be read. | ||
* @returns A promise that resolves to an array of files extracted from the ZIP. | ||
*/ | ||
async readZipFile(file: File): Promise<File[]> { | ||
const zip = new JSZip(); | ||
const unzippedFiles: File[] = []; | ||
|
||
const arrayBuffer = await this.readFileAsArrayBuffer(file); | ||
|
||
// Load the ZIP file | ||
await zip.loadAsync(arrayBuffer); | ||
|
||
// Use the original order in the ZIP file | ||
for (const fileName in zip.files) { | ||
// Skip OS specific files and folders | ||
if (this.shouldSkipFile(fileName)) { | ||
continue; | ||
} | ||
|
||
const zipObject = zip.files[fileName]; | ||
|
||
if (!zipObject.dir) { | ||
const blob = await zipObject.async('blob'); | ||
unzippedFiles.push(new File([blob], fileName, { type: blob.type })); | ||
} | ||
} | ||
|
||
return unzippedFiles.sort((a, b) => a.name.localeCompare(b.name)); | ||
} | ||
|
||
/** | ||
* Determines if a file from the ZIP should be skipped based on its name. | ||
* @param fileName - The name of the file to check. | ||
* @returns True if the file should be skipped, false otherwise. | ||
*/ | ||
private shouldSkipFile(fileName: string): boolean { | ||
return IGNORED_FILE_PREFIXES.some((prefix) => fileName.startsWith(prefix)); | ||
} | ||
|
||
// Function to read a file as ArrayBuffer | ||
readFileAsArrayBuffer(file: File): Promise<ArrayBuffer> { | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onload = () => resolve(reader.result as ArrayBuffer); | ||
reader.onerror = reject; | ||
reader.readAsArrayBuffer(file); | ||
}); | ||
} | ||
} |
Oops, something went wrong.