def detect(appdir): """Detect the apps present in the specified appdir. Parameters: - `appdir`: path to an appdir (i.e. a directory containing a file '__init__.py' Return a list with all the pyFormex apps in that appdir. If a file '.apps.dir' exists in the appdir, the returned list is the contents of that file. Otherwise the list contains all '.py' files in the directory, without the '.py' extension and sorted. """ # Detect, but do not load!!!! # because we are using this on import (before some applications can load) appsdir = os.path.join(appdir, '.apps.dir') if os.path.exists(appsdir): with open(appsdir, 'r') as fil: apps = fil.readlines() return [a.strip('\n').strip() for a in apps] else: files = utils.listTree(appdir, listdirs=False, excludedirs=['.*'], includefiles=['.*\.py$']) apps = [os.path.basename(f) for f in files] apps = [os.path.splitext(f)[0] for f in apps if f[0] not in '._'] return sorted(apps)
def Shaders(): """Return a list of the available GPU shader programs. Shader programs are in the pyformex/glsl directory and consist at least of two files: 'vertex_shader_SHADER.c' and 'fragment_shader_SHADER.c'. This function will return a list of all the SHADER filename parts currently available. The default shader programs do not have the '_SHADER' part and will not be contained in this list. """ from pyformex import utils files = utils.listTree( pf.cfg['shaderdir'], listdirs=False, sorted=True, includefiles=['vertex_shader_.*\.c$', 'fragment_shader_.*\.c$']) files = [os.path.basename(f) for f in files] vshaders = [f[14:-2] for f in files if f.startswith('v')] fshaders = [f[16:-2] for f in files if f.startswith('f')] shaders = set(vshaders) & set(fshaders) return sorted(shaders)
def dicom2numpy(files): """Read a set of DICOM image files. Parameters: - `files`: a list of file names of dicom images of the same size, or a directory containing such images. In the latter case, all the DICOM images in the directory will be read. Returns a tuple of: - `pixar`: a 3D array with the pixel data of all the images. The first axis is the `z` value, the last the `x`. - `scale`: a (3,) array with the scaling factors, in order (x,y,z). """ if isinstance(files, str): files = utils.listTree(files, listdirs=False, includefiles="*.dcm") # read and stack the images print("Using %s to read DICOM files" % readDicom.__name__) pixar = np.dstack([readDicom(f) for f in files]) scale = _dicom_spacing return pixar, scale
"""create_manifest.py This script creates the MANIFEST file which lists all the files to be included in a pyFormex source distribution. """ from pyformex.utils import listTree files = [ 'README', 'post-install', 'pyformex-pyformex.desktop', 'pyformex-viewer', 'setup.py', ] + \ listTree('pyformex',listdirs=False,sorted=True, excludedirs=['.svn'], includedirs=['gui','plugins'], includefiles=['.*\.py$','pyformex(rc)?$']) + \ listTree('pyformex/icons',listdirs=False,sorted=True, excludedirs=['.svn'], includefiles=['.*\.xpm$','pyformex.*\.png$']) + \ listTree('pyformex/lib',listdirs=False,sorted=True, excludedirs=['.svn'], includefiles=['.*\.c$','configure(_py)?$','Makefile.in$','__init__.py$']) + \ listTree('pyformex/examples',listdirs=False,sorted=True, excludedirs=['.svn'], excludefiles=['.*\.pyc','.*~$'], includefiles=['.*\.py$','scripts.cat','README'] ) + \ listTree('pyformex/data',listdirs=False,sorted=True, excludedirs=['.svn'], excludefiles=['.*\.pyc','.*~$']
## # """Setup script for pyFormex To install pyFormex: python setup.py install --prefix=/usr/local To uninstall pyFormex: pyformex --remove """ from distutils.command.install import install as _install from distutils.command.build_ext import build_ext as _build_ext from distutils.core import setup, Extension import os,sys,commands from pyformex.utils import listTree DOC_FILES = [ f[9:] for f in listTree('pyformex/doc',listdirs=False) ] EXT_MODULES = [ 'drawgl', 'misc', '_nurbs_' ] DATA_FILES = [ ('pixmaps', ['pyformex/icons/pyformex-64x64.png']), ('applnk', ['pyformex-pyformex.desktop']), ] class install(_install): def run(self): _install.run(self) print("Running pyFormex post-install script") os.system("./post-install")
def run(): global width, height, FA, dia, dotsize clear() smooth() lights(False) view('front') # reading image files fp = askFilename() if not fp: return print("You selected %s" % fp) dirname, base, ext = utils.splitFilename(fp) if ext: filepat = ['.*\.%s$' % ext[1:]] else: filepat = None files = utils.listTree(dirname, listdirs=False, sorted=True, includefiles=filepat) print("Number of files: %s" % len(files)) pf.GUI.setBusy() DS = DicomStack(files) pf.GUI.setBusy(False) print("z-value of the slices:]n", DS.zvalue()) raw = ack("Use RAW values instead of Hounsfield?") pf.GUI.setBusy() pixar = DS.pixar(raw).astype(Float) # TODO: Set in DicomStack print(pixar.shape) print("Data: %s (%s..%s)" % (pixar.dtype, pixar.min(), pixar.max())) scale = DS.spacing() origin = DS.origin() zscale = origin[1:, 2] - origin[:-1, 2] if allcloseV(scale) and allcloseV(origin[:, :2]) and allcloseV(zscale): scale = scale[0] scale[2] = zscale[0] print("Scale: %s " % scale) else: print("Scale/origin is not uniform!") maxval = pixar.max() nx, ny, nz = pixar.shape # Create a 2D grid of nx*ny elements model = 'Dots' dotsize = 3 if model == 'Dots': base = '1:0' else: base = '4:0123' F = Formex(base).replic2(nx, ny).toMesh().reflect( 1) # Image rows are top down, should change in DicomStack for iz in range(nz): color = pixar[:, :, iz] / Float(maxval) color = repeat(color[..., newaxis], 3).reshape(-1, 3) F.addField('node', color, 'slice_%s' % iz) FA = draw(F, color='fld:slice_0', colormap=None, marksize=dotsize, name='image') pf.GUI.setBusy(False) nframes = nz frame = 0 dia = Dialog([ _I('frame', frame, itemtype='slider', min=0, max=nframes - 1, func=setFrame), ]) dia['frame'].setMinimumWidth(800) dia.show()