diff --git a/miscmaths.cc b/miscmaths.cc index b97c9f8b3261af5f5bda80457f385f0819a54726..cbde2eed0855d1e81012e0e41a16fc9c3f85f7fb 100644 --- a/miscmaths.cc +++ b/miscmaths.cc @@ -1108,9 +1108,27 @@ mat44 newmat_to_mat44(const Matrix& inmat) } return retmat; } - +void ConvertCoords(float& x, float& y, float& z, const Matrix mat) +{ + ColumnVector vec(4); + vec << x << y << z << 1.0; + vec = mat * vec; // apply voxel xfm + x = vec(1); + y = vec(2); + z = vec(3); +} +void ConvertCoords(int& x, int& y, int& z, const Matrix mat) +{ + ColumnVector vec(4); + vec << x << y << z << 1.0; + vec = mat * vec; // apply voxel xfm + x = (int)vec(1); + y = (int)vec(2); + z = (int)vec(3); +} + // Matlab style functions for percentiles, quantiles and median // AUG 06 CB @@ -1725,7 +1743,7 @@ ReturnMatrix SD(const Matrix& mat1,const Matrix& mat2) return ret; } - +//Deprecate? ReturnMatrix vox_to_vox(const ColumnVector& xyz1,const ColumnVector& dims1,const ColumnVector& dims2,const Matrix& xfm){ ColumnVector xyz1_mm(4),xyz2_mm,xyz2(3); xyz1_mm<<xyz1(1)*dims1(1)<<xyz1(2)*dims1(2)<<xyz1(3)*dims1(3)<<1; @@ -1736,7 +1754,7 @@ ReturnMatrix vox_to_vox(const ColumnVector& xyz1,const ColumnVector& dims1,const return xyz2; } - +//Deprecate? ReturnMatrix mni_to_imgvox(const ColumnVector& mni,const ColumnVector& mni_origin,const Matrix& mni2img, const ColumnVector& img_dims){ ColumnVector mni_new_origin(4),img_mm;//homogeneous ColumnVector img_vox(3); diff --git a/miscmaths.h b/miscmaths.h index 3764d6c500cde386aad30d7edb7bc5eb41354cd2..9ff9fe46cf4c9a8d75fa06ab58f7c40fed6b3187 100644 --- a/miscmaths.h +++ b/miscmaths.h @@ -165,7 +165,9 @@ namespace MISCMATHS { mat44 NewmatToMat44(const Matrix& m); mat44 newmat_to_mat44(const Matrix& inmat); Matrix mat44_to_newmat(mat44 inmat); - + void ConvertCoords(float& x, float& y, float& z, const Matrix mat); + void ConvertCoords(int& x, int& y, int& z, const Matrix mat); + void get_axis_orientations(const Matrix& sform_mat, int sform_code, const Matrix& qform_mat, int qform_code, int& icode, int& jcode, int& kcode);