Mercurial > repos > greg > icqsol_add_texture
comparison icqsol_add_texture.py @ 0:4afbbfafc3c2 draft
Uploaded
author | greg |
---|---|
date | Wed, 09 Dec 2015 11:07:55 -0500 |
parents | |
children | 1371f6eeb73c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4afbbfafc3c2 |
---|---|
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('--input_texture', dest='input_texture', help='Image dataset selected from history') | |
14 parser.add_argument('--input_texture_file_format', dest='input_texture_file_format', help='Input texture file format') | |
15 parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, default=float('inf'), help='Maximum edge length') | |
16 parser.add_argument('--output', dest='output', help='Output dataset') | |
17 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type') | |
18 | |
19 args = parser.parse_args() | |
20 | |
21 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | |
22 tmp_dir = icqsol_utils.get_temp_dir() | |
23 | |
24 # Instantiate a ShapeManager for loading the input. | |
25 if input_format == icqsol_utils.VTK: | |
26 shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type) | |
27 else: | |
28 shape_mgr = ShapeManager(file_format=input_format) | |
29 | |
30 # Get the vtk polydata from the input dataset. | |
31 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) | |
32 # The ShapeManager.addTextureToVtkPolyData function expects | |
33 # a specific file extension at the end of the file path. | |
34 tmp_texture_file_path = icqsol_utils.get_input_file_path(tmp_dir, args.input_texture, args.input_texture_file_format) | |
35 | |
36 # Apply the texture to the shape's surface. | |
37 vtk_poly_data = shape_mgr.addTextureToVtkPolyData(vtk_poly_data, | |
38 texture_file=tmp_texture_file_path, | |
39 max_edge_length=args.max_edge_length) | |
40 | |
41 # Define the output file format and type (the output_format can only be 'vtk'). | |
42 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | |
43 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format) | |
44 | |
45 # Make sure the ShapeManager's writer is vtk. | |
46 shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA) | |
47 | |
48 # Save the output. | |
49 shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | |
50 shutil.move(tmp_output_path, args.output) |