Mercurial > repos > iuc > icqsol_refine_shape
comparison icqsol_refine_shape.py @ 0:ee1928e36fb4 draft
Uploaded
| author | iuc |
|---|---|
| date | Mon, 22 Aug 2016 13:59:25 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:ee1928e36fb4 |
|---|---|
| 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('--input', dest='input', help='Shape dataset selected from history') | |
| 10 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_dataset_type', dest='input_dataset_type', help='Input dataset_type') | |
| 12 parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, help='Maximum edge length') | |
| 13 parser.add_argument('--output', dest='output', help='Output dataset') | |
| 14 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type') | |
| 15 | |
| 16 args = parser.parse_args() | |
| 17 | |
| 18 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | |
| 19 tmp_dir = icqsol_utils.get_temp_dir() | |
| 20 | |
| 21 # Instantiate a ShapeManager for loading the input. | |
| 22 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type) | |
| 23 | |
| 24 # Get the vtk polydata from the input dataset. | |
| 25 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) | |
| 26 | |
| 27 # Refine the shape if requested. | |
| 28 vtk_poly_data = shape_mgr.refineVtkPolyData(vtk_poly_data, max_edge_length=args.max_edge_length) | |
| 29 | |
| 30 # Define the output file format and type (the output_format can only be 'vtk'). | |
| 31 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | |
| 32 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format) | |
| 33 | |
| 34 # Make sure the ShapeManager's writer is vtk. | |
| 35 shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA) | |
| 36 | |
| 37 # Save the output. | |
| 38 shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | |
| 39 shutil.move(tmp_output_path, args.output) |
