diff --git a/mris_diff/mris_diff.cpp b/mris_diff/mris_diff.cpp index cb5b2a501f5..de931b1d2d1 100644 --- a/mris_diff/mris_diff.cpp +++ b/mris_diff/mris_diff.cpp @@ -1087,11 +1087,11 @@ static int parse_commandline(int argc, char **argv) { printf("Use Exact = %d\n",UseExact); MRI *mindist; if(UseExact){ - MRISdistanceBetweenSurfacesExact(surf2, surf1); - mindist = MRIcopyMRIS(NULL, surf2, 0, "curv"); + MRISdistanceBetweenSurfacesExact(surf2, surf1); + mindist = MRIcopyMRIS(NULL, surf2, 0, "curv"); } else - mindist = MRISminDist(surf1, surf2); + mindist = MRISminDist(surf1, surf2); if(mindist==NULL) exit(1); printf("Writing mindist to %s\n",pargv[3]); MRIwrite(mindist,pargv[3]); diff --git a/python/bindings/utils/surface.cpp b/python/bindings/utils/surface.cpp index 7a624610113..3c5a4788b28 100644 --- a/python/bindings/utils/surface.cpp +++ b/python/bindings/utils/surface.cpp @@ -1,6 +1,8 @@ #include "mrisurf_base.h" #include "surface.h" #include "xform.h" +#include "mrisurf_metricProperties.h" + namespace surf { @@ -169,6 +171,21 @@ int computeEulerNumber(Bridge surf) } +/* + Count number of face intersections. +*/ +int countIntersections(Bridge surf) +{ + MRIS *mris = surf.mris(); + mrisMarkIntersections(mris); + int nintersections = 0; + for(int n = 0; n < mris->nvertices; n++) { + if (mris->vertices[n].marked) nintersections++; + } + return nintersections; +} + + /* Smoothes an overlay along mesh vertices. */ @@ -178,6 +195,16 @@ py::object smoothOverlay(Bridge surf, vol::Bridge overlay, int steps) } +/* + Smoothes an overlay along mesh vertices. +*/ +py::object surfaceDistance(Bridge surf1, Bridge surf2) +{ + MRISdistanceBetweenSurfacesExact(surf2, surf1); + return vol::Bridge(MRIcopyMRIS(NULL, surf2, 0, "curv")); +} + + /* namespace vec { diff --git a/python/bindings/utils/surface.h b/python/bindings/utils/surface.h index 50e454e2562..c25f6b6894a 100644 --- a/python/bindings/utils/surface.h +++ b/python/bindings/utils/surface.h @@ -41,13 +41,15 @@ void write(Bridge surf, const std::string& filename); void computeNormals(Bridge surf); void computeTangents(Bridge surf); int computeEulerNumber(Bridge surf); +int countIntersections(Bridge surf); + +py::object surfaceDistance(Bridge surf1, Bridge surf2); // overlay utils py::array parameterize(Bridge surf, const arrayf& overlay, int scale, std::string interp); py::array sampleParameterization(Bridge surf, const arrayf& image, std::string interp); py::object smoothOverlay(Bridge surf, vol::Bridge overlay, int steps); - // surface submodule binding inline void bind(py::module &m) { @@ -59,9 +61,11 @@ inline void bind(py::module &m) m.def("compute_normals", &computeNormals); m.def("compute_tangents", &computeTangents); m.def("compute_euler", &computeEulerNumber); + m.def("count_intersections", &countIntersections); m.def("parameterize", ¶meterize); m.def("sample_parameterization", &sampleParameterization); m.def("smooth_overlay", &smoothOverlay); + m.def("distance", &surfaceDistance); // m.def("read_directly", &read_directly); } diff --git a/python/freesurfer/surface.py b/python/freesurfer/surface.py index 3a08a655fb8..c46d1a91149 100644 --- a/python/freesurfer/surface.py +++ b/python/freesurfer/surface.py @@ -79,6 +79,10 @@ def compute_euler(self): '''Computes euler number of the mesh.''' return bindings.surf.compute_euler(self) + def count_intersections(self): + '''Counts the number of face intersection in the mesh.''' + return bindings.surf.count_intersections(self) + def neighboring_faces(self, vertex): '''List of face indices that neighbor a vertex.''' return np.where(self.faces == vertex)[0] @@ -216,3 +220,16 @@ def get_vertex_normals(self): # TODEP def get_vertex_faces(self): # TODEP '''Deprecated - use Surface.neighboring_faces instead''' raise DeprecationWarning('get_vertex_faces has been removed! Use Surface.neighboring_faces or email andrew if you get this!!!!') + + +def distance(a, b): + return bindings.surf.distance(a, b) + + +def read_label(filename, nvertices): + mask = np.zeros(nvertices, dtype=bool) + with open(filename) as f: + lines = f.read().splitlines()[2:] + vertices = np.array([int(l.split()[0]) for l in lines]) + mask[vertices] = True + return Overlay(mask) diff --git a/python/freesurfer/transform.py b/python/freesurfer/transform.py index f360589bfef..0054fce209f 100644 --- a/python/freesurfer/transform.py +++ b/python/freesurfer/transform.py @@ -231,6 +231,9 @@ def transform_to_midspace(a, b, transform=None, resample=True, interp_method='li target: Resampling target geometry. If None, the target is determined by a secondary midspace computed between the *aligned* images. In this case, the target shape and resolution is determined by `b`. + + Returns: + mid_a, mid_b: Midspace-transformed images. """ from scipy.linalg import sqrtm