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