Changed around line 1
+ const niiUpload = document.getElementById('nii-upload');
+ const axialCanvas = document.getElementById('axial-canvas');
+ const coronalCanvas = document.getElementById('coronal-canvas');
+ const sagittalCanvas = document.getElementById('sagittal-canvas');
+
+ let niiData = null;
+ let currentSlice = {
+ axial: 0,
+ coronal: 0,
+ sagittal: 0
+ };
+
+ niiUpload.addEventListener('change', async (event) => {
+ const file = event.target.files[0];
+ if (file) {
+ const arrayBuffer = await file.arrayBuffer();
+ niiData = parseNII(arrayBuffer);
+ initializeViewers();
+ }
+ });
+
+ function parseNII(arrayBuffer) {
+ // NII parsing logic here
+ // This is a placeholder - implement actual NII parsing
+ return {
+ dimensions: [256, 256, 256],
+ data: new Uint8Array(arrayBuffer),
+ voxelDimensions: [1, 1, 1]
+ };
+ }
+
+ function initializeViewers() {
+ if (!niiData) return;
+
+ const [width, height, depth] = niiData.dimensions;
+
+ // Initialize canvases
+ axialCanvas.width = width;
+ axialCanvas.height = height;
+ coronalCanvas.width = width;
+ coronalCanvas.height = depth;
+ sagittalCanvas.width = height;
+ sagittalCanvas.height = depth;
+
+ // Add scroll event listeners
+ axialCanvas.addEventListener('wheel', handleScroll('axial'));
+ coronalCanvas.addEventListener('wheel', handleScroll('coronal'));
+ sagittalCanvas.addEventListener('wheel', handleScroll('sagittal'));
+
+ // Render initial slices
+ renderSlice('axial', currentSlice.axial);
+ renderSlice('coronal', currentSlice.coronal);
+ renderSlice('sagittal', currentSlice.sagittal);
+ }
+
+ function handleScroll(view) {
+ return (event) => {
+ event.preventDefault();
+ const delta = Math.sign(event.deltaY);
+ const maxSlice = niiData.dimensions[view === 'axial' ? 2 : view === 'coronal' ? 1 : 0] - 1;
+
+ currentSlice[view] = Math.max(0, Math.min(maxSlice, currentSlice[view] + delta));
+ renderSlice(view, currentSlice[view]);
+ };
+ }
+
+ function renderSlice(view, sliceIndex) {
+ const canvas = document.getElementById(`${view}-canvas`);
+ const ctx = canvas.getContext('2d');
+ const imageData = ctx.createImageData(canvas.width, canvas.height);
+
+ // Calculate slice data based on view
+ // This is a placeholder - implement actual slice rendering
+ for (let i = 0; i < imageData.data.length; i += 4) {
+ const value = Math.floor(Math.random() * 256); // Replace with actual pixel data
+ imageData.data[i] = value;
+ imageData.data[i + 1] = value;
+ imageData.data[i + 2] = value;
+ imageData.data[i + 3] = 255;
+ }
+
+ ctx.putImageData(imageData, 0, 0);
+ }