Commit 5793593f authored by Cyril Poupon's avatar Cyril Poupon
Browse files

Modified Resamping3d interfaces in python scripts

parent f34a8cee
......@@ -196,7 +196,7 @@ class DwiBundleFilteringTask( Task ):
command += ' -template ' + fileNameT1
command += ' -output ' + outputFileNameRoiOrDensityMap + \
' -transform ' + fileNameTransformationDensityToT1 + \
' -transforms ' + fileNameTransformationDensityToT1 + \
' -order 0'
executeCommand( self, subjectName, command, viewOnly )
......@@ -246,7 +246,7 @@ class DwiBundleFilteringTask( Task ):
command += ' -template ' + fileNameT1
command += ' -output ' + outputFileNameRoiOrDensityMap + \
' -transform ' + fileNameTransformationRoiToT1 + \
' -transforms ' + fileNameTransformationRoiToT1 + \
' -order 0'
executeCommand( self, subjectName, command, viewOnly )
......@@ -317,7 +317,7 @@ class DwiBundleFilteringTask( Task ):
command += ' -template ' + fileNameT1
command += ' -output ' + outputFileNameRoiOrDensityMap + \
' -transform ' + fileNameTransformationRoiToT1 + \
' -transforms ' + fileNameTransformationRoiToT1 + \
' -order 0'
executeCommand( self, subjectName, command, viewOnly )
......
......@@ -173,7 +173,7 @@ class DwiDataConvertionToDtiTkTask( Task ):
command = 'GkgExecuteCommand Resampling3d ' + \
' -reference ' + fileNameTractographyMask + \
' -template ' + fileNameRoughMask + \
' -transform ' + fileNameTractographyMaskToDijTransformation + \
' -transforms ' + fileNameTractographyMaskToDijTransformation + \
' -output ' + fileNameTractographyMaskResampled + \
' -order 0 ' + \
' -verbose true'
......
......@@ -269,7 +269,7 @@ class DwiQualityCheckReportingTask( Task ):
' -template ' + os.path.join( \
directoryNameSusceptibilityArtifactCorrection,
'susceptibility_shift_map' ) + \
' -transform ' + os.path.join( \
' -transforms ' + os.path.join( \
outputDirectorySusceptibilityArtifactCorrection,
't1_to_b0.trm' ) + \
' -output ' + os.path.join( \
......@@ -341,7 +341,8 @@ class DwiQualityCheckReportingTask( Task ):
' -template ' + os.path.join( \
directoryNameEddyCurrentAndMotion,
't2_wo_eddy_current_and_motion' ) + \
' -transform ' + os.path.join( directoryNameToAnatomyMatching,
' -transforms ' + \
os.path.join( directoryNameToAnatomyMatching,
't1_to_dw.trm' ) + \
' -output ' + os.path.join( outputDirectoryTensorFitting,
'mask.ima' ) + \
......
......@@ -285,7 +285,7 @@ class DwiRoughMaskExtractionTask( Task ):
command = 'GkgExecuteCommand Resampling3d ' + \
' -reference ' + dilatedMorphologistBrainMask + \
' -template ' + fileNameAverageT2 + \
' -transform ' + fileNameT1ToDwTransform3d + \
' -transforms ' + fileNameT1ToDwTransform3d + \
' -output ' + fileNameMask + \
' -order 0 ' + \
' -verbose true'
......
......@@ -183,7 +183,7 @@ class DwiSubjectResamplingToTemplateTask( Task ):
' -reference ' + fileNameInputDataInGisFormat + \
' -output ' + fileNameInputDataInGisFormat + \
' -template ' + fileNameTemplate + \
' -transform ' + fileNameIdentityTransformation + \
' -transforms ' + fileNameIdentityTransformation + \
' -order 0'
executeCommand( self, subjectName, command, viewOnly )
......@@ -252,7 +252,7 @@ class DwiSubjectResamplingToTemplateTask( Task ):
' -reference ' + tFileName + '.ima' + \
' -output ' + tFileName + '.ima' + \
' -template ' + fileNameTemplate + \
' -transform ' + fileNameIdentityTransformation
' -transforms ' + fileNameIdentityTransformation
executeCommand( self, subjectName, command, viewOnly )
command = 'AimsFileConvert ' + \
......@@ -306,7 +306,7 @@ class DwiSubjectResamplingToTemplateTask( Task ):
' -reference ' + f + \
' -output ' + fileNameInputDataInGisFormat + \
' -template ' + fileNameTemplate + \
' -transform ' + fileNameIdentityTransformation
' -transforms ' + fileNameIdentityTransformation
executeCommand( self, subjectName, command, viewOnly )
command = 'AimsFileConvert ' + \
......
......@@ -401,7 +401,7 @@ class DwiSusceptibilityArtifactCorrectionTask( Task ):
' -resolution ' + str( resolutionX ) + ' ' + \
str( resolutionY ) + ' ' + \
str( resolutionZ ) + ' ' + \
' -transform ' + fileNameB0ToDwTransform3d + \
' -transforms ' + fileNameB0ToDwTransform3d + \
' -output ' + fileNameResampledUnwrappedB0PhaseDifference + \
' -order 3 ' + \
' -background 0 ' + \
......@@ -606,7 +606,7 @@ class DwiSusceptibilityArtifactCorrectionTask( Task ):
' -resolution ' + str( resolutionX ) + ' ' + \
str( resolutionY ) + ' ' + \
str( resolutionZ ) + ' ' + \
' -transform ' + fileNameB0ToDwTransform3d + \
' -transforms ' + fileNameB0ToDwTransform3d + \
' -output ' + fileNameResampledUnwrappedB0PhaseDifference + \
' -order 3 ' + \
' -background 0 ' + \
......@@ -799,7 +799,7 @@ class DwiSusceptibilityArtifactCorrectionTask( Task ):
' -resolution ' + str( resolutionX ) + ' ' + \
str( resolutionY ) + ' ' + \
str( resolutionZ ) + ' ' + \
' -transform ' + fileNameB0ToDwTransform3d + \
' -transforms ' + fileNameB0ToDwTransform3d + \
' -output ' + fileNameResampledUnwrappedB0PhaseDifference + \
' -order 3 ' + \
' -background 0 ' + \
......@@ -985,7 +985,7 @@ class DwiSusceptibilityArtifactCorrectionTask( Task ):
' -resolution ' + str( resolutionX ) + ' ' + \
str( resolutionY ) + ' ' + \
str( resolutionZ ) + ' ' + \
' -transform ' + fileNameB0ToDwTransform3d + \
' -transforms ' + fileNameB0ToDwTransform3d + \
' -output ' + fileNameResampledUnwrappedB0PhaseDifference + \
' -order 3 ' + \
' -background 0 ' + \
......
......@@ -1127,7 +1127,7 @@ class DwiToAnatomyMatchingTask( Task ):
outputNormalization3dDirectory,
'label-WHS-40um.ima' ) + \
' -template ' + fileNameOutT1 + \
' -transform ' + fileNameTemplateToT1 + \
' -transforms ' + fileNameTemplateToT1 + \
' -output ' + os.path.join( \
outputNormalization3dDirectory,
'label-WHS-40um-resampled-to-t1.ima' ) + \
......@@ -1146,7 +1146,7 @@ class DwiToAnatomyMatchingTask( Task ):
outputNormalization3dDirectory,
'label-Duke-43um.ima' ) + \
' -template ' + fileNameOutT1 + \
' -transform ' + fileNameTemplateToT1 + \
' -transforms ' + fileNameTemplateToT1 + \
' -output ' + os.path.join( \
outputNormalization3dDirectory,
'label-Duke-43um-resampled-to-t1.ima' ) + \
......@@ -1585,7 +1585,7 @@ class DwiToAnatomyMatchingTask( Task ):
command = 'GkgExecuteCommand Resampling3d ' + \
' -reference ' + fileNameOutT1 + \
' -template ' + fileNameOutT1 + \
' -transform ' + fileNameT1ToTalairachTransform3d + \
' -transforms ' + fileNameT1ToTalairachTransform3d + \
' -output ' + fileNameT1InTalairachSpace + \
' -order 3 ' + \
' -background 0 ' + \
......@@ -1632,7 +1632,7 @@ class DwiToAnatomyMatchingTask( Task ):
' -resolution ' + str( resolutionXOfT2Talairach ) + ' ' + \
str( resolutionYOfT2Talairach ) + ' ' + \
str( resolutionZOfT2Talairach ) + ' ' + \
' -transform ' + fileNameDwExtendedToTalairachTransform3d + \
' -transforms ' + fileNameDwExtendedToTalairachTransform3d + \
' -output ' + fileNameAverageT2InTalaraichSpace + \
' -order 3 ' + \
' -background 0 ' + \
......@@ -1662,7 +1662,7 @@ class DwiToAnatomyMatchingTask( Task ):
' -resolution ' + str( resolutionXOfT2Talairach ) + ' ' + \
str( resolutionYOfT2Talairach ) + ' ' + \
str( resolutionZOfT2Talairach ) + ' ' + \
' -transform ' + fileNameDwExtendedToTalairachTransform3d + \
' -transforms ' + fileNameDwExtendedToTalairachTransform3d + \
' -output ' + fileNameDWInTalaraichSpace + \
' -order 3 ' + \
' -background 0 ' + \
......@@ -1681,19 +1681,20 @@ class DwiToAnatomyMatchingTask( Task ):
fileNameRoughMaskInTalairachSpace = os.path.join( outputWorkDirectory,
'mask_talairach' )
command = 'GkgExecuteCommand DwiResampling3d ' + \
' -reference ' + fileNameRoughMaskExtended + \
' -size ' + str( sizeXOfT2Talairach ) + ' ' + \
str( sizeYOfT2Talairach ) + ' ' + \
str( sizeZOfT2Talairach ) + ' ' + \
' -resolution ' + str( resolutionXOfT2Talairach ) + ' ' + \
str( resolutionYOfT2Talairach ) + ' ' + \
str( resolutionZOfT2Talairach ) + ' ' + \
' -transform ' + fileNameDwExtendedToTalairachTransform3d +\
' -output ' + fileNameRoughMaskInTalairachSpace + \
' -order 0 ' + \
' -background 0 ' + \
' -verbose true'
command = \
'GkgExecuteCommand DwiResampling3d ' + \
' -reference ' + fileNameRoughMaskExtended + \
' -size ' + str( sizeXOfT2Talairach ) + ' ' + \
str( sizeYOfT2Talairach ) + ' ' + \
str( sizeZOfT2Talairach ) + ' ' + \
' -resolution ' + str( resolutionXOfT2Talairach ) + ' ' + \
str( resolutionYOfT2Talairach ) + ' ' + \
str( resolutionZOfT2Talairach ) + ' ' + \
' -transforms ' + fileNameDwExtendedToTalairachTransform3d + \
' -output ' + fileNameRoughMaskInTalairachSpace + \
' -order 0 ' + \
' -background 0 ' + \
' -verbose true'
executeCommand( self, subjectName, command, viewOnly )
######################### updating progress bar ########################
......
......@@ -5,6 +5,7 @@
#include <gkg-processing-resampling/SplineResampler.h>
#include <gkg-processing-transform/RigidTransform3d.h>
#include <gkg-processing-transform/AffineTransform3d.h>
#include <gkg-processing-transform/NonLinearTransform3d.h>
#include <gkg-core-io/TypeOf.h>
#include <gkg-processing-process/Process.h>
#include <gkg-core-io/Reader_i.h>
......@@ -31,7 +32,7 @@ class DwiResamplingProcess : public gkg::Process
DwiResamplingProcess( const std::string& fileNameTemplate,
const std::vector< int32_t >& outSize,
const std::vector< double >& outResolution,
const std::string& fileNameTransform,
const std::vector< std::string >& fileNameTransforms,
const std::string& fileNameOut,
int32_t order,
double outBackground,
......@@ -43,7 +44,7 @@ class DwiResamplingProcess : public gkg::Process
const std::string& getFileNameTemplate() const;
const std::vector< int32_t >& getOutSize() const;
const std::vector< double >& getOutResolution() const;
const std::string& getFileNameTransform() const;
const std::vector< std::string >& getFileNameTransforms() const;
const std::string& getFileNameOut() const;
int32_t getOrder() const;
double getOutBackground() const;
......@@ -63,7 +64,7 @@ class DwiResamplingProcess : public gkg::Process
const std::string& _fileNameTemplate;
const std::vector< int32_t >& _outSize;
const std::vector< double >& _outResolution;
const std::string& _fileNameTransform;
const std::vector< std::string >& _fileNameTransforms;
const std::string& _fileNameOut;
int32_t _order;
double _outBackground;
......@@ -76,22 +77,22 @@ class DwiResamplingProcess : public gkg::Process
DwiResamplingProcess::DwiResamplingProcess(
const std::string& fileNameTemplate,
const std::vector< int32_t >& outSize,
const std::vector< double >& outResolution,
const std::string& fileNameTransform,
const std::string& fileNameOut,
int32_t order,
double outBackground,
bool correctQSpaceSampling,
bool ascii,
const std::string& format,
bool verbose )
const std::string& fileNameTemplate,
const std::vector< int32_t >& outSize,
const std::vector< double >& outResolution,
const std::vector< std::string >& fileNameTransforms,
const std::string& fileNameOut,
int32_t order,
double outBackground,
bool correctQSpaceSampling,
bool ascii,
const std::string& format,
bool verbose )
: gkg::Process( "Volume" ),
_fileNameTemplate( fileNameTemplate ),
_outSize( outSize ),
_outResolution( outResolution ),
_fileNameTransform( fileNameTransform ),
_fileNameTransforms( fileNameTransforms ),
_fileNameOut( fileNameOut ),
_order( order ),
_outBackground( outBackground ),
......@@ -166,10 +167,11 @@ const std::vector< double >& DwiResamplingProcess::getOutResolution() const
}
const std::string& DwiResamplingProcess::getFileNameTransform() const
const std::vector< std::string >&
DwiResamplingProcess::getFileNameTransforms() const
{
return _fileNameTransform;
return _fileNameTransforms;
}
......@@ -282,6 +284,14 @@ void DwiResamplingProcess::resample( gkg::Process& process,
double referenceResolutionT = 1.0;
referenceVolume.getResolution( referenceResolution, referenceResolutionT );
// because some Nifti TR values are set to 0
if ( referenceResolutionT <= 0.0 )
{
referenceResolutionT = 1.0;
}
gkg::Volume< T > tmpReferenceVolume( referenceSize );
tmpReferenceVolume.setResolution( referenceResolution,
referenceResolutionT );
......@@ -383,49 +393,97 @@ void DwiResamplingProcess::resample( gkg::Process& process,
if ( dwiResamplingProcess.getVerbose() )
{
std::cout << "reading transform '"
<< dwiResamplingProcess.getFileNameTransform()
<< "' : " << std::flush;
if ( dwiResamplingProcess.getFileNameTransforms().size() == 1U )
{
std::cout << "reading transform '"
<< dwiResamplingProcess.getFileNameTransforms()[ 0 ]
<< "' : " << std::flush;
}
else
{
std::cout << "reading transform '"
<< dwiResamplingProcess.getFileNameTransforms()[ 0 ]
<< "' / '"
<< dwiResamplingProcess.getFileNameTransforms()[ 1 ]
<< "' : " << std::flush;
}
}
gkg::Transform3d< double >* transform3d = 0;
std::string foundTransformText = "undefined transform type";
try
if ( dwiResamplingProcess.getFileNameTransforms().size() == 1U )
{
gkg::RigidTransform3d< double >*
rigidTransform3d = new gkg::RigidTransform3d< double >;
std::ifstream is( dwiResamplingProcess.getFileNameTransform().c_str() );
rigidTransform3d->readTrm( is );
is.close();
transform3d = rigidTransform3d;
foundTransformText = "rigid transformation detected";
try
{
gkg::RigidTransform3d< double >*
rigidTransform3d = new gkg::RigidTransform3d< double >;
std::ifstream
is( dwiResamplingProcess.getFileNameTransforms()[ 0 ].c_str() );
rigidTransform3d->readTrm( is );
is.close();
transform3d = rigidTransform3d;
foundTransformText = "rigid transformation detected";
}
catch ( std::exception& )
{
try
{
gkg::AffineTransform3d< double >*
affineTransform3d =
new gkg::AffineTransform3d< double >;
std::ifstream
is( dwiResamplingProcess.getFileNameTransforms()[ 0 ].c_str() );
affineTransform3d->readTrm( is );
is.close();
transform3d = affineTransform3d;
foundTransformText = "affine transformation detected";
}
catch ( std::exception& )
{
throw std::runtime_error(
"unable to find an adequate linear transform" );
}
}
}
catch ( std::exception& )
else
{
try
{
gkg::AffineTransform3d< double >*
affineTransform3d =
new gkg::AffineTransform3d< double >;
std::ifstream is( dwiResamplingProcess.getFileNameTransform().c_str() );
affineTransform3d->readTrm( is );
is.close();
transform3d = affineTransform3d;
foundTransformText = "affine transformation detected";
gkg::NonLinearTransform3d< double >*
nonLinearTransform3d = new gkg::NonLinearTransform3d< double >;
nonLinearTransform3d->readTrm(
dwiResamplingProcess.getFileNameTransforms()[ 0 ],
dwiResamplingProcess.getFileNameTransforms()[ 1 ] );
transform3d = nonLinearTransform3d;
foundTransformText = "non-linear transformation detected";
}
catch ( std::exception& )
{
throw std::runtime_error(
"unable to find an adequate linear transform" );
"unable to find an adequate non-linear transform" );
}
}
if ( dwiResamplingProcess.getVerbose() )
{
......@@ -578,6 +636,44 @@ void DwiResamplingProcess::resample( gkg::Process& process,
angles.y = ( float )parameters[ 7 ];
angles.z = ( float )parameters[ 8 ];
}
else if ( dynamic_cast< gkg::NonLinearTransform3d< double >* >(
transform3d ) )
{
gkg::NonLinearTransform3d< double >*
nonLinearTransform3d =
dynamic_cast< gkg::NonLinearTransform3d< double >* >( transform3d );
std::vector< double > parameters;
nonLinearTransform3d->getParameterizedLinearTransform3d()->
getDirectParameters( parameters );
// in case of a rigid linear 3D transform
if ( parameters.size() == 6U )
{
angles.x = ( float )parameters[ 0 ];
angles.y = ( float )parameters[ 1 ];
angles.z = ( float )parameters[ 2 ];
}
// in case of an affine linear 3D transform
else if ( parameters.size() == 12U )
{
angles.x = ( float )parameters[ 6 ];
angles.y = ( float )parameters[ 7 ];
angles.z = ( float )parameters[ 8 ];
}
// bad case
else
{
throw std::runtime_error(
"number of parameter count should be 6 or 12" );
}
}
int32_t q = 0;
......@@ -666,18 +762,18 @@ gkg::DwiResampling3dCommand::DwiResampling3dCommand( int32_t argc,
gkg::DwiResampling3dCommand::DwiResampling3dCommand(
const std::string& fileNameReference,
const std::string& fileNameTemplate,
const std::vector< int32_t >& outSize,
const std::vector< double >& outResolution,
const std::string& fileNameTransform,
const std::string& fileNameOut,
int32_t order,
double outBackground,
bool correctQSpaceSampling,
bool ascii,
const std::string& format,
bool verbose )
const std::string& fileNameReference,
const std::string& fileNameTemplate,
const std::vector< int32_t >& outSize,
const std::vector< double >& outResolution,
const std::vector< std::string >& fileNameTransforms,
const std::string& fileNameOut,
int32_t order,
double outBackground,
bool correctQSpaceSampling,
bool ascii,
const std::string& format,
bool verbose )
: gkg::Command()
{
......@@ -688,7 +784,7 @@ gkg::DwiResampling3dCommand::DwiResampling3dCommand(
fileNameTemplate,
outSize,
outResolution,
fileNameTransform,
fileNameTransforms,
fileNameOut,
order,
outBackground,
......@@ -703,7 +799,7 @@ gkg::DwiResampling3dCommand::DwiResampling3dCommand(
"const std::string& fileNameTemplate, "
"const std::vector< int32_t >& outSize, "
"const std::vector< double >& outResolution, "
"const std::string& fileNameTransform, "
"const std::vector< std::string >& fileNameTransforms, "
"const std::string& fileNameOut, "
"int32_t order, "
"double outBackground, "
......@@ -729,7 +825,8 @@ gkg::DwiResampling3dCommand::DwiResampling3dCommand(
outSize );
DECLARE_VECTOR_OF_FLOATINGS_PARAMETER( parameters, std::vector< double >,
outResolution );
DECLARE_STRING_PARAMETER( parameters, std::string, fileNameTransform );
DECLARE_VECTOR_OF_STRINGS_PARAMETER( parameters, std::vector< std::string >,
fileNameTransforms );
DECLARE_STRING_PARAMETER( parameters, std::string, fileNameOut );
DECLARE_INTEGER_PARAMETER( parameters, int32_t, order );
DECLARE_FLOATING_PARAMETER( parameters, double, outBackground );
......@@ -742,7 +839,7 @@ gkg::DwiResampling3dCommand::DwiResampling3dCommand(
fileNameTemplate,
outSize,
outResolution,
fileNameTransform,
fileNameTransforms,
fileNameOut,
order,
outBackground,
......@@ -787,7 +884,7 @@ void gkg::DwiResampling3dCommand::parse()
std::string fileNameTemplate;
std::vector< int32_t > outSize;
std::vector< double > outResolution;
std::string fileNameTransform;
std::vector< std::string > fileNameTransforms;
std::string fileNameOut;
int32_t order = 3;
double outBackground = 0.0;
......@@ -814,9 +911,10 @@ void gkg::DwiResampling3dCommand::parse()
"Output resolution in millimeter",
outResolution,
0, 3 );
application.addSingleOption( "-transform",
"Rigid transform file name",
fileNameTransform );
application.addSeriesOption( "-transforms",
"Linear or non-linear transform file name(s)",
fileNameTransforms,
1, 2 );
application.addSingleOption( "-output",
"Output resampled volume name",
fileNameOut );
......@@ -859,7 +957,7 @@ void gkg::DwiResampling3dCommand::parse()
fileNameTemplate,
outSize,
outResolution,
fileNameTransform,
fileNameTransforms,
fileNameOut,
order,
outBackground,
......@@ -875,18 +973,18 @@ void gkg::DwiResampling3dCommand::parse()
void gkg::DwiResampling3dCommand::execute(
const std::string& fileNameReference,
const std::string& fileNameTemplate,
const std::vector< int32_t >& outSize,
const std::vector< double >& outResolution,
const std::string& fileNameTransform,
const std::string& fileNameOut,
int32_t order,
double outBackground,
bool correctQSpaceSampling,
bool ascii,
const std::string& format,
bool verbose )