diff --git a/AmpScan/AmpScanGUI.py b/AmpScan/AmpScanGUI.py index 80dd68e87ac164e5e78b7d8eb5714134ef80cace..d010817f67daec479f7d2bdfec27f19903d97995 100644 --- a/AmpScan/AmpScanGUI.py +++ b/AmpScan/AmpScanGUI.py @@ -1,9 +1,9 @@ import sys import numpy as np -from core import AmpObject -from registration import regObject -from ampVis import qtVtkWindow -from pressSens import pressSense +from .core import AmpObject +from .registration import regObject +from .ampVis import qtVtkWindow +from .pressSens import pressSense from PyQt5.QtCore import QPoint, QSize, Qt, QTimer, QRect, pyqtSignal from PyQt5.QtGui import (QColor, QFontMetrics, QImage, QPainter, QIcon, QOpenGLVersionProfile) diff --git a/AmpScan/analyse.py b/AmpScan/analyse.py index 9a4c7fc189238deea6479c9369db5daa3b3912bc..e554ffa2e92cb1a2ee3978ec4e02ed7a04c963ab 100644 --- a/AmpScan/analyse.py +++ b/AmpScan/analyse.py @@ -9,7 +9,7 @@ import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from collections import defaultdict -import AmpScan.cython_ext as cyext +#import cython_ext as cyext diff --git a/AmpScan/core.py b/AmpScan/core.py index e329c8bd633cb22acd7320f627d2cd61ff5947a6..2418beae95cc1d1dc0be374672855f487923822d 100644 --- a/AmpScan/core.py +++ b/AmpScan/core.py @@ -33,18 +33,18 @@ Finite Element Analysis import numpy as np import struct -from autoAlign import alignMixin -from trim import trimMixin -from smooth import smoothMixin -from analyse import analyseMixin -from ampVis import visMixin -from fe import feMixin -from tsbSocketDesign import socketDesignMixin - -class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, +from .align import rotMatrix +from .trim import trimMixin +from .smooth import smoothMixin +from .analyse import analyseMixin +from .ampVis import visMixin +from .fe import feMixin +from .tsbSocketDesign import socketDesignMixin + +class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin, feMixin, socketDesignMixin): - def __init__(self, Data, stype): + def __init__(self, data, stype='limb'): c1 = [31.0, 73.0, 125.0] c3 = [170.0, 75.0, 65.0] c2 = [212.0, 221.0, 225.0] @@ -54,19 +54,10 @@ class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, self.CMapN2P = np.transpose(CMap)/255.0 self.CMap02P = np.flip(np.transpose(CMap1)/255.0, axis=0) self.stype = stype - self.actors = {} - if stype in ['limb', 'socket', 'reglimb', 'regsocket', 'MRI']: - self.addData(Data, stype) - elif stype is 'AmpObj': - for d in Data.stype: - setattr(self, d, getattr(Data, d)) - self.stype.append(d) - self.actors = Data.actors - elif stype is 'FE': + if stype is 'FE': self.addFE([Data,]) else: - raise ValueError('stype not supported, please choose from ' + - 'limb, socket, reglimb, regsocket, MRI or AmpObj') + self.read_stl(data) def createCMap(self, cmap=None, n = 50): """ @@ -75,15 +66,6 @@ class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, if cmap is None: cmap = n - - def addData(self, Data, stype): - if isinstance(Data, str): - self.stype.append(stype) - self.read_stl(Data, stype) - # Import stl as filename - elif isinstance(Data, dict): - self.stype.append(stype) - setattr(self, stype, Data) def read_stl(self, filename, unify=True, edges=True, vNorm=True): """ @@ -128,7 +110,7 @@ class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, if edges is True: self.computeEdges() if vNorm is True: - self.vNorm() + self.calcVNorm() def unify_vertices(self): """ @@ -157,7 +139,7 @@ class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, self.edges = np.reshape(self.faces[:, [0, 1, 0, 2, 1, 2]], [-1, 2]) self.edges = np.sort(self.edges, 1) # Get edges on each face - self.edgeFaces = np.reshape(range(len(self.faces)*3), [-1,3]) + self.edgesFace = np.reshape(range(len(self.faces)*3), [-1,3]) # Unify the edges self.edges, indC = np.unique(self.edges, return_inverse=True, axis=0) #Remap the edgesFace array @@ -185,7 +167,7 @@ class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, ndx = np.searchsorted(f[o_idx], range(self.vert.shape[0]), side='right') ndx = np.r_[0, ndx] norms = self.norm[self.faces, :][row, col, :] - self.vNorm = np.zeros(data['vert'].shape) + self.vNorm = np.zeros(self.vert.shape) for i in range(self.vert.shape[0]): self.vNorm[i, :] = norms[ndx[i]:ndx[i+1], :].mean(axis=0) @@ -242,6 +224,10 @@ class AmpObject(alignMixin, trimMixin, smoothMixin, analyseMixin, Centre the AmpObj based upon the mean of all the vertices """ self.translate(-self.vert.mean(axis=0)) + + def rotate(self, rot): + R = rotMatrix(rot) + self.vert = np.dot(self.vert, np.transpose(R)) def man_rot(self, rot): """ diff --git a/AmpScan/fe.py b/AmpScan/fe.py index 1c6e5d113dfcbe9d4533369e215b3c924501fa29..f64ec05df208231d8f8b413ed1262ec805e57835 100644 --- a/AmpScan/fe.py +++ b/AmpScan/fe.py @@ -14,25 +14,26 @@ class feMixin(object): data = np.load(files[0], encoding='bytes').item() for k in list(data.keys()): data[str(k, 'utf-8')] = data.pop(k) + for k, v in data.items(): + setattr(self, k, v) if len(files) == 3: data = {} names = ['vert', 'faces', 'values'] for n, f in zip(names, files): data[n] = np.loadtxt(f) - self.FE = data self.getSurf() def getSurf(self): - valInd = self.FE['values'][:, 0].astype(int) - log = np.isin(self.FE['faces'], valInd) - f = self.FE['faces'][log].reshape([-1, 4]) - log = np.zeros(len(self.FE['vert']), dtype=bool) + valInd = self.values[:, 0].astype(int) + log = np.isin(self.faces, valInd) + f = self.faces[log].reshape([-1, 4]) + log = np.zeros(len(self.vert), dtype=bool) log[valInd] = True fInd = np.cumsum(log) - 1 - self.FE['vert'] = self.FE['vert'][log, :] - self.FE['faces'] = fInd[f].astype(np.int64) - self.FE['values'] = np.array(self.FE['values'][:, 1]) - self.FE['edges'] = np.reshape(self.FE['faces'][:, [0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3]], [-1, 2]) - self.FE['edges'] = np.sort(self.FE['edges'], 1) + self.vert = self.vert[log, :] + self.faces = fInd[f].astype(np.int64) + self.values = np.array(self.values[:, 1]) + self.edges = np.reshape(self.faces[:, [0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3]], [-1, 2]) + self.edges = np.sort(self.edges, 1) # Unify the edges - self.FE['edges'], indC = np.unique(self.FE['edges'], return_inverse=True, axis=0) \ No newline at end of file + self.edges, indC = np.unique(self.edges, return_inverse=True, axis=0) \ No newline at end of file diff --git a/AmpScan/registration.py b/AmpScan/registration.py index 7d608cf33ae8c942ab90d637416942589de20f71..da56c68595deed0b674a8e1741443346cae60783 100644 --- a/AmpScan/registration.py +++ b/AmpScan/registration.py @@ -7,7 +7,7 @@ Created on Wed Sep 13 16:07:10 2017 import numpy as np import pandas as pd from scipy import spatial -from core import AmpObject +from .core import AmpObject """ import os path = ('J:\\Shared Resources\\AmpScan IfLS Team\\' diff --git a/AmpScan/socketDesignGUI.py b/AmpScan/socketDesignGUI.py index d7bc5fe7f9b4dbfc6509e4d0f3fb713ec222a3e0..6d53e65efb0c80b83ea88411acc7db9bc1128685 100644 --- a/AmpScan/socketDesignGUI.py +++ b/AmpScan/socketDesignGUI.py @@ -7,9 +7,9 @@ Created on Tue Oct 10 16:21:12 2017 import sys import numpy as np -from core import AmpObject -from ampVis import qtVtkWindow -from tsbSocketDesign import dragSpline +from .core import AmpObject +from .ampVis import qtVtkWindow +from .tsbSocketDesign import dragSpline from PyQt5.QtWidgets import (QAction, QApplication, QGridLayout, QMainWindow, QFileDialog, QWidget) from PyQt5.QtGui import QIcon