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( '--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( '--max_edge_length', dest='max_edge_length', type=float, default='0', help='Maximum edge length' )
|
|
14 parser.add_argument( '--output', dest='output', help='Output dataset' )
|
|
15 parser.add_argument( '--output_vtk_type', dest='output_vtk_type', help='Output VTK type' )
|
|
16
|
|
17 args = parser.parse_args()
|
|
18
|
|
19 input_format, input_file_type = icqsol_utils.get_format_and_type( args.input_file_format_and_type )
|
|
20 tmp_dir = icqsol_utils.get_temp_dir()
|
|
21
|
|
22 # Instantiate a ShapeManager for loading the input.
|
|
23 if input_format == 'vtk':
|
|
24 shape_mgr = ShapeManager( file_format=input_format, vtk_dataset_type=args.input_dataset_type )
|
|
25 else:
|
|
26 shape_mgr = ShapeManager( file_format=input_format )
|
|
27
|
|
28 # Get the vtk polydata from the input dataset.
|
|
29 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
|
|
30
|
|
31 # Refine the shape if requested.
|
|
32 vtk_poly_data = shape_mgr.refineVtkPolyData(vtk_poly_data, max_edge_length=args.max_edge_length)
|
|
33
|
|
34 # Define the output file format and type (the outpur_format can only be 'vtk').
|
|
35 output_format, output_file_type = icqsol_utils.get_format_and_type( args.output_vtk_type )
|
|
36 tmp_output_path = icqsol_utils.get_temporary_file_path( tmp_dir, output_format )
|
|
37
|
|
38 # Make sure the ShapeManager's writer is vtk.
|
|
39 shape_mgr.setWriter( file_format='vtk', vtk_dataset_type=icqsol_utils.POLYDATA )
|
|
40
|
|
41 # Save the output.
|
|
42 shape_mgr.saveVtkPolyData( vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
|
|
43 shutil.move( tmp_output_path, args.output )
|