Skip to content

Commit

Permalink
fixed coordinate display and search so that MNI coords are in mm, the…
Browse files Browse the repository at this point in the history
… other set (which i call 'magnet' in the code) is in voxel indices. both of these are correctly displayed and can be searched against and toggled between. also, the selected vertex's coords are displayed in the box after search.
  • Loading branch information
smerdis committed Nov 19, 2015
1 parent dfefa58 commit c31c4e3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cortex/webgl/resources/js/facepick.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ FacePick.prototype = {
mniy = vec.y ;
mniz = vec.z ;
$(this.viewer.object).find("#coordsys_mag").prop('checked',true) ;
$(this.viewer.object).find(".units").text("vox");
}
else { //mni or undefined
coordarray = hem.attributes.mnicoords ;
Expand All @@ -179,6 +180,7 @@ FacePick.prototype = {
mniy = coordarray.array[mniidx+1] ;
mniz = coordarray.array[mniidx+2] ;
$(this.viewer.object).find("#coordsys_mni").prop('checked',true) ;
$(this.viewer.object).find(".units").text("mm");
}

this.addMarker(p.hemi, p.ptidx, keep);
Expand Down Expand Up @@ -312,6 +314,7 @@ FacePick.prototype = {
},

addMarker: function(hemi, ptidx, keep) {
console.log('add marker: '+hemi+' idx: '+ptidx) ;
var vert = this._getPos(hemi, ptidx);
for (var i = 0; i < this.axes.length; i++) {
if (keep === true) {
Expand Down
54 changes: 49 additions & 5 deletions cortex/webgl/resources/js/mriview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ var mriview = (function(module) {
}.bind(this));
}

//this fires when the radio button for selecting coord systems is changed
$(this.object).find(".radio").change(function() { //the .radio class is specifically for coord space selection, not all radio buttons
space = $(this.object).find(".radio:checked").val();
ptidx = $(this.object).find("#ptidx").val();
Expand All @@ -1120,11 +1121,13 @@ var mriview = (function(module) {
px = coordarray.array[mniidx] ;
py = coordarray.array[mniidx+1] ;
pz = coordarray.array[mniidx+2] ;
console.log('mm coords: '+px+', '+py+', '+pz) ;
var coord = new THREE.Vector3(px, py, pz);
var vec = this.uniforms.volxfm.value[0].multiplyVector3(coord);
mnix = vec.x ;
mniy = vec.y ;
mniz = vec.z ;
$(this.object).find(".units").text("vox");
}
else { //mni or undefined
coordarray = h.attributes.mnicoords ;
Expand All @@ -1133,34 +1136,75 @@ var mriview = (function(module) {
mnix = coordarray.array[mniidx] ;
mniy = coordarray.array[mniidx+1] ;
mniz = coordarray.array[mniidx+2] ;
$(this.object).find(".units").text("mm");
}

$(this.object).find("#mniX").val(mnix.toFixed(2)) ;
$(this.object).find("#mniY").val(mniy.toFixed(2)) ;
$(this.object).find("#mniZ").val(mniz.toFixed(2)) ;
}
}.bind(this));

//this fires when the coordinate entry form is submitted -- it's time to look up the nearest vertex
$(this.object).find("#mniform").submit(function() {
x = $(this.object).find("#mniX").val();
y = $(this.object).find("#mniY").val();
z = $(this.object).find("#mniZ").val();
space = $(this.object).find(".radio:checked").val();
if (space==="magnet") {
var left = this.picker.lkdt.nearest([x, y, z], 1)[0];
var right = this.picker.rkdt.nearest([x, y, z], 1)[0];
//do some conversions to eventually get mm coords, which are what's stored in the kdtree
var coord = new THREE.Vector3(x, y, z);
var xfm = this.uniforms.volxfm.value[0] ;
var xfm_inv = new THREE.Matrix4() ;
xfm_inv = xfm_inv.getInverse(xfm);
xfm_inv.multiplyVector3(coord) ;
var left = this.picker.lkdt.nearest([coord.x, coord.y, coord.z], 1)[0];
var right = this.picker.rkdt.nearest([coord.x, coord.y, coord.z], 1)[0];
}
else { //mni or undefined
var left = this.picker.mni_lkdt.nearest([x, y, z], 1)[0];
var right = this.picker.mni_rkdt.nearest([x, y, z], 1)[0];
}

if (left[1] < right[1]) {
this.picker.addMarker("left", left[0][3], false);
ptidx = left[0][3] ;
h = this.meshes.left.geometry ;
hemi = "left" ;
}
else {
this.picker.addMarker("right", right[0][3], false);
ptidx = right[0][3] ;
h = this.meshes.right.geometry ;
hemi = "right" ;
}

this.picker.addMarker(hemi, ptidx, false);

if (space==="magnet")
coordarray = h.attributes.position ;
else //mni or undefined
coordarray = h.attributes.mnicoords ;

mniidx = (ptidx)*coordarray.itemSize ;
mnix = coordarray.array[mniidx] ;
mniy = coordarray.array[mniidx+1] ;
mniz = coordarray.array[mniidx+2] ;

//if we're in MNI space, we can just update the box with the coords. if not though, we need to get vox (not mm) coords...
if (space==="magnet") {
var coord2 = new THREE.Vector3(mnix, mniy, mniz);
var vec2 = this.uniforms.volxfm.value[0].multiplyVector3(coord2);
mnix = vec2.x ;
mniy = vec2.y ;
mniz = vec2.z ;
}

//update the hidden fields ptidx and pthem with the picked vertex's info
$(this.object).find("#ptidx").val(ptidx) ;
$(this.object).find("#pthem").val(hemi) ;

//update coords
$(this.object).find("#mniX").val(mnix.toFixed(2)) ;
$(this.object).find("#mniY").val(mniy.toFixed(2)) ;
$(this.object).find("#mniZ").val(mniz.toFixed(2)) ;
return(0); //do not reload page
}.bind(this));

Expand Down
6 changes: 3 additions & 3 deletions cortex/webgl/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@
<input type='radio' name='coordsys' id='coordsys_mag' value='magnet' class='radio'>Magnet</input><br /></span>
<input type='hidden' name='ptidx' id='ptidx' value='null'/>
<input type='hidden' name='pthem' id='pthem' value='null'/>
X: <input type='text' name='mniX' id='mniX' value='X' class='mniinput' />mm<br />
Y: <input type='text' name='mniY' id='mniY' value='Y' class='mniinput' />mm<br />
Z: <input type='text' name='mniZ' id='mniZ' value='Z' class='mniinput' />mm<br />
X: <input type='text' name='mniX' id='mniX' value='X' class='mniinput' /><span name='units' class='units'></span><br />
Y: <input type='text' name='mniY' id='mniY' value='Y' class='mniinput' /><span name='units' class='units'></span><br />
Z: <input type='text' name='mniZ' id='mniZ' value='Z' class='mniinput' /><span name='units' class='units'></span><br />
<input type='submit' id='mnisubmit' name='mnisubmit' value='Go' />
</form>
</div>
Expand Down

0 comments on commit c31c4e3

Please sign in to comment.