comparison icqsol_refine_shape.py @ 2:da0ef88d5af2 draft

Uploaded
author greg
date Fri, 04 Dec 2015 09:24:26 -0500
parents a38daf377d55
children 918771601157
comparison
equal deleted inserted replaced
1:5f8e40447578 2:da0ef88d5af2
5 import icqsol_utils 5 import icqsol_utils
6 from icqsol.shapes.icqShapeManager import ShapeManager 6 from icqsol.shapes.icqShapeManager import ShapeManager
7 7
8 # Parse Command Line. 8 # Parse Command Line.
9 parser = argparse.ArgumentParser() 9 parser = argparse.ArgumentParser()
10 parser.add_argument( '--input', dest='input', help='Shape dataset selected from history' ) 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' ) 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' ) 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' ) 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' ) 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' ) 15 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')
16 16
17 args = parser.parse_args() 17 args = parser.parse_args()
18 18
19 input_format, input_file_type = icqsol_utils.get_format_and_type( args.input_file_format_and_type ) 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() 20 tmp_dir = icqsol_utils.get_temp_dir()
21 21
22 # Instantiate a ShapeManager for loading the input. 22 # Instantiate a ShapeManager for loading the input.
23 if input_format == 'vtk': 23 if input_format == 'vtk':
24 shape_mgr = ShapeManager( file_format=input_format, vtk_dataset_type=args.input_dataset_type ) 24 shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type)
25 else: 25 else:
26 shape_mgr = ShapeManager( file_format=input_format ) 26 shape_mgr = ShapeManager(file_format=input_format)
27 27
28 # Get the vtk polydata from the input dataset. 28 # Get the vtk polydata from the input dataset.
29 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) 29 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
30 30
31 # Refine the shape if requested. 31 # Refine the shape if requested.
32 vtk_poly_data = shape_mgr.refineVtkPolyData(vtk_poly_data, max_edge_length=args.max_edge_length) 32 vtk_poly_data = shape_mgr.refineVtkPolyData(vtk_poly_data, max_edge_length=args.max_edge_length)
33 33
34 # Define the output file format and type (the outpur_format can only be 'vtk'). 34 # Define the output file format and type (the output_format can only be 'vtk').
35 output_format, output_file_type = icqsol_utils.get_format_and_type( args.output_vtk_type ) 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 ) 36 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)
37 37
38 # Make sure the ShapeManager's writer is vtk. 38 # Make sure the ShapeManager's writer is vtk.
39 shape_mgr.setWriter( file_format='vtk', vtk_dataset_type=icqsol_utils.POLYDATA ) 39 shape_mgr.setWriter(file_format='vtk', vtk_dataset_type=icqsol_utils.POLYDATA)
40 40
41 # Save the output. 41 # Save the output.
42 shape_mgr.saveVtkPolyData( vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) 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 ) 43 shutil.move(tmp_output_path, args.output)