Commit 3c0c6bf2 authored by schurade's avatar schurade
Browse files

[ADD] start filling the meta info class, added a header file that will contain...

[ADD] start filling the meta info class, added a header file that will contain several enums for infos related to datasets
parent f8fbac6a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WDATAHANDLERENUMS_H
#define WDATAHANDLERENUMS_H
/**
* Dataset types and number values taken from the nifti1.h, at this point it's unknown if it makes sense
* to keep the bit coding, but it doesn't hurt either
*/
enum dataType
{
W_DT_NONE = 0,
W_DT_UNKNOWN = 0, /* what it says, dude */
W_DT_BINARY = 1, /* binary (1 bit/voxel) */
W_DT_UNSIGNED_CHAR = 2, /* unsigned char (8 bits/voxel) */
W_DT_SIGNED_SHORT = 4, /* signed short (16 bits/voxel) */
W_DT_SIGNED_INT = 8, /* signed int (32 bits/voxel) */
W_DT_FLOAT = 16, /* float (32 bits/voxel) */
W_DT_COMPLEX = 32, /* complex (64 bits/voxel) */
W_DT_DOUBLE = 64, /* double (64 bits/voxel) */
W_DT_RGB = 128, /* RGB triple (24 bits/voxel) */
W_DT_ALL = 255, /* not very useful (?) */
W_DT_INT8 = 256, /* signed char (8 bits) */
W_DT_UINT16 = 512, /* unsigned short (16 bits) */
W_DT_UINT32 = 768, /* unsigned int (32 bits) */
W_DT_INT64 = 1024, /* long long (64 bits) */
W_DT_UINT64 = 1280, /* unsigned long long (64 bits) */
W_DT_FLOAT128 = 1536, /* long double (128 bits) */
W_DT_COMPLEX128 = 1792, /* double pair (128 bits) */
W_DT_COMPLEX256 = 2048, /* long double pair (256 bits) */
W_DT_RGBA32 = 2304 /* 4 byte RGBA (32 bits/voxel) */
};
enum qformOrientation
{
Left_to_Right,
Posterior_to_Anterior,
Inferior_to_Superior
};
#endif // WDATAHANDLERENUMS_H
......@@ -33,29 +33,29 @@
#include "WGrid.h"
#include "WValueSetBase.h"
#include "WValueSet.hpp"
#include "WMetaInfo.h"
#include "io/nifti/nifti1_io.h"
WLoaderNIfTI::WLoaderNIfTI( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler )
: m_fileName( fileName ), m_dataHandler( dataHandler )
: m_fileName( fileName ),
m_dataHandler( dataHandler )
{
}
void WLoaderNIfTI::operator()()
{
nifti_image* image = nifti_image_read( m_fileName.c_str(), 0 );
int columns = image->dim[1];
int rows = image->dim[2];
int frames = image->dim[3];
nifti_image* header = nifti_image_read( m_fileName.c_str(), 0 );
int columns = header->dim[1];
int rows = header->dim[2];
int frames = header->dim[3];
std::cout << "grid dimensions: " << columns << " " << rows << " " << frames
<< std::endl;
switch( image->datatype )
switch( header->datatype )
{
case DT_SIGNED_SHORT:
std::cout << "data type: DT_SIGNED_SHORT" << std::endl;
break;
default:
std::cout << "unknown data type " << image->datatype << std::endl;
std::cout << "unknown data type " << header->datatype << std::endl;
assert( 0 );
}
boost::shared_ptr< WValueSetBase > newValueSet;
......@@ -63,36 +63,81 @@ void WLoaderNIfTI::operator()()
nifti_image* filedata = nifti_image_read( m_fileName.c_str(), 1 );
unsigned int valueDim = image->dim[4];
unsigned int valueDim = header->dim[4];
unsigned int nbTens = columns * rows * frames;
unsigned int nbValues = nbTens * valueDim;
nifti_image_infodump( image );
nifti_image_infodump( header );
if( image->datatype == DT_SIGNED_SHORT && valueDim == 1 )
if( header->datatype == DT_SIGNED_SHORT && valueDim == 1 )
{
std::cout << "DataType SIGNED_SHORT: " << image->datatype << std::endl;
std::cout << "DataType SIGNED_SHORT: " << header->datatype << std::endl;
int16_t* myImage = reinterpret_cast<int16_t*>( filedata->data );
std::vector< int16_t > data( nbValues );
for( unsigned int i = 0; i < nbValues; i++ )
{
data[i] = myImage[i];
}
newValueSet = boost::shared_ptr< WValueSetBase > (
new WValueSet< int16_t >( 0, valueDim, data ) );
newValueSet = boost::shared_ptr< WValueSetBase > ( new WValueSet< int16_t >( 0, valueDim, data ) );
newGrid = boost::shared_ptr< WGrid >( new WGrid( nbValues ) );
}
else
{
std::cout << "unknown data type " << image->datatype << std::endl;
std::cout << "unknown data type " << header->datatype << std::endl;
newValueSet = boost::shared_ptr< WValueSetBase >();
newGrid = boost::shared_ptr< WGrid >();
}
boost::shared_ptr< WMetaInfo > metaInfo = boost::shared_ptr<WMetaInfo>(
new WMetaInfo() );
boost::shared_ptr< WMetaInfo > metaInfo = boost::shared_ptr<WMetaInfo>( new WMetaInfo() );
fillMetaInfo( metaInfo, header );
boost::shared_ptr< WDataSet > newDataSet = boost::shared_ptr< WDataSet >(
new WDataSetSingle( newValueSet, newGrid, metaInfo ) );
m_dataHandler->addDataSet( newDataSet );
}
void WLoaderNIfTI::fillMetaInfo( boost::shared_ptr< WMetaInfo > metaInfo, nifti_image* header )
{
metaInfo->setName( m_fileName );
metaInfo->setFileName( m_fileName );
metaInfo->setDataType( header->datatype );
metaInfo->setNx( header->nx );
metaInfo->setNy( header->ny );
metaInfo->setNz( header->nz );
metaInfo->setDx( header->dx );
metaInfo->setDy( header->dy );
metaInfo->setDz( header->dz );
metaInfo->setXyzUnits( header->xyz_units );
metaInfo->setQformCode( header->qform_code );
metaInfo->setQuaternB( header->quatern_b );
metaInfo->setQuaternC( header->quatern_c );
metaInfo->setQuaternD( header->quatern_d );
metaInfo->setQoffsetX( header->qoffset_x );
metaInfo->setQoffsetY( header->qoffset_y );
metaInfo->setQoffsetZ( header->qoffset_z );
metaInfo->setQfac( header->qfac );
metaInfo->setFreqDim( header->freq_dim );
metaInfo->setPhaseDim( header->phase_dim );
metaInfo->setSliceDim( header->slice_dim );
std::vector<float>xyzMatrix( 16, 0 );
for ( int i = 0; i < 4; ++i )
{
for ( int j = 0; j < 4; ++j)
{
xyzMatrix[ i * 4 + j ] = header->qto_xyz.m[i][j];
}
}
metaInfo->setQtoXyzMatrix( xyzMatrix );
std::vector<float>ijkMatrix( 16, 0 );
for ( int i = 0; i < 4; ++i )
{
for ( int j = 0; j < 4; ++j)
{
ijkMatrix[ i * 4 + j ] = header->qto_ijk.m[i][j];
}
}
metaInfo->setQtoIjkMatrix( ijkMatrix );
}
......@@ -28,6 +28,9 @@
#include <boost/shared_ptr.hpp>
#include "WLoader.h"
#include "WMetaInfo.h"
#include "io/nifti/nifti1_io.h"
class WDataSet;
class WDataHandler;
......@@ -53,6 +56,8 @@ public:
protected:
private:
void fillMetaInfo( boost::shared_ptr< WMetaInfo > metaInfo, nifti_image* header );
std::string m_fileName;
boost::shared_ptr< WDataHandler > m_dataHandler;
};
......
......@@ -22,9 +22,43 @@
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "WMetaInfo.h"
WMetaInfo::WMetaInfo() :
m_name( "" ),
m_fileName( "" ),
m_dataType( 0 ),
m_nx( 0 ),
m_ny( 0 ),
m_nz( 0 ),
m_dx( 0.0 ),
m_dy( 0.0 ),
m_dz( 0.0 ),
m_xyzUnits( 0 ),
m_xyzUnitsName( "" ),
m_qformCode( 0 ),
m_qformCodeName( "" ),
// m_qtoXyzMatrix
// m_qtoIjkMatrix
m_quaternB( 0.0 ),
m_quaternC( 0.0 ),
m_quaternD( 0.0 ),
m_qoffsetX( 0.0 ),
m_qoffsetY( 0.0 ),
m_qoffsetZ( 0.0 ),
m_qfac( 0.0 ),
m_qformOrientationI( 0 ),
m_qformOrientationJ( 0 ),
m_qformOrientationK( 0 ),
m_freqDim( 0 ),
m_phaseDim( 0 ),
m_sliceDim( 0 )
{
}
std::string WMetaInfo::getName() const
{
return m_name;
......@@ -44,3 +78,263 @@ void WMetaInfo::setFileName( std::string fileName )
{
m_fileName = fileName;
}
int WMetaInfo::getDataType() const
{
return m_dataType;
}
void WMetaInfo::setDataType( int dataType )
{
m_dataType = dataType;
}
int WMetaInfo::WMetaInfo::getNx() const
{
return m_nx;
}
void WMetaInfo::setNx( int nx )
{
m_nx = nx;
}
int WMetaInfo::WMetaInfo::getNy() const
{
return m_ny;
}
void WMetaInfo::setNy( int ny )
{
m_ny = ny;
}
int WMetaInfo::WMetaInfo::getNz() const
{
return m_nz;
}
void WMetaInfo::setNz( int nz )
{
m_nz = nz;
}
float WMetaInfo::getDx() const
{
return m_dx;
}
void WMetaInfo::setDx( float dx )
{
m_dx = dx;
}
float WMetaInfo::getDy() const
{
return m_dy;
}
void WMetaInfo::setDy( float dy )
{
m_dy = dy;
}
float WMetaInfo::getDz() const
{
return m_dz;
}
void WMetaInfo::setDz( float dz )
{
m_dz = dz;
}
int WMetaInfo::getXyzUnits() const
{
return m_xyzUnits;
}
void WMetaInfo::setXyzUnits( int xyzUnits )
{
m_xyzUnits = xyzUnits;
}
std::string WMetaInfo::getXyzUnitsName() const
{
return m_xyzUnitsName;
}
void WMetaInfo::setXyzUnitsName( std::string xyzUnitsName )
{
m_xyzUnitsName = xyzUnitsName;
}
int WMetaInfo::getFreqDim() const
{
return m_freqDim;
}
void WMetaInfo::setFreqDim( int freqDim )
{
m_freqDim = freqDim;
}
int WMetaInfo::getPhaseDim() const
{
return m_phaseDim;
}
void WMetaInfo::setPhaseDim( int phaseDim )
{
m_phaseDim = phaseDim;
}
int WMetaInfo::getSliceDim() const
{
return m_sliceDim;
}
void WMetaInfo::setSliceDim( int sliceDim )
{
m_sliceDim = sliceDim;
}
int WMetaInfo::getQformCode() const
{
return m_qformCode;
}
void WMetaInfo::setQformCode( int qformCode )
{
m_qformCode = qformCode;
}
std::string WMetaInfo::getQformCodeName() const
{
return m_qformCodeName;
}
void WMetaInfo::setQformCodeName( std::string qformCodeName )
{
m_qformCodeName = qformCodeName;
}
std::vector<float> WMetaInfo::getQtoXyzMatrix() const
{
return m_qtoXyzMatrix;
}
void WMetaInfo::setQtoXyzMatrix( std::vector<float> qtoXyzMatrix )
{
m_qtoXyzMatrix = qtoXyzMatrix;
}
std::vector<float> WMetaInfo::getQtoIjkMatrix() const
{
return m_qtoIjkMatrix;
}
void WMetaInfo::setQtoIjkMatrix( std::vector<float> qtoIjkMatrix )
{
m_qtoIjkMatrix = qtoIjkMatrix;
}
float WMetaInfo::getQuaternB() const
{
return m_quaternB;
}
void WMetaInfo::setQuaternB( float quaternB )
{
m_quaternB = quaternB;
}
float WMetaInfo::getQuaternC() const
{
return m_quaternC;
}
void WMetaInfo::setQuaternC( float quaternC )
{
m_quaternC = quaternC;
}
float WMetaInfo::getQuaternD() const
{
return m_quaternD;
}
void WMetaInfo::setQuaternD( float quaternD )
{
m_quaternD = quaternD;
}
float WMetaInfo::getQoffsetX() const
{
return m_qoffsetX;
}
void WMetaInfo::setQoffsetX( float qoffsetX )
{
m_qoffsetX = qoffsetX;
}
float WMetaInfo::getQoffsetY() const
{
return m_qoffsetY;
}
void WMetaInfo::setQoffsetY( float qoffsetY )
{
m_qoffsetY = qoffsetY;
}
float WMetaInfo::getQoffsetZ() const
{
return m_qoffsetZ;
}
void WMetaInfo::setQoffsetZ( float qoffsetZ )
{
m_qoffsetZ = qoffsetZ;
}
float WMetaInfo::getQfac() const
{
return m_qfac;
}
void WMetaInfo::setQfac( float qfac )
{
m_qfac = qfac;
}
int WMetaInfo::getQformOrientationI() const
{
return m_qformOrientationI;
}
void WMetaInfo::setQformOrientationI( int qformOrientationI )
{
m_qformOrientationI = qformOrientationI;
}
int WMetaInfo::getQformOrientationJ() const
{
return m_qformOrientationJ;
}
void WMetaInfo::setQformOrientationJ( int qformOrientationJ )
{
m_qformOrientationJ = qformOrientationJ;
}
int WMetaInfo::getQformOrientationK() const
{
return m_qformOrientationK;
}
void WMetaInfo::setQformOrientationK( int qformOrientationK )
{
m_qformOrientationK = qformOrientationK;
}
......@@ -25,6 +25,7 @@
#define WMETAINFO_H
#include <string>
#include <vector>
/**
* Stores meta information such as types, file names, etc. associated with a
......@@ -38,26 +39,93 @@ class WMetaInfo
friend class WMetaInfoTest;
public:
/**
* \return Name of the WDataSet
*/
std::string getName() const;
WMetaInfo();
/**
* Reset the name of the DataSet
*/
std::string getName() const;
void setName( std::string name );
/**
* \return The file name from which the DataSet got its data.
*/
std::string getFileName() const;
/**
* Reset the file name from which the data is gathered for the WDataSet.
*/
void setFileName( std::string fileName );
int getDataType() const;
void setDataType( int dataType );
int getNx() const;
void setNx( int nx );
int getNy() const;
void setNy( int ny );
int getNz() const;
void setNz( int nz );
float getDx() const;
void setDx( float dx );
float getDy() const;
void setDy( float dy );
float getDz() const;
void setDz( float dz );
int getXyzUnits() const;
void setXyzUnits( int xyzUnits );
std::string getXyzUnitsName() const;
void setXyzUnitsName( std::string xyzUnitsName );
int getFreqDim() const;
void setFreqDim( int freqDim );
int getPhaseDim() const;
void setPhaseDim( int phaseDim );
int getSliceDim() const;
void setSliceDim( int sliceDim );
int getQformCode() const;
void setQformCode( int qformCode );
std::string getQformCodeName() const;
void setQformCodeName( std::string qformCodeName );
std::vector<float> getQtoXyzMatrix() const;
void setQtoXyzMatrix( std::vector<float> qtoXyzMatrix );
std::vector<float> getQtoIjkMatrix() const;
void setQtoIjkMatrix( std::vector<float> qtoIjkMatrix );
float getQuaternB() const;
void setQuaternB( float quaternB );
float getQuaternC() const;
void setQuaternC( float quaternC );
float getQuaternD() const;
void setQuaternD( float quaternD );
float getQoffsetX() const;
void setQoffsetX( float qoffsetX );
float getQoffsetY() const;
void setQoffsetY( float qoffsetY );
float getQoffsetZ() const;
void setQoffsetZ( float qoffsetZ );
float getQfac() const;
void setQfac( float qfac );