Commit cf5982ec authored by katjaq's avatar katjaq
Browse files

Merge remote-tracking branch 'OpenNeuroLab/master'

parents 6edbcc98 6307ee44
const express = require('express');
const controller = require('./mri.controller');
const upload_controller = require('./upload.controller');
const multer = require('multer');
const router = express.Router();
const controller = require('./mri.controller');
const uploadController = require('./upload.controller');
router.get('', controller.validator, controller.mri);
router.get('/json', controller.validator, tokenAuthentication, controller.api_mri_get);
router.post('/json', controller.validator_post, tokenAuthentication, controller.api_mri_post);
router.get('/upload', upload_controller.token);
router.get('/upload', uploadController.token);
router.post('/upload',
multer({dest: './tmp/'}).array('atlas'),
upload_controller.validator,
upload_controller.other_validations,
upload_controller.upload);
uploadController.validator,
uploadController.other_validations,
uploadController.upload);
router.get('/reset', controller.reset);
......
{
"clientID": "GET YOURS AT https://github.com/settings/applications/new",
"clientSecret": "GET YOURS AT https://github.com/settings/applications/new",
"callbackURL": "http://brainbox.dev/auth/github/callback"
"clientID": "GET YOURS AT https://github.com/settings/applications/new",
"clientSecret": "GET YOURS AT https://github.com/settings/applications/new",
"callbackURL": "http://brainbox.dev/auth/github/callback"
}
This diff is collapsed.
......@@ -213,11 +213,11 @@ const getProjectFilesSlice = function getProjectFilesSlice(req, projShortname, s
}
return new Promise((resolve, reject) => {
start = parseInt(start);
length = parseInt(length);
start = parseInt(start);
length = parseInt(length);
req.db.get('project')
.findOne({shortname: projShortname, backup: {$exists: 0}}, '-_id')
.then(project => {
.findOne({shortname: projShortname, backup: {$exists: 0}}, '-_id')
.then(project => {
// Check access
if (checkAccess.toProject(project, loggedUser, 'view') === false) {
const msg = 'User ' + loggedUser + ' is not allowed to view project ' + projShortname;
......@@ -237,19 +237,19 @@ const getProjectFilesSlice = function getProjectFilesSlice(req, projShortname, s
arr.push(req.db.get('mri').findOne({source: list[i], backup: {$exists: 0}}, {_id: 0}));
}
Promise.all(arr)
.then(mris => {
.then(mris => {
let j;
for (j = 0; j < mris.length; j++) {
if (mris[j]) {
// Check j-th mri annotation access
checkAccess.filterAnnotationsByProjects(mris[j], [project], loggedUser);
// Append to list
if (namesFlag) {
newList[j] = {source: mris[j].source, name: mris[j].name};
} else {
newList[j] = mris[j];
}
// Check j-th mri annotation access
checkAccess.filterAnnotationsByProjects(mris[j], [project], loggedUser);
// Append to list
if (namesFlag) {
newList[j] = {source: mris[j].source, name: mris[j].name};
} else {
newList[j] = mris[j];
}
} else {
newList[j] = {
source: list[start + j],
......@@ -259,16 +259,16 @@ const getProjectFilesSlice = function getProjectFilesSlice(req, projShortname, s
}
resolve(newList);
})
.catch(err => {
console.log('ERROR:', err);
reject();
.catch(err => {
console.log('ERROR:', err);
reject();
});
} else {
console.log('project is empty');
console.log('project is empty');
}
})
.catch(err => {
console.log('ERROR:', err);
.catch(err => {
console.log('ERROR:', err);
reject();
});
});
......
const fs = require('fs');
const zlib = require('zlib');
const fileType = require('file-type');
// const fs = require('fs');
// const zlib = require('zlib');
// const fileType = require('file-type');
const MRILoader = function () {
/*
Var loadNifti = function(nii) {
var vox_offset=352;
var sizeof_hdr=nii.readUInt32LE(0);
var dimensions=nii.readUInt16LE(40);
var mri={};
mri.hdr=nii.slice(0,vox_offset);
mri.dim=[];
mri.dim[0]=nii.readUInt16LE(42);
mri.dim[1]=nii.readUInt16LE(44);
mri.dim[2]=nii.readUInt16LE(46);
mri.datatype=nii.readUInt16LE(70);
mri.pixdim=[];
mri.pixdim[0]=nii.readFloatLE(80);
mri.pixdim[1]=nii.readFloatLE(84);
mri.pixdim[2]=nii.readFloatLE(88);
vox_offset=nii.readFloatLE(108);
var tmp;
switch(mri.datatype) {
case 2: // UCHAR
mri.data=nii.slice(vox_offset);
break;
case 4: // SHORT
tmp=nii.slice(vox_offset);
mri.data=new Int16Array(mri.dim[0]*mri.dim[1]*mri.dim[2]);
for(var j=0;j<mri.dim[0]*mri.dim[1]*mri.dim[2];j++)
mri.data[j]=tmp.readInt16LE(j*2);
break;
case 8: // INT
tmp=nii.slice(vox_offset);
mri.data=new Uint32Array(mri.dim[0]*mri.dim[1]*mri.dim[2]);
for(var k=0;k<mri.dim[0]*mri.dim[1]*mri.dim[2];k++)
mri.data[k]=tmp.readUInt32LE(k*4);
break;
case 16: // FLOAT
tmp=nii.slice(vox_offset);
mri.data=new Float32Array(mri.dim[0]*mri.dim[1]*mri.dim[2]);
for(var l=0;l<mri.dim[0]*mri.dim[1]*mri.dim[2];l++)
mri.data[l]=tmp.readFloatLE(l*4);
break;
default:
console.log("ERROR: Unknown dataType: "+mri.datatype);
}
return mri;
var vox_offset=352;
var sizeof_hdr=nii.readUInt32LE(0);
var dimensions=nii.readUInt16LE(40);
var mri={};
mri.hdr=nii.slice(0,vox_offset);
mri.dim=[];
mri.dim[0]=nii.readUInt16LE(42);
mri.dim[1]=nii.readUInt16LE(44);
mri.dim[2]=nii.readUInt16LE(46);
mri.datatype=nii.readUInt16LE(70);
mri.pixdim=[];
mri.pixdim[0]=nii.readFloatLE(80);
mri.pixdim[1]=nii.readFloatLE(84);
mri.pixdim[2]=nii.readFloatLE(88);
vox_offset=nii.readFloatLE(108);
var tmp;
switch(mri.datatype) {
case 2: // UCHAR
mri.data=nii.slice(vox_offset);
break;
case 4: // SHORT
tmp=nii.slice(vox_offset);
mri.data=new Int16Array(mri.dim[0]*mri.dim[1]*mri.dim[2]);
for(var j=0;j<mri.dim[0]*mri.dim[1]*mri.dim[2];j++)
mri.data[j]=tmp.readInt16LE(j*2);
break;
case 8: // INT
tmp=nii.slice(vox_offset);
mri.data=new Uint32Array(mri.dim[0]*mri.dim[1]*mri.dim[2]);
for(var k=0;k<mri.dim[0]*mri.dim[1]*mri.dim[2];k++)
mri.data[k]=tmp.readUInt32LE(k*4);
break;
case 16: // FLOAT
tmp=nii.slice(vox_offset);
mri.data=new Float32Array(mri.dim[0]*mri.dim[1]*mri.dim[2]);
for(var l=0;l<mri.dim[0]*mri.dim[1]*mri.dim[2];l++)
mri.data[l]=tmp.readFloatLE(l*4);
break;
default:
console.log("ERROR: Unknown dataType: "+mri.datatype);
}
return mri;
}
var loadBrainNifti = function(nii,callback) {
var brain=loadNifti(nii);
var brain=loadNifti(nii);
var i,sum=0,min,max;
min=brain.data[0];
max=min;
for(i=0;i<brain.dim[0]*brain.dim[1]*brain.dim[2];i++) {
sum+=brain.data[i];
var i,sum=0,min,max;
min=brain.data[0];
max=min;
for(i=0;i<brain.dim[0]*brain.dim[1]*brain.dim[2];i++) {
sum+=brain.data[i];
if(brain.data[i]<min) min=brain.data[i];
if(brain.data[i]>max) max=brain.data[i];
}
brain.sum=sum;
brain.min=min;
brain.max=max;
if(brain.data[i]<min) min=brain.data[i];
if(brain.data[i]>max) max=brain.data[i];
}
brain.sum=sum;
brain.min=min;
brain.max=max;
callback(brain);
callback(brain);
}
var loadBrainMGZ = function(data,callback) {
var hdr_sz=284;
var brain={};
var datatype;
brain.dim=[];
brain.dim[0]=data.readInt32BE(4);
brain.dim[1]=data.readInt32BE(8);
brain.dim[2]=data.readInt32BE(12);
datatype=data.readInt32BE(20);
brain.pixdim=[];
brain.pixdim[0]=data.readFloatBE(30);
brain.pixdim[1]=data.readFloatBE(34);
brain.pixdim[2]=data.readFloatBE(38);
var tmp
switch(datatype) {
case 0: // MGHUCHAR
brain.data=data.slice(hdr_sz);
break;
case 1: // MGHINT
tmp=data.slice(hdr_sz);
brain.data=new Uint32Array(brain.dim[0]*brain.dim[1]*brain.dim[2]);
for(var j=0;j<brain.dim[0]*brain.dim[1]*brain.dim[2];j++)
brain.data[j]=tmp.readUInt32BE(j*4);
break;
case 3: // MGHFLOAT
tmp=data.slice(hdr_sz);
brain.data=new Float32Array(brain.dim[0]*brain.dim[1]*brain.dim[2]);
for(var k=0;k<brain.dim[0]*brain.dim[1]*brain.dim[2];k++)
brain.data[k]=tmp.readFloatBE(k*4);
break;
case 4: // MGHSHORT
tmp=data.slice(hdr_sz);
brain.data=new Int16Array(brain.dim[0]*brain.dim[1]*brain.dim[2]);
for(var l=0;l<brain.dim[0]*brain.dim[1]*brain.dim[2];l++)
brain.data[l]=tmp.readInt16BE(l*2);
break;
default:
console.log("ERROR: Unknown dataType: "+datatype);
}
var i,sum=0,min,max;
min=brain.data[0];
max=min;
for(i=0;i<brain.dim[0]*brain.dim[1]*brain.dim[2];i++) {
sum+=brain.data[i];
if(brain.data[i]<min) min=brain.data[i];
if(brain.data[i]>max) max=brain.data[i];
}
brain.sum=sum;
brain.min=min;
brain.max=max;
callback(brain);
var hdr_sz=284;
var brain={};
var datatype;
brain.dim=[];
brain.dim[0]=data.readInt32BE(4);
brain.dim[1]=data.readInt32BE(8);
brain.dim[2]=data.readInt32BE(12);
datatype=data.readInt32BE(20);
brain.pixdim=[];
brain.pixdim[0]=data.readFloatBE(30);
brain.pixdim[1]=data.readFloatBE(34);
brain.pixdim[2]=data.readFloatBE(38);
var tmp
switch(datatype) {
case 0: // MGHUCHAR
brain.data=data.slice(hdr_sz);
break;
case 1: // MGHINT
tmp=data.slice(hdr_sz);
brain.data=new Uint32Array(brain.dim[0]*brain.dim[1]*brain.dim[2]);
for(var j=0;j<brain.dim[0]*brain.dim[1]*brain.dim[2];j++)
brain.data[j]=tmp.readUInt32BE(j*4);
break;
case 3: // MGHFLOAT
tmp=data.slice(hdr_sz);
brain.data=new Float32Array(brain.dim[0]*brain.dim[1]*brain.dim[2]);
for(var k=0;k<brain.dim[0]*brain.dim[1]*brain.dim[2];k++)
brain.data[k]=tmp.readFloatBE(k*4);
break;
case 4: // MGHSHORT
tmp=data.slice(hdr_sz);
brain.data=new Int16Array(brain.dim[0]*brain.dim[1]*brain.dim[2]);
for(var l=0;l<brain.dim[0]*brain.dim[1]*brain.dim[2];l++)
brain.data[l]=tmp.readInt16BE(l*2);
break;
default:
console.log("ERROR: Unknown dataType: "+datatype);
}
var i,sum=0,min,max;
min=brain.data[0];
max=min;
for(i=0;i<brain.dim[0]*brain.dim[1]*brain.dim[2];i++) {
sum+=brain.data[i];
if(brain.data[i]<min) min=brain.data[i];
if(brain.data[i]>max) max=brain.data[i];
}
brain.sum=sum;
brain.min=min;
brain.max=max;
callback(brain);
}
this.loadBrain = function(path,callback) {
if(!fs.existsSync(path)) {
console.log("ERROR: File does not exist:",path); //modify call error object
return;
} else {
var datagz;
try {
datagz=fs.readFileSync(path);
var ft=fileType(datagz);
var ext=path.split('.').pop();
switch(ft.ext) {
case 'gz': {
switch(ext) {
case 'gz':
zlib.gunzip(datagz,function(err,nii){if(err) console.log("ERROR:",err);loadBrainNifti(nii,callback)}); //modify call error object
break;
case 'mgz':
zlib.gunzip(datagz,function(err,nii){if(err) console.log("ERROR:",err);loadBrainMGZ(nii,callback)}); //modify call error object
break;
}
break;
}
case 'zip':
zlib.inflate(datagz,function(err,nii){if(err) console.log("ERROR:",err);loadBrainNifti(nii,callback)}); //modify call error object
break;
default:
switch(ext) {
case 'nii':
loadBrainNifti(datagz,callback);
break;
case 'mgh':
loadBrainMGZ(datagz, callback);
break;
}
break; //modify call error object
}
} catch(e) {
console.log(new Date(),"ERROR: Cannot read brain data"); //modify call error object
}
}
return null;
if(!fs.existsSync(path)) {
console.log("ERROR: File does not exist:",path); //modify call error object
return;
} else {
var datagz;
try {
datagz=fs.readFileSync(path);
var ft=fileType(datagz);
var ext=path.split('.').pop();
switch(ft.ext) {
case 'gz': {
switch(ext) {
case 'gz':
zlib.gunzip(datagz,function(err,nii){if(err) console.log("ERROR:",err);loadBrainNifti(nii,callback)}); //modify call error object
break;
case 'mgz':
zlib.gunzip(datagz,function(err,nii){if(err) console.log("ERROR:",err);loadBrainMGZ(nii,callback)}); //modify call error object
break;
}
break;
}
case 'zip':
zlib.inflate(datagz,function(err,nii){if(err) console.log("ERROR:",err);loadBrainNifti(nii,callback)}); //modify call error object
break;
default:
switch(ext) {
case 'nii':
loadBrainNifti(datagz,callback);
break;
case 'mgh':
loadBrainMGZ(datagz, callback);
break;
}
break; //modify call error object
}
} catch(e) {
console.log(new Date(),"ERROR: Cannot read brain data"); //modify call error object
}
}
return null;
}
*/
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
"debug": "~2.0.0",
"dompurify": "^0.8.3",
"express": "~4.9.0",
"express-session": "^1.14.0",
"express-session": "^1.15.6",
"express-validator": "^2.20.8",
"fast-json-patch": "^1.1.1",
"file-type": "^3.8.0",
......@@ -25,7 +25,7 @@
"jsdom": "^9.5.0",
"keypress": "^0.2.1",
"merge": "^1.2.0",
"mongodb": "^2.2.5",
"mongodb": "^2.2.33",
"monk": "^3.1.1",
"morgan": "~1.3.0",
"multer": "^1.2.0",
......@@ -33,11 +33,12 @@
"passport": "^0.3.2",
"passport-github": "^1.1.0",
"passport-local": "^1.0.0",
"request": "^2.74.0",
"request": "^2.83.0",
"serve-favicon": "~2.1.3",
"struct": "0.0.11",
"url": "^0.11.0",
"validator": "^6.0.0",
"webpage": "^0.3.0",
"ws": "^1.1.1"
},
"devDependencies": {
......
......@@ -6,205 +6,205 @@ var AtlasMakerDraw = {
/**
* @function resizeWindow
*/
resizeWindow: function resizeWindow() {
var me=AtlasMakerWidget;
var l=me.traceLog(resizeWindow,1);if(l)console.log.apply(undefined,l);
resizeWindow: function resizeWindow() {
var me=AtlasMakerWidget;
var l=me.traceLog(resizeWindow,1);if(l)console.log.apply(undefined,l);
var wH=me.container.height();
var wW=me.container.width();
var wAspect=wW/wH;
var bAspect=me.brain_W*me.brain_Wdim/(me.brain_H*me.brain_Hdim);
/*
if(me.editMode==1) {
*/
// In edit mode width or height can be fixed to 100%
// depending on the slice and container aspect ratio
if(wAspect>bAspect)
$('#resizable').css({width:(100*bAspect/wAspect)+'%',height:'100%'});
else
$('#resizable').css({width:'100%',height:(100*wAspect/bAspect)+'%'});
/*
} else {
// In display mode slice width is always fixed to 100%
$('#resizable').css({width:'100%',height:(100*wAspect/bAspect)+'%'});
// Slice height cannot be larger than window's inner height:
var sliceH=me.container.height();
var windowH=window.innerHeight;
if(sliceH>windowH) {
var f=windowH/sliceH;
$('#resizable').css({width:(f*100)+'%',height:f*(100*wAspect/bAspect)+'%'});
}
}
*/
},
var wH=me.container.height();
var wW=me.container.width();
var wAspect=wW/wH;
var bAspect=me.brain_W*me.brain_Wdim/(me.brain_H*me.brain_Hdim);
/*
if(me.editMode==1) {
*/
// In edit mode width or height can be fixed to 100%
// depending on the slice and container aspect ratio
if(wAspect>bAspect)
$('#resizable').css({width:(100*bAspect/wAspect)+'%',height:'100%'});
else
$('#resizable').css({width:'100%',height:(100*wAspect/bAspect)+'%'});
/*
} else {
// In display mode slice width is always fixed to 100%
$('#resizable').css({width:'100%',height:(100*wAspect/bAspect)+'%'});
// Slice height cannot be larger than window's inner height:
var sliceH=me.container.height();
var windowH=window.innerHeight;
if(sliceH>windowH) {
var f=windowH/sliceH;
$('#resizable').css({width:(f*100)+'%',height:f*(100*wAspect/bAspect)+'%'});
}
}
*/
},
/**
* @function configureBrainImage
*/
configureBrainImage: function configureBrainImage() {
var me=AtlasMakerWidget;
var l=me.traceLog(configureBrainImage);if(l)console.log.apply(undefined,l);
if(me.User.view==null)
me.User.view="sag";
var s2v=me.User.s2v;
switch(me.User.view) {
case 'sag': me.brain_W=s2v.sdim[1]; me.brain_H=s2v.sdim[2]; me.brain_D=s2v.sdim[0]; me.brain_Wdim=s2v.wpixdim[1]; me.brain_Hdim=s2v.wpixdim[2]; break; // sagital
case 'cor': me.brain_W=s2v.sdim[0]; me.brain_H=s2v.sdim[2]; me.brain_D=s2v.sdim[1]; me.brain_Wdim=s2v.wpixdim[0]; me.brain_Hdim=s2v.wpixdim[2]; break; // coronal
case 'axi': me.brain_W=s2v.sdim[0]; me.brain_H=s2v.sdim[1]; me.brain_D=s2v.sdim[2]; me.brain_Wdim=s2v.wpixdim[0]; me.brain_Hdim=s2v.wpixdim[1]; break; // axial
}
configureBrainImage: function configureBrainImage() {
var me=AtlasMakerWidget;
var l=me.traceLog(configureBrainImage);if(l)console.log.apply(undefined,l);
if(me.User.view==null)
me.User.view="sag";
var s2v=me.User.s2v;
switch(me.User.view) {
case 'sag': me.brain_W=s2v.sdim[1]; me.brain_H=s2v.sdim[2]; me.brain_D=s2v.sdim[0]; me.brain_Wdim=s2v.wpixdim[1]; me.brain_Hdim=s2v.wpixdim[2]; break; // sagital
case 'cor': me.brain_W=s2v.sdim[0]; me.brain_H=s2v.sdim[2]; me.brain_D=s2v.sdim[1]; me.brain_Wdim=s2v.wpixdim[0]; me.brain_Hdim=s2v.wpixdim[2]; break; // coronal
case 'axi': me.brain_W=s2v.sdim[0]; me.brain_H=s2v.sdim[1]; me.brain_D=s2v.sdim[2]; me.brain_Wdim=s2v.wpixdim[0]; me.brain_Hdim=s2v.wpixdim[1]; break; // axial
}
me.canvas.width=me.brain_W;
me.canvas.height=me.brain_H*me.brain_Hdim/me.brain_Wdim;
me.brain_offcn.width=me.brain_W;
me.brain_offcn.height=me.brain_H;
me.brain_px=me.brain_offtx.getImageData(0,0,me.brain_offcn.width,me.brain_offcn.height);
if(me.User.slice==null || me.User.slice>=me.brain_D-1)
me.User.slice=parseInt(me.brain_D/2);
me.canvas.width=me.brain_W;
me.canvas.height=me.brain_H*me.brain_Hdim/me.brain_Wdim;
me.brain_offcn.width=me.brain_W;
me.brain_offcn.height=me.brain_H;
me.brain_px=me.brain_offtx.getImageData(0,0,me.brain_offcn.width,me.brain_offcn.height);
if(me.User.slice==null || me.User.slice>=me.brain_D-1)
me.User.slice=parseInt(me.brain_D/2);
me.sendUserDataMessage(JSON.stringify({'view':me.User.view,'slice':me.User.slice}));
// configure toolbar slider
$(".slider#slice").data({max:me.brain_D-1,val:me.User.slice});
if($("#slice .thumb")[0]) $("#slice .thumb")[0].style.left=(me.User.slice/(me.brain_D-1)*100)+"%";
me.drawImages();
me.initCursor();
},