/* CreateSeveralVMRs.qs This script is meant to create several VMR projects via a user interface.. The script can be run directly via menu > Scripts > Create_VMRs or via doubleclicking on the function name 'Create_VMRs()' in the 'Defined Functions' window of the Script Editor. The script does not require manual modifications, because a user interface for the script is provided. Pop-up dialogs will ask for necessary files and values. Hester Breman, Brain Innovation; january 2007. */ function Create_VMRs(){ BrainVoyagerQX.ShowLogTab(); BrainVoyagerQX.PrintToLog("Create several VMRs..."); BrainVoyagerQX.TimeOutMessageBox("Via this wizard several VMRs will be created...", 3); // *************** CREATE VARIABLES FOR VMR PROJECT *********************** var bvqx = Application.BrainVoyagerQX; var cancel = false; var nrvmrs = Input.getNumber("Please enter the number of VMRs to be created"); var strFileType = new Array(nrvmrs); var strFirstFile= new Array(nrvmrs); var longNrOfSlices = new Array(nrvmrs); var longSwapBytes = new Array(nrvmrs); var longx_res = new Array(nrvmrs); var longy_res = new Array(nrvmrs); var longbyte_per_pixel = new Array(nrvmrs); BrainVoyagerQX.TimeOutMessageBox("Now all first files for " + nrvmrs.toString() + " VMRs can be selected", 3); MessageBox.information("Please choose the first files of the anatomical series"); //if (tmp != "undefined") { for (vmrcounter = 0; vmrcounter < nrvmrs; vmrcounter++) { var tmp = FileDialog.getOpenFileName("*.*", "Please choose first file for project number " + (vmrcounter+1).toString()); strFirstFile.unshift(tmp); } //} else { // cancel = true; //} // *************** CREATE VMR DIALOG *********************** var paramDialog = new Dialog; paramDialog.width=700; paramDialog.title = "Values needed for the creation of VMR project"; var nameLabel = new Label; var rawDataTypeBox = new ComboBox; rawDataTypeBox.label = "Raw data type"; // own filetypes, defined in a *.uff file, can be added to the itemlist and should bear the name of the uff file, f.e. "BRIK" in case the file is called "BRIK.uff" rawDataTypeBox.itemList= ["DICOM", "ANALYZE","SIEMENS","GE_I","GE_MR", "PHILIPS_REC"]; var nrOfSlicesBox = new NumberEdit; nrOfSlicesBox.label = "Nr of slices"; var swapBytesBox = new CheckBox; swapBytesBox.text = "Swap bytes"; swapBytesBox.checked = true; var xResImgBox = new NumberEdit; xResImgBox.label = "x resolution image"; var yResImgBox = new NumberEdit; yResImgBox.label = "y resolution image"; var bytePerPixelBox = new SpinBox; bytePerPixelBox.label = "Bytes per pixel"; bytePerPixelBox.value = 2; paramDialog.add(nameLabel); paramDialog.add(rawDataTypeBox); paramDialog.add(nrOfSlicesBox); paramDialog.add(swapBytesBox); paramDialog.add(xResImgBox); paramDialog.add(yResImgBox); paramDialog.add(bytePerPixelBox); paramDialog.okButtonText = "OK"; // *************** COLLECT DATA ABOUT VMR PROJECT *********************** BrainVoyagerQX.TimeOutMessageBox("Now all parameters for " + nrvmrs.toString() + " the VMRs can be provided", 3); var vmrcounter; if (!cancel) { for (vmrcounter = 0; vmrcounter < nrvmrs; vmrcounter++) { nameLabel.text = "First file of project: " + strFirstFile[vmrcounter]; if (paramDialog.exec()) { /* strFileType.unshift(rawDataTypeBox.currentItem); longNrOfSlices.unshift(nrOfSlicesBox.value); longSwapBytes.unshift(swapBytesBox.checked); longx_res.unshift(xResImgBox.value); longy_res .unshift(yResImgBox.value); longbyte_per_pixel.unshift(bytePerPixelBox.value); */ strFileType[vmrcounter] = rawDataTypeBox.currentItem; longNrOfSlices[vmrcounter] = nrOfSlicesBox.value; longSwapBytes[vmrcounter] = swapBytesBox.checked; longx_res[vmrcounter] = xResImgBox.value; longy_res[vmrcounter] = yResImgBox.value; longbyte_per_pixel[vmrcounter] = bytePerPixelBox.value; } else { cancel = true; } } } // *************** CREATE THE VMR PROJECT *********************** if (!cancel) { for (vmrcounter = 0; vmrcounter < nrvmrs; vmrcounter++) { BrainVoyagerQX.PrintToLog("Creating project " + (vmrcounter+1).toString() + " of " + nrvmrs.toString()); var docVMR = bvqx.CreateProjectVMR(strFileType[vmrcounter], strFirstFile[vmrcounter], longNrOfSlices[vmrcounter], longSwapBytes[vmrcounter], longx_res[vmrcounter], longy_res[vmrcounter], longbyte_per_pixel[vmrcounter]); var vmrname = strFirstFile[vmrcounter]; var tmpfile = new File(vmrname); var newname = tmpfile.path + "/" + tmpfile.baseName + ".vmr"; docVMR.SaveAs(newname); BrainVoyagerQX.PrintToLog("Saved as " + newname); docVMR.Close(); } } BrainVoyagerQX.PrintToLog("Finished."); }