Skip to content

Instantly share code, notes, and snippets.

@stowler
Created April 16, 2013 20:13
Show Gist options
  • Save stowler/5399213 to your computer and use it in GitHub Desktop.
Save stowler/5399213 to your computer and use it in GitHub Desktop.
mm->vox integers per FSL fslmeants INPUT
FSL fslmeants INPUT
------------------------------------------------
Appears to round coordinate floats to integers via MISCMATHS::round
(adding or subtracting .5 then truncating decimal via cast):
If user inputs mm coordinates as fslmeants argument (-c --usemm), fslmeants
rounds to integer voxel coordinates using call to MISCMATHS::round().
From fslmeants.cc:
...
238 if (usemm.value()) {
239 // convert from mm to newimage voxels
240 v = (vin[0].newimagevox2mm_mat()).i() * v;
241 } else {
...
244 }
245 x = v(1); y = v(2); z = v(3);
246 mask(MISCMATHS::round(x),MISCMATHS::round(y),MISCMATHS::round(z)) = 1.0;
...
...which calls round() from miscmaths.cc :
...
455 // General mathematical functions
456
457 int round(int x) { return x; }
458
459 int round(float x)
460 {
461 if (x>0.0) return ((int) (x+0.5));
462 else return ((int) (x-0.5));
463 }
464
465 int round(double x)
466 {
467 if (x>0.0) return ((int) (x+0.5));
468 else return ((int) (x-0.5));
469 }
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment