Пример #1
0
void TrackThread::track( int id, bool negDir, Fib& result )
{
    int xs = 0;
    int ys = 0;
    int zs = 0;

    getXYZ( id, xs, ys, zs );

    double xx, xy, xz, yy, yz, zz;
    float newDirX, newDirY, newDirZ;
    float dirX, dirY, dirZ, norm;
    int oldId = 0;
    Matrix iT; // interpolated tensor

//  float x = xs * m_dx + 0.5 * m_dx;
//  float y = ys * m_dy + 0.5 * m_dy;
//  float z = zs * m_dz + 0.5 * m_dz;

    float x = xs * m_dx;
    float y = ys * m_dy;
    float z = zs * m_dz;
    float curFA = getInterpolatedFA( id, x, y, z );

    if ( curFA < m_minStartFA )
    {
        return;
    }

    if ( negDir )
    {
        dirX = m_evec1->at( id ).x() * -1.0;
        dirY = m_evec1->at( id ).y() * -1.0;
        dirZ = m_evec1->at( id ).z() * -1.0;
    }
    else
    {
        dirX = m_evec1->at( id ).x();
        dirY = m_evec1->at( id ).y();
        dirZ = m_evec1->at( id ).z();
    }
    norm = sqrt( dirX * dirX + dirY * dirY + dirZ * dirZ );
    dirX = dirX / norm;
    dirY = dirY / norm;
    dirZ = dirZ / norm;

    int lc = 0;
    while ( true )
    {
        curFA = getInterpolatedFA( id, x, y, z );

        if ( curFA > m_minFA && ( x == x ) && ( y == y ) && ( z == z ) )
        {
            result.addVert( x, y, z, curFA );
        }
        else
        {
            break;
        }

        x += dirX * m_stepSize;
        y += dirY * m_stepSize;
        z += dirZ * m_stepSize;

        id = getID( x, y, z );

        if ( oldId == id )
        {
            ++lc;
            if ( lc > maxStepsInVoxel )
            {
                //printf( "stop tracking, fiber never left voxel \n" );
                break;
            }
        }
        else
            lc = 0;

        iT = getInterpolatedTensor( id, x, y, z );

        xx = iT( 1, 1 );
        xy = iT( 1, 2 );
        xz = iT( 1, 3 );
        yy = iT( 2, 2 );
        yz = iT( 2, 3 );
        zz = iT( 3, 3 );

        // dir = tensor(xyz) * dir;
        newDirX = xx * dirX + xy * dirY + xz * dirZ;
        newDirY = xy * dirX + yy * dirY + yz * dirZ;
        newDirZ = xz * dirX + yz * dirY + zz * dirZ;

        norm = sqrt( newDirX * newDirX + newDirY * newDirY + newDirZ * newDirZ );
        newDirX = newDirX / norm;
        newDirY = newDirY / norm;
        newDirZ = newDirZ / norm;

        newDirX = m_smoothness * dirX + ( 1.0 - m_smoothness ) * newDirX;
        newDirY = m_smoothness * dirY + ( 1.0 - m_smoothness ) * newDirY;
        newDirZ = m_smoothness * dirZ + ( 1.0 - m_smoothness ) * newDirZ;

        norm = sqrt( newDirX * newDirX + newDirY * newDirY + newDirZ * newDirZ );
        dirX = newDirX / norm;
        dirY = newDirY / norm;
        dirZ = newDirZ / norm;
        oldId = id;
    }
}
Пример #2
0
void TWCThread::track( int id, bool negDir, QVector<float>& result, QVector<float>& extraResult )
{
    int xs = 0;
    int ys = 0;
    int zs = 0;
    getXYZ( id, xs, ys, zs );

    double xx, xy, xz, yy, yz, zz;
    float newDirX, newDirY, newDirZ;

    int oldId = 0;
    Matrix iT; // interpolated tensor

    // getStart direction
    float dirX, dirY, dirZ;
    if ( negDir )
    {
        dirX = m_evecs[0]->at( id ).x() * -1.0;
        dirY = m_evecs[0]->at( id ).y() * -1.0;
        dirZ = m_evecs[0]->at( id ).z() * -1.0;
    }
    else
    {
        dirX = m_evecs[0]->at( id ).x();
        dirY = m_evecs[0]->at( id ).y();
        dirZ = m_evecs[0]->at( id ).z();
    }

    float norm = sqrt( dirX * dirX + dirY * dirY + dirZ * dirZ );
    dirX = dirX / norm;
    dirY = dirY / norm;
    dirZ = dirZ / norm;

    float x = xs * m_dx;
    float y = ys * m_dy;
    float z = zs * m_dz;
    float curFA = getInterpolatedFA( id, x, y, z );

    int lc = 0;
    while ( true )
    {
        curFA = getInterpolatedFA( id, x, y, z );

        if ( curFA > 0.2 && ( x == x ) && ( y == y ) && ( z == z ) )
        {
            result.push_back( x );
            result.push_back( y );
            result.push_back( z );

            extraResult.push_back( FMath::fa( getInterpolatedTensor( id, x, y, z, dirX, dirY, dirZ ) ) );
        }
        else
        {
            break;
        }

        x += dirX * m_stepSize;
        y += dirY * m_stepSize;
        z += dirZ * m_stepSize;

        id = getID( x, y, z );

        if ( oldId == id )
        {
            ++lc;
            if ( lc > maxStepsInVoxel )
            {
                //printf( "stop tracking, fiber never left voxel \n" );
                break;
            }
        }
        else
            lc = 0;

        iT = getInterpolatedTensor( id, x, y, z, dirX, dirY, dirZ );

        xx = iT( 1, 1 );
        xy = iT( 1, 2 );
        xz = iT( 1, 3 );
        yy = iT( 2, 2 );
        yz = iT( 2, 3 );
        zz = iT( 3, 3 );

        // dir = tensor(xyz) * dir;
        newDirX = xx * dirX + xy * dirY + xz * dirZ;
        newDirY = xy * dirX + yy * dirY + yz * dirZ;
        newDirZ = xz * dirX + yz * dirY + zz * dirZ;

        norm = sqrt( newDirX * newDirX + newDirY * newDirY + newDirZ * newDirZ );
        newDirX = newDirX / norm;
        newDirY = newDirY / norm;
        newDirZ = newDirZ / norm;

        newDirX = m_smoothness * dirX + ( 1.0 - m_smoothness ) * newDirX;
        newDirY = m_smoothness * dirY + ( 1.0 - m_smoothness ) * newDirY;
        newDirZ = m_smoothness * dirZ + ( 1.0 - m_smoothness ) * newDirZ;

        norm = sqrt( newDirX * newDirX + newDirY * newDirY + newDirZ * newDirZ );
        dirX = newDirX / norm;
        dirY = newDirY / norm;
        dirZ = newDirZ / norm;
        oldId = id;
    }
}