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 Jun 1, 2021
2 parents 96b770e + 3498e97 commit 15268bc
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 10 deletions.
10 changes: 10 additions & 0 deletions freeview/LayerMRI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4432,3 +4432,13 @@ bool LayerMRI::Load3DRegions( const QString& fn )
emit Region3DAdded();
return bSuccess;
}


void LayerMRI::Close3DRegion()
{
if ( m_current3DRegion )
{
m_current3DRegion->Close();
emit ActorUpdated();
}
}
2 changes: 2 additions & 0 deletions freeview/LayerMRI.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ class LayerMRI : public LayerVolumeBase

bool Load3DRegions(const QString& fn);

void Close3DRegion();

public slots:
virtual void SetModified();
void SetActiveFrame( int nFrame );
Expand Down
8 changes: 5 additions & 3 deletions freeview/MyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MyUtils
static void FloodFill( char* data, int x, int y, int dim_x, int dim_y, int fill_value, int border_value );

template <class T> static double GetDistance( const T* pt1, const T* pt2 );
template <class T> static void GetVector( T* pt1, T* pt2, double* v_out );
template <class T> static void GetVector( T* pt1, T* pt2, double* v_out, bool bNormalize = true);
template <class T> static bool Equal( T* pt1, T* p2, int n = 3 );
template <class T> static T** AllocateMatrix(int ny, int nx);
template <class T> static void FreeMatrix(T** p, int ny);
Expand Down Expand Up @@ -107,7 +107,7 @@ double MyUtils::Dot( T* v1, T* v2 )
}

template <class T>
void MyUtils::GetVector( T* pt1_in, T* pt2_in, double* v_out )
void MyUtils::GetVector( T* pt1_in, T* pt2_in, double* v_out, bool bNormalize )
{
T pt1[3], pt2[3];
for ( int i = 0; i < 3; i++ )
Expand All @@ -124,7 +124,9 @@ void MyUtils::GetVector( T* pt1_in, T* pt2_in, double* v_out )

for ( int i = 0; i < 3; i++ )
{
v_out[i] = ( (double)pt2[i] - (double)pt1[i] ) / dist;
v_out[i] = ( (double)pt2[i] - (double)pt1[i] );
if (bNormalize)
v_out[i] /= dist;
}
}

Expand Down
36 changes: 32 additions & 4 deletions freeview/Region3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "LayerMRI.h"
#include "LayerPropertyMRI.h"
#include "vtkSplineFilter.h"
#include <vtkKdTreePointLocator.h>
#include "vtkCleanPolyData.h"
#include <QDebug>

Region3D::Region3D(LayerMRI* owner ) : QObject(owner), m_mri(owner)
{
Expand All @@ -28,7 +31,16 @@ Region3D::Region3D(LayerMRI* owner ) : QObject(owner), m_mri(owner)
m_actor->GetProperty()->SetLineWidth( 5*ratio );

m_points = vtkSmartPointer<vtkPoints>::New();
m_interpolatedPoints = vtkSmartPointer<vtkPoints>::New();
m_color = Qt::blue;

m_locator = vtkSmartPointer<vtkKdTreePointLocator>::New();
QList<vtkActor*> list = m_mri->GetContourActors(true);
if (!list.isEmpty())
{
m_locator->SetDataSet(vtkPolyData::SafeDownCast( list.first()->GetMapper()->GetInput() ));
m_locator->BuildLocator();
}
}

Region3D::~Region3D()
Expand Down Expand Up @@ -65,7 +77,20 @@ void Region3D::RebuildOutline( bool bInterpolate )
m_mri->GetVolumeInfo(dim, vs);
spline->SetSubdivideToLength();
spline->SetLength(qMin(qMin(vs[0],vs[1]), vs[2])/3);
mapper->SetInputConnection(spline->GetOutputPort());
spline->Update();
m_interpolatedPoints = spline->GetOutput()->GetPoints();
polydata = vtkSmartPointer<vtkPolyData>::New();
lines = vtkSmartPointer<vtkCellArray>::New();
lines->InsertNextCell( m_interpolatedPoints->GetNumberOfPoints() );
for ( int i = 0; i < m_interpolatedPoints->GetNumberOfPoints(); i++ )
{
lines->InsertCellPoint( i );
}
polydata->SetPoints( m_interpolatedPoints );
polydata->SetLines( lines );
vtkSmartPointer<vtkCleanPolyData> clean = vtkSmartPointer<vtkCleanPolyData>::New();
clean->SetInputData(polydata);
mapper->SetInputConnection(clean->GetOutputPort());
}
else
{
Expand Down Expand Up @@ -125,9 +150,12 @@ QColor Region3D::GetColor()
bool Region3D::HasPoint(double *pt, double dist)
{
double th = dist*dist;
for (int i = 0; i < m_points->GetNumberOfPoints(); i++)
vtkPoints* pts = m_points;
if (m_interpolatedPoints.GetPointer())
pts = m_interpolatedPoints;
for (int i = 0; i < pts->GetNumberOfPoints(); i++)
{
if (vtkMath::Distance2BetweenPoints(pt, m_points->GetPoint(i)) < th)
if (vtkMath::Distance2BetweenPoints(pt, pts->GetPoint(i)) < th)
return true;
}
return false;
Expand Down Expand Up @@ -200,7 +228,7 @@ bool Region3D::Load( FILE* fp )
}
m_color = QColor(r, g, b);

RebuildOutline( false );
RebuildOutline( true );

return true;
}
3 changes: 3 additions & 0 deletions freeview/Region3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class vtkClipPolyData;
class vtkCleanPolyData;
class RenderView3D;
class LayerMRI;
class vtkKdTreePointLocator;

class Region3D : public QObject
{
Expand Down Expand Up @@ -62,6 +63,8 @@ class Region3D : public QObject

vtkSmartPointer<vtkActor> m_actor;
vtkSmartPointer<vtkPoints> m_points;
vtkSmartPointer<vtkPoints> m_interpolatedPoints;
vtkSmartPointer<vtkKdTreePointLocator> m_locator;

LayerMRI* m_mri;
QColor m_color;
Expand Down
2 changes: 2 additions & 0 deletions freeview/RenderView3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,8 @@ void RenderView3D::CloseSelectRegion(int nAction)
{
if (nAction == Interactor::MM_SurfaceRegion)
mri->CloseSurfaceRegion();
else if (nAction == Interactor::MM_DrawOnSurface)
mri->Close3DRegion();
}
}

Expand Down
3 changes: 2 additions & 1 deletion trc/blood.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,10 @@ void Blood::MatchStreamlineEnds() {
ivalid2++;
}

if (!mMask.empty())
if (!mMask.empty()) {
imask++;
iaseg++;
}
}
}
else { // Have labeling ROIs
Expand Down
3 changes: 2 additions & 1 deletion trc/coffin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2678,11 +2678,12 @@ bool Coffin::ProposePathFull() {
if (!IsInMask(cpoint)) {
*isrej = true;

if (mDebug)
if (mDebug) {
mLog << "Reject due to control point "
<< isrej - mRejectControl.begin() << " off mask at "
<< cpoint[0] << " " << cpoint[1] << " " << cpoint[2] << endl;
LogObjectiveNaN(0);
}
}

cpoint += 3;
Expand Down
3 changes: 2 additions & 1 deletion trc/dmri_trk2trk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,10 @@ int main(int argc, char **argv) {
streamlines.erase(streamlines.begin(), streamlines.begin() + kstrmean);
streamlines.erase(streamlines.begin() + 1, streamlines.end());

if (!properties.empty())
if (!properties.empty()) {
properties.erase(properties.begin(), properties.begin() + kstrmean);
properties.erase(properties.begin() + 1, properties.end());
}
}

// Write transformed streamlines to volume
Expand Down

0 comments on commit 15268bc

Please sign in to comment.