comparison icqsol_compose_shapes.py @ 0:1574fdcc16df draft default tip

Uploaded
author iuc
date Tue, 23 Aug 2016 14:59:12 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1574fdcc16df
1 #!/usr/bin/env python
2 import argparse
3 import shutil
4
5 import icqsol_utils
6
7 # Parse Command Line.
8 parser = argparse.ArgumentParser()
9 parser.add_argument('--expression', dest='expression', help='Composition expression')
10 parser.add_argument('--shape_dataset', dest='shape_datasets', action='append', nargs=4, help='Shape datasets selected from history')
11 parser.add_argument('--output', dest='output', help='Output dataset')
12 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output file format and type')
13
14 args = parser.parse_args()
15
16 tmp_dir = icqsol_utils.get_temp_dir()
17 shape_tuples = []
18 shape_mgr = icqsol_utils.get_shape_manager()
19
20 # Load the shapes.
21 for (expression_var, dataset_path, galaxy_ext, vtk_dataset_type) in args.shape_datasets:
22 # Define the file format and type.
23 format, file_type = icqsol_utils.get_format_and_type(galaxy_ext)
24 if format == icqsol_utils.VTK:
25 shape_mgr.setReader(file_format=format, vtk_dataset_type=vtk_dataset_type)
26 else:
27 shape_mgr.setReader(file_format=format)
28 icqsol_path = icqsol_utils.get_input_file_path(tmp_dir, dataset_path, format)
29 shape_tuple = (expression_var, shape_mgr.loadAsShape(icqsol_path))
30 shape_tuples.append(shape_tuple)
31
32 # Define the output file format and type.
33 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
34 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)
35
36 shape_mgr.setWriter(file_format=output_format, vtk_dataset_type=icqsol_utils.POLYDATA)
37
38 # Compose the shapes.
39 composite_shape = shape_mgr.composeShapes(shape_tuples, args.expression)
40
41 # Save the output.
42 shape_mgr.saveShape(shape=composite_shape, file_name=tmp_output_path, file_type=output_file_type)
43 shutil.move(tmp_output_path, args.output)