Skip to content

Commit 3e23f3f

Browse files
committed
Merge branch 'dev' of github.com:freesurfer/freesurfer into dev
2 parents bd3e088 + db2bd8b commit 3e23f3f

File tree

8 files changed

+141
-13
lines changed

8 files changed

+141
-13
lines changed

freeview/MainWindow.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,10 @@ void MainWindow::RunScript()
20132013
{
20142014
CommandSetSurfaceOverlayOpacity( sa );
20152015
}
2016+
else if ( cmd == "setsurfaceoverlayoffset")
2017+
{
2018+
CommandSetSurfaceOverlayOffset(sa);
2019+
}
20162020
else if ( cmd == "setsurfaceoverlayframe")
20172021
{
20182022
CommandSetSurfaceOverlayFrame( sa );
@@ -3603,7 +3607,7 @@ void MainWindow::CommandLoadSurface( const QStringList& cmd )
36033607
QVariantMap sup_options;
36043608
valid_overlay_options << "overlay_reg" << "overlay_method" << "overlay_threshold" << "overlay_color"
36053609
<< "overlay_rh" << "overlay_opacity" << "overlay_frame" << "overlay_smooth" << "overlay_custom"
3606-
<< "overlay_mask";
3610+
<< "overlay_mask" << "overlay_offset";
36073611
bool bNoAutoLoad = m_defaultSettings["no_autoload"].toBool();
36083612
for (int nOverlay = 0; nOverlay < overlay_list.size(); nOverlay++)
36093613
{
@@ -3622,6 +3626,7 @@ void MainWindow::CommandLoadSurface( const QStringList& cmd )
36223626
QStringList overlay_thresholds;
36233627
QStringList overlay_custom;
36243628
QStringList overlay_mask;
3629+
QString overlay_offset;
36253630
bool bSecondHalfData = false;
36263631
for ( int k = sa_fn.size()-1; k >= 0; k-- )
36273632
{
@@ -3650,6 +3655,8 @@ void MainWindow::CommandLoadSurface( const QStringList& cmd )
36503655
overlay_custom = subArgu.split(",", MD_SkipEmptyParts);
36513656
else if (subOption == "overlay_mask")
36523657
overlay_mask = subArgu.split(",", MD_SkipEmptyParts);
3658+
else if (subOption == "overlay_offset")
3659+
overlay_offset = subArgu;
36533660
}
36543661
}
36553662
if (overlay_reg.isEmpty())
@@ -3764,6 +3771,9 @@ void MainWindow::CommandLoadSurface( const QStringList& cmd )
37643771

37653772
if (!overlay_mask.isEmpty())
37663773
m_scripts.insert(1, QStringList("setsurfaceoverlaymask") << overlay_mask);
3774+
3775+
if (!overlay_offset.isEmpty())
3776+
m_scripts.insert(1, QStringList("setsurfaceoverlayoffset") << overlay_offset);
37673777
}
37683778
else if ( subOption == "mrisps" )
37693779
{
@@ -4077,6 +4087,30 @@ void MainWindow::CommandSetSurfaceOverlayOpacity(const QStringList &cmd)
40774087
}
40784088
}
40794089

4090+
void MainWindow::CommandSetSurfaceOverlayOffset(const QStringList &cmd)
4091+
{
4092+
LayerSurface* surf = (LayerSurface*)GetLayerCollection( "Surface" )->GetActiveLayer();
4093+
if ( surf )
4094+
{
4095+
SurfaceOverlay* overlay = surf->GetActiveOverlay();
4096+
if ( overlay )
4097+
{
4098+
bool ok;
4099+
double val = cmd[1].toDouble(&ok);
4100+
if (ok)
4101+
{
4102+
overlay->GetProperty()->SetOffset(val);
4103+
surf->UpdateOverlay(true);
4104+
overlay->EmitDataUpdated();
4105+
}
4106+
else
4107+
{
4108+
cerr << "Invalid input for overlay offset.\n";
4109+
}
4110+
}
4111+
}
4112+
}
4113+
40804114
void MainWindow::CommandSetSurfaceOverlayFrame(const QStringList &cmd)
40814115
{
40824116
LayerSurface* surf = (LayerSurface*)GetLayerCollection( "Surface" )->GetActiveLayer();

freeview/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ public slots:
404404
void CommandSetSurfaceOverlaySmooth ( const QStringList& cmd );
405405
void CommandSetSurfaceOverlayMask ( const QStringList& cmd );
406406
void CommandSetSurfaceOverlayCustom ( const QStringList& cmd );
407+
void CommandSetSurfaceOverlayOffset ( const QStringList& cmd );
407408
void CommandSetSurfaceColor ( const QStringList& cmd );
408409
void CommandSetSurfaceEdgeColor ( const QStringList& cmd );
409410
void CommandSetSurfaceEdgeThickness ( const QStringList& cmd );

freeview/RenderView3D.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,12 @@ void RenderView3D::DoUpdateRASPosition( int posX, int posY, bool bCursor, bool b
553553
picker->GetPickPosition( pos );
554554
prop = picker->GetViewProp();
555555
LayerMRI* mri_sel = (LayerMRI*)lc_mri->HasProp(prop);
556-
if (mri_sel->GetProperty()->GetShowAsContour())
556+
if (mri_sel && mri_sel->GetProperty()->GetShowAsContour())
557557
{
558558
lc_mri->SetCursorRASPosition( pos );
559559
MainWindow::GetMainWindow()->SetSlicePosition( pos );
560560
}
561-
else if ( lc_mri->HasProp( prop ) || lc_roi->HasProp( prop ) )
561+
else if ( mri_sel || lc_roi->HasProp( prop ) )
562562
{
563563
if ( bCursor )
564564
{

freeview/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ int main(int argc, char *argv[])
200200
"':overlay_custom=[filename]val,r,g,b,val2,r2,g2,b2...' Set customized overlay color. If only given one argument as filename, customized color scale will be loaded from the given file.\n\n"
201201
"':overlay_opacity=opacity' Set opacity of overlay.\n\n"
202202
"':overlay_threshold=low,(mid,)high(,percentile)' Set overlay threshold values, separated by comma. When overlay method is linear or linearopaque, only 2 numbers (low and high) are needed. When method is piecewise, 3 numbers are needed. If last element is 'percentile', use the give numbers as percentile.\n\n"
203+
"':overlay_offset=offset' Set the offset for overlay threshold setting.\n\n"
203204
"':overlay_mask=filename(,invert)' Use given label file as mask for overlay. If invert is specified, use the inverted mask.\n\n"
204205
"':overlay_frame=frame_number' Set active frame of multi-frame overlay.\n\n"
205206
"':overlay_smooth=smooth_steps' Set smooth steps for overlay.\n\n"

include/MRISurfOverlay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class MRISurfOverlay
9999
bool __isStatsData(int nthOverlay);
100100
bool __isShapeMeasurement(int nthOverlay);
101101

102+
int __getFrameCount();
103+
102104
int __nVertices;
103105
int __nFaces; // # of triangles, we need this for MRI_CURV_FILE output
104106

include/gifti.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ int MRISwriteGIFTISurface(MRIS *mris, gifti_image *image, const char *out_fname)
4242

4343
// function to output multiple overlays
4444
int MRISwriteGIFTICombined(MRIS *mris, MRISurfOverlay *poverlays, const char *out_fname);
45+
4546
// overloaded functions to handle combined GIFTI with multiple intents
4647
int MRISwriteGIFTIIntent(MRIS *mris, const MRI *mri, int stframe, int endframe, gifti_image *image, int intent_code, const char *out_fname, const char *curv_fname, const char *datatype);
4748
int MRISwriteGIFTIShape(MRIS *mris, const MRI *mri, int stframe, int endframe, gifti_image *image, int intent_code, const char *curv_fname, const char *datatype);
4849
int MRISwriteGIFTIStats(MRIS *mris, const MRI *mri, int stframe, int endframe, gifti_image *image, int intent_code, const char *curv_fname, const char *datatype);
4950

51+
// function to return SHAPE and <STATS> intent counts
52+
int getShapeStatIntentCount(const char *fgifti);
53+
5054

5155

5256
#endif

utils/MRISurfOverlay.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,32 @@ bool MRISurfOverlay::__isStatsData(int nthOverlay)
683683

684684
return statsData;
685685
}
686+
687+
int MRISurfOverlay::__getFrameCount()
688+
{
689+
int count = 0;
690+
for (int n = 0; n < __noverlay; n++)
691+
{
692+
int overlayFormat = getFileFormat(__overlayInfo[n].__foverlay);
693+
if (overlayFormat == MRI_MGH_FILE)
694+
{
695+
MRI *tempMRI = MRIreadHeader(__overlayInfo[n].__foverlay, MRI_MGH_FILE);
696+
if (tempMRI == NULL)
697+
return count;
698+
699+
count += tempMRI->nframes;
700+
MRIfree(&tempMRI);
701+
}
702+
else if (overlayFormat == GIFTI_FILE)
703+
{
704+
int intents = getShapeStatIntentCount(__overlayInfo[__currFrame].__foverlay);
705+
count += intents;
706+
}
707+
else // MRI_CURV_FILE, ASCII_FILE, VTK_FILE, and old curv format
708+
count++;
709+
710+
__overlayInfo[n].__format = overlayFormat;
711+
}
712+
713+
return count;
714+
}

utils/gifti.cpp

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum, MRI *outmri,
11101110
gifti_free_image(image);
11111111

11121112
return mris;
1113-
}
1113+
} // end of mrisReadGIFTIdanum()
11141114

11151115

11161116
/*-----------------------------------------------------------
@@ -1275,7 +1275,7 @@ MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume)
12751275
/* And we're done. */
12761276
gifti_free_image(image);
12771277
return (mri);
1278-
}
1278+
} // end of MRISreadGiftiAsMRI()
12791279

12801280
/*
12811281
* insert username and current date into meta data
@@ -1359,7 +1359,7 @@ int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const cha
13591359
gifti_free_image(image);
13601360

13611361
return ERROR_NONE;
1362-
}
1362+
} // end of MRISwriteGIFTI()
13631363

13641364
/*-----------------------------------------------------------
13651365
Parameters: MRI structure (surface-encoded volume),
@@ -1471,7 +1471,7 @@ int mriWriteGifti(MRI *mri, const char *out_fname)
14711471
gifti_free_image(image);
14721472

14731473
return ERROR_NONE;
1474-
}
1474+
} // end of mriWriteGifti()
14751475

14761476

14771477

@@ -1524,7 +1524,7 @@ int MRISwriteGIFTIIntent(MRIS *mris, int intent_code, gifti_image *image, const
15241524
} // end of if NIFTI_INTENT_<stats>
15251525

15261526
return NO_ERROR;
1527-
} // end of MRISwriteGIFTIIntent()
1527+
} // end of MRISwriteGIFTIIntent(MRIS *mris, ...)
15281528

15291529

15301530
/*
@@ -1613,7 +1613,7 @@ int MRISwriteGIFTIShape(MRIS *mris, gifti_image *image, int intent_code, const c
16131613
}
16141614

16151615
return NO_ERROR;
1616-
} // end of MRISwriteGIFTIShape()
1616+
} // end of MRISwriteGIFTIShape(MRIS *mris, ...)
16171617

16181618

16191619
/*
@@ -1676,7 +1676,7 @@ int MRISwriteGIFTIStats(MRIS *mris, gifti_image *image, int intent_code)
16761676
}
16771677

16781678
return NO_ERROR;
1679-
} // end of MRISwriteGIFTIStats()
1679+
} // end of MRISwriteGIFTIStats(MRIS *mris, ...)
16801680

16811681

16821682
/*
@@ -2304,7 +2304,7 @@ int MRISwriteGIFTIIntent(MRIS *mris, const MRI *mri, int stframe, int endframe,
23042304
} // end of if NIFTI_INTENT_<stats>
23052305

23062306
return NO_ERROR;
2307-
}
2307+
} // end of MRISwriteGIFTIIntent(MRIS *mris, const MRI *mri, ...)
23082308

23092309

23102310
/*
@@ -2424,7 +2424,7 @@ int MRISwriteGIFTIShape(MRIS *mris, const MRI *mri, int stframe, int endframe, g
24242424
#endif
24252425

24262426
return NO_ERROR;
2427-
} // end of MRISwriteGIFTIShape()
2427+
} // end of MRISwriteGIFTIShape(MRIS *mris, const MRI *mri, ...)
24282428

24292429

24302430
/*
@@ -2513,4 +2513,61 @@ int MRISwriteGIFTIStats(MRIS *mris, const MRI *mri, int stframe, int endframe, g
25132513
#endif
25142514

25152515
return NO_ERROR;
2516-
} // end of MRISwriteGIFTIStats()
2516+
} // end of MRISwriteGIFTIStats(MRIS *mris, const MRI *mri, ...)
2517+
2518+
2519+
int getShapeStatIntentCount(const char *fgifti)
2520+
{
2521+
/*
2522+
* attempt to read the file
2523+
*/
2524+
gifti_image *image = gifti_read_image(fgifti, 1);
2525+
if (NULL == image) {
2526+
fprintf(stderr, "getShapeStatIntentCount(): gifti_read_image() returned NULL\n");
2527+
return 0;
2528+
}
2529+
2530+
// make sure version is recoded before validation
2531+
if (!strcmp(image->version, "1")) {
2532+
free(image->version);
2533+
image->version = strcpyalloc(GIFTI_XML_VERSION);
2534+
}
2535+
2536+
/*
2537+
* check for compliance
2538+
*/
2539+
int valid = gifti_valid_gifti_image(image, 1);
2540+
if (valid == 0) {
2541+
fprintf(stderr, "getShapeStatIntentCount(): GIFTI file %s is invalid!\n", fgifti);
2542+
gifti_free_image(image);
2543+
return 0;
2544+
}
2545+
2546+
/*
2547+
* Now parse the DataArrays, count NIFTI_INTENT_SHAPE and NIFTI_INTENT_<stat>
2548+
*/
2549+
int count = 0;
2550+
int endDAnum = image->numDA;
2551+
for (int numDA = 0; numDA < endDAnum; numDA++) {
2552+
giiDataArray *darray = image->darray[numDA];
2553+
2554+
// skip these intents
2555+
if ((darray->intent == NIFTI_INTENT_POINTSET) ||
2556+
(darray->intent == NIFTI_INTENT_TRIANGLE) ||
2557+
(darray->intent == NIFTI_INTENT_LABEL) ||
2558+
(darray->intent == NIFTI_INTENT_GENMATRIX) ||
2559+
(darray->intent == NIFTI_INTENT_VECTOR) ||
2560+
(darray->intent == NIFTI_INTENT_RGB_VECTOR) ||
2561+
(darray->intent == NIFTI_INTENT_RGBA_VECTOR))
2562+
continue;
2563+
2564+
count++;
2565+
}
2566+
2567+
/*
2568+
* And we're done.
2569+
*/
2570+
gifti_free_image(image);
2571+
2572+
return count;
2573+
} // end of getShapeStatIntentCount()

0 commit comments

Comments
 (0)