Last active
December 16, 2015 07:19
-
-
Save stowler/5397788 to your computer and use it in GitHub Desktop.
mm->vox integers per AFNI controller window user INPUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AFNI controller window user INPUT | |
------------------------------------------------ | |
Appears to use implicit casting + boundary handling to create integer voxel | |
coordinates from the user-specified mm coordinates in the "Jump to (xyz)" box: | |
In afni.c , typical use of AFNI_jumpto_dicom() calls AFNI_jumpto_dicom_OLD(), | |
which converts user-provided mm coordinates to integer voxel coordinates in | |
three steps: | |
1) uses THD_dicomm_to_3dmm() to get floating-point voxel (not mm) coordinates from image (anat_now) | |
2) uses THD_3dmm_to_3dind() to turn those floating-point "index coordinates" to integer index coordinates (iv.ijk) | |
- includes truncation via implicit cast | |
(because iv.ijk is just integers per typedef struct { int ijk[3] ; } THD_ivec3 ; ) | |
3) pulls integers coordiantes ii, jj, and kk respectively from integer vector iv.ijk | |
Those three steps are invoked in this afni.c function: | |
9811 int AFNI_jumpto_dicom_OLD( Three_D_View *im3d , float xx, float yy, float zz ) | |
9812 { | |
9813 THD_dataxes *daxes ; | |
9814 THD_fvec3 fv ; THD_ivec3 iv ; | |
9815 int ii,jj,kk ; | |
9816 | |
9817 ENTRY("AFNI_jumpto_dicom_OLD") ; | |
9818 | |
9819 LOAD_ANAT_VIEW(im3d) ; /* 02 Nov 1996 */ | |
9820 | |
9821 fv = THD_dicomm_to_3dmm( im3d->anat_now , TEMP_FVEC3(xx,yy,zz) ) ; | |
9822 iv = THD_3dmm_to_3dind ( im3d->anat_now , fv ) ; | |
9823 ii = iv.ijk[0] ; jj = iv.ijk[1] ; kk = iv.ijk[2] ; | |
9824 | |
9825 daxes = CURRENT_DAXES(im3d->anat_now) ; | |
9826 if( ii >= 0 && ii < daxes->nxx && | |
9827 jj >= 0 && jj < daxes->nyy && kk >= 0 && kk < daxes->nzz ){ | |
9828 | |
9829 AFNI_set_viewpoint( im3d , ii,jj,kk , REDISPLAY_ALL ) ; /* jump */ | |
9830 RETURN(1) ; | |
9831 } else { | |
9832 BEEPIT ; WARNING_message("Jumpto DICOM failed -- bad coordinates?!") ; | |
9833 RETURN(-1) ; | |
9834 } | |
9835 } | |
...which relies on heavy lifting by THD_3dmm_to_3dind() in thd_coords.c : | |
146 THD_ivec3 THD_3dmm_to_3dind( THD_3dim_dataset *dset , THD_fvec3 fv ) | |
147 { | |
148 THD_dataxes *daxes ; | |
149 THD_ivec3 iv ; | |
150 | |
151 daxes = CURRENT_DAXES(dset) ; | |
152 | |
153 iv.ijk[0] = (fv.xyz[0] - daxes->xxorg) / daxes->xxdel + 0.499 ; | |
154 iv.ijk[1] = (fv.xyz[1] - daxes->yyorg) / daxes->yydel + 0.499 ; | |
155 iv.ijk[2] = (fv.xyz[2] - daxes->zzorg) / daxes->zzdel + 0.499 ; | |
156 | |
157 if( iv.ijk[0] < 0 ) iv.ijk[0] = 0 ; | |
158 else if( iv.ijk[0] > daxes->nxx-1 ) iv.ijk[0] = daxes->nxx-1 ; | |
159 | |
160 if( iv.ijk[1] < 0 ) iv.ijk[1] = 0 ; | |
161 else if( iv.ijk[1] > daxes->nyy-1 ) iv.ijk[1] = daxes->nyy-1 ; | |
162 | |
163 if( iv.ijk[2] < 0 ) iv.ijk[2] = 0 ; | |
164 else if( iv.ijk[2] > daxes->nzz-1 ) iv.ijk[2] = daxes->nzz-1 ; | |
165 | |
166 return iv ; | |
167 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment