Changed around line 1
+ class ImageViewer {
+ constructor() {
+ this.initializeElements();
+ this.setupEventListeners();
+ this.imageData = null;
+ }
+
+ initializeElements() {
+ this.fileInput = document.getElementById('file-input');
+ this.canvases = {
+ axial: document.getElementById('axial-canvas'),
+ sagittal: document.getElementById('sagittal-canvas'),
+ coronal: document.getElementById('coronal-canvas')
+ };
+ this.sliders = {
+ axial: document.getElementById('axial-slider'),
+ sagittal: document.getElementById('sagittal-slider'),
+ coronal: document.getElementById('coronal-slider')
+ };
+ this.contexts = {
+ axial: this.canvases.axial.getContext('2d'),
+ sagittal: this.canvases.sagittal.getContext('2d'),
+ coronal: this.canvases.coronal.getContext('2d')
+ };
+ }
+
+ setupEventListeners() {
+ this.fileInput.addEventListener('change', (e) => this.handleFileUpload(e));
+
+ Object.entries(this.canvases).forEach(([view, canvas]) => {
+ canvas.addEventListener('wheel', (e) => this.handleWheel(e, view));
+ });
+
+ Object.entries(this.sliders).forEach(([view, slider]) => {
+ slider.addEventListener('input', (e) => this.updateSlice(view, e.target.value));
+ });
+ }
+
+ handleFileUpload(event) {
+ const file = event.target.files[0];
+ if (!file) return;
+
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ // Here we would parse the NII file format
+ // This is a placeholder for the actual NII parsing logic
+ this.imageData = {
+ dimensions: [256, 256, 256],
+ data: new Uint8Array(e.target.result)
+ };
+ this.initializeViewers();
+ };
+ reader.readAsArrayBuffer(file);
+ }
+
+ handleWheel(event, view) {
+ event.preventDefault();
+ const slider = this.sliders[view];
+ const delta = Math.sign(event.deltaY);
+ const newValue = parseInt(slider.value) + delta;
+
+ if (newValue >= slider.min && newValue <= slider.max) {
+ slider.value = newValue;
+ this.updateSlice(view, newValue);
+ }
+ }
+
+ updateSlice(view, sliceIndex) {
+ if (!this.imageData) return;
+
+ // This is a placeholder for actual slice rendering logic
+ const context = this.contexts[view];
+ const canvas = this.canvases[view];
+
+ // Clear canvas
+ context.fillStyle = 'black';
+ context.fillRect(0, 0, canvas.width, canvas.height);
+
+ // Placeholder visualization
+ context.fillStyle = 'white';
+ context.font = '20px Arial';
+ context.fillText(`${view} view - slice ${sliceIndex}`, 10, 30);
+ }
+
+ initializeViewers() {
+ if (!this.imageData) return;
+
+ Object.values(this.sliders).forEach(slider => {
+ slider.min = 0;
+ slider.max = this.imageData.dimensions[0] - 1;
+ slider.value = Math.floor(this.imageData.dimensions[0] / 2);
+ });
+
+ Object.keys(this.canvases).forEach(view => {
+ this.updateSlice(view, Math.floor(this.imageData.dimensions[0] / 2));
+ });
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new ImageViewer();
+ });