Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:freesurfer/freesurfer into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Greve committed Nov 29, 2021
2 parents fa7095a + c3a388c commit 8352175
Show file tree
Hide file tree
Showing 24 changed files with 297 additions and 177 deletions.
23 changes: 20 additions & 3 deletions freeview/LayerSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,14 +1221,14 @@ int LayerSurface::GetVertexIndexAtTarget( double* pos, double* distance, int sur
return m_surfaceSource->FindVertexAtRAS( realRas, distance, surface_type );
}

bool LayerSurface::GetRASAtVertex( int nVertex, double* ras )
bool LayerSurface::GetRASAtVertex( int nVertex, double* ras, int surface_type )
{
if ( m_surfaceSource == NULL )
{
return false;
}

return m_surfaceSource->GetRASAtVertex( nVertex, ras );
return m_surfaceSource->GetRASAtVertex( nVertex, ras, surface_type );
}

void LayerSurface::GetSurfaceRASAtTarget( double* pos_in, double* ras_out )
Expand Down Expand Up @@ -2282,7 +2282,8 @@ bool LayerSurface::GetCorrelationOverlayDataAtVertex(int nVert, float *output, i

bool LayerSurface::IsInflated()
{
return (GetFileName().toLower().contains("inflated") || GetActiveSurface() == FSSurface::SurfaceInflated);
return (QFileInfo(GetFileName()).fileName().toLower().contains("inflated") ||
GetActiveSurface() == FSSurface::SurfaceInflated);
}

bool LayerSurface::GetActiveLabelCentroidPosition(double *pos)
Expand Down Expand Up @@ -3203,3 +3204,19 @@ void LayerSurface::GetCenterOfActor(double *pt)
bbox.GetCenter(pt);
}
}

bool LayerSurface::SavePathAsControlPoints(const QString& fn, bool bMarks)
{
SurfacePath* sp = NULL;
if (bMarks)
{
sp = m_marks;
}
else if (!m_paths.isEmpty())
sp = GetActivePath();

if (sp)
return sp->SaveAsControlPoints(fn);
else
return false;
}
4 changes: 3 additions & 1 deletion freeview/LayerSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LayerSurface : public LayerEditable

int GetVertexIndexAtTarget( double* ras, double* distance, int surface_type = -1 );

bool GetRASAtVertex ( int nVertex, double* ras_out );
bool GetRASAtVertex ( int nVertex, double* ras_out, int surface_type = -1 );
bool GetSurfaceRASAtVertex( int nVertex, double* ras_out );

int GetVertexAtSurfaceRAS(double* ras, double* distance );
Expand Down Expand Up @@ -456,6 +456,8 @@ public slots:

void GetCenterOfActor(double* pt);

bool SavePathAsControlPoints(const QString& fn, bool bMarks = false);

Q_SIGNALS:
void SurfaceAnnotationAdded( SurfaceAnnotation* );
void SurfaceLabelAdded( SurfaceLabel* );
Expand Down
50 changes: 49 additions & 1 deletion freeview/RenderView3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "SurfaceRegion.h"
#include "SurfaceROI.h"
#include "SurfaceOverlayProperty.h"
#include "SurfacePath.h"
#include <vtkProp.h>
#include <vtkCellPicker.h>
#include <vtkRenderWindow.h>
Expand Down Expand Up @@ -58,12 +59,14 @@
#include <vtkCubeAxesActor.h>
#include <vtkTextProperty.h>
#include <QFileInfo>
#include <QFileDialog>
#include "MyUtils.h"
#include "FSSurface.h"
#include "Interactor3DPathEdit.h"
#include <QElapsedTimer>
#include "vtkInteractorStyleMyTrackballCamera.h"
#include <vtkCubeAxesActor.h>
#include <QMessageBox>

#define SLICE_PICKER_PIXEL_TOLERANCE 15

Expand Down Expand Up @@ -619,7 +622,7 @@ bool RenderView3D::MapInflatedCoords(LayerSurface *surf, double *pos_in, double
surf->SetCurrentVertex(nVertex);
else
surf->SetMouseVertex(nVertex);
if (QFileInfo(surf->GetFileName()).fileName().contains("inflated") || surf->GetActiveSurface() == FSSurface::SurfaceInflated)
if (surf->IsInflated())
{
if (m_cursor3D->IsShown())
m_cursorInflatedSurf->Show();
Expand Down Expand Up @@ -1600,6 +1603,24 @@ void RenderView3D::TriggerContextMenu( QMouseEvent* event )
menu->addSeparator();
menu->addAction(act);
}

surf = (LayerSurface*)mainwnd->GetActiveLayer("Surface");
if (surf)
{
menu->addSeparator();
if (surf->GetMarks() && surf->GetMarks()->GetNumberOfPoints() > 0)
{
act = new QAction("Save Marked Vertices As Control Points", this);
connect(act, SIGNAL(triggered()), SLOT(SaveMarksAsControlPoints()));
menu->addAction(act);
}
if (surf->GetActivePath())
{
act = new QAction("Save Path As Control Points", this);
connect(act, SIGNAL(triggered()), SLOT(SavePathAsControlPoints()));
menu->addAction(act);
}
}
menu->exec(event->globalPos());
}

Expand Down Expand Up @@ -1801,3 +1822,30 @@ int RenderView3D::GetAxesFlyMode()
{
return m_actorAxesActor->GetFlyMode();
}

void RenderView3D::SavePathAsControlPoints()
{
LayerSurface* surf = (LayerSurface*)MainWindow::GetMainWindow()->GetActiveLayer("Surface");
if (surf && surf->GetActivePath())
SavePathAsControlPoints(surf->GetActivePath());
}

void RenderView3D::SaveMarksAsControlPoints()
{
LayerSurface* surf = (LayerSurface*)MainWindow::GetMainWindow()->GetActiveLayer("Surface");
if (surf && surf->GetMarks())
SavePathAsControlPoints(surf->GetMarks());
}

void RenderView3D::SavePathAsControlPoints(SurfacePath *sp)
{
LayerSurface* surf = (LayerSurface*)MainWindow::GetMainWindow()->GetActiveLayer("Surface");
QString fn = QFileDialog::getSaveFileName( this, QString("Save %1 As").arg(sp->IsPathMade()?"Path":"Vertices"),
"",
"Control Point files (*)");
if ( !fn.isEmpty())
{
if (!surf->SavePathAsControlPoints(fn, !sp->IsPathMade()))
QMessageBox::warning(this, "Error", "Failed to save file " + fn);
}
}
4 changes: 4 additions & 0 deletions freeview/RenderView3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Interactor3DPathEdit;
class RenderView3D;
class vtkInteractorStyleMyTrackballCamera;
class Region3D;
class SurfacePath;

class RenderView3D : public RenderView
{
Expand Down Expand Up @@ -174,10 +175,13 @@ public slots:
void SetAxesFlyMode(int n);
void DeleteCurrent3DRegion();
void DeleteAll3DRegions();
void SavePathAsControlPoints();
void SaveMarksAsControlPoints();

protected:
void DoUpdateRASPosition( int posX, int posY, bool bCursor = false, bool bSlicePickOnly = false );
void DoUpdateConnectivityDisplay();
void SavePathAsControlPoints(SurfacePath* sp);

void HighlightSliceFrame( int n );

Expand Down
29 changes: 29 additions & 0 deletions freeview/SurfacePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,32 @@ double SurfacePath::GetLength()
else
return 0;
}

bool SurfacePath::SaveAsControlPoints(const QString &filename)
{
QFile file( filename );
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QString strg = file.errorString();
if (strg.isEmpty())
cerr << "Can not open file for writing\n";
else
cerr << qPrintable(strg) << "\n";
return false;
}

QTextStream out(&file);
for (int n = 0; n < m_listVertices.size(); n++)
{
double pt[3];
m_mris->GetRASAtVertex(m_listVertices[n], pt, m_mris->IsInflated()?FSSurface::SurfaceWhite:-1);
out << QString("%1 %2 %3\n").arg(pt[0]).arg(pt[1]).arg(pt[2]);
}
out << QString("info\nnumpoints %1\nuseRealRAS 1\n").arg( m_listVertices.size() );
return true;
}

int SurfacePath::GetNumberOfPoints()
{
return m_listVertices.size();
}
4 changes: 4 additions & 0 deletions freeview/SurfacePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class SurfacePath : public QObject

double GetLength();

int GetNumberOfPoints();

bool SaveAsControlPoints(const QString& filename);

signals:
void ColorChanged( const QColor& );
void Progress(int n);
Expand Down
20 changes: 5 additions & 15 deletions packages/dcm2niix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,18 @@ if(APPLE)
endif()

### start of addition for FREESURFER
# we should not need this if we use target_compile_definitions()
#target_link_libraries(dcm2niix nifti ${ZLIB_LIBRARIES})

set(LIBRARY dcm2niix)
add_library(dcm2niix STATIC
dcm2fsWrapper.cpp
set(DCM2NIIXFSLIB dcm2niixfs)
add_library(${DCM2NIIXFSLIB} STATIC
dcm2niix_fswrapper.cpp
nii_dicom.cpp
jpg_0XC3.cpp
ujpeg.cpp
nifti1_io_core.cpp
nii_foreign.cpp
nii_ortho.cpp
nii_dicom_batch.cpp)
target_compile_definitions(${LIBRARY} PUBLIC -DMGH_FREESURFER -DUSING_MGH_NIFTI_IO)

# DON'T build dcm2niixfsexe
#set(DCM2NIIXFSEXE dcm2niixfsexe)
#add_executable(${DCM2NIIXFSEXE} dcm2fsmain.cpp)
#target_link_libraries(${DCM2NIIXFSEXE} dcm2niixfs nifti ${ZLIB_LIBRARIES})
target_compile_definitions(${DCM2NIIXFSLIB} PUBLIC -DUSING_DCM2NIIXFSWRAPPER -DUSING_MGH_NIFTI_IO)
### end of addition for FREESURFER

#install(TARGETS ${PROGRAMS} DESTINATION bin)
### additions for FREESURFER
#install(TARGETS ${LIBRARY} DESTINATION bin)
#install(TARGETS ${DCM2NIIXFSEXE} DESTINATION bin)

25 changes: 0 additions & 25 deletions packages/dcm2niix/dcm2fsWrapper.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <stdio.h>

#include "nii_dicom.h"
#include "dcm2fsWrapper.h"
#include "dcm2niix_fswrapper.h"

struct TDCMopts dcm2fsWrapper::tdcmOpts;
//MRIFSSTRUCT dcm2fsWrapper::mrifsStruct;
struct TDCMopts dcm2niix_fswrapper::tdcmOpts;

/* oct06 version
/* These are the TDCMopts defaults set in dcm2niix
isIgnoreTriggerTimes = false
isTestx0021x105E = false
isAddNamePostFixes = true
Expand Down Expand Up @@ -41,17 +40,19 @@ isProgress = 0
compressFlag = 0
dirSearchDepth = 5
gzLevel = 6
filename = "%s_%p" // seriesNum_protocol
filename = "%s_%p" // seriesNum_protocol -f "%s_%p"
outdir = "..."
indir = "..."
pigzname = '\000'
optsname = "..."
optsname = "~/.dcm2nii.ini"
indirParent = "..."
imageComments = ""
seriesNumber = nnn
numSeries = 0
*/
void dcm2fsWrapper::setOpts(const char* dcmindir, const char* niioutdir)

// set TDCMopts defaults, overwrite settings to output in mgz orientation
void dcm2niix_fswrapper::setOpts(const char* dcmindir, const char* niioutdir)
{
memset(&tdcmOpts, 0, sizeof(tdcmOpts));
setDefaultOpts(&tdcmOpts, NULL);
Expand All @@ -61,6 +62,7 @@ void dcm2fsWrapper::setOpts(const char* dcmindir, const char* niioutdir)
if (niioutdir != NULL)
strcpy(tdcmOpts.outdir, niioutdir);

// set the options for freesurfer mgz orientation
tdcmOpts.isRotate3DAcq = false;
tdcmOpts.isFlipY = false;
tdcmOpts.isIgnoreSeriesInstanceUID = true;
Expand All @@ -71,57 +73,49 @@ void dcm2fsWrapper::setOpts(const char* dcmindir, const char* niioutdir)
//tdcmOpts.isForceOnsetTimes = false;
}

bool dcm2fsWrapper::isDICOM(const char* file)
// interface to isDICOMfile() in nii_dicom.cpp
bool dcm2niix_fswrapper::isDICOM(const char* file)
{
return isDICOMfile(file);
}

int dcm2fsWrapper::dcm2NiiOneSeries(const char* dcmfile)
/*
* interface to nii_loadDirCore() to search all dicom files from the directory input file is in,
* and convert dicom files with the same series as given file.
*/
int dcm2niix_fswrapper::dcm2NiiOneSeries(const char* dcmfile)
{
// get seriesNo for given dicom file
struct TDICOMdata tdicomData = readDICOM((char*)dcmfile);

double seriesNo = (double)tdicomData.seriesUidCrc;
if (tdcmOpts.isIgnoreSeriesInstanceUID)
seriesNo = (double)tdicomData.seriesNum;

// set TDCMopts to convert just one series
tdcmOpts.seriesNumber[0] = seriesNo;
tdcmOpts.numSeries = 1;

//memset(&mrifsStruct, 0, sizeof(mrifsStruct));
return nii_loadDirCore(tdcmOpts.indir, &tdcmOpts);
}

int dcm2fsWrapper::saveNii(const char* nii)
{
FILE *fp = fopen(nii, "wb");
if (!fp)
return 1;

MRIFSSTRUCT* mrifsStruct = getMrifsStruct();

//if (!opts.isSaveNativeEndian) swapEndian(&hdr, im, true); //byte-swap endian (e.g. little->big)
fwrite(&mrifsStruct->hdr0, sizeof(mrifsStruct->hdr0), 1, fp);
uint32_t pad = 0;
fwrite(&pad, sizeof( pad), 1, fp);
fwrite(mrifsStruct->imgM, mrifsStruct->imgsz, 1, fp);
fclose(fp);

return 0;
}

MRIFSSTRUCT* dcm2fsWrapper::getMrifsStruct(void)
// interface to nii_getMrifsStruct()
MRIFSSTRUCT* dcm2niix_fswrapper::getMrifsStruct(void)
{
return nii_getMrifsStruct();
}

nifti_1_header* dcm2fsWrapper::getNiiHeader(void)
// return nifti header saved in MRIFSSTRUCT
nifti_1_header* dcm2niix_fswrapper::getNiiHeader(void)
{
MRIFSSTRUCT* mrifsStruct = getMrifsStruct();
return &mrifsStruct->hdr0;
}

const unsigned char* dcm2fsWrapper::getMRIimg(void)
// return image data saved in MRIFSSTRUCT
const unsigned char* dcm2niix_fswrapper::getMRIimg(void)
{
MRIFSSTRUCT* mrifsStruct = getMrifsStruct();
return mrifsStruct->imgM;
}

Loading

0 comments on commit 8352175

Please sign in to comment.