annotate icqsol_coarsen_shape.py @ 0:6ff7cf6ec553 draft default tip

Uploaded
author iuc
date Tue, 23 Aug 2016 14:56:49 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
2 import argparse
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
3 import shutil
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
4
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
5 import icqsol_utils
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
6
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
7 # Parse Command Line.
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
8 parser = argparse.ArgumentParser()
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
9 parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
10 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
11 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
12 parser.add_argument('--min_cell_area', dest='min_cell_area', type=float, help='Minimum cell area')
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
13 parser.add_argument('--output', dest='output', help='Output dataset')
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
14 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
15
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
16 args = parser.parse_args()
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
17
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
18 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
19 tmp_dir = icqsol_utils.get_temp_dir()
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
20
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
21 # Instantiate a ShapeManager for loading the input.
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
22 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
23
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
24 # Get the vtk polydata from the input dataset.
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
25 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
26
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
27 # Coarsen the shape if requested.
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
28 vtk_poly_data = shape_mgr.coarsenVtkPolyData(vtk_poly_data, min_cell_area=args.min_cell_area)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
29
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
30 # Define the output file format and type (the output_format can only be 'vtk').
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
31 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
32 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
33
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
34 # Make sure the ShapeManager's writer is vtk.
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
35 shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
36
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
37 # Save the output.
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
38 shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
6ff7cf6ec553 Uploaded
iuc
parents:
diff changeset
39 shutil.move(tmp_output_path, args.output)