annotate icqsol_rotate_shape.py @ 0:f63d4da328a3 draft default tip

Uploaded
author iuc
date Tue, 23 Aug 2016 15:02:48 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
2 import argparse
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
3 import shutil
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
4 import operator
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
5
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
6 import icqsol_utils
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
7
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
8 # Parse Command Line.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
9 parser = argparse.ArgumentParser()
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
10 parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
11 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
12 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
13 parser.add_argument('--rotation_degrees', dest='rotation_degrees', type=float, default=0.0, help='Rotation angle in degrees')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
14 parser.add_argument('--rotation_axis_x', dest='rotation_axis_x', type=float, default=1.0, help='X coordinate of rotation axis')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
15 parser.add_argument('--rotation_axis_y', dest='rotation_axis_y', type=float, default=0.0, help='Y coordinate of rotation axis')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
16 parser.add_argument('--rotation_axis_z', dest='rotation_axis_z', type=float, default=0.0, help='Z coordinate of rotation axis')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
17 parser.add_argument('--output', dest='output', help='Output file name')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
18 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type')
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
19
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
20 args = parser.parse_args()
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
21
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
22 # Get the format of the input - either vtk or ply.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
23 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
24 tmp_dir = icqsol_utils.get_temp_dir()
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
25
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
26 # Instantiate a ShapeManager for loading the input.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
27 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
28
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
29 # Get the vtk polydata from the input dataset.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
30 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
31
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
32 # Only rotate if the axis has some non-zero coordinates.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
33 # FIXME: this should be handled in a Galaxy tool validator.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
34 axis = (args.rotation_axis_x, args.rotation_axis_y, args.rotation_axis_z)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
35 if reduce(operator.mul, axis) != 0.0:
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
36 # Rotate (in place operation).
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
37 shape_mgr.rotateVtkPolyData(vtk_poly_data, angleDeg=args.rotation_degrees, axis=axis)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
38
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
39 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
40
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
41 # Save the output.
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
42 tmp_dir = icqsol_utils.get_temp_dir()
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
43 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, icqsol_utils.VTK)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
44 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
f63d4da328a3 Uploaded
iuc
parents:
diff changeset
45 shutil.move(tmp_output_path, args.output)