0
|
1 #!/usr/bin/env python
|
|
2 import argparse
|
|
3 import shutil
|
|
4
|
|
5 import icqsol_utils
|
|
6 from icqsol.shapes.icqShapeManager import ShapeManager
|
|
7
|
|
8 # Parse Command Line.
|
|
9 parser = argparse.ArgumentParser()
|
1
|
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')
|
|
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')
|
|
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')
|
|
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')
|
|
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')
|
|
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')
|
|
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')
|
|
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')
|
|
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')
|
|
28 parser.add_argument('--translate', dest='translate', help='Translate cloned shape')
|
|
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')
|
0
|
31
|
|
32 args = parser.parse_args()
|
|
33
|
|
34 if args.origin_x is not None and args.origin_y is not None and args.origin_z is not None:
|
1
|
35 origin = [args.origin_x, args.origin_y, args.origin_z]
|
0
|
36 if args.length_x is not None and args.length_y is not None and args.length_z is not None:
|
1
|
37 lengths = [args.length_x, args.length_y, args.length_z]
|
0
|
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:
|
1
|
39 rotation_axis = [args.rotation_axis_x, args.rotation_axis_y, args.rotation_axis_z]
|
0
|
40
|
|
41 # Define the output file format and type.
|
1
|
42 format, file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
|
0
|
43 tmp_dir = icqsol_utils.get_temp_dir()
|
|
44 cloning = True if args.create_process == 'clone' else False
|
|
45
|
|
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)
|
|
48
|
|
49 if cloning:
|
|
50 # We're cloning an existing shape selected from the history.
|
1
|
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)
|
|
53 new_shape = shape_mgr.cloneShape(shape_to_clone)
|
|
54 if icqsol_utils.asbool(args.rotate):
|
|
55 shape_mgr.rotateShape(new_shape, axis=rotation_axis, angleDeg=args.rotation_degree)
|
|
56 if icqsol_utils.asbool(args.translate):
|
|
57 shape_mgr.translateShape(new_shape, disp=origin)
|
0
|
58 else:
|
|
59 # Create the primitive shape.
|
|
60 if args.shape == 'box':
|
1
|
61 new_shape = shape_mgr.createShape('box',
|
|
62 origin=origin,
|
|
63 lengths=lengths)
|
0
|
64 elif args.shape == 'cone':
|
1
|
65 new_shape = shape_mgr.createShape('cone',
|
|
66 radius=args.radius,
|
|
67 origin=origin,
|
|
68 lengths=lengths,
|
|
69 n_theta=args.n_theta)
|
0
|
70 elif args.shape == 'cylinder':
|
1
|
71 new_shape = shape_mgr.createShape('cylinder',
|
|
72 radius=args.radius,
|
|
73 origin=origin,
|
|
74 lengths=lengths,
|
|
75 n_theta=args.n_theta)
|
0
|
76 elif args.shape == 'sphere':
|
1
|
77 new_shape = shape_mgr.createShape('sphere',
|
|
78 radius=args.radius,
|
|
79 origin=origin,
|
|
80 n_theta=args.n_theta,
|
|
81 n_phi=args.n_phi)
|
0
|
82
|
|
83 # Save the output.
|
1
|
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)
|
|
86 shutil.move(tmp_output_path, args.output)
|