From 0723c0b769c3a8b21afae87aaa70270d6f7ff509 Mon Sep 17 00:00:00 2001 From: Michael Krayer Date: Fri, 13 Aug 2021 01:16:27 +0200 Subject: [PATCH] storing triangulation data as long list of vertices now. Seems to have improved performance due to better memory access pattern. --- field.py | 148 +++++++++++++++++++++++++------------------------------ 1 file changed, 68 insertions(+), 80 deletions(-) diff --git a/field.py b/field.py index 8a0da86..82af5f9 100644 --- a/field.py +++ b/field.py @@ -696,6 +696,7 @@ class Features3d: import pyvista as pv import vtk from scipy import ndimage, spatial + from time import time # Check if '_input' is available: might have been dropped after initialization assert self._input is not None, "'_input' not available. Initialize object with keep_input=True flag." # Wrap data for VTK using pyvista @@ -707,22 +708,21 @@ class Features3d: # Compute full contour: ensure we only have triangles to efficiently extract points # later on. if report: print('[Features3d.triangulate] computing isocontour using {}...'.format(contour_method)) - contour_ = datavtk.contour([self._threshold],method=contour_method,compute_scalars=False) - assert contour_.is_all_triangles(), "Contouring produced non-triangle cells." + contour = datavtk.contour([self._threshold],method=contour_method,compute_scalars=False) + assert contour.is_all_triangles(), "Contouring produced non-triangle cells." # Compute the connectivity of the triangulated surface: first we run an ordinary # connectivity filter neglecting periodic wrapping. if report: print('[Features3d.triangulate] computing connectivity...') alg = vtk.vtkPolyDataConnectivityFilter() # ~twice as fast as default vtkConnectivityFilter - alg.SetInputData(contour_) + alg.SetInputData(contour) alg.SetExtractionModeToAllRegions() alg.SetColorRegions(True) alg.Update() - contour_ = pv.filters._get_output(alg) + contour = pv.filters._get_output(alg) # Now determine the boundary points, i.e. points on the boundary which have a corresponding # vertex on the other side of the domain if report: print('[Features3d.triangulate] correcting connectivity for periodic boundaries...') - points = contour_.points - bd_points_xyz = np.zeros((0,3),dtype=points.dtype) + bd_points_xyz = np.zeros((0,3),dtype=contour.points.dtype) bd_points_idx = np.zeros((0,),dtype=np.int) for axis in range(3): if not self.periodicity[axis]: continue @@ -732,19 +732,19 @@ class Features3d: period[axis] = bound_pos-datavtk.origin[axis] bound_dist = 1e-5*datavtk.spacing[axis] # Lower boundary - li = np.abs(points[:,axis]-datavtk.origin[axis])