def main(): # pragma: no cover import os from pyNastran.converters.stl.stl_reader import STL m1 = STL() m1.read_stl('tetgen_test.stl') m1.flip_normals() m1.write_stl('tetgen_test_flipped.stl') del m1 os.system('tetgen.exe -pqcvVqY tetgen_test_flipped.stl') m = Tetgen() base = 'tetgen_test_flipped.1' m.read_tetgen(base + '.node', base + '.smesh', base + '.ele', dimension_flag=3) m.write_nastran(base + '.bdf')
def stl_reshape(data): if '--xy' not in data: data['--xy'] = False if '--yz' not in data: data['--yz'] = False if '--xz' not in data: data['--xz'] = False if '--scale' not in data: data['--scale'] = None if '--xscale' not in data: data['--xscale'] = None if '--yscale' not in data: data['--yscale'] = None if '--zscale' not in data: data['--zscale'] = None if '<xshift>' not in data: data['<xshift>'] = None if '<yshift>' not in data: data['<yshift>'] = None if '<zshift>' not in data: data['<zshift>'] = None if '--stats' not in data: data['--stats'] = None if '--mirror' not in data: data['--mirror'] = None if '--flip_normals' not in data: data['--flip_normals'] = None in_stl_filename = data['<in_stl_filename>'] out_stl_filename = data['<out_stl_filename>'] assert in_stl_filename != out_stl_filename stl = STL() stl.read_stl(in_stl_filename) if data['<fmt>'] in ['False', False]: is_binary = True fmt = None else: fmt = data['<fmt>'] is_binary = False print('is_binary=%s' % is_binary) if data['--xy'] or data['--yz'] or data['--xz']: scale = 1. if data['--scale'] is not None: scale = float(data['--scale']) if data['--xy']: assert data['--yz'] is False assert data['--xz'] is False axes = 'xy' elif data['--yz']: assert data['--xy'] is False assert data['--xz'] is False axes = 'yz' elif data['--xz']: assert data['--xy'] is False assert data['--yz'] is False axes = 'xz' #print('flip_axes = %r' % axes) #print(data) stl.flip_axes(axes, scale) elif data['--xscale'] or data['--yscale'] or data['--zscale']: xscale = 1. yscale = 1. zscale = 1. if data['--xscale'] is not None: xscale = float(data['--xscale'].strip("'")) if data['--yscale'] is not None: yscale = float(data['--yscale'].strip("'")) if data['--zscale'] is not None: zscale = float(data['--zscale'].strip("'")) x = deepcopy(stl.nodes[:, 0]) y = deepcopy(stl.nodes[:, 1]) z = deepcopy(stl.nodes[:, 2]) stl.nodes[:, 0] = x * xscale stl.nodes[:, 1] = y * yscale stl.nodes[:, 2] = z * zscale elif data['<xshift>'] or data['<yshift>'] or data['<zshift>']: xshift = 1. yshift = 1. zshift = 1. if data['<xshift>'] is not None: if isinstance(xshift, basestring): xshift = float(data['<xshift>'].strip("'")) else: xshift = float(data['<xshift>']) if data['<yshift>'] is not None: if isinstance(xshift, basestring): yshift = float(data['<yshift>'].strip("'")) else: yshift = float(data['<yshift>']) if data['<zshift>'] is not None: if isinstance(xshift, basestring): zshift = float(data['<zshift>'].strip("'")) else: zshift = float(data['<zshift>']) print('delta = (%s, %s, %s)' % (xshift, yshift, zshift)) stl.nodes[:, 0] += xshift stl.nodes[:, 1] += yshift stl.nodes[:, 2] += zshift elif data['--scale'] : scale = float(data['--scale']) stl.nodes *= scale elif data['--stats'] : xmax, ymax, zmax = stl.nodes.max(axis=0) xmin, ymin, zmin = stl.nodes.min(axis=0) print('xyz_max = (%g, %g, %g)' % (xmax, ymax, zmax)) print('xyz_min = (%g, %g, %g)' % (xmin, ymin, zmin)) return elif data['--mirror']: #plane = data['plane'] #assert plane in ['xy', 'yz', 'xz'], 'plane=%r' % plane xyz = data['<xyz>'] tol = float(data['<tol>']) stl.create_mirror_model(xyz, tol) elif data['--flip_normals']: stl.flip_normals() else: raise RuntimeError('unsupported reshape...data=%s' % data) stl.write_stl(out_stl_filename, is_binary=is_binary, float_fmt=fmt)