From bd3502526fc09d85c48b4575fd329a6612253668 Mon Sep 17 00:00:00 2001 From: Matthew Webster <mwebster@fmrib.ox.ac.uk> Date: Fri, 11 Jan 2008 14:57:26 +0000 Subject: [PATCH] added ConvertCoords --- miscmaths.cc | 24 +++++++++++++++++++++--- miscmaths.h | 4 +++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/miscmaths.cc b/miscmaths.cc index b97c9f8..cbde2ee 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 3764d6c..9ff9fe4 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); -- GitLab