def isosurf_builtin(self, event=None): from PYME.experimental import isosurface from PYME.LMVis import gl_render3D_shaders as glrender from PYME.LMVis.layers.mesh import TriangleRenderLayer glcanvas = new_mesh_viewer() #glrender.showGLFrame() glcanvas.layer_data = {} for i in range(self.image.data.shape[3]): isolevel = self.do.Offs[i] + .5 / self.do.Gains[i] T = isosurface.isosurface(self.image.data[:, :, :, i].astype('f'), isolevel=isolevel, voxel_size=self.image.voxelsize, origin=self.image.origin) glcanvas.layer_data[self.image.names[i]] = T layer = TriangleRenderLayer( glcanvas.layer_data, dsname=self.image.names[i], method='shaded', context=glcanvas.gl_context, cmap=['C', 'M', 'Y', 'R', 'G', 'B'][i % 6], #normal_mode='Per face', #use face normals rather than vertex normals, as there is currently a bug in computation of vertex normals ) glcanvas.add_layer(layer) layer.engine._outlines = False layer.show_lut = False self.canvases.append(glcanvas) glcanvas.displayMode = '3D' glcanvas.fit_bbox() glcanvas.Refresh()
def gen_isosurface(visFr): from PYME.LMVis.layers.mesh import TriangleRenderLayer from PYME.recipes.surface_fitting import DualMarchingCubes oc_name = gen_octree_from_points(visFr) surf_name, surf_count = visFr.pipeline.new_ds_name('surf', return_count=True) recipe = visFr.pipeline.recipe dmc = DualMarchingCubes(recipe, invalidate_parent=False, input=oc_name, output=surf_name) if dmc.configure_traits(kind='modal'): recipe.add_module(dmc) recipe.execute() print('Isosurface generated, adding layer') layer = TriangleRenderLayer(visFr.pipeline, dsname=surf_name, method='shaded', cmap=['C', 'M', 'Y', 'R', 'G', 'B'][surf_count % 6]) visFr.add_layer(layer) dmc._invalidate_parent = True print('Isosurface layer added')
def gen_isosurface_from_tesselation(visFr): from PYME.LMVis.layers.mesh import TriangleRenderLayer from PYME.recipes.surface_fitting import MarchingTetrahedra surf_count = 0 oc_name = 'delaunay%d' % surf_count surf_name, surf_count = visFr.pipeline.new_ds_name('surf') recipe = visFr.pipeline.recipe mt = MarchingTetrahedra(recipe, invalidate_parent=False, input=oc_name, output=surf_name) if mt.configure_traits(kind='modal'): recipe.add_module(mt) recipe.execute() print('Isosurface generated, adding layer') layer = TriangleRenderLayer(visFr.pipeline, dsname=surf_name, method='shaded', cmap=['C', 'M', 'Y', 'R', 'G', 'B'][surf_count % 6]) visFr.add_layer(layer) mt._invalidate_parent = True print('Isosurface layer added')
def open_surface(visFr): import wx # from PYME.experimental import triangle_mesh from PYME.experimental import _triangle_mesh as triangle_mesh from PYME.LMVis.layers.mesh import TriangleRenderLayer filename = wx.FileSelector( "Choose a file to open", default_extension='stl', wildcard='STL mesh (*.stl)|*.stl|PLY mesh (*.ply)|*.ply') #print filename if not filename == '': surf_count = 0 surf_name = 'surf%d' % surf_count while surf_name in visFr.pipeline.dataSources.keys(): surf_count += 1 surf_name = 'surf%d' % surf_count ext = filename.split('.')[-1] if ext == 'stl': visFr.pipeline.dataSources[ surf_name] = triangle_mesh.TriangleMesh.from_stl(filename) elif ext == 'ply': visFr.pipeline.dataSources[ surf_name] = triangle_mesh.TriangleMesh.from_ply(filename) else: raise ValueError('Invalid file extension .' + str(ext)) layer = TriangleRenderLayer(visFr.pipeline, dsname=surf_name, method='shaded') visFr.add_layer(layer)
def gen_isosurface_from_tesselation(visFr): from PYME.LMVis.layers.mesh import TriangleRenderLayer from PYME.recipes.surface_fitting import DelaunayMarchingTetrahedra if 'delaunay0' not in visFr.pipeline.dataSources.keys(): del_name = add_tesselation(visFr) else: _, c = visFr.pipeline.new_ds_name('delaunay', return_count=True) del_name = 'delaunay{}'.format(c-1) if 'dn' not in visFr.pipeline.dataSources[del_name].keys(): # visFr.pipeline.selectDataSource(del_name) estimate_density(visFr) surf_name, surf_count = visFr.pipeline.new_ds_name('surf', return_count=True) recipe = visFr.pipeline.recipe mt = DelaunayMarchingTetrahedra(recipe, invalidate_parent=False, input=del_name, output=surf_name) if mt.configure_traits(kind='modal'): recipe.add_modules_and_execute([mt,]) print('Isosurface generated, adding layer') layer = TriangleRenderLayer(visFr.pipeline, dsname=surf_name, method='shaded', cmap = ['C', 'M', 'Y', 'R', 'G', 'B'][surf_count % 6]) visFr.add_layer(layer) mt._invalidate_parent = True print('Isosurface layer added')
def add_tesselation_layer(visFr): from PYME.LMVis.layers.mesh import TriangleRenderLayer surf_name = add_tesselation(visFr) if surf_name is not None: layer = TriangleRenderLayer(visFr.pipeline, dsname=surf_name, method='flat', cmap='hot') visFr.add_layer(layer) print('Tesselation layer added')
def OnLoadHarmonicRepresentation(self, wx_event): import wx from PYME.IO import tabular, FileUtils from PYME.Analysis.points.spherical_harmonics import scaled_shell_from_hdf import PYME.experimental._triangle_mesh as triangle_mesh from PYME.LMVis.layers.mesh import TriangleRenderLayer fdialog = wx.FileDialog( None, 'Load Spherical Harmonic Representation', wildcard='Harmonic shell (*.hdf)|*.hdf', style=wx.FD_OPEN, defaultDir=FileUtils.nameUtils.genShiftFieldDirectoryPath()) succ = fdialog.ShowModal() if (succ == wx.ID_OK): path = fdialog.GetPath() fdialog.Destroy() else: fdialog.Destroy() return shell = scaled_shell_from_hdf(path) points = tabular.MappingFilter(self.pipeline.selectedDataSource) separations, closest_points = shell.distance_to_shell( (points['x'], points['y'], points['z']), d_angles=self.d_angle) self._shells.append(shell) shell_number = len(self._shells) points.addColumn('distance_to_loaded_shell%d' % shell_number, separations) points.addColumn( 'inside_shell%d' % shell_number, shell.check_inside(points['x'], points['y'], points['z'])) self.pipeline.addDataSource('shell%d_mapped' % shell_number, points) self.pipeline.selectDataSource('shell%d_mapped' % shell_number) v, f = shell.get_mesh_vertices_faces(self.d_angle) surf = triangle_mesh.TriangleMesh(v, f) self.pipeline.dataSources['shell_surface'] = surf layer = TriangleRenderLayer(self.pipeline, dsname='shell_surface', method='shaded', cmap='C') self.vis_frame.add_layer(layer) self.vis_frame.RefreshView()
def OnCalcHarmonicRepresentation(self, wx_event): from PYME.recipes import surface_fitting import PYME.experimental._triangle_mesh as triangle_mesh from PYME.LMVis.layers.mesh import TriangleRenderLayer recipe = self.pipeline.recipe shell_maker = surface_fitting.SphericalHarmonicShell( recipe, input_name=self.pipeline.selectedDataSourceKey, output_name='harmonic_shell') if shell_maker.configure_traits(kind='modal'): recipe.add_modules_and_execute([ shell_maker, ]) shell = recipe.namespace['harmonic_shell'] shell_mapped = recipe.namespace['shell_mapped'] self._shells.append(shell) self.pipeline.addDataSource('shell_mapped', shell_mapped) self.pipeline.selectDataSource('shell_mapped') # Add a surface rendering v, f = shell.get_mesh_vertices_faces(self.d_angle) surf = triangle_mesh.TriangleMesh(v, f) self.pipeline.dataSources['shell_surface'] = surf layer = TriangleRenderLayer(self.pipeline, dsname='shell_surface', method='shaded', cmap='C') self.vis_frame.add_layer(layer) self.vis_frame.RefreshView()