-
Matthew Webster authoredMatthew Webster authored
streamlines.cc 33.58 KiB
/* Copyright (C) 2012 University of Oxford */
/* CCOPYRIGHT */
#include "streamlines.h"
#include "warpfns/fnirt_file_reader.h"
#include "warpfns/warpfns.h"
namespace TRACT{
ColumnVector mean_sph_pol(ColumnVector& A, ColumnVector& B){
// A and B contain th, ph f.
float th,ph;
ColumnVector rA(3), rB(3);
rA << (sin(A(1))*cos(A(2))) << (sin(A(1))*sin(A(2))) << (cos(A(1)));
rB << (sin(B(1))*cos(B(2))) << (sin(B(1))*sin(B(2))) << (cos(B(1)));
if(sum(SP(rA,rB)).AsScalar()>0)
cart2sph((rA+rB)/2,th,ph);
else
cart2sph((rA-rB)/2,th,ph);
A(1)=th; A(2)=ph;
return A;
}
void read_masks(vector<string>& masks, const string& filename){
ifstream fs(filename.c_str());
string tmp;
if(fs){
fs>>tmp;
do{
masks.push_back(tmp);
fs>>tmp;
}while(!fs.eof());
}
else{
cerr<<filename<<" does not exist"<<endl;
exit(0);
}
}
void imgradient(const volume<float>& im,volume4D<float>& grad){
grad.reinitialize(im.xsize(),im.ysize(),im.zsize(),3);
copybasicproperties(im,grad[0]);
int fx,fy,fz,bx,by,bz;
float dx,dy,dz;
for (int z=0; z<grad.zsize(); z++){
fz = z ==(grad.zsize()-1) ? 0 : 1;
bz = z == 0 ? 0 : -1;
dz = (fz==0 || bz==0) ? 1.0 : 2.0;
for (int y=0; y<grad.ysize(); y++){
fy = y ==(grad.ysize()-1) ? 0 : 1;
by = y == 0 ? 0 : -1;
dy = (fy==0 || by==0) ? 1.0 : 2.0;
for (int x=0; x<grad.xsize(); x++){
fx = x ==(grad.xsize()-1) ? 0 : 1;
bx = x == 0 ? 0 : -1;
dx = (fx==0 || bx==0) ? 1.0 : 2.0;
grad[0](x,y,z) = (im(x+fx,y,z) - im(x+bx,y,z))/dx;
grad[1](x,y,z) = (im(x,y+fy,z) - im(x,y+by,z))/dy;
grad[2](x,y,z) = (im(x,y,z+fz) - im(x,y,z+bz))/dz;
}
}
}
}