Mercurial > repos > greg > icqsol_scale_shape
comparison icqsol_scale_shape.py @ 0:c8b87f2bb2e8 draft
Uploaded
| author | greg |
|---|---|
| date | Sat, 05 Dec 2015 10:36:31 -0500 |
| parents | |
| children | 89216e1c25b8 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:c8b87f2bb2e8 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 import argparse | |
| 3 import shutil | |
| 4 import operator | |
| 5 | |
| 6 import icqsol_utils | |
| 7 from icqsol.shapes.icqShapeManager import ShapeManager | |
| 8 | |
| 9 # Parse Command Line. | |
| 10 parser = argparse.ArgumentParser() | |
| 11 parser.add_argument('--input', dest='input', help='Shape dataset selected from history') | |
| 12 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type') | |
| 13 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type') | |
| 14 parser.add_argument('--scale_x', dest='scale_x', type=float, default=1.0, help='X scaling factor') | |
| 15 parser.add_argument('--scale_y', dest='scale_y', type=float, default=1.0, help='Y scaling factor') | |
| 16 parser.add_argument('--scale_z', dest='scale_z', type=float, default=1.0, help='Z scaling factor') | |
| 17 parser.add_argument('--output', dest='output', help='Output file name') | |
| 18 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type') | |
| 19 | |
| 20 args = parser.parse_args() | |
| 21 | |
| 22 # Get the format of the input - either vtk or ply. | |
| 23 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | |
| 24 tmp_dir = icqsol_utils.get_temp_dir() | |
| 25 | |
| 26 # Instantiate a ShapeManager for loading the input. | |
| 27 if input_format == icqsol_utils.VTK: | |
| 28 shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type) | |
| 29 else: | |
| 30 shape_mgr = ShapeManager(file_format=input_format) | |
| 31 | |
| 32 # Get the vtk polydata from the input dataset. | |
| 33 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) | |
| 34 | |
| 35 # Scale (in place operation). | |
| 36 # FIXME: this should be handled in a Galaxy tool validator. | |
| 37 factors = (args.scale_x, args.scale_y, args.scale_z) | |
| 38 if reduce(operator.and_, [f > 0 for f in factors]): | |
| 39 # All factors must be > 0 | |
| 40 shape_mgr.scaleVtkPolyData(vtk_poly_data, factors=factors) | |
| 41 | |
| 42 # Save the output. | |
| 43 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | |
| 44 tmp_dir = icqsol_utils.get_temp_dir() | |
| 45 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, icqsol_utils.VTK) | |
| 46 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | |
| 47 shutil.move(tmp_output_path, args.output) |
