Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from chamberm/magnet-tracking
Browse files Browse the repository at this point in the history
Magnet tracking
  • Loading branch information
chamberm committed Sep 16, 2015
2 parents 7d781cd + 98e19f8 commit ada9fa3
Show file tree
Hide file tree
Showing 41 changed files with 2,342 additions and 924 deletions.
2 changes: 1 addition & 1 deletion src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool Logger::printIfGLError( wxString str )
str.Append( wxT( " - GL_INVALID_OPERATION" ) );
break;
default:
str.Append( wxString::Format( wxT( " - ADD ERROR MESSAGE HERE: ERROR CODE: %x" ), error ) );
str.Append( wxString::Format( wxT( " - ADD ERROR MESSAGE HERE: ERROR CODE: %i" ), error ) );
break;
}

Expand Down
42 changes: 39 additions & 3 deletions src/dataset/Anatomy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,14 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
{
m_originalAxialOrientation = ORIENTATION_LEFT_TO_RIGHT;
}
if( pHeader->sto_xyz.m[1][1] < 0.0 )
{
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
}
else
{
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
}
}
else if( pHeader->qform_code > 0 )
{
Expand All @@ -708,6 +716,14 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
{
m_originalAxialOrientation = ORIENTATION_LEFT_TO_RIGHT;
}
if( pHeader->qto_xyz.m[1][1] < 0.0 )
{
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
}
else
{
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
}
}

// Check the data type.
Expand Down Expand Up @@ -901,6 +917,12 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
if( m_originalAxialOrientation == ORIENTATION_RIGHT_TO_LEFT )
{
flipAxisInternal( X_AXIS, false );
DatasetManager::getInstance()->setFlippedXOnLoad(true);
}
if( m_originalSagOrientation == ORIENTATION_ANT_TO_POST )
{
flipAxisInternal( Y_AXIS, false );
DatasetManager::getInstance()->setFlippedYOnLoad(true);
}

if( m_isLoaded && m_type == VECTORS )
Expand All @@ -927,9 +949,6 @@ bool Anatomy::save( wxXmlNode *pNode, const wxString &rootPath ) const

void Anatomy::saveNifti( wxString fileName )
{
// Prevents copying the whole vector
vector<float> *pDataset = m_useEqualizedDataset ? &m_equalizedDataset : &m_floatDataset;

int dims[] = { 4, m_columns, m_rows, m_frames, m_bands, 0, 0, 0 };
nifti_image* pImage(NULL);
pImage = nifti_make_new_nim( dims, m_dataType, 1 );
Expand Down Expand Up @@ -982,6 +1001,16 @@ void Anatomy::saveNifti( wxString fileName )
pImage->qoffset_z = qz;
pImage->qfac = qfac;

//Save RAI (example: drew a new anat, on a RAI-based, if load again, it will be flipped for visu. So need to reorient it's data now.)
if(pImage->qto_xyz.m[0][0] < 0)
{
flipAxis(Y_AXIS);
flipAxis(X_AXIS);
}

// Prevents copying the whole vector
vector<float> *pDataset = m_useEqualizedDataset ? &m_equalizedDataset : &m_floatDataset;

if( m_type == HEAD_BYTE )
{
vector<unsigned char> tmp( pDataset->size() );
Expand Down Expand Up @@ -1049,6 +1078,13 @@ void Anatomy::saveNifti( wxString fileName )
pImage->data = &(*pDataset)[0];
nifti_image_write( pImage );
}

//Deflip
if(pImage->qto_xyz.m[0][0] < 0)
{
flipAxis(Y_AXIS);
flipAxis(X_AXIS);
}
}

void Anatomy::saveToNewFilename( const wxString &fullPath )
Expand Down
7 changes: 7 additions & 0 deletions src/dataset/Anatomy.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ friend class PropertiesWindow;
ORIENTATION_RIGHT_TO_LEFT,
ORIENTATION_UNDEFINED
};
enum SagOrientation
{
ORIENTATION_ANT_TO_POST,
ORIENTATION_POST_TO_ANT,
};

public:
//constructor/destructor
Expand All @@ -61,6 +66,7 @@ friend class PropertiesWindow;
void add( Anatomy* anatomy);

float at( const int i ) const;
unsigned int getSize() { return m_floatDataset.size(); }
std::vector<float>* getFloatDataset();
std::vector<float>* getEqualizedDataset();
void setFloatDataset(std::vector<float>& dataset) { m_floatDataset = dataset; }
Expand Down Expand Up @@ -182,6 +188,7 @@ friend class PropertiesWindow;
unsigned int m_cdf[256];

AxialOrientation m_originalAxialOrientation;
SagOrientation m_originalSagOrientation;
};

#endif /* ANATOMY_H_ */
22 changes: 17 additions & 5 deletions src/dataset/DatasetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ DatasetManager::DatasetManager(void)
: m_nextIndex( 1 ),
m_niftiTransform( 4, 4 ),
m_forceLoadingAsMaximas( false ),
m_forceLoadingAsRestingState( false )
m_forceLoadingAsRestingState( false ),
m_loadedFlipX( false ),
m_loadedFlipY( false )
{
}

Expand Down Expand Up @@ -213,6 +215,16 @@ int DatasetManager::getRows() const
return 1;
}

int DatasetManager::getBands() const
{
if( !m_anatomies.empty() )
{
map<DatasetIndex, Anatomy *>::const_iterator it = m_anatomies.begin();
return it->second->getBands();
}
return 1;
}

//////////////////////////////////////////////////////////////////////////

float DatasetManager::getVoxelX() const
Expand Down Expand Up @@ -373,7 +385,7 @@ DatasetIndex DatasetManager::load( const wxString &filename, const wxString &ext
result = loadMesh( filename, extension );
}
}
else if( wxT( "fib" ) == extension || wxT( "trk" ) == extension || wxT( "bundlesdata" ) == extension || wxT( "Bfloat" ) == extension || wxT( "tck" ) == extension )
else if( wxT( "fib" ) == extension || wxT( "trk" ) == extension || wxT( "bundlesdata" ) == extension || wxT( "Bfloat" ) == extension || wxT( "tck" ) == extension || wxT( "vtk" ) == extension)
{
if( !isAnatomyLoaded() )
{
Expand Down Expand Up @@ -643,7 +655,7 @@ DatasetIndex DatasetManager::loadRestingState( const wxString &filename, nifti_i
}
//////////////////////////////////////////////////////////////////////////

// Loads a fiber set. Extension supported: .fib, .bundlesdata, .trk and .tck
// Loads a fiber set. Extension supported: .fib, .vtk, .bundlesdata, .trk and .tck
DatasetIndex DatasetManager::loadFibers( const wxString &filename )
{
Fibers* l_fibers = new Fibers();
Expand All @@ -670,11 +682,11 @@ DatasetIndex DatasetManager::loadFibers( const wxString &filename )
return BAD_INDEX;
}

DatasetIndex DatasetManager::createFibers( std::vector<std::vector<Vector> >* RTT )
DatasetIndex DatasetManager::createFibers()
{
Fibers* l_fibers = new Fibers();

l_fibers->convertFromRTT( RTT );
l_fibers->convertFromRTT();

l_fibers->setThreshold( THRESHOLD );
l_fibers->setShow ( SHOW );
Expand Down
11 changes: 9 additions & 2 deletions src/dataset/DatasetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ class DatasetManager
int getColumns() const;
int getFrames() const;
int getRows() const;
int getBands() const;
float getVoxelX() const;
float getVoxelY() const;
float getVoxelZ() const;
FMatrix & getNiftiTransform() { return m_niftiTransform; }
bool getFlippedXOnLoad() { return m_loadedFlipX; }
bool getFlippedYOnLoad() { return m_loadedFlipY; }
void setFlippedXOnLoad(bool flip) { m_loadedFlipX = flip;}
void setFlippedYOnLoad(bool flip) { m_loadedFlipY = flip;}

bool isDatasetLoaded() const { return !m_datasets.empty(); }
bool isAnatomyLoaded() const { return !m_anatomies.empty(); }
Expand Down Expand Up @@ -86,7 +91,7 @@ class DatasetManager
DatasetIndex createMaximas( const wxString &filename ) { return insert( new Maximas( filename ) ); }

void remove( const DatasetIndex index );
DatasetIndex createFibers( std::vector<std::vector<Vector> >* RTT );
DatasetIndex createFibers();
DatasetIndex addFibers( Fibers* fibers );

protected:
Expand All @@ -112,7 +117,7 @@ class DatasetManager
// Loads an anatomy. Extension supported: .nii and .nii.gz
DatasetIndex loadAnatomy( const wxString &filename, nifti_image *pHeader, nifti_image *pBody );

// Loads a fiber set. Extension supported: .fib, .bundlesdata, .trk and .tck
// Loads a fiber set. Extension supported: .fib, .vtk, .bundlesdata, .trk and .tck
DatasetIndex loadFibers( const wxString &filename );


Expand Down Expand Up @@ -150,6 +155,8 @@ class DatasetManager

bool m_forceLoadingAsMaximas;
bool m_forceLoadingAsRestingState;
bool m_loadedFlipX;
bool m_loadedFlipY;
};

#endif //DATASETMANAGER_H_
Loading

0 comments on commit ada9fa3

Please sign in to comment.