<commit_before>#!/usr/bin/env python
import argparse
import shutil
from pkg_resources import resource_filename

import icqsol_utils
from icqsol.shapes.icqShapeManager import ShapeManager

# Parse Command Line.
parser = argparse.ArgumentParser()
parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, default='0', help='Maximum edge length')
parser.add_argument('--texture', dest='texture', default='stone', help='Select texture (currently stone, wood, or checkerboard)')
parser.add_argument('--output', dest='output', help='Output dataset')
parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')

args = parser.parse_args()

input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
tmp_dir = icqsol_utils.get_temp_dir()

# Instantiate a ShapeManager for loading the input.
if input_format == icqsol_utils.VTK:
    shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type)
else:
    shape_mgr = ShapeManager(file_format=input_format)

# Get the vtk polydata from the input dataset.
vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)

# Add texture. We use setuptools, which installs the package as a python "egg", 
# essentially a zip file containing the modules and data files. Must use resource_filename
# to access the data files.
texture_name_to_filename = {
    'stone': resource_filename('icqsol', 'textures/220px-COnglomerate-sandstone_layers_Nerriga.jpg'),
    'wood': resource_filename('icqsol', 'textures/Swietenia_macrophylla_wood.jpg'),
    'checkerboard': resource_filename('icqsol', 'textures/checkerboard.png'),
}

# Selected texture is "stone" if the texture name does not match any of our values.s
texture_file = texture_name_to_filename.get(args.texture, 'stone')
vtk_poly_data = shape_mgr.addTextureToVtkPolyData(vtk_poly_data, texture_file=texture_file, max_edge_length=args.max_edge_length)

# Define the output file format and type (the output_format can only be 'vtk').
output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)

# Make sure the ShapeManager's writer is vtk.
shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)

# Save the output.
shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
shutil.move(tmp_output_path, args.output)<commit_msg> make sure max_edge_length is non-zero when calling refine<commit_after>#!/usr/bin/env python
import argparse
import shutil
from pkg_resources import resource_filename

import icqsol_utils
from icqsol.shapes.icqShapeManager import ShapeManager

# Parse Command Line.
parser = argparse.ArgumentParser()
parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, default='0', help='Maximum edge length')
parser.add_argument('--texture', dest='texture', default='stone', help='Select texture (currently stone, wood, or checkerboard)')
parser.add_argument('--output', dest='output', help='Output dataset')
parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')

args = parser.parse_args()

input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
tmp_dir = icqsol_utils.get_temp_dir()

# Instantiate a ShapeManager for loading the input.
if input_format == icqsol_utils.VTK:
    shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type)
else:
    shape_mgr = ShapeManager(file_format=input_format)

# Get the vtk polydata from the input dataset.
vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)

# Add texture. We use setuptools, which installs the package as a python "egg", 
# essentially a zip file containing the modules and data files. Must use resource_filename
# to access the data files.
texture_name_to_filename = {
    'stone': resource_filename('icqsol', 'textures/220px-COnglomerate-sandstone_layers_Nerriga.jpg'),
    'wood': resource_filename('icqsol', 'textures/Swietenia_macrophylla_wood.jpg'),
    'checkerboard': resource_filename('icqsol', 'textures/checkerboard.png'),
}

# Selected texture is "stone" if the texture name does not match any of our values.s
texture_file = texture_name_to_filename.get(args.texture, 'stone')
max_edge_length = args.max_edge_length
if max_edge_length <= 0:
    # no refinement will be applied
    max_edge_length = float('inf') 
vtk_poly_data = shape_mgr.addTextureToVtkPolyData(vtk_poly_data, texture_file=texture_file, max_edge_length=args.max_edge_length)

# Define the output file format and type (the output_format can only be 'vtk').
output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)

# Make sure the ShapeManager's writer is vtk.
shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)

# Save the output.
shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
shutil.move(tmp_output_path, args.output)
{'fraction_non_alphanumeric': 0.10217726727241556, 'fraction_numerical': 0.0015429453111606378, 'mean_word_length': 7.655786350148368, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6638650', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1901, 'n_words': 413}