Skip to content

Commit b37d238

Browse files
authored
Merge pull request #12 from chamberm/Refactor
Better TCK and peaks handling
2 parents a9a132f + cbb9fef commit b37d238

File tree

13 files changed

+248
-132
lines changed

13 files changed

+248
-132
lines changed

src/GLSL/fibers.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ uniform bool isDistcoloring;
1212

1313
varying vec4 myColor;
1414

15+
1516
float lookupTex()
1617
{
1718
vec3 v = VaryingTexCoord0.xyz;

src/dataset/Anatomy.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,11 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
699699
}
700700
if( pHeader->sto_xyz.m[1][1] < 0.0 )
701701
{
702-
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
702+
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
703703
}
704704
else
705705
{
706-
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
706+
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
707707
}
708708
}
709709
else if( pHeader->qform_code > 0 )
@@ -718,16 +718,16 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
718718
}
719719
if( pHeader->qto_xyz.m[1][1] < 0.0 )
720720
{
721-
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
721+
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
722722
}
723723
else
724724
{
725-
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
725+
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
726726
}
727727
}
728728

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

982982
case RGB:
983983
{
984-
unsigned char* pData = (unsigned char*)pBody->data;
985-
986-
m_floatDataset.resize( datasetSize * 3 );
987-
988-
for( int i(0); i < datasetSize; ++i )
989-
{
990-
m_floatDataset[i * 3] = (float)pData[i] / 255.0f;
991-
m_floatDataset[i * 3 + 1] = (float)pData[datasetSize + i] / 255.0f;
992-
m_floatDataset[i * 3 + 2] = (float)pData[(2 * datasetSize) + i] / 255.0f;
993-
}
994-
984+
m_floatDataset.resize( datasetSize * 3 );
985+
if(pHeader->datatype == 2)
986+
{
987+
unsigned char* pData = (unsigned char*)pBody->data;
988+
for( int i(0); i < datasetSize; ++i )
989+
{
990+
m_floatDataset[i * 3] = (float)pData[i] / 255.0f;
991+
m_floatDataset[i * 3 + 1] = (float)pData[datasetSize + i] / 255.0f;
992+
m_floatDataset[i * 3 + 2] = (float)pData[(2 * datasetSize) + i] / 255.0f;
993+
}
994+
}
995+
else
996+
{
997+
float* pData = (float*)pBody->data;
998+
for( int i(0); i < datasetSize; ++i )
999+
{
1000+
m_floatDataset[i * 3] = (float)pData[i];
1001+
m_floatDataset[i * 3 + 1] = (float)pData[datasetSize + i];
1002+
m_floatDataset[i * 3 + 2] = (float)pData[(2 * datasetSize) + i];
1003+
}
1004+
}
9951005
flag = true;
9961006
break;
9971007
}
@@ -1028,7 +1038,7 @@ bool Anatomy::load( nifti_image *pHeader, nifti_image *pBody )
10281038
flipAxisInternal( X_AXIS, false );
10291039
DatasetManager::getInstance()->setFlippedXOnLoad(true);
10301040
}
1031-
if( m_originalSagOrientation == ORIENTATION_ANT_TO_POST )
1041+
if( m_originalSagOrientation == ORIENTATION_POST_TO_ANT )
10321042
{
10331043
flipAxisInternal( Y_AXIS, false );
10341044
DatasetManager::getInstance()->setFlippedYOnLoad(true);

src/dataset/Fibers.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,23 @@ bool Fibers::load( const wxString &filename )
194194
/* OcTree points classification */
195195
m_pOctree = new Octree( 2, m_pointArray, m_countPoints );
196196

197+
197198
//Global properties for opacity rendering
198199
computeGLobalProperties();
199200

201+
if(DatasetManager::getInstance()->getFlippedXOnLoad())
202+
{
203+
flipAxis(X_AXIS);
204+
std::cout << "flipX save\n";
205+
}
206+
207+
if(DatasetManager::getInstance()->getFlippedYOnLoad())
208+
{
209+
flipAxis(Y_AXIS);
210+
std::cout << "flipY save\n";
211+
}
212+
213+
200214
return res;
201215
}
202216

@@ -1964,13 +1978,13 @@ void Fibers::fitToAnat(bool saving)
19641978
if(DatasetManager::getInstance()->getFlippedXOnLoad())
19651979
{
19661980
flipAxis(X_AXIS);
1967-
std::cout << "flipX \n";
1981+
std::cout << "flipX save\n";
19681982
}
19691983

1970-
if(DatasetManager::getInstance()->getFlippedXOnLoad())
1984+
if(DatasetManager::getInstance()->getFlippedYOnLoad())
19711985
{
19721986
flipAxis(Y_AXIS);
1973-
std::cout << "flipY \n";
1987+
std::cout << "flipY save\n";
19741988
}
19751989
}
19761990

@@ -2047,13 +2061,13 @@ void Fibers::fitToAnat(bool saving)
20472061
if(DatasetManager::getInstance()->getFlippedXOnLoad())
20482062
{
20492063
flipAxis(X_AXIS);
2050-
std::cout << "flipX \n";
2064+
std::cout << "flipX not saving\n";
20512065
}
20522066

2053-
if(DatasetManager::getInstance()->getFlippedXOnLoad())
2067+
if(DatasetManager::getInstance()->getFlippedYOnLoad())
20542068
{
20552069
flipAxis(Y_AXIS);
2056-
std::cout << "flipY \n";
2070+
std::cout << "flipY not saving\n";
20572071
}
20582072
}
20592073

@@ -3759,9 +3773,9 @@ void Fibers::setFibersLength()
37593773
{
37603774
// The values are in pixel, we need to set them in millimeters using the spacing
37613775
// specified in the anatomy file ( m_datasetHelper->xVoxel... ).
3762-
dx = ( currentFiberPoints[i].x - currentFiberPoints[i - 1].x ) * voxelX;
3763-
dy = ( currentFiberPoints[i].y - currentFiberPoints[i - 1].y ) * voxelY;
3764-
dz = ( currentFiberPoints[i].z - currentFiberPoints[i - 1].z ) * voxelZ;
3776+
dx = ( currentFiberPoints[i].x - currentFiberPoints[i - 1].x );
3777+
dy = ( currentFiberPoints[i].y - currentFiberPoints[i - 1].y );
3778+
dz = ( currentFiberPoints[i].z - currentFiberPoints[i - 1].z );
37653779
FArray currentVector( dx, dy, dz );
37663780
m_length[j] += ( float )currentVector.norm();
37673781
}

src/dataset/Fibers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Fibers : public DatasetInfo
111111
void setLocalGlobal(bool value);
112112
void setUsingEndpts(bool value);
113113

114-
void flipAxis( AxisType i_axe );
114+
void flipAxis( AxisType i_axe);
115115
void fitToAnat( bool saving);
116116

117117
int getFibersCount() const { return m_countLines; }

src/dataset/FibersGroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class FibersGroup : public DatasetInfo
6666
bool load( wxString filename ) { return false; };
6767
void draw() {};
6868
void smooth() {};
69-
void flipAxis( AxisType i_axe ) {};
69+
void flipAxis( AxisType i_axe) {};
7070
void drawVectors() {};
7171
void generateTexture() {};
7272
void generateGeometry() {};

src/dataset/Maximas.cpp

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ bool Maximas::load( nifti_image *pHeader, nifti_image *pBody )
130130
}
131131
if( pHeader->sto_xyz.m[1][1] < 0.0 )
132132
{
133-
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
133+
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
134134
}
135135
else
136136
{
137-
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
137+
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
138138
}
139139
}
140140
else if( pHeader->qform_code > 0 )
@@ -149,11 +149,11 @@ bool Maximas::load( nifti_image *pHeader, nifti_image *pBody )
149149
}
150150
if( pHeader->qto_xyz.m[1][1] < 0.0 )
151151
{
152-
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
152+
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
153153
}
154154
else
155155
{
156-
m_originalSagOrientation = ORIENTATION_POST_TO_ANT;
156+
m_originalSagOrientation = ORIENTATION_ANT_TO_POST;
157157
}
158158
}
159159

@@ -163,7 +163,7 @@ bool Maximas::load( nifti_image *pHeader, nifti_image *pBody )
163163
RTTrackingHelper::getInstance()->setMaximaFlip(Vector(-1,1,1));
164164
flipAnat( X_AXIS );
165165
}
166-
if( m_originalSagOrientation == ORIENTATION_ANT_TO_POST )
166+
if( m_originalSagOrientation == ORIENTATION_POST_TO_ANT)
167167
{
168168
flipAxis( Y_AXIS, true );
169169
RTTrackingHelper::getInstance()->setMaximaFlip(Vector(1,-1,1));
@@ -264,32 +264,24 @@ bool Maximas::createStructure ( std::vector< float > &i_fileFloatData )
264264

265265
FMatrix transform = FMatrix( DatasetManager::getInstance()->getNiftiTransform() );
266266
FMatrix rotMat( 3, 3 );
267-
transform.getSubMatrix( rotMat, 0, 0 );
268-
rotMat(0,0) = 1;
269-
rotMat(1,1) = 1;
270-
rotMat(2,2) = 1;
271-
storedRot = rotMat;
272-
273-
274-
/*float voxelX = DatasetManager::getInstance()->getVoxelX();
275-
float voxelY = DatasetManager::getInstance()->getVoxelY();
276-
float voxelZ = DatasetManager::getInstance()->getVoxelZ();
277-
FMatrix transform = FMatrix( DatasetManager::getInstance()->getNiftiTransform() );
278-
FMatrix rotMat( 3, 3 );
279-
transform.getSubMatrix( rotMat, 0, 0 );
280-
rotMat(0,0) = 1;
281-
rotMat(1,1) = 1;
282-
rotMat(2,2) = 1;
283-
FMatrix test( rotMat );
284-
test = invert(rotMat);
285-
rotMat = test;*/
267+
transform.getSubMatrix( rotMat, 0, 0 );
268+
269+
storedRot = rotMat*(1.0f/abs(rotMat(0,0))); //Divide by identity values for scaling
286270

271+
//std::cout << storedRot( 0, 0 ) << " " << storedRot( 0, 1 ) << " " << storedRot( 0, 2 ) << std::endl;
272+
//std::cout << storedRot( 1, 0 ) << " " << storedRot( 1, 1 ) << " " << storedRot( 1, 2 ) << std::endl;
273+
//std::cout << storedRot( 2, 0 ) << " " << storedRot( 2, 1 ) << " " << storedRot( 2, 2 ) << std::endl;
274+
//
287275
//Fetching the directions
288276
for( it = i_fileFloatData.begin(), i = 0; it != i_fileFloatData.end(); it += m_bands, ++i )
289277
{
290-
m_mainDirections[i].insert( m_mainDirections[i].end(), it, it + m_bands );
278+
m_mainDirections[i].insert( m_mainDirections[i].end(), it, it + m_bands );
279+
}
291280

292-
/*FMatrix p1( 3, 1 );
281+
for( int i = 0; i < m_mainDirections.size(); i++ )
282+
{
283+
284+
FMatrix p1( 3, 1 );
293285
FMatrix p2( 3, 1 );
294286
FMatrix p3( 3, 1 );
295287
p1( 0, 0 ) = m_mainDirections[i][0];
@@ -300,14 +292,13 @@ bool Maximas::createStructure ( std::vector< float > &i_fileFloatData )
300292
p2( 1, 0 ) = m_mainDirections[i][4];
301293
p2( 2, 0 ) = m_mainDirections[i][5];
302294

303-
304295
p3( 0, 0 ) = m_mainDirections[i][6];
305296
p3( 1, 0 ) = m_mainDirections[i][7];
306297
p3( 2, 0 ) = m_mainDirections[i][8];
307298

308-
FMatrix rotP1 = rotMat * p1;
309-
FMatrix rotP2 = rotMat * p2;
310-
FMatrix rotP3 = rotMat * p3;
299+
FMatrix rotP1 = invert(storedRot) * p1;
300+
FMatrix rotP2 = invert(storedRot) * p2;
301+
FMatrix rotP3 = invert(storedRot) * p3;
311302

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

320311
m_mainDirections[i][6] = rotP3( 0, 0 );
321312
m_mainDirections[i][7] = rotP3( 1, 0 );
322-
m_mainDirections[i][8] = rotP3( 2, 0 );*/
313+
m_mainDirections[i][8] = rotP3( 2, 0 );
323314

324315
}
325316

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

341332
if(m_doRotate)
342-
rot = invert(storedRot);
343-
else
344333
rot = storedRot;
334+
else
335+
rot = invert(storedRot);
345336

337+
//std::cout << rot( 0, 0 ) << " " << rot( 0, 1 ) << " " << rot( 0, 2 ) << std::endl;
338+
//std::cout << rot( 1, 0 ) << " " << rot( 1, 1 ) << " " << rot( 1, 2 ) << std::endl;
339+
//std::cout << rot( 2, 0 ) << " " << rot( 2, 1 ) << " " << rot( 2, 2 ) << std::endl;
346340

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

361-
362355
p3( 0, 0 ) = m_mainDirections[i][6];
363356
p3( 1, 0 ) = m_mainDirections[i][7];
364357
p3( 2, 0 ) = m_mainDirections[i][8];
@@ -591,7 +584,7 @@ int zoomS = 300;
591584

592585
wxBoxSizer *pBoxMain = new wxBoxSizer( wxVERTICAL );
593586

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

src/dataset/Octree.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,37 @@ Octree::~Octree()
3737
//////////////////////////////////////////
3838
void Octree::findBoundingBox()
3939
{
40-
m_maxPointX = m_pointArray[0];
41-
m_maxPointY = m_pointArray[1];
42-
m_maxPointZ = m_pointArray[2];
40+
DatasetManager *pDatMan = DatasetManager::getInstance();
4341

44-
m_minPointX = m_pointArray[0];
45-
m_minPointY = m_pointArray[1];
46-
m_minPointZ = m_pointArray[2];
42+
m_maxPointX = pDatMan->getColumns() * pDatMan->getVoxelX();
43+
m_maxPointY = pDatMan->getRows() * pDatMan->getVoxelY();
44+
m_maxPointZ = pDatMan->getFrames() * pDatMan->getVoxelZ();
4745

48-
//Find the bounding box for the dataSet
49-
for(int i=0; i < m_countPoints; i++)
50-
{
51-
if(m_pointArray[i*3] > m_maxPointX)
52-
m_maxPointX = m_pointArray[i*3];
46+
m_minPointX = 0.0f;
47+
m_minPointY = 0.0f;
48+
m_minPointZ = 0.0f;
5349

54-
if(m_pointArray[i*3+1] > m_maxPointY)
55-
m_maxPointY = m_pointArray[i*3+1];
50+
////Find the bounding box for the dataSet
51+
//for(int i=0; i < m_countPoints; i++)
52+
//{
53+
// if(m_pointArray[i*3] > m_maxPointX)
54+
// m_maxPointX = m_pointArray[i*3];
5655

57-
if(m_pointArray[i*3+2] > m_maxPointZ)
58-
m_maxPointZ = m_pointArray[i*3+2];
56+
// if(m_pointArray[i*3+1] > m_maxPointY)
57+
// m_maxPointY = m_pointArray[i*3+1];
5958

60-
if(m_pointArray[i*3] < m_minPointX)
61-
m_minPointX = m_pointArray[i*3];
59+
// if(m_pointArray[i*3+2] > m_maxPointZ)
60+
// m_maxPointZ = m_pointArray[i*3+2];
6261

63-
if(m_pointArray[i*3+1] < m_minPointY)
64-
m_minPointY = m_pointArray[i*3+1];
62+
// if(m_pointArray[i*3] < m_minPointX)
63+
// m_minPointX = m_pointArray[i*3];
6564

66-
if(m_pointArray[i*3+2] < m_minPointZ)
67-
m_minPointZ = m_pointArray[i*3+2];
68-
}
65+
// if(m_pointArray[i*3+1] < m_minPointY)
66+
// m_minPointY = m_pointArray[i*3+1];
67+
68+
// if(m_pointArray[i*3+2] < m_minPointZ)
69+
// m_minPointZ = m_pointArray[i*3+2];
70+
//}
6971
}
7072

7173
//////////////////////////////////////////

0 commit comments

Comments
 (0)