Commit 262a61c9 authored by Stefan Philips's avatar Stefan Philips
Browse files

[ADD] Extend NIFTI-Loader to load WDataSetSingle (more dimensional voxel) data...

[ADD] Extend NIFTI-Loader to load WDataSetSingle (more dimensional voxel) data and WDataSetSphericalHarmonics
parent e0337a68
......@@ -37,6 +37,9 @@
#include "../WDataSetSingle.h"
#include "../WDataSetVector.h"
#include "../WDataSetScalar.h"
// TODO(philips): polish WDataSetSegmentation for check in
// #include "../WDataSetSegmentation.h"
#include "../WDataSetSphericalHarmonics.h"
#include "../WDataSetRawHARDI.h"
#include "../WGrid.h"
#include "../WGridRegular3D.h"
......@@ -173,69 +176,87 @@ boost::shared_ptr< WDataSet > WLoaderNIfTI::load()
}
boost::shared_ptr< WDataSet > newDataSet;
if( vDim == 3 )
// known description
std::string description( header->descrip );
// TODO(philips): polish WDataSetSegmentation for check in
// if ( !description.compare( "WDataSetSegmentation" ) )
// {
// wlog::debug( "WLoaderNIfTI" ) << "Load as segmentation" << std::endl;
// newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSegmentation( newValueSet, newGrid ) );
// }
// else
if ( !description.compare( "WDataSetSphericalHarmonics" ) )
{
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetVector( newValueSet, newGrid ) );
wlog::debug( "WLoaderNIfTI" ) << "Load as spherical harmonics" << std::endl;
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSphericalHarmonics( newValueSet, newGrid ) );
}
else if( vDim == 1 )
{
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetScalar( newValueSet, newGrid ) );
}
else if( vDim > 20 && header->dim[ 5 ] == 1 ) // hardi data, order 1
// unknown description
else
{
std::string gradientFileName = m_fileName;
using wiotools::getSuffix;
std::string suffix = getSuffix( m_fileName );
if( suffix == ".gz" )
if( vDim == 3 )
{
WAssert( gradientFileName.length() > 3, "" );
gradientFileName.resize( gradientFileName.length() - 3 );
suffix = getSuffix( gradientFileName );
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetVector( newValueSet, newGrid ) );
}
WAssert( suffix == ".nii", "Input file is not a nifti file." );
WAssert( gradientFileName.length() > 4, "" );
gradientFileName.resize( gradientFileName.length() - 4 );
gradientFileName += ".bvec";
// check if the file exists
std::ifstream i( gradientFileName.c_str() );
if( i.bad() || !i.is_open() )
else if( vDim == 1 )
{
if( i.is_open() )
{
i.close();
}
// cannot find the appropriate gradient vectors, build a dataSetSingle instead of hardi
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSingle( newValueSet, newGrid ) );
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetScalar( newValueSet, newGrid ) );
}
else
else if( vDim > 20 && header->dim[ 5 ] == 1 ) // hardi data, order 1
{
// read gradients, there should be 3 * vDim values in the file
typedef std::vector< wmath::WVector3D > GradVec;
boost::shared_ptr< GradVec > newGradients = boost::shared_ptr< GradVec >( new GradVec( vDim ) );
std::string gradientFileName = m_fileName;
using wiotools::getSuffix;
std::string suffix = getSuffix( m_fileName );
if( suffix == ".gz" )
{
WAssert( gradientFileName.length() > 3, "" );
gradientFileName.resize( gradientFileName.length() - 3 );
suffix = getSuffix( gradientFileName );
}
WAssert( suffix == ".nii", "Input file is not a nifti file." );
// the file should contain the x-coordinates in line 0, y-coordinates in line 1,
// z-coordinates in line 2
for( unsigned int j = 0; j < 3; ++j )
WAssert( gradientFileName.length() > 4, "" );
gradientFileName.resize( gradientFileName.length() - 4 );
gradientFileName += ".bvec";
// check if the file exists
std::ifstream i( gradientFileName.c_str() );
if( i.bad() || !i.is_open() )
{
for( unsigned int k = 0; k < vDim; ++k )
if( i.is_open() )
{
i >> newGradients->operator[] ( k )[ j ];
i.close();
}
// cannot find the appropriate gradient vectors, build a dataSetSingle instead of hardi
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSingle( newValueSet, newGrid ) );
}
bool success = !i.eof();
i.close();
else
{
// read gradients, there should be 3 * vDim values in the file
typedef std::vector< wmath::WVector3D > GradVec;
boost::shared_ptr< GradVec > newGradients = boost::shared_ptr< GradVec >( new GradVec( vDim ) );
WAssert( success, "Gradient file did not contain enough gradients." );
// the file should contain the x-coordinates in line 0, y-coordinates in line 1,
// z-coordinates in line 2
for( unsigned int j = 0; j < 3; ++j )
{
for( unsigned int k = 0; k < vDim; ++k )
{
i >> newGradients->operator[] ( k )[ j ];
}
}
bool success = !i.eof();
i.close();
WAssert( success, "Gradient file did not contain enough gradients." );
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetRawHARDI( newValueSet, newGrid, newGradients ) );
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetRawHARDI( newValueSet, newGrid, newGradients ) );
}
}
else
{
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSingle( newValueSet, newGrid ) );
}
}
else
{
newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSingle( newValueSet, newGrid ) );
}
newDataSet->setFileName( m_fileName );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment