0
|
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( '--expression', dest='expression', help='Composition expression' )
|
|
11 parser.add_argument( '--shape_dataset', dest='shape_datasets', action='append', nargs=4, help='Shape datasets selected from history' )
|
|
12 parser.add_argument( '--output', dest='output', help='Output dataset' )
|
|
13 parser.add_argument( '--output_vtk_type', dest='output_vtk_type', help='Output file format and type' )
|
|
14
|
|
15 args = parser.parse_args()
|
|
16
|
|
17 tmp_dir = icqsol_utils.get_temp_dir()
|
|
18 shape_tuples = []
|
|
19 shape_mgr = ShapeManager()
|
|
20
|
|
21 # Load the shapes.
|
|
22 for ( expression_var, dataset_path, galaxy_ext, vtk_dataset_type ) in args.shape_datasets:
|
|
23 # Define the file format and type.
|
|
24 format, file_type = icqsol_utils.get_format_and_type( galaxy_ext )
|
|
25 if format == 'vtk':
|
|
26 shape_mgr.setReader( file_format=format, vtk_dataset_type=vtk_dataset_type )
|
|
27 else:
|
|
28 shape_mgr.setReader( file_format=format )
|
|
29 icqsol_path = icqsol_utils.get_input_file_path( tmp_dir, dataset_path, format )
|
|
30 shape_tuple = ( expression_var, shape_mgr.loadAsShape( icqsol_path ) )
|
|
31 shape_tuples.append( shape_tuple )
|
|
32
|
|
33 # Define the output file format and type.
|
|
34 output_format, output_file_type = icqsol_utils.get_format_and_type( args.output_vtk_type )
|
|
35 tmp_output_path = icqsol_utils.get_temporary_file_path( tmp_dir, output_format )
|
|
36
|
|
37 shape_mgr.setWriter( file_format=output_format, vtk_dataset_type=icqsol_utils.POLYDATA )
|
|
38
|
|
39 # Compose the shapes.
|
|
40 composite_shape = shape_mgr.composeShapes( shape_tuples, args.expression )
|
|
41
|
|
42 # Save the output.
|
|
43 shape_mgr.saveShape( shape=composite_shape, file_name=tmp_output_path, file_type=output_file_type )
|
|
44 shutil.move( tmp_output_path, args.output )
|