Skip to content

Commit

Permalink
nf: sse using surface et al (freesurfer#708)
Browse files Browse the repository at this point in the history
* More of the necessary code but not enabled

* Add the .py

* fall thru seen to happen

* mrisurf_base.h was being too widely used, causing conflicts

* Start connection MRIS_MP in to the Surface support

* Builds

* Clean up the dev merge

* make nsize and dist_nsize be the same type in MRIS and MRIS_MP

* Add the dump code

* MAX_NEIGHBOURS has increased

* Next small step towards being able to use templates for more of the distortion code

* latest dev merged, next steps towards a faster surface distortion

* Closer but not there yet for implementing MRIScomputeSSE for MRIS_MP

* Builds

* builds

* Add specific includes for mrisurf_metricProperties.h
  • Loading branch information
emtpgeek authored and ahoopes committed Sep 13, 2019
1 parent f0d94f0 commit edd6c68
Show file tree
Hide file tree
Showing 98 changed files with 21,361 additions and 6,103 deletions.
2 changes: 1 addition & 1 deletion anatomicuts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ install(PROGRAMS

install_pyscript(
diffusionUtils
anatomiCutsUtils
anatomiCutsUtils.py
)
32 changes: 17 additions & 15 deletions hiam_make_surfaces/hiam_make_surfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,31 @@
#include <math.h>
#include <ctype.h>

#include "macros.h"

#include "mri.h"
#include "mrimorph.h"
#include "mrinorm.h"

#include "mrisurf.h"
#include "mrisurf_project.h"
#include "mrishash_internals.h"

#include "macros.h"
#include "error.h"
#include "diag.h"
#include "proto.h"
#include "timer.h"
#include "mri.h"
#include "macros.h"
#include "mrimorph.h"
#include "mrinorm.h"
#include "matrix.h"

#define VERTEX_EDGE(vec, v0, v1) VECTOR_LOAD(vec,v1->x-v0->x,v1->y-v0->y,v1->z-v0->z)

#define MAX_4_NEIGHBORS 100
#define MAX_3_NEIGHBORS 70
#define MAX_2_NEIGHBORS 20
#define MAX_1_NEIGHBORS 8

#define REPULSE_K 1.0

#undef REPULSE_E // differs from mrisurf_base.h 0.25
#define REPULSE_E 0.5

#define MAX_MOMENTUM_MM 1

static int get_option(int argc, char *argv[]) ;
Expand Down Expand Up @@ -94,8 +96,8 @@ static double mrisComputeGaussianCurvatureSpringEnergy(MRI_SURFACE *mris, double

static double mrismomentumTimeStep(MRI_SURFACE *mris, float momentum, float dt, float tol,
float n_averages);
static int mrisProjectSurface(MRI_SURFACE *mris);
static int mrisComputeTangentPlanes(MRI_SURFACE *mris);
static int my_mrisProjectSurface(MRI_SURFACE *mris);
static int my_mrisComputeTangentPlanes(MRI_SURFACE *mris);
static int FindSpikes(MRI_SURFACE *mris, int iter);
static int SmoothSpikes(MRI_SURFACE *mris, int niter);

Expand Down Expand Up @@ -1122,7 +1124,7 @@ mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) {
if (FZERO(l_curv))
return(NO_ERROR) ;

mrisComputeTangentPlanes(mris) ;
my_mrisComputeTangentPlanes(mris) ;
v_n = VectorAlloc(3, MATRIX_REAL) ;
v_A = VectorAlloc(2, MATRIX_REAL) ;
v_e1 = VectorAlloc(3, MATRIX_REAL) ;
Expand Down Expand Up @@ -1197,7 +1199,7 @@ mrisComputeQuadraticCurvatureEnergy(MRI_SURFACE *mris) {
double sse = 0.0 ;


mrisComputeTangentPlanes(mris) ;
my_mrisComputeTangentPlanes(mris) ;
v_n = VectorAlloc(3, MATRIX_REAL) ;
v_A = VectorAlloc(2, MATRIX_REAL) ;
v_e1 = VectorAlloc(3, MATRIX_REAL) ;
Expand Down Expand Up @@ -1782,12 +1784,12 @@ mrismomentumTimeStep(MRI_SURFACE *mris, float momentum, float dt, float tol,
}
}

mrisProjectSurface(mris) ;
my_mrisProjectSurface(mris) ;
return(delta_t) ;
}

static int
mrisProjectSurface(MRI_SURFACE *mris) {
my_mrisProjectSurface(MRI_SURFACE *mris) {

/* MRISupdateSurface(mris) ;*/
switch (mris->status) {
Expand Down Expand Up @@ -1815,7 +1817,7 @@ mrisProjectSurface(MRI_SURFACE *mris) {


static int
mrisComputeTangentPlanes(MRI_SURFACE *mris) {
my_mrisComputeTangentPlanes(MRI_SURFACE *mris) {
VECTOR *v_n, *v_e1, *v_e2, *v ;
int vno ;
VERTEX *vertex ;
Expand Down
9 changes: 5 additions & 4 deletions hiam_register/hiam_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
#include <ctype.h>

#include "macros.h"

#include "mri.h"
#include "mrisurf.h"
#include "mrisurf_project.h"

#include "error.h"
#include "diag.h"
#include "proto.h"
#include "mrisurf.h"
#include "mri.h"
#include "macros.h"
#include "timer.h"

static char vcid[] = "$Id: hiam_register.c,v 1.6 2011/12/12 03:28:32 greve Exp $";
Expand Down Expand Up @@ -92,7 +94,6 @@ static int use_defaults = 1 ;

#define IMAGES_PER_SURFACE 3 /* mean, variance, and dof */
#define SURFACES sizeof(curvature_names) / sizeof(curvature_names[0])
#define PARAM_IMAGES (IMAGES_PER_SURFACE*SURFACES)
#define NSIGMAS (sizeof(sigmas) / sizeof(sigmas[0]))
#define MAX_NBHD_SIZE 200

Expand Down
10 changes: 6 additions & 4 deletions include/mrishash_SurfaceFromMRIS.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#include "mrishash.h"
#include "mrisurf_SurfaceFromMRIS_generated.h"

MRIS_HASH_TABLE* MHTcreateFaceTable (SurfaceFromMRIS::Analysis::Surface surface);
MRIS_HASH_TABLE* MHTcreateFaceTable_Resolution (SurfaceFromMRIS::Analysis::Surface surface, int which, float res);
MRIS_HASH_TABLE* MHTcreateVertexTable (SurfaceFromMRIS::Analysis::Surface surface, int which);
MRIS_HASH_TABLE* MHTcreateVertexTable_Resolution(SurfaceFromMRIS::Analysis::Surface surface, int which, float res);
namespace Minimal_Surface_MRIS = SurfaceFromMRIS::XYZPosition;

MRIS_HASH_TABLE* MHTcreateFaceTable (Minimal_Surface_MRIS::Surface surface);
MRIS_HASH_TABLE* MHTcreateFaceTable_Resolution (Minimal_Surface_MRIS::Surface surface, int which, float res);
MRIS_HASH_TABLE* MHTcreateVertexTable (Minimal_Surface_MRIS::Surface surface, int which);
MRIS_HASH_TABLE* MHTcreateVertexTable_Resolution(Minimal_Surface_MRIS::Surface surface, int which, float res);

28 changes: 11 additions & 17 deletions include/mrisurf.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ void MRIS_checkAcquiredTemp(MRIS* mris, MRIS_TempAssigned temp, int MRIS_acquire
void MRIS_releaseTemp (MRIS* mris, MRIS_TempAssigned temp, int MRIS_acquireTemp_result); // ... be allowed to release it


FaceNormCacheEntry const * getFaceNorm(MRIS const * const mris, int fno);
void setFaceNorm(MRIS const * const mris, int fno, float nx, float ny, float nz);


// Support for writing traces that can be compared across test runs to help find where differences got introduced
//
void mrisVertexHash(MRIS_HASH* hash, MRIS const * mris, int vno);
Expand Down Expand Up @@ -668,9 +664,6 @@ int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_avgs);
int mrisLogIntegrationParms(FILE *fp, MRI_SURFACE *mris,
INTEGRATION_PARMS *parms) ;

MRIS* MRISprojectOntoSphere (MRIS* mris_src, MRIS* mris_dst, double r) ;
MRIS* MRISprojectOntoEllipsoid(MRIS* mris_src, MRIS* mris_dst, float a, float b, float c) ;

int MRISsampleDistances(MRI_SURFACE *mris, int *nbr_count,int n_nbrs);
int MRISsampleAtEachDistance(MRI_SURFACE *mris, int nbhd_size,
int nbrs_per_distance) ;
Expand Down Expand Up @@ -777,11 +770,6 @@ MRI_SURFACE *MRISremoveNegativeVertices(MRI_SURFACE *mris,
int MRIScomputeFaceAreas(MRI_SURFACE *mris) ;
int MRISupdateEllipsoidSurface(MRI_SURFACE *mris) ;

MRIS* MRIStranslate_along_vertex_dxdydz(MRIS* mris_src, MRIS* mris_dst, double dt);

MRIS* MRISrotate(MRIS* mris_src, MRIS* mris_dst,
float alpha, float beta, float gamma) ;

MRI *MRISwriteIntoVolume(MRI_SURFACE *mris, MRI *mri, int which) ;
MRI_SURFACE *MRISreadFromVolume(MRI *mri, MRI_SURFACE *mris, int which) ;

Expand Down Expand Up @@ -2123,15 +2111,13 @@ void mrisRemoveEdge(MRIS *mris, int vno1, int vno2);

// Neighbourhoods
//
#define MAX_NEIGHBORS (1024)
void mrisVertexReplacingNeighbors(MRIS * mris, int vno, int vnum);
void mrisForgetNeighborhoods (MRIS * mris);

int MRISresetNeighborhoodSize (MRIS *mris, int nsize) ;
void MRISsetNeighborhoodSize (MRIS *mris, int nsize) ; // Doesn't compute distances if not already present
void MRISsetNeighborhoodSizeAndDist (MRIS *mris, int nsize) ; // Always computes distances

#define MRIS_MAX_NEIGHBORHOOD_LINKS 50 // bound on nlinks
int MRISfindNeighborsAtVertex (MRIS *mris, int vno, int nlinks, size_t listCapacity, int* vlist, int* hops);
// sets vlist[*] to the neighboring vno
// sets hops [*] to -1 for [vno] and the number of hops for all entries returned in the vlist
Expand Down Expand Up @@ -2185,8 +2171,14 @@ int MRIStranslate (MRIS *mris, float dx, float dy, float dz);
void MRISmoveOrigin(MRIS *mris, float x0, float y0, float z0);
int MRISscale (MRIS *mris, double scale);

void MRISblendXYZandTXYZ(MRIS* mris, float xyzScale, float txyzScale); // x = x*xyzScale + tx*txyzScale etc.
void MRISblendXYZandNXYZ(MRIS* mris, float nxyzScale); // x = x + nx*nxyzScale etc.
void MRISblendXYZandTXYZ(MRIS* mris, float xyzScale, float txyzScale); // x = x*xyzScale + tx*txyzScale etc.
void MRISblendXYZandNXYZ(MRIS* mris, float nxyzScale); // x = x + nx*nxyzScale etc.


void MRIStranslate_along_vertex_dxdydz(MRIS* dst, MRIS* src, double dt); // dst.x = src.x + src.dx*dt, etc.
void MRIStranslate_along_vertex_dxdydz(MRIS_MP* dst, MRIS_MP* src, double dt);

MRIS* MRISrotate(MRIS* mris_src, MRIS* mris_dst, float alpha, float beta, float gamma) ;

void mrisDisturbVertices(MRIS *mris, double amount);

Expand All @@ -2209,7 +2201,9 @@ int mrisComputeSurfaceDimensions(MRIS *mris);
// dist is created by calls to MRISsetNeighborhoodSizeAndDist
// dist_orig must be explicitly created
//
void MRISfreeDistsButNotOrig(MRIS *mris);
void MRISfreeDistsButNotOrig(MRIS* mris);
void MRISfreeDistsButNotOrig(MRISPV* mris);
void MRISfreeDistsButNotOrig(MRIS_MP* mris);

void MRISmakeDistOrig (MRIS *mris, int vno); // makes it the same size as the current VERTEX.dist
void MRISgrowDistOrig (MRIS *mris, int vno, int minimumCapacity); // same size as current or bigger
Expand Down
13 changes: 8 additions & 5 deletions include/mrisurf_FACE_VERTEX_MRIS_generated.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

#pragma once
// GENERATED SOURCE - DO NOT DIRECTLY EDIT
//
// =======================================
#include "mrisurf_aaa.h"
#define SEPARATE_VERTEX_TOPOLOGY
struct face_type_ {
vertices_per_face_t v ;
Expand All @@ -20,17 +22,16 @@ struct VERTEX_TOPOLOGY {
// the whole fits in much less than one cache line, so further ordering is no use
pSeveralInt f ; // size() is num. array[v->num] the fno's of the neighboring faces
pSeveralUchar n ; // size() is num. array[v->num] the face.v[*] index for this vertex
pSeveralInt e ; // edge state for neighboring vertices (used by MRI_EDGE,MRI_CORNER)
pSeveralInt e ; // edge state for neighboring vertices
pSeveralInt v ; // size() is vtotal. array[v->vtotal or more] of vno, head sorted by hops
short const vnum ; // number of 1-hop neighbors should use [p]VERTEXvnum(i,
short vnum ; // number of 1-hop neighbors should use [p]VERTEXvnum(i)
short v2num ; // number of 1, or 2-hop neighbors
short v3num ; // number of 1,2,or 3-hop neighbors
short vtotal ; // total # of neighbors. copy of vnum.nsizeCur
short nsizeMaxClock ; // copy of mris->nsizeMaxClock when v#num
uchar nsizeMax ; // the max nsize that was used to fill in vnum etc
uchar nsizeCur ; // index of the current v#num in vtotal
uchar num ; // number of neighboring faces
VERTEX_TOPOLOGY() : vnum(0) {}
uchar num ; // number of neighboring faces
}; // VERTEX_TOPOLOGY

struct vertex_type_ {
Expand Down Expand Up @@ -185,6 +186,7 @@ struct MRIS {
float x0 ; // center of spherical expansion
float y0 ;
float z0 ;
// v_temporal_pole, v_frontal_pole, and v_occipital_pole don't appear to be used, and are unusual being pointers to vertices
PVERTEX v_temporal_pole ;
PVERTEX v_frontal_pole ;
PVERTEX v_occipital_pole ;
Expand Down Expand Up @@ -282,7 +284,7 @@ struct MRIS {
ELTX(short,nsizeMaxClock) SEP \
ELTT(uchar,nsizeMax) SEP \
ELTT(uchar,nsizeCur) SEP \
ELTT(uchar,num) SEP \
ELTT(uchar,num) \
// end of macro

#define LIST_OF_VERTEX_ELTS_1 \
Expand Down Expand Up @@ -435,6 +437,7 @@ struct MRIS {
ELTT(int,tempsAssigned) SEP \
ELTP(FACE,faces) SEP \
ELTP(MRI_EDGE,edges) SEP \
ELTP(MRI_CORNER,corners) SEP \
ELTP(FaceNormCacheEntry,faceNormCacheEntries) SEP \
ELTP(FaceNormDeferredEntry,faceNormDeferredEntries) SEP \
ELTP(STRIP,strips) SEP \
Expand Down
1 change: 1 addition & 0 deletions include/mrisurf_MRIS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mrisurf_FACE_VERTEX_MRIS_generated.h"
1 change: 1 addition & 0 deletions include/mrisurf_MRISPV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mrisurf_MRIS_PropertiesInVectors.h"
Loading

0 comments on commit edd6c68

Please sign in to comment.