var scriptPath = VQ.getScriptPath().replace(/[/\\][^/\\]+$/, "");
var outputPath = "";
//---------------------------------------------------------
// Start - Only for internal testing (users can disregard or remove)
//---------------------------------------------------------
var isTestModule = scriptPath.indexOf("extern/t/TestModules") !== -1;
VQ.setTestMode(isTestModule);
function getArtifactOutputFolder() {
const cachePath = VQ.getCache();
return cachePath.substring(0, cachePath.lastIndexOf("/") + 1) + "artifacts";
}
if(VQ.isTestMode()){
outputPath = getArtifactOutputFolder();
}
//---------------------------------------------------------
// End - Only for internal testing (users can disregard or remove)
//---------------------------------------------------------
VQ.setConfig('Data/resampleROI',1,true);
VQ.setConfig('DICOM/useFOR', 1, true);
VQ.setConfig('Data/orientation', "Neurologist (LR)", true);
VQ.setConfig('Data/dynamicSupportEnabled', true, true);
VQ.setConfig('Data/disableMIPViewer', true, true);
//----------------------------------------------
var dm = VQ.dataManager();
var mw = VQ.mainWin();
var CTTestData = scriptPath + "/data/CTSynthetic.dcm";
var PETTestData = scriptPath + "/data/PETSynthetic.dcm";
dm.openDat(0, [CTTestData]);
dm.openDat(1, [PETTestData]);
if(outputPath == ""){
outputPath = scriptPath;
}
// Switch to 3D ROI Tool
mw.setViewMode('Slice View','3D ROI Tool');
var op = VQ.currentOp();
op.setCurrentLayer(0);
//-------------Static Layer ROI-------------------------------------------------------------------
// Draw ROIs
var centerX = dm.getDimX()/2;
var centerY = dm.getDimY()/2;
var centerZ = dm.getDimZ()/2;
//This should be ROI index 1
var S_LRY_0_R1_id = op.addROI("Static Layer 0 ROI 1", "red");
op.drawSphere(centerX, centerY, centerZ, 20, 1);
//-----------2 Dynamic Layers - 1 Dynamic ROI---------------------------------------------------------------------
function getNumDynamicTimepoints() {
var dm = VQ.dataManager();
for (var d = 0; d < dm.size(); d++) {
var n = dm.count(VQ.index(d));
if (n > 1) return n;
}
return 0;
}
var total = getNumDynamicTimepoints();
VQ.debug("Total dynamic timepoints: " + total);
//Just in case we want to use different data.
//But testing with 4 timepoints so we get a dynamic layer on timepoint 0 and 2
if (total > 0) {
var subset = [];
for (var i = 0; i < total; i += 2) subset.push(i);
var roiOp = VQ.currentOp();
if (!roiOp.setDynamicLayerTimepoints(subset))
VQ.debug("setDynamicLayerTimepoints failed");
}
//At this point we should have a static layer index at 0, and dynamic layer at layer index 1 and layer index 2
//The dyanmic layer at 1 corresponds to data timepoint 0 and data timepoing 2 respectively
// Draw ROIs
var posX = dm.getDimX()/4;
var posY = dm.getDimY()/2;
var posZ = dm.getDimZ()/2;
if(op.setCurrentLayer(1)){
var D_LRY_1_R1_id = op.addROI("Dynamic ROI 1", "red");
op.drawSphere(posX, posY, posZ, 5, 1);
}
if(op.setCurrentLayer(2)){
//Grow the dynamic ROI
var D_LRY_2_R1_id = op.addROI("Dynamic ROI 1", "red");
op.drawSphere(posX, posY, posZ, 10, 1);
}
//Note the ROIs have to have the same name for the stats to know they are actually the same ROI
//So now we have:
//1 static ROI that will be applied to all dataset leaves
//1 dynamic ROI where the first dynamic layer ROI will be applied to dynamic timepoints 0 and 1
// and the second dynamic layer ROI will be applied to the dynamic timepoint 2 and 3
//--------------------------------------------------------------------------------
var expectedcsv = scriptPath + "/data/DynamicQuantification-Table.csv";
var outputcsv = outputPath + '/DynamicQuantification-Table.csv';
VQ.currentOp().exportTable(outputcsv, false);
var resultLines = VQ.readFile(outputcsv);
var expectedLines = VQ.readFile(expectedcsv);
VQ.debug("COUNT_RESULT:" + resultLines.length);
VQ.debug("COUNT_EXPECTED:" + expectedLines.length);
var len = Math.max(resultLines.length, expectedLines.length);
for (i=0;i<len;i++) {
VQ.debug("LINE_RESULT:" + (i < resultLines.length ? resultLines[i] : "<missing result line>"));
VQ.debug("LINE_EXPECTED:" + (i < expectedLines.length ? expectedLines[i] : "<missing expected line>"));
}
if(VQ.isTestMode()){
VQ.quit();
}