annotate icqsol_add_texture.py @ 0:d6bbaddfa5af draft default tip

Uploaded
author iuc
date Tue, 23 Aug 2016 14:55:34 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
2 import argparse
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
3 import shutil
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
4
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
5 import icqsol_utils
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
6
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
7 # Parse Command Line.
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
8 parser = argparse.ArgumentParser()
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
9 parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
d6bbaddfa5af 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')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
11 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
12 parser.add_argument('--input_texture', dest='input_texture', help='Image dataset selected from history')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
13 parser.add_argument('--input_texture_file_format', dest='input_texture_file_format', help='Input texture file format')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
14 parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, default=float('inf'), help='Maximum edge length')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
15 parser.add_argument('--output', dest='output', help='Output dataset')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
16 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
17
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
18 args = parser.parse_args()
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
19
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
20 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
21 tmp_dir = icqsol_utils.get_temp_dir()
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
22
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
23 # Instantiate a ShapeManager for loading the input.
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
24 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
25
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
26 # Get the vtk polydata from the input dataset.
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
27 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
28
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
29 # Apply the texture to the shape's surface.
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
30 vtk_poly_data = shape_mgr.addTextureToVtkPolyData(vtk_poly_data,
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
31 texture_file=args.input_texture,
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
32 max_edge_length=args.max_edge_length,
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
33 texture_file_format=args.input_texture_file_format)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
34
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
35 # Define the output file format and type (the output_format can only be 'vtk').
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
36 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
37 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
38
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
39 # Make sure the ShapeManager's writer is vtk.
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
40 shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
41
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
42 # Save the output.
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
43 shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
d6bbaddfa5af Uploaded
iuc
parents:
diff changeset
44 shutil.move(tmp_output_path, args.output)