Mercurial > repos > greg > icqsol_translate_shape
comparison icqsol_translate_shape.py @ 0:0e26a1b31cac draft
Uploaded
author | greg |
---|---|
date | Fri, 04 Dec 2015 09:28:55 -0500 |
parents | |
children | 415160ef2f85 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0e26a1b31cac |
---|---|
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() | |
10 parser.add_argument('--input', dest='input', help='Shape dataset selected from history') | |
11 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_dataset_type', dest='input_dataset_type', help='Input dataset_type') | |
13 parser.add_argument('--displacement_x', dest='displacement_x', type=float, default=1.0, help='X coordinate of displacement') | |
14 parser.add_argument('--displacement_y', dest='displacement_y', type=float, default=0.0, help='Y coordinate of displacement') | |
15 parser.add_argument('--displacement_z', dest='displacement_z', type=float, default=0.0, help='Z coordinate of displacement') | |
16 parser.add_argument('--output', dest='output', help='Output file name') | |
17 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type') | |
18 | |
19 args = parser.parse_args() | |
20 | |
21 # Get the format of the input - either vtk or ply. | |
22 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | |
23 tmp_dir = icqsol_utils.get_temp_dir() | |
24 | |
25 # Instantiate a ShapeManager for loading the input. | |
26 if input_format == 'vtk': | |
27 shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type) | |
28 else: | |
29 shape_mgr = ShapeManager(file_format=input_format) | |
30 | |
31 # Get the vtk polydata from the input dataset. | |
32 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) | |
33 | |
34 # Translate (in place operation). | |
35 displ = (args.displacement_x, args.displacement_y, args.displacement_z) | |
36 shape_mgr.translateVtkPolyData(vtk_poly_data, displ=displ) | |
37 | |
38 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | |
39 tmp_dir = icqsol_utils.get_temp_dir() | |
40 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, 'vtk') | |
41 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | |
42 shutil.move(tmp_output_path, args.output) |