Skip to content

Commit

Permalink
fixed for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
chamberm committed Sep 1, 2015
1 parent 4e11b5b commit 6cccb53
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 116 deletions.
1 change: 1 addition & 0 deletions src/dataset/Anatomy.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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
3 changes: 2 additions & 1 deletion src/dataset/RTFMRIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ RTFMRIHelper::RTFMRIHelper()
m_isRTFMRIActive( false ),
m_isRTFMRIDirty( false ),
m_isRTFMRIReady( false ),
m_isSeedFromfMRI( false )
m_isSeedFromfMRI( false ),
m_isTractoDrivenRSN( false )
{
}

Expand Down
244 changes: 131 additions & 113 deletions src/dataset/RTTFibers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ Vector RTTFibers::advecIntegrateHARDI( Vector vin, const std::vector<float> &sti
float wm = m_pMaskInfo->at(s_number);
float gm = 0;
float F = 0;

if(m_pGMInfo != NULL && RTTrackingHelper::getInstance()->isGMAllowed())
{
gm = m_pGMInfo->at(s_number);
Expand Down Expand Up @@ -1320,21 +1321,29 @@ bool RTTFibers::checkExclude( unsigned int sticksNumber)
///////////////////////////////////////////////////////////////////////////
bool RTTFibers::withinMapThreshold(unsigned int sticksNumber, Vector pos)
{
if(sticksNumber > m_pMaskInfo->getSize())
{
return false;
}

bool isOk = false;
float gmVal = 0;
bool insideNotBox = false;

if(m_pGMInfo != NULL && RTTrackingHelper::getInstance()->isGMAllowed())
{
gmVal = m_pGMInfo->at(sticksNumber);
if(gmVal > 0)
if(sticksNumber < m_pGMInfo->getSize())
{
m_countGMstep++;
gmVal = m_pGMInfo->at(sticksNumber);
if(gmVal > 0)
{
m_countGMstep++;
}
else
{
m_countGMstep = 0;
}
}
else
{
m_countGMstep = 0;
}
}

//Child (Only works for 1 inclusion or 1 exclusion child so far.)
Expand Down Expand Up @@ -1453,130 +1462,139 @@ void RTTFibers::performHARDIRTT(Vector seed, int bwdfwd, vector<float>& points,
std::vector<float> sticks;

m_countGMstep = 0;
absPeak = std::abs(m_pMaximasInfo->getMainDirData()->at(sticksNumber)[0] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[1] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[2]);

if( sticksNumber < m_pMaximasInfo->getMainDirData()->size() && withinMapThreshold(sticksNumber, currPosition) && !m_stop && absPeak != 0)
if( sticksNumber < m_pMaximasInfo->getMainDirData()->size() )
{
bool initWithDir = RTTrackingHelper::getInstance()->isInitSeed();
sticks = pickDirection(m_pMaximasInfo->getMainDirData()->at(sticksNumber), initWithDir, currPosition);

currDirection.x = flippedAxes.x * sticks[0];
currDirection.y = flippedAxes.y * sticks[1];
currDirection.z = flippedAxes.z * sticks[2];

//Direction for seeding (forward or backward)
currDirection.normalize();
currDirection *= bwdfwd;

//Next position
nextPosition = currPosition + ( m_step * currDirection );

//Get the voxel stepped into
currVoxelx = (int)( floor(nextPosition.x / xVoxel) );
currVoxely = (int)( floor(nextPosition.y / yVoxel) );
currVoxelz = (int)( floor(nextPosition.z / zVoxel) );

//Corresponding stick number
sticksNumber = currVoxelz * columns * rows + currVoxely * columns + currVoxelx;
absPeak = std::abs(m_pMaximasInfo->getMainDirData()->at(sticksNumber)[0] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[1] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[2]);

if( sticksNumber < m_pMaximasInfo->getMainDirData()->size() && absPeak != 0 && withinMapThreshold(sticksNumber, nextPosition))
if( withinMapThreshold(sticksNumber, currPosition) && !m_stop && absPeak != 0)
{
bool initWithDir = RTTrackingHelper::getInstance()->isInitSeed();
sticks = pickDirection(m_pMaximasInfo->getMainDirData()->at(sticksNumber), initWithDir, currPosition);

sticks = m_pMaximasInfo->getMainDirData()->at(sticksNumber);
sticks[0] *= flippedAxes.x;
sticks[1] *= flippedAxes.y;
sticks[2] *= flippedAxes.z;
sticks[3] *= flippedAxes.x;
sticks[4] *= flippedAxes.y;
sticks[5] *= flippedAxes.z;
sticks[6] *= flippedAxes.x;
sticks[7] *= flippedAxes.y;
sticks[8] *= flippedAxes.z;

//Advection next direction
nextDirection = advecIntegrateHARDI( currDirection, sticks, sticksNumber, nextPosition );
currDirection.x = flippedAxes.x * sticks[0];
currDirection.y = flippedAxes.y * sticks[1];
currDirection.z = flippedAxes.z * sticks[2];

//Direction of seeding
nextDirection *= bwdfwd;
nextDirection.normalize();
//Direction for seeding (forward or backward)
currDirection.normalize();
currDirection *= bwdfwd;

if( currDirection.Dot(nextDirection) < 0 ) //Ensures the two vectors have the same directions
{
nextDirection *= -1;
}
//Next position
nextPosition = currPosition + ( m_step * currDirection );

//Angle value
float dot = currDirection.Dot(nextDirection);
float acos = std::acos( dot );
angle = 180 * acos / M_PI;
//Get the voxel stepped into
currVoxelx = (int)( floor(nextPosition.x / xVoxel) );
currVoxely = (int)( floor(nextPosition.y / yVoxel) );
currVoxelz = (int)( floor(nextPosition.z / zVoxel) );

///////////////////////////
//Tracking along the fiber
//////////////////////////
float it = 2;
bool insideBox = false;
while( angle <= m_angleThreshold && withinMapThreshold(sticksNumber, nextPosition) && !m_stop)
//Corresponding stick number
sticksNumber = currVoxelz * columns * rows + currVoxely * columns + currVoxelx;
if( sticksNumber < m_pMaximasInfo->getMainDirData()->size())
{
//Insert point to be rendered
points.push_back( currPosition.x );
points.push_back( currPosition.y );
points.push_back( currPosition.z );
color.push_back( std::abs(currDirection.x) );
color.push_back( std::abs(currDirection.y) );
color.push_back( std::abs(currDirection.z) );
color.push_back( m_alpha );

//Advance
currPosition = nextPosition;
currDirection = nextDirection;

//Next position
nextPosition = currPosition + ( m_step * currDirection );

//Stepped voxels
currVoxelx = (int)( floor(nextPosition.x / xVoxel) );
currVoxely = (int)( floor(nextPosition.y / yVoxel) );
currVoxelz = (int)( floor(nextPosition.z / zVoxel) );

//Corresponding tensor number
sticksNumber = currVoxelz * columns * rows + currVoxely * columns + currVoxelx;
absPeak = std::abs(m_pMaximasInfo->getMainDirData()->at(sticksNumber)[0] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[1] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[2]);

if( sticksNumber > m_pMaximasInfo->getMainDirData()->size() || absPeak == 0 || m_step*it > m_maxFiberLength) //Out of anatomy
if( absPeak != 0 && withinMapThreshold(sticksNumber, nextPosition))
{
break;
}

sticks = m_pMaximasInfo->getMainDirData()->at(sticksNumber);
sticks[0] *= flippedAxes.x;
sticks[1] *= flippedAxes.y;
sticks[2] *= flippedAxes.z;
sticks[3] *= flippedAxes.x;
sticks[4] *= flippedAxes.y;
sticks[5] *= flippedAxes.z;
sticks[6] *= flippedAxes.x;
sticks[7] *= flippedAxes.y;
sticks[8] *= flippedAxes.z;

//Advection next direction
nextDirection = advecIntegrateHARDI( currDirection, sticks, sticksNumber, nextPosition );
sticks = m_pMaximasInfo->getMainDirData()->at(sticksNumber);
sticks[0] *= flippedAxes.x;
sticks[1] *= flippedAxes.y;
sticks[2] *= flippedAxes.z;
sticks[3] *= flippedAxes.x;
sticks[4] *= flippedAxes.y;
sticks[5] *= flippedAxes.z;
sticks[6] *= flippedAxes.x;
sticks[7] *= flippedAxes.y;
sticks[8] *= flippedAxes.z;

//Advection next direction
nextDirection = advecIntegrateHARDI( currDirection, sticks, sticksNumber, nextPosition );

//Direction of seeding
nextDirection *= bwdfwd;
nextDirection.normalize();

if( currDirection.Dot(nextDirection) < 0 ) //Ensures the two vectors have the same directions
{
nextDirection *= -1;
}

//Direction of seeding (backward of forward)
nextDirection *= bwdfwd;
nextDirection.normalize();
//Angle value
float dot = currDirection.Dot(nextDirection);
float acos = std::acos( dot );
angle = 180 * acos / M_PI;

///////////////////////////
//Tracking along the fiber
//////////////////////////
float it = 2;
bool insideBox = false;
while( angle <= m_angleThreshold && withinMapThreshold(sticksNumber, nextPosition) && !m_stop)
{
//Insert point to be rendered
points.push_back( currPosition.x );
points.push_back( currPosition.y );
points.push_back( currPosition.z );
color.push_back( std::abs(currDirection.x) );
color.push_back( std::abs(currDirection.y) );
color.push_back( std::abs(currDirection.z) );
color.push_back( m_alpha );

//Advance
currPosition = nextPosition;
currDirection = nextDirection;

//Next position
nextPosition = currPosition + ( m_step * currDirection );

//Stepped voxels
currVoxelx = (int)( floor(nextPosition.x / xVoxel) );
currVoxely = (int)( floor(nextPosition.y / yVoxel) );
currVoxelz = (int)( floor(nextPosition.z / zVoxel) );

//Corresponding tensor number
sticksNumber = currVoxelz * columns * rows + currVoxely * columns + currVoxelx;
if( sticksNumber < m_pMaximasInfo->getMainDirData()->size())
{
absPeak = std::abs(m_pMaximasInfo->getMainDirData()->at(sticksNumber)[0] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[1] + m_pMaximasInfo->getMainDirData()->at(sticksNumber)[2]);

if( currDirection.Dot(nextDirection) < 0 ) //Ensures both vectors points in the same direction
{
nextDirection *= -1;
}
if( absPeak == 0 || m_step*it > m_maxFiberLength) //Out of anatomy
{
break;
}

sticks = m_pMaximasInfo->getMainDirData()->at(sticksNumber);
sticks[0] *= flippedAxes.x;
sticks[1] *= flippedAxes.y;
sticks[2] *= flippedAxes.z;
sticks[3] *= flippedAxes.x;
sticks[4] *= flippedAxes.y;
sticks[5] *= flippedAxes.z;
sticks[6] *= flippedAxes.x;
sticks[7] *= flippedAxes.y;
sticks[8] *= flippedAxes.z;

//Advection next direction
nextDirection = advecIntegrateHARDI( currDirection, sticks, sticksNumber, nextPosition );

//Direction of seeding (backward of forward)
nextDirection *= bwdfwd;
nextDirection.normalize();

if( currDirection.Dot(nextDirection) < 0 ) //Ensures both vectors points in the same direction
{
nextDirection *= -1;
}

//Angle value
float dot = currDirection.Dot(nextDirection);
float acos = std::acos( dot );
angle = 180 * acos / M_PI;
//Angle value
float dot = currDirection.Dot(nextDirection);
float acos = std::acos( dot );
angle = 180 * acos / M_PI;

it++;
it++;
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/TrackingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ TrackingWindow::TrackingWindow( wxWindow *pParent, MainFrame *pMf, wxWindowID id
pBoxMagnet1->Add( m_pBtnPlaceMagnetR, 1, wxEXPAND | wxALL, 1 );
pBoxMagnet1->Add( m_pBtnPlaceMagnetG, 1, wxEXPAND | wxALL, 1 );
pBoxMagnet1->Add( m_pBtnPlaceMagnetB, 1, wxEXPAND | wxALL, 1 );
m_pTrackingSizer->Add( pBoxMagnet1, 0, wxFIXED_MINSIZE | wxEXPAND, 0 );*/
m_pTrackingSizer->Add( pBoxMagnet1, 0, wxFIXED_MINSIZE | wxEXPAND, 0 );
m_pTrackingSizer->Add( m_pToggleMagnetMode, 1, wxEXPAND | wxALL, 1 );
m_pTrackingSizer->Add( m_pToggleMagnetMode, 1, wxEXPAND | wxALL, 1 );*/

}

Expand Down

0 comments on commit 6cccb53

Please sign in to comment.