Mercurial > repos > iuc > icqsol_create_shape
comparison icqsol_create_shape.py @ 0:fe94052daa00 draft default tip
Uploaded
| author | iuc |
|---|---|
| date | Tue, 23 Aug 2016 15:00:22 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:fe94052daa00 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 import argparse | |
| 3 import shutil | |
| 4 | |
| 5 import icqsol_utils | |
| 6 | |
| 7 # Parse Command Line. | |
| 8 parser = argparse.ArgumentParser() | |
| 9 parser.add_argument('--create_process', dest='create_process', help='Shape creation process (create or clone)') | |
| 10 parser.add_argument('--shape_input', dest='shape_input', default=None, help='Shape file if create_process is clone') | |
| 11 parser.add_argument('--shape', dest='shape', default=None, help='Shape if create_process is create') | |
| 12 parser.add_argument('--origin_x', dest='origin_x', type=float, default=None, help='X coordinate of origin') | |
| 13 parser.add_argument('--origin_y', dest='origin_y', type=float, default=None, help='Y coordinate of origin') | |
| 14 parser.add_argument('--origin_z', dest='origin_z', type=float, default=None, help='Z coordinate of origin') | |
| 15 parser.add_argument('--length_x', dest='length_x', type=float, default=None, help='X coordinate of end') | |
| 16 parser.add_argument('--length_y', dest='length_y', type=float, default=None, help='Y coordinate of end') | |
| 17 parser.add_argument('--length_z', dest='length_z', type=float, default=None, help='Z coordinate of end') | |
| 18 parser.add_argument('--angle', dest='angle', type=float, default=None, help='Angle') | |
| 19 parser.add_argument('--radius', dest='radius', type=float, default=None, help='Radius') | |
| 20 parser.add_argument('--n_theta', dest='n_theta', type=int, default=0, help='Number of slices') | |
| 21 parser.add_argument('--n_phi', dest='n_phi', type=int, default=0, help='Number of stacks') | |
| 22 parser.add_argument('--rotate', dest='rotate', help='Rotate cloned shape') | |
| 23 parser.add_argument('--rotation_axis_x', dest='rotation_axis_x', type=float, default=None, help='X component of rotation axis') | |
| 24 parser.add_argument('--rotation_axis_y', dest='rotation_axis_y', type=float, default=None, help='Y component of rotation axis') | |
| 25 parser.add_argument('--rotation_axis_z', dest='rotation_axis_z', type=float, default=None, help='Z component of rotation axis') | |
| 26 parser.add_argument('--rotation_degree', dest='rotation_degree', type=float, default=None, help='Degree of rotation around axis') | |
| 27 parser.add_argument('--translate', dest='translate', help='Translate cloned shape') | |
| 28 parser.add_argument('--output', dest='output', default=None, help='Output dataset') | |
| 29 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output file format and type') | |
| 30 | |
| 31 args = parser.parse_args() | |
| 32 | |
| 33 if args.origin_x is not None and args.origin_y is not None and args.origin_z is not None: | |
| 34 origin = [args.origin_x, args.origin_y, args.origin_z] | |
| 35 if args.length_x is not None and args.length_y is not None and args.length_z is not None: | |
| 36 lengths = [args.length_x, args.length_y, args.length_z] | |
| 37 if args.rotation_axis_x is not None and args.rotation_axis_y is not None and args.rotation_axis_z is not None: | |
| 38 rotation_axis = [args.rotation_axis_x, args.rotation_axis_y, args.rotation_axis_z] | |
| 39 | |
| 40 # Define the output file format and type. | |
| 41 format, file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | |
| 42 tmp_dir = icqsol_utils.get_temp_dir() | |
| 43 cloning = True if args.create_process == 'clone' else False | |
| 44 | |
| 45 # TODO: fix this to handle inputPLY files for cloning, but producing VTK POLYDATA. | |
| 46 shape_mgr = icqsol_utils.get_shape_manager(format, icqsol_utils.POLYDATA) | |
| 47 | |
| 48 if cloning: | |
| 49 # We're cloning an existing shape selected from the history. | |
| 50 tmp_input_path = icqsol_utils.get_input_file_path(tmp_dir, args.shape_input, '.%s' % format) | |
| 51 shape_to_clone = shape_mgr.loadAsShape(tmp_input_path) | |
| 52 new_shape = shape_mgr.cloneShape(shape_to_clone) | |
| 53 if icqsol_utils.asbool(args.rotate): | |
| 54 shape_mgr.rotateShape(new_shape, axis=rotation_axis, angleDeg=args.rotation_degree) | |
| 55 if icqsol_utils.asbool(args.translate): | |
| 56 shape_mgr.translateShape(new_shape, disp=origin) | |
| 57 else: | |
| 58 # Create the primitive shape. | |
| 59 if args.shape == 'box': | |
| 60 new_shape = shape_mgr.createShape('box', | |
| 61 origin=origin, | |
| 62 lengths=lengths) | |
| 63 elif args.shape == 'cone': | |
| 64 new_shape = shape_mgr.createShape('cone', | |
| 65 radius=args.radius, | |
| 66 origin=origin, | |
| 67 lengths=lengths, | |
| 68 n_theta=args.n_theta) | |
| 69 elif args.shape == 'cylinder': | |
| 70 new_shape = shape_mgr.createShape('cylinder', | |
| 71 radius=args.radius, | |
| 72 origin=origin, | |
| 73 lengths=lengths, | |
| 74 n_theta=args.n_theta) | |
| 75 elif args.shape == 'sphere': | |
| 76 new_shape = shape_mgr.createShape('sphere', | |
| 77 radius=args.radius, | |
| 78 origin=origin, | |
| 79 n_theta=args.n_theta, | |
| 80 n_phi=args.n_phi) | |
| 81 | |
| 82 # Save the output. | |
| 83 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, '.%s' % format) | |
| 84 shape_mgr.saveShape(shape=new_shape, file_name=tmp_output_path, file_type=file_type) | |
| 85 shutil.move(tmp_output_path, args.output) |
