Commit 26bc966d authored by Marc Modat's avatar Marc Modat

Went through the Wall and pedantic on MacOs 10.9

parent 9c55ba6e
......@@ -56,28 +56,23 @@ else(BUILD_NR_SLICER_EXT)
endif(BUILD_NR_SLICER_EXT)
option(USE_SSE "To enable SEE computation in some case" ON)
option(USE_CUDA "To enable CUDA for a GPU implementation of the code" OFF)
option(USE_DOUBLE "To force double precision instead of single precision" OFF)
if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# OpenMP is disable when the compiler is based on Clang
find_package(OpenMP)
if(OPENMP_FOUND)
option(USE_OPENMP "To use openMP for multi-CPU processing" ON)
endif(OPENMP_FOUND)
endif(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
find_package(OpenMP)
if(OPENMP_FOUND)
option(USE_OPENMP "To use openMP for multi-CPU processing" ON)
endif(OPENMP_FOUND)
option(BUILD_SHARED_LIBS "Build the libraries as shared." OFF)
if(BUILD_SHARED_LIBS)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message(WARNING "certain libraries cannot be built shared on MACOSX, forcing them to STATIC")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build the libraries as shared." FORCE)
set(NIFTYREG_LIBRARY_TYPE STATIC)
else()
if(NOT APPLE)
option(USE_CUDA "To enable CUDA for a GPU implementation of the code" OFF)
option(BUILD_SHARED_LIBS "Build the libraries as shared." OFF)
if(BUILD_SHARED_LIBS)
set(NIFTYREG_LIBRARY_TYPE SHARED)
endif()
else()
else(BUILD_SHARED_LIBS)
set(NIFTYREG_LIBRARY_TYPE STATIC)
endif(BUILD_SHARED_LIBS)
else(NOT APPLE)
set(NIFTYREG_LIBRARY_TYPE STATIC)
endif()
endif(NOT APPLE)
#-----------------------------------------------------------------------------
......@@ -172,10 +167,6 @@ if(USE_CUDA)
if(CUDA_FOUND)
# Display the CUDA version
message(STATUS "The CUDA version you have is v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}")
# Check that the compiler is not Clang based, it won't compile otherwise
if(${CUDA_HOST_COMPILER} MATCHES "Clang")
message(FATAL_ERROR "The CUDA version of NiftyReg cannot be used with a clang based compiler")
endif(${CUDA_HOST_COMPILER} MATCHES "Clang")
# Compile an executable to check if there is at least one suitable graphical card
try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
${CMAKE_BINARY_DIR}
......@@ -202,6 +193,7 @@ if(USE_CUDA)
else(RUN_RESULT_VAR)
# Check if ptxas information should be displayed
set(CUDA_CAPABILITY "" CACHE STRING "CUDA capability to use to generate the ptxas information (1.0, 2.0, 3.0) [0]")
mark_as_advanced(FORCE CUDA_CAPABILITY)
if(CUDA_CAPABILITY EQUAL "1.0")
set(CUDA_NVCC_FLAGS
"${CUDA_NVCC_FLAGS} --ptxas-options=-v --generate-code arch=compute_10,code=sm_10")
......
......@@ -57,7 +57,6 @@ void Usage(char *exec)
printf("\t-aff <filename>\t\tFilename which contains the output affine transformation. [outputAffine.txt]\n");
printf("\t-inaff <filename>\tFilename which contains an input affine transformation. (Affine*Reference=Floating) [none]\n");
printf("\t-affFlirt <filename>\tFilename which contains an input affine transformation from Flirt. [none]\n");
printf("\t-rmask <filename>\tFilename of a mask image in the reference space.\n");
printf("\t-fmask <filename>\tFilename of a mask image in the floating space. (Only used when symmetric turned on)\n");
......@@ -113,7 +112,6 @@ int main(int argc, char **argv)
char *inputAffineName=NULL;
int inputAffineFlag=0;
int flirtAffineFlag=0;
char *referenceMaskName=NULL;
int referenceMaskFlag=0;
......@@ -195,12 +193,6 @@ int main(int argc, char **argv)
inputAffineName=argv[++i];
inputAffineFlag=1;
}
else if(strcmp(argv[i], "-affFlirt")==0 || strcmp(argv[i], "--affFlirt")==0)
{
inputAffineName=argv[++i];
inputAffineFlag=1;
flirtAffineFlag=1;
}
else if(strcmp(argv[i], "-rmask")==0 || strcmp(argv[i], "-tmask")==0 || strcmp(argv[i], "--rmask")==0)
{
referenceMaskName=argv[++i];
......@@ -464,7 +456,7 @@ int main(int argc, char **argv)
// Set the input affine transformation if defined
if(inputAffineFlag==1)
REG->SetInputTransform(inputAffineName,flirtAffineFlag);
REG->SetInputTransform(inputAffineName);
// Set the verbose type
REG->SetVerbose(verbose);
......
......@@ -74,7 +74,7 @@ int main(int argc, char **argv)
return 0;
}
// Check if help is required
for(size_t i=1; i<argc; ++i)
for(int i=1; i<argc; ++i)
{
if(strcmp(argv[i],"-h")==0 ||
strcmp(argv[i],"-H")==0 ||
......@@ -89,7 +89,7 @@ int main(int argc, char **argv)
}
// Command line
printf("\nCommand line:\n\t");
for(size_t i=0; i<argc; ++i)
for(int i=0; i<argc; ++i)
printf("%s ",argv[i]);
printf("\n\n");
......@@ -314,7 +314,7 @@ int main(int argc, char **argv)
size_t affineNumber = (argc - 4)/2;
// All affine matrices are read in
mat44 *affineMatrices = (mat44 *)malloc(affineNumber*sizeof(mat44));
for(size_t i=4, j=0; i<argc; i+=2,++j)
for(int i=4, j=0; i<argc; i+=2,++j)
{
if(reg_isAnImageFileName(argv[i]))
{
......@@ -379,7 +379,7 @@ int main(int argc, char **argv)
tempImage->scl_inter=0.f;
tempImage->data = (void *)malloc(tempImage->nvox*tempImage->nbyper);
// warp all floating images and sum them up
for(size_t i=5, j=0; i<argc; i+=2,++j)
for(int i=5, j=0; i<argc; i+=2,++j)
{
nifti_image *floatingImage = reg_io_ReadImageFile(argv[i]);
if(floatingImage==NULL)
......@@ -444,7 +444,7 @@ int main(int argc, char **argv)
sprintf(msg,"reg_average: Number of input transformations: %i",(argc-4)/operation);
reg_print_msg_debug(msg);
#endif
for(size_t i=(operation==2?4:5); i<argc; i+=operation)
for(int i=(operation==2?4:5); i<argc; i+=operation)
{
nifti_image *transformation = reg_io_ReadImageFile(argv[i]);
if(transformation==NULL)
......@@ -557,7 +557,7 @@ int main(int argc, char **argv)
nifti_image *tempImage = nifti_copy_nim_info(averageImage);
tempImage->data = (void *)malloc(tempImage->nvox*tempImage->nbyper);
// Iterate over all the transformation parametrisations
for(size_t i=(operation==2?4:5); i<argc; i+=operation)
for(int i=(operation==2?4:5); i<argc; i+=operation)
{
nifti_image *transformation = reg_io_ReadImageFile(argv[i]);
if(transformation==NULL)
......
......@@ -79,7 +79,6 @@ void Usage(char *exec)
printf("\n*** Initial transformation options (One option will be considered):\n");
printf("\t-aff <filename>\t\tFilename which contains an affine transformation (Affine*Reference=Floating)\n");
printf("\t-affFlirt <filename>\tFilename which contains a flirt affine transformation (Flirt from the FSL package)\n");
printf("\t-incpp <filename>\tFilename ofloatf control point grid input\n\t\t\t\tThe coarse spacing is defined by this file.\n");
printf("\n*** Output options:\n");
......@@ -324,24 +323,10 @@ int main(int argc, char **argv)
/* read the input parameter */
for(int i=1; i<argc; i++)
{
if(strcmp(argv[i], "-help")==0 || strcmp(argv[i], "-Help")==0 ||
strcmp(argv[i], "-HELP")==0 || strcmp(argv[i], "-h")==0 ||
strcmp(argv[i], "--h")==0 || strcmp(argv[i], "--help")==0 ||
strcmp(argv[i], "--xml")==0 || strcmp(argv[i], "-version")==0 ||
strcmp(argv[i], "-Version")==0 || strcmp(argv[i], "-V")==0 ||
strcmp(argv[i], "-v")==0 || strcmp(argv[i], "--v")==0 ||
strcmp(argv[i], "--version")==0 || strcmp(argv[i], "-helpPenalty")==0 ||
#ifdef _USE_CUDA
strcmp(argv[i], "-gpu")==0 ||
#endif
strcmp(argv[i], "-vel")==0 || strcmp(argv[i], "-sym")==0)
{
// argument has already been parsed
NULL;
}
else if(strcmp(argv[i],"-ref")==0 || strcmp(argv[i],"-target")==0 ||
strcmp(argv[i],"--ref")==0 || strcmp(argv[i],"-flo")==0 ||
strcmp(argv[i],"-source")==0 || strcmp(argv[i],"--flo")==0 )
if(strcmp(argv[i],"-ref")==0 || strcmp(argv[i],"-target")==0 ||
strcmp(argv[i],"--ref")==0 || strcmp(argv[i],"-flo")==0 ||
strcmp(argv[i],"-source")==0 || strcmp(argv[i],"--flo")==0 )
{
// argument has already been parsed
++i;
......@@ -367,33 +352,7 @@ int main(int argc, char **argv)
}
// Read the affine matrix
reg_tool_ReadAffineFile(&affineMatrix,
referenceImage,
floatingImage,
affineTransformationName,
false);
// Send the transformation to the registration object
REG->SetAffineTransformation(&affineMatrix);
}
else if(strcmp(argv[i], "-affFlirt")==0 || (strcmp(argv[i],"--affFlirt")==0))
{
// Check first if the specified affine file exist
char *affineTransformationName=argv[++i];
if(FILE *aff=fopen(affineTransformationName, "r"))
{
fclose(aff);
}
else
{
fprintf(stderr,"The specified input affine file (%s) can not be read\n",
affineTransformationName);
return 1;
}
// Read the affine matrix
reg_tool_ReadAffineFile(&affineMatrix,
referenceImage,
floatingImage,
affineTransformationName,
true);
affineTransformationName);
// Send the transformation to the registration object
REG->SetAffineTransformation(&affineMatrix);
}
......@@ -702,7 +661,18 @@ int main(int argc, char **argv)
checkMemory=true;
}
#endif
else
/* All the following arguments should have already been parsed */
else if(strcmp(argv[i], "-help")!=0 && strcmp(argv[i], "-Help")!=0 &&
strcmp(argv[i], "-HELP")!=0 && strcmp(argv[i], "-h")!=0 &&
strcmp(argv[i], "--h")!=0 && strcmp(argv[i], "--help")!=0 &&
strcmp(argv[i], "--xml")!=0 && strcmp(argv[i], "-version")!=0 &&
strcmp(argv[i], "-Version")!=0 && strcmp(argv[i], "-V")!=0 &&
strcmp(argv[i], "-v")!=0 && strcmp(argv[i], "--v")!=0 &&
strcmp(argv[i], "--version")!=0 && strcmp(argv[i], "-helpPenalty")!=0 &&
#ifdef _USE_CUDA
strcmp(argv[i], "-gpu")!=0 &&
#endif
strcmp(argv[i], "-vel")!=0 && strcmp(argv[i], "-sym")!=0)
{
fprintf(stderr,"Err:\tParameter %s unknown.\n",argv[i]);
PetitUsage(argv[0]);
......
......@@ -214,7 +214,7 @@ int main(int argc, char **argv)
}
else{
refMask = (int *)calloc(refMaskVoxNumber,sizeof(int));
for(size_t i=0;i<refMaskVoxNumber;++i) refMask[i]=i;
for(int i=0;i<refMaskVoxNumber;++i) refMask[i]=i;
}
/* Create the warped floating image */
......
......@@ -210,7 +210,7 @@ int main(int argc, char **argv)
{
memcpy(makesource->data, &(temp_data[ii*makesource->nvox*source->nbyper]), makesource->nbyper*makesource->nvox);
char outname[100];
int n=sprintf(outname,"%s%i.nii",param->finalResultName,ii);
sprintf(outname,"%s%i.nii",param->finalResultName,ii);
printf("Writing '%s' (%i of %i)\n",outname,ii+1,source->nt);
nifti_set_filenames(makesource,outname, 0, 0); // might want to set this
nifti_image_write(makesource);
......@@ -396,11 +396,11 @@ int main(int argc, char **argv)
mask->nvox=mask->nx*mask->ny*mask->nz;
mask->data = (void *)malloc(mask->nvox*mask->nbyper);
PrecisionTYPE *intensityPtrM = static_cast<PrecisionTYPE *>(mask->data);
for(int i=0; i<mask->nvox; i++) intensityPtrM[i]=1.0;
for(size_t i=0; i<mask->nvox; i++) intensityPtrM[i]=1.0;
}
PrecisionTYPE masksum=0.0;
PrecisionTYPE *intensityPtrM = static_cast<PrecisionTYPE *>(mask->data);
for(int i=0; i<mask->nvox; i++)
for(size_t i=0; i<mask->nvox; i++)
{
if(intensityPtrM[i]) masksum++;
}
......@@ -433,7 +433,7 @@ int main(int argc, char **argv)
if(!flag->outputCPPFlag)
{
char buffer[40];
int n=sprintf(buffer,"ppcnrfinal-%s",style);
sprintf(buffer,"ppcnrfinal-%s",style);
if(flag->aladin || flag->flirt)
{
strcat(buffer,".txt");
......@@ -502,8 +502,8 @@ int main(int argc, char **argv)
PrecisionTYPE *Mean = new PrecisionTYPE [image->nt];
PrecisionTYPE *Cov = new PrecisionTYPE [image->nt*image->nt];
PrecisionTYPE cov;
char pcaname[20];
char outname[20];
// char pcaname[20];
// char outname[20];
for(int prinCompNumber=1; prinCompNumber<=param->prinComp; prinCompNumber++)
{
......@@ -525,7 +525,7 @@ int main(int argc, char **argv)
for(int t=0; t<image->nt; t++)
{
Mean[t]=0.f;
for(int i=0; i<voxelNumber; i++)
for(size_t i=0; i<voxelNumber; i++)
{
if(intensityPtrM[i]) Mean[t] += *intensityPtr++;
}
......@@ -542,7 +542,7 @@ int main(int argc, char **argv)
{
PrecisionTYPE *currentIntensityPtr1 = &intensityPtr[t*voxelNumber];
cov=0.f;
for(int i=0; i<voxelNumber; i++)
for(size_t i=0; i<voxelNumber; i++)
{
if(intensityPtrM[i]) cov += (*currentIntensityPtr1++ - Mean[t]) * (*currentIntensityPtr2++ - Mean[t2]);
}
......@@ -781,7 +781,7 @@ int main(int argc, char **argv)
{
PrecisionTYPE *intensityPtr1 = static_cast<PrecisionTYPE *>(image->data);
PrecisionTYPE *intensityPtr2 = static_cast<PrecisionTYPE *>(imagep->data);
for(int i=0; i<voxelNumber; i++)
for(size_t i=0; i<voxelNumber; i++)
{
for(int t=0; t<image->nt; t++)
{
......@@ -800,7 +800,7 @@ int main(int argc, char **argv)
{
PrecisionTYPE *intensityPtr1 = static_cast<PrecisionTYPE *>(image->data);
PrecisionTYPE *intensityPtr2 = static_cast<PrecisionTYPE *>(imagep->data);
for(int i=0; i<voxelNumber; i++)
for(size_t i=0; i<voxelNumber; i++)
{
for(int t=0; t<image->nt; t++)
{
......@@ -812,7 +812,7 @@ int main(int argc, char **argv)
{
PrecisionTYPE *intensityPtr1 = static_cast<PrecisionTYPE *>(image->data);
PrecisionTYPE *intensityPtr2 = static_cast<PrecisionTYPE *>(imagep->data);
for(int i=0; i<voxelNumber; i++)
for(size_t i=0; i<voxelNumber; i++)
{
for(int c=0; c<prinCompNumber; c++) // Add up component contributions
{
......@@ -876,7 +876,7 @@ int main(int argc, char **argv)
char regCommandB[1055]="";
if(!flag->flirt)
{
int n=sprintf(regCommandB,"%s -%s ",regCommandAll,style);
sprintf(regCommandB,"%s -%s ",regCommandAll,style);
char buffer[20];
if(flag->aladin)
{
......@@ -884,7 +884,7 @@ int main(int argc, char **argv)
}
else
{
n=sprintf(buffer,"float%s%i.nii", style,imageNumber+1);
sprintf(buffer,"float%s%i.nii", style,imageNumber+1);
}
strcat(regCommandB,buffer);
char buffer2[30];
......@@ -952,11 +952,11 @@ int main(int argc, char **argv)
if(flag->pca3)
{
char cppname[20];
n=sprintf(cppname,"cpp%i.nii",prinCompNumber);
sprintf(cppname,"cpp%i.nii",prinCompNumber);
if(!flag->aladin & !flag->flirt)
{
char buffer[20];
int n=sprintf(buffer,"float%s1.nii",style);
sprintf(buffer,"float%s1.nii",style);
nifti_image *dof = nifti_image_read(buffer,true);
nifti_image *dofs = nifti_copy_nim_info(dof);
dofs->nt = dofs->dim[4] = images->nt;
......@@ -966,7 +966,7 @@ int main(int argc, char **argv)
for(int t=0; t<images->nt; t++)
{
char buffer[20];
int n=sprintf(buffer,"float%s%i.nii",style, t+1);
sprintf(buffer,"float%s%i.nii",style, t+1);
nifti_image *dof = nifti_image_read(buffer,true);
PrecisionTYPE *intensityPtrDD = static_cast<PrecisionTYPE *>(dof->data);
int r=dof->nvox/3.0;
......@@ -986,7 +986,7 @@ int main(int argc, char **argv)
for(int t=0; t<images->nt; t++)
{
char buffer[20];
int n=sprintf(buffer,"float%s%i.txt",style,t+1);
sprintf(buffer,"float%s%i.txt",style,t+1);
std::ifstream ifs(buffer);
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
final_string+=str;
......@@ -1007,7 +1007,7 @@ int main(int argc, char **argv)
if(!flag->aladin & !flag->flirt)
{
char buffer[20];
int n=sprintf(buffer,"float%s1.nii",style);
sprintf(buffer,"float%s1.nii",style);
nifti_image *dof = nifti_image_read(buffer,true);
nifti_image *dofs = nifti_copy_nim_info(dof);
dofs->nt = dofs->dim[4] = images->nt;
......@@ -1017,7 +1017,7 @@ int main(int argc, char **argv)
for(int t=0; t<images->nt; t++)
{
char buffer[20];
int n=sprintf(buffer,"float%s%i.nii",style, t+1);
sprintf(buffer,"float%s%i.nii",style, t+1);
nifti_image *dof = nifti_image_read(buffer,true);
PrecisionTYPE *intensityPtrDD = static_cast<PrecisionTYPE *>(dof->data);
int r=dof->nvox/3.0;
......@@ -1038,7 +1038,7 @@ int main(int argc, char **argv)
for(int t=0; t<images->nt; t++)
{
char buffer[20];
int n=sprintf(buffer,"float%s%i.txt",style,t+1);
sprintf(buffer,"float%s%i.txt",style,t+1);
std::ifstream ifs(buffer);
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
final_string+=str;
......
......@@ -26,7 +26,6 @@ typedef struct
{
char *referenceImageName;
char *floatingImageName;
char *affineMatrixName;
char *inputTransName;
char *outputResultName;
float sourceBGValue;
......@@ -37,8 +36,6 @@ typedef struct
{
bool referenceImageFlag;
bool floatingImageFlag;
bool affineMatrixFlag;
bool affineFlirtFlag;
bool inputTransFlag;
bool outputResultFlag;
bool outputBlankFlag;
......@@ -58,25 +55,19 @@ void Usage(char *exec)
{
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("Usage:\t%s -ref <filename> -flo <filename> [OPTIONS].\n",exec);
printf("\t-ref <filename>\tFilename of the reference image (mandatory)\n");
printf("\t-flo <filename>\tFilename of the floating image (mandatory)\n\n");
printf("\t-ref <filename>\n\t\tFilename of the reference image (mandatory)\n");
printf("\t-flo <filename>\n\t\tFilename of the floating image (mandatory)\n\n");
#ifdef _SVN_REV
fprintf(stderr,"\n-v Print the subversion revision number\n");
#endif
printf("* * OPTIONS * *\n");
printf("\t*\tOnly one of the following tranformation is taken into account\n");
printf("\t-aff <filename>\t\tFilename which contains an affine transformation (Affine*Reference=floating)\n");
printf("\t-affFlirt <filename>\t\tFilename which contains a radiological flirt affine transformation\n");
printf("\t-trans <filename>\t\tFilename of the control point grid image (from reg_f3d)\n");
printf("\t-res <filename> \tFilename of the resampled image [none]\n");
printf("\t-blank <filename> \tFilename of the resampled blank grid [none]\n");
printf("\t*\tOthers\n");
printf("\t-inter <int> \t\tInterpolation order (0,1,3)[3] (0=NN, 1=LIN; 3=CUB)\n");
printf("\t-pad <int> \t\tInterpolation padding value [0]\n");
printf("\t-voff\t\t\tTurns verbose off [on]\n");
printf("\t-trans <filename>\n\t\tFilename of the file containing the transformation parametrisation (from reg_aladin, reg_f3d or reg_transform)\n");
printf("\t-res <filename>\n\t\tFilename of the resampled image [none]\n");
printf("\t-blank <filename>\n\t\tFilename of the resampled blank grid [none]\n");
printf("\t-inter <int>\n\t\tInterpolation order (0,1,3)[3] (0=NN, 1=LIN; 3=CUB)\n");
printf("\t-pad <int>\n\t\tInterpolation padding value [0]\n");
printf("\t-voff\n\t\tTurns verbose off [on]\n");
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
return;
}
......@@ -153,11 +144,6 @@ int main(int argc, char **argv)
{
param->interpolation=atoi(argv[++i]);
}
else if(strcmp(argv[i], "-pad") == 0 ||
(strcmp(argv[i],"--pad")==0))
{
param->paddingValue=(float)atof(argv[++i]);
}
else if(strcmp(argv[i], "-NN") == 0)
{
param->interpolation=0;
......@@ -172,6 +158,11 @@ int main(int argc, char **argv)
{
param->interpolation=3;
}
else if(strcmp(argv[i], "-pad") == 0 ||
(strcmp(argv[i],"--pad")==0))
{
param->paddingValue=(float)atof(argv[++i]);
}
else if(strcmp(argv[i], "-blank") == 0 ||
(strcmp(argv[i],"--blank")==0))
{
......@@ -235,7 +226,7 @@ int main(int argc, char **argv)
startProgress("reg_resample");
// Set up progress indicators
float iProgressStep=1, nProgressSteps;
// float iProgressStep=1, nProgressSteps;
/* *********************************** */
/* DISPLAY THE RESAMPLING PARAMETERS */
......@@ -406,7 +397,13 @@ int main(int argc, char **argv)
warpedImage->cal_max=floatingImage->cal_max;
warpedImage->scl_slope=floatingImage->scl_slope;
warpedImage->scl_inter=floatingImage->scl_inter;
warpedImage->datatype = floatingImage->datatype;
if(param->paddingValue==std::numeric_limits<float>::quiet_NaN() &&
(floatingImage->datatype!=NIFTI_TYPE_FLOAT32 ||
floatingImage->datatype!=NIFTI_TYPE_FLOAT64)){
warpedImage->datatype = NIFTI_TYPE_FLOAT32;
reg_tools_changeDatatype<float>(floatingImage);
}
else warpedImage->datatype = floatingImage->datatype;
warpedImage->nbyper = floatingImage->nbyper;
warpedImage->nvox = (size_t)warpedImage->dim[1] * (size_t)warpedImage->dim[2] *
(size_t)warpedImage->dim[3] * (size_t)warpedImage->dim[4];
......
......@@ -46,6 +46,7 @@ typedef struct
bool halfTransFlag;
bool invertAffFlag;
bool invertNRRFlag;
bool flirtAff2NRFlag;
bool makeAffFlag;
bool aff2rigFlag;
} FLAG;
......@@ -110,9 +111,9 @@ void Usage(char *exec)
printf("\t\tInvert a non-rigid transformation and save the result as a deformation field.\n");
printf("\t\tfilename1 - Input transformation file name\n");
printf("\t\tfilename2 - Input floating (source) image where the inverted transformation is defined\n");
printf("\t\tfilename3 - Output inverted transformation file name\n\n");
printf("\t\tfilename3 - Output inverted transformation file name\n");
printf("\t\tNote that the cubic b-spline grid parametrisations can not be inverted without approximation,\n");
printf("\t\tas a result, they are converted into deformation fields before inversion.\n");
printf("\t\tas a result, they are converted into deformation fields before inversion.\n\n");
printf("\t-half <filename1> <filename2>\n");
printf("\t\tThe input transformation is halfed and stored using the same transformation type.\n");
......@@ -123,10 +124,17 @@ void Usage(char *exec)
printf("\t\tCreate an affine transformation matrix\n\n");
printf("\t-aff2rig <filename1> <filename2>\n");
printf("\t\tExtract the rigid component from an affine transformation matrix\n\n");
printf("\t\tExtract the rigid component from an affine transformation matrix\n");
printf("\t\tfilename1 - Input transformation file name\n");
printf("\t\tfilename2 - Output transformation file name\n\n");
printf("\t-flirtAff2NR <filename1> <filename2> <filename3> <filename4>\n");
printf("\t\tConvert a flirt (FSL) affine transformation to a NiftyReg affine transformation\n");
printf("\t\tfilename1 - Input FLIRT (FSL) affine transformation file name\n");
printf("\t\tfilename2 - Image used as a reference (-ref arg in FLIRT)\n");
printf("\t\tfilename3 - Image used as a floating (-in arg in FLIRT)\n");
printf("\t\tfilename4 - Output affine transformation file name\n\n");
printf("\t* The supported transformation types are:\n");
printf("\t\t- cubic B-Spline parametrised grid (reference image is required)\n");
printf("\t\t- a dense deformation field\n");
......@@ -154,7 +162,7 @@ int main(int argc, char **argv)
FLAG *flag = (FLAG *)calloc(1,sizeof(FLAG));
// Parse the input data
for(size_t i=1; i<argc; ++i)
for(int i=1; i<argc; ++i)
{
if(strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--h")==0 ||
strcmp(argv[i],"-H")==0 || strcmp(argv[i],"--H")==0 ||
......@@ -242,6 +250,14 @@ int main(int argc, char **argv)
param->inputTransName=argv[++i];
param->outputTransName=argv[++i];
}
else if(strcmp(argv[i],"-flirtAff2NR")==0 || strcmp(argv[i],"--flirtAff2NR")==0)
{
flag->flirtAff2NRFlag=true;
param->inputTransName=argv[++i];
param->referenceImageName=argv[++i];
param->referenceImage2Name=argv[++i];
param->outputTransName=argv[++i];
}
else
{
fprintf(stderr, "[NiftyReg ERROR] Unrecognised argument: %s\n",
......@@ -869,7 +885,7 @@ int main(int argc, char **argv)
if(flag->halfTransFlag)
{
// Read the input transformation
mat44 *affineTrans;
mat44 *affineTrans=NULL;
nifti_image *inputTransImage=NULL;
if(!reg_isAnImageFileName(param->inputTransName))
{
......@@ -1172,6 +1188,19 @@ int main(int argc, char **argv)
affine = nifti_quatern_to_mat44(qb,qc,qd,qx,qy,qz,1.f,1.f,1.f,qfac);
reg_tool_WriteAffineFile(&affine, param->outputTransName);
}
/* ********************************************************** */
// Convert a flirt affine transformation to a NiftyReg affine //
/* ********************************************************** */
if(flag->flirtAff2NRFlag)
{
mat44 affine;
nifti_image *referenceImage=reg_io_ReadImageHeader(param->referenceImageName);
nifti_image *floatingImage=reg_io_ReadImageHeader(param->referenceImage2Name);
reg_tool_ReadAffineFile(&affine,referenceImage,floatingImage,param->inputTransName,true);
reg_tool_WriteAffineFile(&affine, param->outputTransName);
nifti_image_free(referenceImage);
nifti_image_free(floatingImage);
}
// Free allocated object
free(param);
free(flag);
......
This diff is collapsed.