Skip to content

Commit

Permalink
show all files returned from dcm2niix
Browse files Browse the repository at this point in the history
  • Loading branch information
hanayik committed Oct 21, 2024
1 parent 1baa8a1 commit 0e1447f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<li>
<!-- optional: save nii file in the niivue canvas from conversion -->
<label for="saveButton" id="saveButtonLabel">Optional: save the nifti file you are viewing</label>
<button id="saveButton" class="hidden">Save nifti</button>
<button id="saveButton" class="hidden">Save selected file</button>
</li>
</ol>

Expand Down
30 changes: 19 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ const nv = new Niivue({
// reference to the results list from dcm2niix for use later
let resultFileList = []
let conversionTime = 0
let downloadFile = null


const handleSaveButtonClick = () => {
const name = nv.volumes[0].name
nv.volumes[0].saveToDisk(name)
let url = URL.createObjectURL(downloadFile);
const downloadLink = document.createElement('a');
downloadLink.href = url;
downloadLink.download = downloadFile.name;
downloadLink.click()
}

const showSaveButton = () => {
Expand Down Expand Up @@ -66,14 +70,18 @@ const handleFileSelectChange = async (event) => {
if (selectedIndex === -1) {
return
}
removeAllVolumes()
const selectedFile = resultFileList[selectedIndex]
console.log(selectedFile);
const image = await NVImage.loadFromFile({
file: selectedFile,
name: selectedFile.name
})
await nv.addVolume(image)
downloadFile = selectedFile
// only load the file in niivue if it is nifti
if (selectedFile.name.endsWith('.nii')) {
removeAllVolumes()
console.log(selectedFile);
const image = await NVImage.loadFromFile({
file: selectedFile,
name: selectedFile.name
})
await nv.addVolume(image)
}
showSaveButton()
}

Expand Down Expand Up @@ -116,7 +124,7 @@ const runDcm2niix = async (files) => {
showText(`Conversion time: ${conversionTime} seconds`)
// filter out files that are not nifti (.nii) so we don't show them
// in the select dropdown
resultFileList = resultFileList.filter(file => file.name.endsWith('.nii'))
// resultFileList = resultFileList.filter(file => file.name.endsWith('.nii'))
updateSelectItems(resultFileList)
console.log(resultFileList);
hideLoadingCircle()
Expand Down Expand Up @@ -227,7 +235,7 @@ async function main() {

// handle drag and drop
dropTarget.ondrop = handleDrop;
dropTarget.ondragover = (e) => {e.preventDefault();}
dropTarget.ondragover = (e) => { e.preventDefault(); }

// when user clicks save
saveButton.onclick = handleSaveButtonClick
Expand Down

0 comments on commit 0e1447f

Please sign in to comment.