From b915b42d6ebef28de02435f7382b0110e32068a3 Mon Sep 17 00:00:00 2001 From: Joshua Steer <Joshua.Steer@soton.ac.uk> Date: Tue, 30 Oct 2018 09:35:19 +0000 Subject: [PATCH] Updates to trim --- AmpScan/ampVis.py | 9 ++++++--- AmpScan/trim.py | 43 ++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/AmpScan/ampVis.py b/AmpScan/ampVis.py index 3a13a99..b33ab41 100644 --- a/AmpScan/ampVis.py +++ b/AmpScan/ampVis.py @@ -289,7 +289,7 @@ class visMixin(object): def genIm(self, size=[512, 512], views=[[0, -1, 0]], background=[1.0, 1.0, 1.0], projection=True, shading=True, mag=10, out='im', fh='test.tiff', - zoom=1.0, az = 0, crop=False): + zoom=1.0, az = 0, crop=False, cam=None): r""" Creates a temporary off screen vtkRenWin which is then either returned as a numpy array or saved as a .png file @@ -326,6 +326,7 @@ class visMixin(object): self.addActor() # Generate a renderer window win = vtkRenWin() + win.OffScreenRenderingOn() # Set the number of viewports win.setnumViewports(len(views)) # Set the background colour @@ -334,13 +335,15 @@ class visMixin(object): win.setProjection(projection) win.SetSize(size[0], size[1]) win.Modified() - win.OffScreenRenderingOn() + for i, view in enumerate(views): # win.addAxes([self.actor,], color=[0.0, 0.0, 0.0], viewport=i) win.setView(view, i) # win.setProjection(projection, viewport=i) win.renderActors([self.actor,], zoom=zoom) win.rens[0].GetActiveCamera().Azimuth(az) + if cam is not None: + win.rens[0].SetActiveCamera(cam) win.Render() if out == 'im': im = win.getImage() @@ -351,7 +354,7 @@ class visMixin(object): mask = np.all(im == 1, axis=2) mask = ~np.all(mask, axis=0) im = im[:, mask, :] - return im + return im, win elif out == 'fh': win.getScreenshot(fh) return diff --git a/AmpScan/trim.py b/AmpScan/trim.py index 3e198b8..4a31d59 100644 --- a/AmpScan/trim.py +++ b/AmpScan/trim.py @@ -30,25 +30,26 @@ class trimMixin(object): >>> amp.planarTrim(100, 2) """ - if type(height)==float: +# if isinstance(height, float): # planar values for each vert on face - fv = self.vert[self.faces, plane] - # Number points on each face are above cut plane - fvlogic = (fv > height).sum(axis=1) - # Faces with points both above and below cut plane - adjf = self.faces[np.logical_or(fvlogic == 2, fvlogic == 1)] - # Get adjacent vertices - adjv = np.unique(adjf) - # Get vert above height and set to height - abvInd = adjv[self.vert[adjv, plane] > height] - self.vert[abvInd, plane] = height - # Find all verts above plane - delv = self.vert[:, plane] > height - # Reorder verts to account for deleted one - vInd = np.cumsum(~delv) - 1 - self.faces = self.faces[fvlogic != 3, :] - self.faces = vInd[self.faces] - self.vert = self.vert[~delv, :] - self.calcStruct() - else: - raise TypeError("height arg must be a float") \ No newline at end of file + fv = self.vert[self.faces, plane] + # Number points on each face are above cut plane + fvlogic = (fv > height).sum(axis=1) + # Faces with points both above and below cut plane + adjf = self.faces[np.logical_or(fvlogic == 2, fvlogic == 1)] + # Get adjacent vertices + adjv = np.unique(adjf) + # Get vert above height and set to height + abvInd = adjv[self.vert[adjv, plane] > height] + self.vert[abvInd, plane] = height + # Find all verts above plane + delv = self.vert[:, plane] > height + # Reorder verts to account for deleted one + vInd = np.cumsum(~delv) - 1 + self.faces = self.faces[fvlogic != 3, :] + self.faces = vInd[self.faces] + self.vert = self.vert[~delv, :] + self.values = self.values[~delv] + self.calcStruct() +# else: +# raise TypeError("height arg must be a float") \ No newline at end of file -- GitLab