Skip to content

Commit

Permalink
Merge pull request #12 from chamberm/Refactor
Browse files Browse the repository at this point in the history
Better TCK and peaks handling
  • Loading branch information
chamberm committed Nov 28, 2019
2 parents a9a132f + cbb9fef commit b37d238
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 132 deletions.
1 change: 1 addition & 0 deletions src/GLSL/fibers.fs
Expand Up @@ -12,6 +12,7 @@ uniform bool isDistcoloring;

varying vec4 myColor;


float lookupTex()
{
vec3 v = VaryingTexCoord0.xyz;
Expand Down
44 changes: 27 additions & 17 deletions src/dataset/Anatomy.cpp
Expand Up @@ -699,11 +699,11 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
}
if( pHeader->sto_xyz.m[1][1] < 0.0 )
{
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
}
else
{
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
}
}
else if( pHeader->qform_code > 0 )
Expand All @@ -718,16 +718,16 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
}
if( pHeader->qto_xyz.m[1][1] < 0.0 )
{
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
}
else
{
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
}
}

// Check the data type.
if( pHeader->datatype == 2 )
if( pHeader->datatype == 2 || (pHeader->datatype == 16 && pHeader->dim[4] == 3))
{
if( pHeader->dim[4] == 1 )
{
Expand Down Expand Up @@ -981,17 +981,27 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )

case RGB:
{
unsigned char* pData = (unsigned char*)pBody->data;

m_floatDataset.resize( datasetSize * 3 );

for( int i(0); i < datasetSize; ++i )
{
m_floatDataset[i * 3] = (float)pData[i] / 255.0f;
m_floatDataset[i * 3 + 1] = (float)pData[datasetSize + i] / 255.0f;
m_floatDataset[i * 3 + 2] = (float)pData[(2 * datasetSize) + i] / 255.0f;
}

m_floatDataset.resize( datasetSize * 3 );
if(pHeader->datatype == 2)
{
unsigned char* pData = (unsigned char*)pBody->data;
for( int i(0); i < datasetSize; ++i )
{
m_floatDataset[i * 3] = (float)pData[i] / 255.0f;
m_floatDataset[i * 3 + 1] = (float)pData[datasetSize + i] / 255.0f;
m_floatDataset[i * 3 + 2] = (float)pData[(2 * datasetSize) + i] / 255.0f;
}
}
else
{
float* pData = (float*)pBody->data;
for( int i(0); i < datasetSize; ++i )
{
m_floatDataset[i * 3] = (float)pData[i];
m_floatDataset[i * 3 + 1] = (float)pData[datasetSize + i];
m_floatDataset[i * 3 + 2] = (float)pData[(2 * datasetSize) + i];
}
}
flag = true;
break;
}
Expand Down Expand Up @@ -1028,7 +1038,7 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
flipAxisInternal( X_AXIS, false );
DatasetManager::getInstance()->setFlippedXOnLoad(true);
}
if( m_originalSagOrientation == ORIENTATION_ANT_TO_POST )
if( m_originalSagOrientation == ORIENTATION_POST_TO_ANT )
{
flipAxisInternal( Y_AXIS, false );
DatasetManager::getInstance()->setFlippedYOnLoad(true);
Expand Down
32 changes: 23 additions & 9 deletions src/dataset/Fibers.cpp
Expand Up @@ -194,9 +194,23 @@ bool Fibers::load( const wxString &filename )
/* OcTree points classification */
m_pOctree = new Octree( 2, m_pointArray, m_countPoints );


//Global properties for opacity rendering
computeGLobalProperties();

if(DatasetManager::getInstance()->getFlippedXOnLoad())
{
flipAxis(X_AXIS);
std::cout << "flipX save\n";
}

if(DatasetManager::getInstance()->getFlippedYOnLoad())
{
flipAxis(Y_AXIS);
std::cout << "flipY save\n";
}


return res;
}

Expand Down Expand Up @@ -1964,13 +1978,13 @@ void Fibers::fitToAnat(bool saving)
if(DatasetManager::getInstance()->getFlippedXOnLoad())
{
flipAxis(X_AXIS);
std::cout << "flipX \n";
std::cout << "flipX save\n";
}

if(DatasetManager::getInstance()->getFlippedXOnLoad())
if(DatasetManager::getInstance()->getFlippedYOnLoad())
{
flipAxis(Y_AXIS);
std::cout << "flipY \n";
std::cout << "flipY save\n";
}
}

Expand Down Expand Up @@ -2047,13 +2061,13 @@ void Fibers::fitToAnat(bool saving)
if(DatasetManager::getInstance()->getFlippedXOnLoad())
{
flipAxis(X_AXIS);
std::cout << "flipX \n";
std::cout << "flipX not saving\n";
}

if(DatasetManager::getInstance()->getFlippedXOnLoad())
if(DatasetManager::getInstance()->getFlippedYOnLoad())
{
flipAxis(Y_AXIS);
std::cout << "flipY \n";
std::cout << "flipY not saving\n";
}
}

Expand Down Expand Up @@ -3759,9 +3773,9 @@ void Fibers::setFibersLength()
{
// The values are in pixel, we need to set them in millimeters using the spacing
// specified in the anatomy file ( m_datasetHelper->xVoxel... ).
dx = ( currentFiberPoints[i].x - currentFiberPoints[i - 1].x ) * voxelX;
dy = ( currentFiberPoints[i].y - currentFiberPoints[i - 1].y ) * voxelY;
dz = ( currentFiberPoints[i].z - currentFiberPoints[i - 1].z ) * voxelZ;
dx = ( currentFiberPoints[i].x - currentFiberPoints[i - 1].x );
dy = ( currentFiberPoints[i].y - currentFiberPoints[i - 1].y );
dz = ( currentFiberPoints[i].z - currentFiberPoints[i - 1].z );
FArray currentVector( dx, dy, dz );
m_length[j] += ( float )currentVector.norm();
}
Expand Down
2 changes: 1 addition & 1 deletion src/dataset/Fibers.h
Expand Up @@ -111,7 +111,7 @@ class Fibers : public DatasetInfo
void setLocalGlobal(bool value);
void setUsingEndpts(bool value);

void flipAxis( AxisType i_axe );
void flipAxis( AxisType i_axe);
void fitToAnat( bool saving);

int getFibersCount() const { return m_countLines; }
Expand Down
2 changes: 1 addition & 1 deletion src/dataset/FibersGroup.h
Expand Up @@ -66,7 +66,7 @@ class FibersGroup : public DatasetInfo
bool load( wxString filename ) { return false; };
void draw() {};
void smooth() {};
void flipAxis( AxisType i_axe ) {};
void flipAxis( AxisType i_axe) {};
void drawVectors() {};
void generateTexture() {};
void generateGeometry() {};
Expand Down
63 changes: 28 additions & 35 deletions src/dataset/Maximas.cpp
Expand Up @@ -130,11 +130,11 @@ bool Maximas::load( nifti_image *pHeader, nifti_image *pBody )
}
if( pHeader->sto_xyz.m[1][1] < 0.0 )
{
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
}
else
{
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
}
}
else if( pHeader->qform_code > 0 )
Expand All @@ -149,11 +149,11 @@ bool Maximas::load( nifti_image *pHeader, nifti_image *pBody )
}
if( pHeader->qto_xyz.m[1][1] < 0.0 )
{
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
}
else
{
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
}
}

Expand All @@ -163,7 +163,7 @@ bool Maximas::load( nifti_image *pHeader, nifti_image *pBody )
RTTrackingHelper::getInstance()->setMaximaFlip(Vector(-1,1,1));
flipAnat( X_AXIS );
}
if( m_originalSagOrientation == ORIENTATION_ANT_TO_POST )
if( m_originalSagOrientation == ORIENTATION_POST_TO_ANT)
{
flipAxis( Y_AXIS, true );
RTTrackingHelper::getInstance()->setMaximaFlip(Vector(1,-1,1));
Expand Down Expand Up @@ -264,32 +264,24 @@ bool Maximas::createStructure ( std::vector< float > &i_fileFloatData )

FMatrix transform = FMatrix( DatasetManager::getInstance()->getNiftiTransform() );
FMatrix rotMat( 3, 3 );
transform.getSubMatrix( rotMat, 0, 0 );
rotMat(0,0) = 1;
rotMat(1,1) = 1;
rotMat(2,2) = 1;
storedRot = rotMat;


/*float voxelX = DatasetManager::getInstance()->getVoxelX();
float voxelY = DatasetManager::getInstance()->getVoxelY();
float voxelZ = DatasetManager::getInstance()->getVoxelZ();
FMatrix transform = FMatrix( DatasetManager::getInstance()->getNiftiTransform() );
FMatrix rotMat( 3, 3 );
transform.getSubMatrix( rotMat, 0, 0 );
rotMat(0,0) = 1;
rotMat(1,1) = 1;
rotMat(2,2) = 1;
FMatrix test( rotMat );
test = invert(rotMat);
rotMat = test;*/
transform.getSubMatrix( rotMat, 0, 0 );

storedRot = rotMat*(1.0f/abs(rotMat(0,0))); //Divide by identity values for scaling

//std::cout << storedRot( 0, 0 ) << " " << storedRot( 0, 1 ) << " " << storedRot( 0, 2 ) << std::endl;
//std::cout << storedRot( 1, 0 ) << " " << storedRot( 1, 1 ) << " " << storedRot( 1, 2 ) << std::endl;
//std::cout << storedRot( 2, 0 ) << " " << storedRot( 2, 1 ) << " " << storedRot( 2, 2 ) << std::endl;
//
//Fetching the directions
for( it = i_fileFloatData.begin(), i = 0; it != i_fileFloatData.end(); it += m_bands, ++i )
{
m_mainDirections[i].insert( m_mainDirections[i].end(), it, it + m_bands );
m_mainDirections[i].insert( m_mainDirections[i].end(), it, it + m_bands );
}

/*FMatrix p1( 3, 1 );
for( int i = 0; i < m_mainDirections.size(); i++ )
{

FMatrix p1( 3, 1 );
FMatrix p2( 3, 1 );
FMatrix p3( 3, 1 );
p1( 0, 0 ) = m_mainDirections[i][0];
Expand All @@ -300,14 +292,13 @@ bool Maximas::createStructure ( std::vector< float > &i_fileFloatData )
p2( 1, 0 ) = m_mainDirections[i][4];
p2( 2, 0 ) = m_mainDirections[i][5];

p3( 0, 0 ) = m_mainDirections[i][6];
p3( 1, 0 ) = m_mainDirections[i][7];
p3( 2, 0 ) = m_mainDirections[i][8];

FMatrix rotP1 = rotMat * p1;
FMatrix rotP2 = rotMat * p2;
FMatrix rotP3 = rotMat * p3;
FMatrix rotP1 = invert(storedRot) * p1;
FMatrix rotP2 = invert(storedRot) * p2;
FMatrix rotP3 = invert(storedRot) * p3;

m_mainDirections[i][0] = rotP1( 0, 0 );
m_mainDirections[i][1] = rotP1( 1, 0 );
Expand All @@ -319,7 +310,7 @@ bool Maximas::createStructure ( std::vector< float > &i_fileFloatData )

m_mainDirections[i][6] = rotP3( 0, 0 );
m_mainDirections[i][7] = rotP3( 1, 0 );
m_mainDirections[i][8] = rotP3( 2, 0 );*/
m_mainDirections[i][8] = rotP3( 2, 0 );

}

Expand All @@ -339,10 +330,13 @@ void Maximas::rotatePeaks()
FMatrix rot;

if(m_doRotate)
rot = invert(storedRot);
else
rot = storedRot;
else
rot = invert(storedRot);

//std::cout << rot( 0, 0 ) << " " << rot( 0, 1 ) << " " << rot( 0, 2 ) << std::endl;
//std::cout << rot( 1, 0 ) << " " << rot( 1, 1 ) << " " << rot( 1, 2 ) << std::endl;
//std::cout << rot( 2, 0 ) << " " << rot( 2, 1 ) << " " << rot( 2, 2 ) << std::endl;

for( int i = 0; i < m_mainDirections.size(); i++ )
{
Expand All @@ -358,7 +352,6 @@ void Maximas::rotatePeaks()
p2( 1, 0 ) = m_mainDirections[i][4];
p2( 2, 0 ) = m_mainDirections[i][5];


p3( 0, 0 ) = m_mainDirections[i][6];
p3( 1, 0 ) = m_mainDirections[i][7];
p3( 2, 0 ) = m_mainDirections[i][8];
Expand Down Expand Up @@ -591,7 +584,7 @@ int zoomS = 300;

wxBoxSizer *pBoxMain = new wxBoxSizer( wxVERTICAL );

wxToggleButton *m_pToggleRotPeaks = new wxToggleButton( pParent, wxID_ANY,wxT("Rotate peaks with header"), wxDefaultPosition, wxSize(zoomS*2, -1) );
wxToggleButton *m_pToggleRotPeaks = new wxToggleButton( pParent, wxID_ANY,wxT("Un-rotate peaks with header"), wxDefaultPosition, wxSize(zoomS*2, -1) );
pParent->Connect( m_pToggleRotPeaks->GetId(), wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(PropertiesWindow::OnToggleRotatePeaks) );
pBoxMain->Add( m_pToggleRotPeaks, 0, wxFIXED_MINSIZE | wxEXPAND, 0 );

Expand Down
46 changes: 24 additions & 22 deletions src/dataset/Octree.cpp
Expand Up @@ -37,35 +37,37 @@ Octree::~Octree()
//////////////////////////////////////////
void Octree::findBoundingBox()
{
m_maxPointX = m_pointArray[0];
m_maxPointY = m_pointArray[1];
m_maxPointZ = m_pointArray[2];
DatasetManager *pDatMan = DatasetManager::getInstance();

m_minPointX = m_pointArray[0];
m_minPointY = m_pointArray[1];
m_minPointZ = m_pointArray[2];
m_maxPointX = pDatMan->getColumns() * pDatMan->getVoxelX();
m_maxPointY = pDatMan->getRows() * pDatMan->getVoxelY();
m_maxPointZ = pDatMan->getFrames() * pDatMan->getVoxelZ();

//Find the bounding box for the dataSet
for(int i=0; i < m_countPoints; i++)
{
if(m_pointArray[i*3] > m_maxPointX)
m_maxPointX = m_pointArray[i*3];
m_minPointX = 0.0f;
m_minPointY = 0.0f;
m_minPointZ = 0.0f;

if(m_pointArray[i*3+1] > m_maxPointY)
m_maxPointY = m_pointArray[i*3+1];
////Find the bounding box for the dataSet
//for(int i=0; i < m_countPoints; i++)
//{
// if(m_pointArray[i*3] > m_maxPointX)
// m_maxPointX = m_pointArray[i*3];

if(m_pointArray[i*3+2] > m_maxPointZ)
m_maxPointZ = m_pointArray[i*3+2];
// if(m_pointArray[i*3+1] > m_maxPointY)
// m_maxPointY = m_pointArray[i*3+1];

if(m_pointArray[i*3] < m_minPointX)
m_minPointX = m_pointArray[i*3];
// if(m_pointArray[i*3+2] > m_maxPointZ)
// m_maxPointZ = m_pointArray[i*3+2];

if(m_pointArray[i*3+1] < m_minPointY)
m_minPointY = m_pointArray[i*3+1];
// if(m_pointArray[i*3] < m_minPointX)
// m_minPointX = m_pointArray[i*3];

if(m_pointArray[i*3+2] < m_minPointZ)
m_minPointZ = m_pointArray[i*3+2];
}
// if(m_pointArray[i*3+1] < m_minPointY)
// m_minPointY = m_pointArray[i*3+1];

// if(m_pointArray[i*3+2] < m_minPointZ)
// m_minPointZ = m_pointArray[i*3+2];
//}
}

//////////////////////////////////////////
Expand Down

0 comments on commit b37d238

Please sign in to comment.