-
Notifications
You must be signed in to change notification settings - Fork 11
/
ply2vtp.py
executable file
·49 lines (37 loc) · 1.15 KB
/
ply2vtp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python
"""Generate a VTK style vtp file from a ply file
usage: ply2vtp.py mesh.ply mesh.vtp"""
__author__ = "Benjamin Barad"
__email__ = "[email protected]"
__license__ = "GPLv3"
import gc
import glob
import os
import click
import numpy as np
from pycurv import pycurv_io as io
from scipy.ndimage.morphology import distance_transform_edt
import vtk
@click.command()
@click.argument('input_ply', type=str)
@click.argument('output_vtp', type=str)
def convert_from_CLI(input_ply, output_vtp):
"""Click wrapper for convert script"""
ply_to_vtp(input_ply, output_vtp)
def ply_to_vtp(plyfilename, vtpfilename):
"""Convert an input ply file to a vtp file"""
print("open")
plyfile = vtk.vtkPLYReader()
plyfile.SetFileName(plyfilename)
plyfile.Update()
surf = plyfile.GetOutput()
writer = vtk.vtkXMLPolyDataWriter()
fname = vtpfilename
writer.SetFileName(fname)
writer.SetInputData(surf)
if writer.Write() != 1:
raise pexceptions.PySegInputError(
expr='save_vtp', msg='Error writing the file {}.'.format(fname))
gc.collect()
if __name__ == '__main__':
convert_from_CLI()