<commit_before>#!/usr/bin/env python

"""
Combine multiple shape objects
"""

import argparse
import time
import sys
import re

from icqsol.tools.geometry.icqShape import Shape

# time stamp
tid = re.sub(r'\.', '', str(time.time()))

parser = argparse.ArgumentParser(description='Create composite shape.')

parser.add_argument('--input', dest='input', nargs='+', default=[],
                    help='List of input files (PLY or VTK)')

parser.add_argument('--compose', dest='expression',
                    help='Expression with +, -,, and * on shapes $0, $1...')

parser.add_argument('--ascii', dest='ascii', action='store_true',
                    help='Save data in ASCII format (default is binary)')

parser.add_argument('--output', dest='output',
                    default='createCompositeShape-{0}.vtk'.format(tid),
                    help='Output file.')

args = parser.parse_args()

if not args.expression:
    print 'ERROR: must specify --compose <expression>'
    sys.exit(2)

if len(args.input) == 0:
    print 'ERROR: must specify input files: --input <file1> <file2> ...'
    sys.exit(3)

shp = Shape()
argShapes = []
for inputFile in args.input:
    s = Shape.load(inputFile)
    argShapes.append(s)

expr = args.expression
for i in range(len(argShapes)):
    expr = re.sub(r'\${}'.format(i), 'argShapes[{}]'.format(i), expr)
compositeShape = eval(expr)

if args.output:
    fileFormat = 'vtk'
    fileType = 'binary'
    if args.ascii:
        fileType = 'ascii'
    if args.output.lower().find('.ply') >= 0:
        fileFormat = 'ply'
    compositeShape.save(args.output, file_format=fileFormat,
                        file_type=fileType)<commit_msg>first implementation, not yet tested<commit_after>#!/usr/bin/env python

"""
Apply a surface field to a shape
"""

import argparse
import time
import sys
import re
from math import exp, log, sin, cos, pi, tan, acos, asin, atan2, atan, pi

import vtk
from icqsol.tools.geometry.icqShape import Shape

# time stamp
tid = re.sub(r'\.', '', str(time.time()))

parser = argparse.ArgumentParser(description='Apply a surface field to a shape')

parser.add_argument('--input', dest='input', default='',
                    help='Input files (PLY or VTK)')

parser.add_argument('--expression', dest='expression',
                    help='Expression of the coordinates x, y, and z')

parser.add_argument('--ascii', dest='ascii', action='store_true',
                    help='Save data in ASCII format (default is binary)')

parser.add_argument('--output', dest='output',
                    default='createSurfaceFieldFromExpression-{0}.vtk'.format(tid),
                    help='Output file.')

args = parser.parse_args() 

if not args.expression:
    print 'ERROR: must specify --compose <expression>'
    sys.exit(2)

if not args.input:
    print 'ERROR: must specify input file: --input <file>'
    sys.exit(3)

shp = Shape.load(args.input)
pdata = shp.toVTKPolyData()
points = pdata.GetPoints()
numPoints = points.GetNumberOfPoints()
data = vtk.vtkFloatArray()
data.SetNumberOfComponents(1)
data.SetNumberOfTuples(numPoints)
for i in range(numPoints):
    x, y, z = points.GetPoint(i)
    fieldValue = eval(args.expression)
    data.SetTuple1(i, fieldValue)
pdata.GetPointData().SetScalars(data)

if args.output:
    writer = vtk.vtkPolyDataWriter()
    if args.output.lower().find('.ply') >= 0:
        writer = vtk.vtkPLYWriter()
    writer.SetFileName(args.output)
    if args.ascii:
        writer.SetfileTypeToASCII()
    else:
        writer.SetFileTypeToBinary()       
    if vtk.VTK_MAJOR_VERSION >= 6:
        writer.SetInputData(pdata)
    else:
        writer.SetInput(pdata)
    writer.Write()
    writer.Update()

{'fraction_non_alphanumeric': 0.14575446187128177, 'fraction_numerical': 0.004597079502433748, 'mean_word_length': 3.1796610169491526, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, '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': '3515596', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1163, 'n_words': 287}