diff --git a/AmpScan/registration.py b/AmpScan/registration.py index 4cf2039b7a850176f707dc661483d012f30a211d..ce105833a3fb265ab13a848510ac974a20121bce 100644 --- a/AmpScan/registration.py +++ b/AmpScan/registration.py @@ -86,53 +86,52 @@ class registration(object): [self.b.vert, self.b.faces, self.b.values])) regData = copy.deepcopy(bData) self.reg = AmpObject(regData, stype='reg') + self.disp = AmpObject({'vert': np.zeros(self.reg.vert.shape), + 'faces': self.reg.faces, + 'values':self.reg.values}) if scale is not None: tmin = self.t.vert.min(axis=0)[2] rmin = self.reg.vert.min(axis=0)[2] SF = ((tmin-scale)/(rmin-scale)) - 1 logic = self.reg.vert[:, 2] < scale d = (self.reg.vert[logic, 2] - scale) * SF - self.reg.vert[logic, 2] += d + self.disp.vert[logic, 2] += d + self.reg.vert = self.b.vert + self.disp.vert normals = np.cross(self.t.vert[self.t.faces[:,1]] - self.t.vert[self.t.faces[:,0]], self.t.vert[self.t.faces[:,2]] - self.t.vert[self.t.faces[:,0]]) mag = (normals**2).sum(axis=1) - if subset is None: - rVert = self.reg.vert - else: - rVert = self.reg.vert[subset] for step in np.arange(steps, 0, -1, dtype=float): # Index of 10 centroids nearest to each baseline vertex - ind = tTree.query(rVert, neigh)[1] -# D = np.zeros(self.reg.vert.shape) + ind = tTree.query(self.reg.vert, neigh)[1] # Define normals for faces of nearest faces norms = normals[ind] # Get a point on each face fPoints = self.t.vert[self.t.faces[ind, 0]] # Calculate dot product between point on face and normals d = np.einsum('ijk, ijk->ij', norms, fPoints) - t = (d - np.einsum('ijk, ik->ij', norms, rVert))/mag[ind] + t = (d - np.einsum('ijk, ik->ij', norms, self.reg.vert))/mag[ind] # Calculate the vector from old point to new point - G = rVert[:, None, :] + np.einsum('ijk, ij->ijk', norms, t) + G = self.reg.vert[:, None, :] + np.einsum('ijk, ij->ijk', norms, t) # Ensure new points lie inside points otherwise set to 99999 # Find smallest distance from old to new point if inside is False: - G = G - rVert[:, None, :] + G = G - self.reg.vert[:, None, :] GMag = np.sqrt(np.einsum('ijk, ijk->ij', G, G)) GInd = GMag.argmin(axis=1) else: - G, GInd = self.__calcBarycentric(rVert, G, ind) + G, GInd = self.__calcBarycentric(self.reg.vert, G, ind) # Define vector from baseline point to intersect point D = G[np.arange(len(G)), GInd, :] - rVert += D/step +# rVert += D/step + self.disp.vert += D/step if smooth > 0 and step > 1: -# v = self.reg.vert[~subset] - self.reg.lp_smooth(smooth, brim = fixBrim) -# self.reg.vert[~subset] = v + self.disp.lp_smooth(smooth, brim = fixBrim) + self.reg.vert = self.b.vert + self.disp.vert else: + self.reg.vert = self.b.vert + self.disp.vert self.reg.calcNorm() - self.reg.calcStruct() self.reg.values[:] = self.calcError(error) diff --git a/AmpScan/ssm.py b/AmpScan/ssm.py index ba5133be3dd728f0fa5ba614029ce27510ea2ecc..4cb054114d06f753b486c4110968915fb28a4d80 100644 --- a/AmpScan/ssm.py +++ b/AmpScan/ssm.py @@ -9,6 +9,7 @@ import os import numpy as np from .core import AmpObject from .registration import registration +import os class pca(object): @@ -60,7 +61,7 @@ class pca(object): """ self.fnames = [f for f in os.listdir(path) if f.endswith('.stl')] - self.shapes = [AmpObject(path + f, 'limb', unify=unify) for f in self.fnames] + self.shapes = [AmpObject(os.path.join(path, f), 'limb', unify=unify) for f in self.fnames] for s in self.shapes: s.lp_smooth(3, brim=True) @@ -100,7 +101,7 @@ class pca(object): self.registered.append(r) if save is not None: for f, r in zip(self.fnames, self.registered): - r.save(save + f) + r.save(os.path.join(save, f)) self.X = np.array([r.vert.flatten() for r in self.registered]).T if baseline is True: self.X = np.c_[self.X, self.baseline.vert.flatten()] diff --git a/GUIs/AmpScanGUI.py b/GUIs/AmpScanGUI.py index 4ff33f64f4c2845c4bd52750c3e029c8225922ef..5534d4ebf92300bb5535bfb92093ad7a89d1952a 100644 --- a/GUIs/AmpScanGUI.py +++ b/GUIs/AmpScanGUI.py @@ -1,12 +1,10 @@ import sys import numpy as np -from vtk.util import numpy_support import vtk from AmpScan import AmpObject from AmpScan.registration import registration from AmpScan.align import align from AmpScan.ampVis import qtVtkWindow -from AmpScan.pressSens import pressSense from PyQt5.QtCore import QPoint, QSize, Qt, QTimer, QRect, pyqtSignal from PyQt5.QtGui import (QColor, QFontMetrics, QImage, QPainter, QIcon, QOpenGLVersionProfile)