from pathlib import Path import numpy as np import pyvista as pv VTKFILE_NOMINAL = Path("~/data/stage-laurent-f/datasets/Rotor37/processed/nominal_blade_rotated.vtk") # load nominal blade nominal = pv.read(VTKFILE_NOMINAL) # for each generated/sampled blade gen_files = Path("./output").glob("gen*.txt") pc_files = Path("./output").glob("pc*.txt") files = list(gen_files) + list(pc_files) for gen_file in files: # load numpy txt blade = np.loadtxt(gen_file) # get top and bottom index (filter outliers a bit) top = int(blade.shape[0] * 0.001) bot = int(blade.shape[0] * 0.999) # sort blade coordinates sorted_blade = np.sort(blade, axis=0) # get center of blade center = (sorted_blade[bot, :] + sorted_blade[top, :]) / 2 # translate blade to world origin blade -= center # save to txt np.savetxt(f"output/test_{gen_file.stem}.txt", blade) # swap nominal points to blade points nominal.points = blade # save altered blade to vtk nominal.save(f"output/test_{gen_file.stem}.vtk")