Skip to content
Snippets Groups Projects
Commit e8809446 authored by Matthew Webster's avatar Matthew Webster
Browse files

All MJ changes for LR

parent fb5779b2
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,9 @@
/* CCOPYRIGHT */
// Miscellaneous maths functions
#define NOMINMAX
#include <cstdlib>
#include <cmath>
#include "miscmaths.h"
#include "miscprob.h"
#include "stdlib.h"
......@@ -1083,6 +1085,95 @@ void get_axis_orientations(const Matrix& sform_mat, int sform_code,
} }
nifti_mat44_to_orientation(v2mm,&icode,&jcode,&kcode);
}
Matrix mat44_to_newmat(mat44 inmat)
{
Matrix retmat(4,4);
for (int ii=0; ii<4; ii++) {
for (int jj=0; jj<4; jj++) {
retmat(ii+1,jj+1) = inmat.m[ii][jj];
}
}
return retmat;
}
mat44 newmat_to_mat44(const Matrix& inmat)
{
mat44 retmat;
for (int ii=0; ii<4; ii++) {
for (int jj=0; jj<4; jj++) {
retmat.m[ii][jj] = inmat(ii+1,jj+1);
}
}
return retmat;
}
int FslGetLeftRightOrder(int sform_code, const Matrix& sform_mat,
int qform_code, const Matrix& qform_mat)
{
int retval;
// call the function within fslio
retval = FslGetLeftRightOrder2(sform_code,newmat_to_mat44(sform_mat),
qform_code,newmat_to_mat44(qform_mat));
return retval;
}
short FslGetVox2mmMatrix(Matrix& vox2mm,
int sform_code, const Matrix& sform_mat,
int qform_code, const Matrix& qform_mat,
float dx, float dy, float dz)
{
int retval;
mat44 vox2mm44;
// call the function within fslio
retval = FslGetVox2mmMatrix2(&vox2mm44,sform_code,newmat_to_mat44(sform_mat),
qform_code,newmat_to_mat44(qform_mat),
dx,dy,dz);
vox2mm = mat44_to_newmat(vox2mm44);
return retval;
}
Matrix Vox2FlirtCoord(int sform_code, const Matrix& sform_mat,
int qform_code, const Matrix& qform_mat,
float dx, float dy, float dz,
int nx, int ny, int nz)
{
Matrix v2f(4,4);
Identity(v2f);
v2f(1,1)=dx; v2f(2,2)=dy; v2f(3,3)=dz;
if (FslGetLeftRightOrder(sform_code,sform_mat,qform_code,qform_mat) == FSL_NEUROLOGICAL) {
Matrix swapx(4,4);
Identity(swapx);
swapx(1,1)=-1;
swapx(1,4)=nx-1;
v2f = v2f * swapx;
}
return v2f;
}
Matrix FslGetVox2VoxMatrix(const Matrix& flirt_in2ref,
int sform_code_in, const Matrix& sform_mat_in,
int qform_code_in, const Matrix& qform_mat_in,
float dx_in, float dy_in, float dz_in,
int nx_in, int ny_in, int nz_in,
int sform_code_ref, const Matrix& sform_mat_ref,
int qform_code_ref, const Matrix& qform_mat_ref,
float dx_ref, float dy_ref, float dz_ref,
int nx_ref, int ny_ref, int nz_ref)
{
Matrix vox2flirt_in, vox2flirt_ref, vox2vox;
vox2flirt_in = Vox2FlirtCoord(sform_code_in,sform_mat_in,qform_code_in,
qform_mat_in,dx_in,dy_in,dz_in,
nx_in,ny_in,nz_in);
vox2flirt_ref = Vox2FlirtCoord(sform_code_ref,sform_mat_ref,qform_code_ref,
qform_mat_ref,dx_ref,dy_ref,dz_ref,
nx_ref,ny_ref,nz_ref);
vox2vox = vox2flirt_ref.i() * flirt_in2ref * vox2flirt_in;
return vox2vox;
}
// Added by MWW
......@@ -1647,7 +1738,6 @@ ReturnMatrix geqt(const Matrix& mat,const float a)
return res;
}
ReturnMatrix leqt(const Matrix& mat1,const Matrix& mat2)
{
int ctrcol = std::min(mat1.Ncols(),mat2.Ncols());
......
......@@ -15,6 +15,7 @@
#define __miscmaths_h
#include <cmath>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <assert.h>
......@@ -23,7 +24,7 @@
#include <string>
#include <iterator>
#include "fslio/fslio.h"
#include "config.h"
#include "newmatap.h"
#include "kernel.h"
......@@ -43,6 +44,10 @@ namespace MISCMATHS {
// IO/string stuff
template <class T> string num2str(T n, int width=-1);
#if defined(_MSC_VER) && (_MSC_VER < 1300)
template <class T> string num2str(T n) { return num2str(n -1); }
#endif
string size(const Matrix& mat);
bool isnum(const string& str);
ReturnMatrix read_ascii_matrix(const string& filename, int nrows, int ncols);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment