VivoQuant 5.4.1
Loading...
Searching...
No Matches
00-Example.vqs

A list of some commonly used functions.

//
// Example VQScript
//
// Please see
// http://www.davidflanagan.com/javascript5/
// for more details on ECMAScript/JavaScript
//
//
// VQ is a global object
// allowing access to VQ components
//
for (var i=0; i<10; i++) { // Show a simple loop 0-9
VQ.debug("Simple loop: "+i); // writes 'Simple loop: 0', ... to log file
}
var dm = VQ.dataManager(); // get the Data Manager object:
// loadDataLocal(dm);
loadDataRemote(dm);
// Examples of how to setup the images
// c.setPal(0, "gold"); // Ref: palette to gold
// c.setRange(0, 0.05, 0.9); // Ref: range from 5-90%
var mainWin = VQ.mainWin();
if (0) { preProcessing(); }
if (0) { userInteraction(); }
metaData(dm);
setupMinMax(dm, 0, 0.995);
if (0) { saveImageSeries(); }
bedremoval();
smoothing();
doubleOtsu();
VQ.debug( "Value: "+dm.getValue(0,1,2, 0) );
VQ.showMessage("This is a message to the user:\nYou're welcome!");
if (0) {
VQ.writeFile("/tmp/blub.txt", "Hallo Welt\n");
VQ.appendFile("/tmp/blub.txt", "Hello World\n");
}
// storeData("folder:///home/lackas/Users/Desktop/VQScriptOutput");
// VQ.quit(); // and we are done
/* FUNCTIONS */
function bedremoval() {
// CT Bed removal
VQ.triggerAction("Tools|CT|Bed removal");
}
function doubleOtsu() {
// go into 3D ROI mode:
mainWin.setViewMode("Slice View", "3D ROI Tool");
VQ.vtkController().setAutoUpdate(false);
// switch page to Segmentation algorithms,
// not really required, but easier to debug
VQ.getWidget("tabWidget").setCurrentIndex(3);
// shortcut:
var op = VQ.currentOp();
// create ROIs:
op.addROI("Otsu 1", "red");
op.addROI("Bone", "peachpuff");
// select Input/Output ROI:
op.setInputROI(0);
op.setCurrentROI(1);
// Selecting algorithm:
VQ.getWidget("MagicSegmentationSelector").setCurrentIndex(3);
// Would be nice to have: widget.setEditText("Otsu Thresholding");
// Apply algorithm:
VQ.debug("Setup first otsu");
VQ.getWidget("MagicApply").click();
// update Input/Output ROI:
op.setInputROI(1);
op.setCurrentROI(2);
// Apply again:
VQ.debug("Setup 2nd otsu");
VQ.getWidget("MagicApply").click();
// Hide temporary ROI (name, color, immutable, hidden)
VQ.debug("Double otsu done");
VQ.vtkController().setAutoUpdate(true);
op.editROI(1, "Temp", "red", false, true);
}
function setupMinMax(dm, id, thres) {// use Min/Max Tool to set percentile based value
var minMaxTool = VQ.minMaxTool();
var cutOff = minMaxTool.computePercentileCutoff(id, thres);
VQ.debug("**** cutOff = "+cutOff);
var min = dm.getMinCached(id);
var max = dm.getMaxCached(id);
VQ.debug("**** min=" +min+", max="+max);
VQ.sliceViewer().setMinMaxCache(id, min, cutOff);
}
function saveImageSeries() { // saving series of images
mainWin.setViewMode("Slice View", "3D ROI Tool");
var progress = VQ.progressDialog("Saving Images", "Cancel", 0, dm.getDimX());
for(var x=0; x<dm.getDimX(); x++) { // set position to third in all three dim
progress.setValue(x);
c.setPos(0, x);
// store an image (type 0=MIP, 1=S, 2=C, 3=T, 4=All, 5=Everything)
// for each sagittal slice position
VQ.mainWin().saveImage("out"+VQ.counter(x,3)+".png", 4); // counter() adds leading 0
}
progress.hide();
}
function metaData(dm) {
// print some information, such as dim, vs and patientsname:
VQ.debug("* Dimensions: " + dm.getDimX() + "x" + dm.getDimY() + "x" + dm.getDimZ() );
VQ.debug("* Voxel Size: " + dm.voxelSizeXY() + "mm, "+dm.voxelSizeZ() + "mm");
VQ.debug("* PatientsName:" + dm.getDesc(0, "patientsname"));
// access the controler (pos sliders, palette, alpha, int, dim, ...)
var c = VQ.controler();
VQ.debug("* Position:" + c.getPos(0) + ":" + c.getPos(1) + ":" + c.getPos(2));
VQ.debug("* Palette :" + c.getPalname(0));
}
function userInteraction() { // examples of user interaction
var item = VQ.getItem("Select View", "View", ["sagittal", "coronal", "transversal"]);
var i = VQ.getInt("Integer Title", "Integer", 42, 0, 100, 1);
var d = VQ.getDouble("Double Title", "Double", 3.141, 3, 4, 3);
var t = VQ.getText("Text Title", "Text", "VQScript rulez!", 0);
VQ.debug("* item="+item+", i="+i+", d="+d+", t="+t);
}
function loadDataRemote(dm) { // Testing access to DICOM repositories
var pwd = '';
var dcmRepURL = "ipacs://lackas:"+pwd+"@bioscan.ipacs.invicro.com";
var projectName = "/flectct-segmentation";
var dcmRep = VQ.dcmRep(dcmRepURL);
VQ.debug("* ping="+dcmRep.ping());
VQ.debug("* projects="+dcmRep.getProjectList());
dcmRep.setProject(projectName); // select project
var studies = VQ.queryStudies(dcmRep, "Mouse*"); // search for patient "Mouse*"
for (var i=0; i<studies.length; ++i) {
if (studies[i].PatientsName != "Mouse 15") { continue; } // skip all but "Mouse 15"
VQ.debug("* patient["+i+"]: " +studies[i].PatientsName); // print meta-info
VQ.debug("* studyuid["+i+"]: "+studies[i].StudyInstanceUID);
var series = VQ.querySeries(dcmRep, studies[i].StudyInstanceUID); // fetch series by study id
for (var j=0; j<series.length; ++j) {
VQ.debug(" * series["+j+"]: "+series[j].SeriesInstanceUID + ", "+series[j].Modality);
// // optional print image information
// var images = VQ.queryImages(dcmRep, studies[i].StudyInstanceUID,
// series[j].SeriesInstanceUID);
// for (var k=0; k<images.length; ++k) {
// VQ.debug(" * image["+k+"]: "+images[k].SOPInstanceUID);
// }
// download images:
var files = VQ.downloadImages(dcmRep,
studies[i].StudyInstanceUID, series[j].SeriesInstanceUID);
dm.openDat(0, files); // open data
dm.setDesc(0, "__repository_url", dcmRepURL); // set source (to be able to load datapoints,
dm.setDesc(0, "__project", projectName); // such as 3D ROIs, annotations, etc...)
}
}
// VQ.abort(); // end script here
}
function loadDataLocal(dm) {
// define a list with file names (one or multiple for one dataset)
var list = new Array( "/Users/lackas/Desktop/VQTraining/1.3.6.1.4.1.33793.1.4.0.58478.1299815620.2.dcm" );
if (!dm.openDat(0, list)) { // open as reference=0, input1=1, ...
throw("Could not load data");
}
}
function preProcessing() { // use a pre-defined protocol to pre-process data
var protocol = 'autoCrop=true|bedRemoval=true|calibFactor=false|calibFactorValue=CT=1000 Humpf, NM=123.45 kBq|coRegister=true|coRegisterFast=true|coRegisterVersor=false|comment=false|commentText=kBq/ml|convertUnit=false|convertUnitUnit=|qualityControl=false|resample=true|resampleVoxSize=0.3|storeData=false';
var res = VQ.preProcess(protocol);
// VQ.showMessage( res );
VQ.debug( "Pre-Processing: "+res );
VQ.abort();
}
function storeData(repURL) {
VQ.debug("storeData("+repURL+")");
var dcmRep = VQ.dcmRep(repURL);
for (var i=0; i<dm.size(); ++i) {
VQ.storeData( dcmRep, i );
}
}
function smoothing() {
mainWin.setViewMode("Slice View", "Filtering");
VQ.getWidget("cbSelect").setCurrentIndex(4);
VQ.getWidget("buttonBox").accepted();
}