Mercurial > repos > greg > icqsol_rotate_shape
comparison icqsol_rotate_shape.py @ 2:9767d2d8505e draft
Uploaded
author | greg |
---|---|
date | Sat, 05 Dec 2015 10:30:11 -0500 |
parents | e778cabd999c |
children | 59f7e97dc5bf |
comparison
equal
deleted
inserted
replaced
1:41bc84dbe8ae | 2:9767d2d8505e |
---|---|
9 # Parse Command Line. | 9 # Parse Command Line. |
10 parser = argparse.ArgumentParser() | 10 parser = argparse.ArgumentParser() |
11 parser.add_argument('--input', dest='input', help='Shape dataset selected from history') | 11 parser.add_argument('--input', dest='input', help='Shape dataset selected from history') |
12 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type') | 12 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type') |
13 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type') | 13 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type') |
14 parser.add_argument('--rotation_angle_degrees', dest='rotation_angle_degrees', type=float, default=0.0, help='Rotation angle in degrees') | 14 parser.add_argument('--rotation_degrees', dest='rotation_degrees', type=float, default=0.0, help='Rotation angle in degrees') |
15 parser.add_argument('--rotation_axis_x', dest='rotation_axis_x', type=float, default=1.0, help='X coordinate of rotation axis') | 15 parser.add_argument('--rotation_axis_x', dest='rotation_axis_x', type=float, default=1.0, help='X coordinate of rotation axis') |
16 parser.add_argument('--rotation_axis_y', dest='rotation_axis_y', type=float, default=0.0, help='Y coordinate of rotation axis') | 16 parser.add_argument('--rotation_axis_y', dest='rotation_axis_y', type=float, default=0.0, help='Y coordinate of rotation axis') |
17 parser.add_argument('--rotation_axis_z', dest='rotation_axis_z', type=float, default=0.0, help='Z coordinate of rotation axis') | 17 parser.add_argument('--rotation_axis_z', dest='rotation_axis_z', type=float, default=0.0, help='Z coordinate of rotation axis') |
18 parser.add_argument('--output', dest='output', help='Output file name') | 18 parser.add_argument('--output', dest='output', help='Output file name') |
19 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type') | 19 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type') |
23 # Get the format of the input - either vtk or ply. | 23 # Get the format of the input - either vtk or ply. |
24 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | 24 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) |
25 tmp_dir = icqsol_utils.get_temp_dir() | 25 tmp_dir = icqsol_utils.get_temp_dir() |
26 | 26 |
27 # Instantiate a ShapeManager for loading the input. | 27 # Instantiate a ShapeManager for loading the input. |
28 if input_format == 'vtk': | 28 if input_format == icqsol_utils.VTK: |
29 shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type) | 29 shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type) |
30 else: | 30 else: |
31 shape_mgr = ShapeManager(file_format=input_format) | 31 shape_mgr = ShapeManager(file_format=input_format) |
32 | 32 |
33 # Get the vtk polydata from the input dataset. | 33 # Get the vtk polydata from the input dataset. |
34 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) | 34 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) |
35 | 35 |
36 # Only rotate if the axis has some non-zero coordinates. | 36 # Only rotate if the axis has some non-zero coordinates. |
37 # FIXME: this should be handled in a Galaxy tool validator. | |
37 axis = (args.rotation_axis_x, args.rotation_axis_y, args.rotation_axis_z) | 38 axis = (args.rotation_axis_x, args.rotation_axis_y, args.rotation_axis_z) |
38 if reduce(operator.mul, axis) != 0.0: | 39 if reduce(operator.mul, axis) != 0.0: |
39 # Rotate (in place operation). | 40 # Rotate (in place operation). |
40 shape_mgr.rotateVtkPolyData(vtk_poly_data, angleDeg=args.rotation_angle_degrees, axis=axis) | 41 shape_mgr.rotateVtkPolyData(vtk_poly_data, angleDeg=args.rotation_degrees, axis=axis) |
41 | 42 |
42 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | 43 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) |
43 | 44 |
45 # Save the output. | |
44 tmp_dir = icqsol_utils.get_temp_dir() | 46 tmp_dir = icqsol_utils.get_temp_dir() |
45 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, 'vtk') | 47 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, icqsol_utils.VTK) |
46 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | 48 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) |
47 shutil.move(tmp_output_path, args.output) | 49 shutil.move(tmp_output_path, args.output) |