annotate icqsol_translate_shape.py @ 0:88af59c4a2e5 draft default tip

Uploaded
author iuc
date Tue, 23 Aug 2016 15:05:48 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
2 import argparse
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
3 import shutil
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
4
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
5 import icqsol_utils
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
6
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
7 # Parse Command Line.
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
8 parser = argparse.ArgumentParser()
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
9 parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
10 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
11 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
12 parser.add_argument('--displacement_x', dest='displacement_x', type=float, default=1.0, help='X coordinate of displacement')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
13 parser.add_argument('--displacement_y', dest='displacement_y', type=float, default=0.0, help='Y coordinate of displacement')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
14 parser.add_argument('--displacement_z', dest='displacement_z', type=float, default=0.0, help='Z coordinate of displacement')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
15 parser.add_argument('--output', dest='output', help='Output file name')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
16 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type')
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
17
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
18 args = parser.parse_args()
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
19
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
20 # Get the format of the input - either vtk or ply.
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
21 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
22 tmp_dir = icqsol_utils.get_temp_dir()
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
23
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
24 # Instantiate a ShapeManager for loading the input.
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
25 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
26
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
27 # Get the vtk polydata from the input dataset.
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
28 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
29
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
30 # Translate (in place operation).
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
31 displ = (args.displacement_x, args.displacement_y, args.displacement_z)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
32 shape_mgr.translateVtkPolyData(vtk_poly_data, displ=displ)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
33
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
34 # Save the output.
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
35 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
36 tmp_dir = icqsol_utils.get_temp_dir()
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
37 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, icqsol_utils.VTK)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
38 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
88af59c4a2e5 Uploaded
iuc
parents:
diff changeset
39 shutil.move(tmp_output_path, args.output)