From ba1cedc53695eea8ecff799293ba44ac669864ca Mon Sep 17 00:00:00 2001 From: nrnhines Date: Thu, 12 Oct 2023 16:32:56 -0400 Subject: [PATCH] Soma contour centroid oriented so 1 end is largest positive direction. (#2491) A temporary pull request to allow comparison with #2470 This was an attempt to see if this produces the same result as #2470. But the conclusion was that this is not easy. We are still merging this PR/change because we thought it would be helpful to have this change into the NEURON master branch as a reference point if we ever have to compare this change in isolation. --- share/lib/hoc/import3d/import3d_gui.hoc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/share/lib/hoc/import3d/import3d_gui.hoc b/share/lib/hoc/import3d/import3d_gui.hoc index 67b9173a97..acde58f828 100755 --- a/share/lib/hoc/import3d/import3d_gui.hoc +++ b/share/lib/hoc/import3d/import3d_gui.hoc @@ -1227,14 +1227,21 @@ proc contour2centroid() {local i, j, imax, imin, ok localobj mean, pts, d, max, tobj = m.symmeig(m) // major axis is the one with largest eigenvalue major = m.getcol(tobj.max_ind) + // For plotting and round-off error consistency + // between meschach and eigen use the heuristic that + // major axis points in positive direction. + // i.e. if greatest value is negative, reverse orientation. + if (major.x[major.c.abs().max_ind()] < 0) { + major.mul(-1) + } // minor is normal and in xy plane minor = m.getcol(3-tobj.min_ind-tobj.max_ind) minor.x[2] = 0 minor.div(minor.mag) -if (g != nil) { -g.beginline(4, 3) g.line(mean.x[0], mean.x[1]) -g.line(mean.x[0] + 20*major.x[0], mean.x[1] + 20*major.x[1]) g.flush -} + if (g != nil) { + g.beginline(4, 3) g.line(mean.x[0], mean.x[1]) + g.line(mean.x[0] + 20*major.x[0], mean.x[1] + 20*major.x[1]) g.flush + } d = new Vector(pts.ncol) rad = new Vector(pts.ncol) for i=0, pts.ncol-1 {