Skip to content
Snippets Groups Projects
Commit 12969674 authored by Joshua Steer's avatar Joshua Steer
Browse files

pca, registration and smooth updates

parent 01a13b91
No related branches found
No related tags found
No related merge requests found
......@@ -25,8 +25,10 @@ class pca(object):
r"""
Function to import multiple stl files from folder
"""
self.shapes = [AmpObject(path + f, 'limb', unify=unify) for f in
os.listdir(path) if f.endswith('.stl')]
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]
for s in self.shapes:
s.lp_smooth(3, brim=True)
def sliceFiles(self, height):
r"""
......@@ -35,12 +37,22 @@ class pca(object):
for s in self.shapes:
s.planarTrim(height)
def register(self, scale=None):
def register(self, scale=None, save=None, baseline=True):
r"""
Function to register all the shapes to a baseline
"""
self.registered = [registration(self.baseline, t, fixBrim=True, steps=10).reg for t in self.shapes]
self.registered = []
for t in self.shapes:
r = registration(self.baseline, t, fixBrim=True, steps=5, scale=scale, smooth=1, neigh=50).reg
r.lp_smooth()
self.registered.append(r)
if save is not None:
for f, r in zip(self.fnames, self.registered):
r.save(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()]
def pca(self):
r"""
......
......@@ -48,7 +48,7 @@ class registration(object):
def point2plane(self, steps = 1, neigh = 10, inside = True, subset = None,
scale=False, smooth=1, fixBrim=False):
scale=None, smooth=1, fixBrim=False):
r"""
Point to Plane method for registration between the two meshes
......@@ -70,9 +70,6 @@ class registration(object):
If True, the nodes on the brim line will not be included in the smooth
"""
if fixBrim is True:
eidx = (self.b.faceEdges == -99999).sum(axis=1).astype(bool)
vBrim = np.unique(self.b.edges[eidx, :])
# Calc FaceCentroids
fC = self.t.vert[self.t.faces].mean(axis=1)
# Construct knn tree
......@@ -84,7 +81,7 @@ class registration(object):
if scale is not None:
tmin = self.t.vert.min(axis=0)[2]
rmin = self.reg.vert.min(axis=0)[2]
SF = 1 - ((tmin-scale)/(rmin-scale))
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
......@@ -122,14 +119,9 @@ class registration(object):
D = G[np.arange(len(G)), GInd, :]
rVert += D/step
if smooth > 0 and step > 1:
if fixBrim is True:
bPoints = rVert[vBrim, :].copy()
# v = self.reg.vert[~subset]
self.reg.lp_smooth(smooth)
self.reg.vert[vBrim, :] = bPoints
self.reg.lp_smooth(smooth, brim = fixBrim)
# self.reg.vert[~subset] = v
else:
self.reg.lp_smooth(smooth)
else:
self.reg.calcNorm()
......
......@@ -9,7 +9,7 @@ import copy
class smoothMixin(object):
def lp_smooth(self, n=1):
def lp_smooth(self, n=1, brim = True):
r"""
Function to apply a laplacian smooth to the mesh. This method replaces
each vertex with the mean of its connected neighbours
......@@ -21,6 +21,10 @@ class smoothMixin(object):
number of iterations of smoothing
"""
if brim is True:
eidx = (self.faceEdges == -99999).sum(axis=1).astype(bool)
vBrim = np.unique(self.edges[eidx, :])
else: vBrim = []
# Flatten the edges array to 1D
e = self.edges.flatten()
# Get the indicies to sort edges
......@@ -36,7 +40,10 @@ class smoothMixin(object):
# List all vertices
vert = copy.deepcopy(self.vert)
neighVerts = vert[self.edges[row, 1-col], :]
for j in np.arange(self.vert.shape[0]):
vRange = np.arange(self.vert.shape[0])
log = np.isin(vRange, vBrim)
vRange = vRange[~log]
for j in vRange:
# Calculate the mean of the vertex set
self.vert[j, :] = neighVerts[ndx[j]:ndx[j+1]].mean(axis=0)
self.calcNorm()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment