This repository was archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverter.py
More file actions
145 lines (111 loc) · 3.99 KB
/
converter.py
File metadata and controls
145 lines (111 loc) · 3.99 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3.7
#######################################################
# A Vault Client Hello World! program in Python3.7 #
#######################################################
"""
converter.py
General purpose command line converter for Euclideon Vault using python
Requires Vault SDK shared libraries (.so or .dll)
Converts any point cloud format supported by Vault SDK to UDS format
By default will produce one UDS for each model provided
If no models are provided the program will attempt to convert the sample file located
at ../../samplefiles/DirCube.uds
--merge produces a single uds from the input files
output files are stored in:
./convertedUDS/[inputName].uds for individual mode
./mergedUDS/[firstInputName].uds for merge mode
Usage:
converter username password [models] [--merge]
"""
import vault
import os
from os.path import abspath
from sys import exit
from sys import argv
#######################################################
####################### Setup #########################
#######################################################
# Load the SDK and fetch symbols
SDKPath = abspath("./vaultSDK") #this is where we will look for the dll first
vault.LoadVaultSDK(SDKPath)
vaultSDK = vault.vaultSDK
appName = "PythonSample_Convert"
#some default values; these should be overwritten by argv
modelFiles = [abspath("../../samplefiles/DirCube.uds")]
outFile = abspath("./ConvertedUDS.uds")
serverPath = "https://earth.vault.euclideon.com"
userName = "Username"
userPass = "Password"
vaultContext = vault.vdkContext()
convertContext = vault.vdkConvertContext()
def vault_login():
"""
Connect to vault server and requests a license
Returns
-------
None.
"""
try:
vaultContext.Connect(serverPath, appName, userName, userPass)
vaultContext.RequestLicense(vault.vdkLicenseType.Convert)
convertContext.Create(vaultContext)
except vault.VdkException as err:
err.printout()
exit()
def vault_logout():
# Exit gracefully
convertContext.Destroy()
vaultContext.Disconnect()
def convert_model(modelFiles, outFile):
"""
performs a conversion of a list of input files to the output UDS at path outfile
Parameters
----------
modelFiles : List[string]
List of paths to files to be converted
outFile : string
path to the output file to be written
Returns
-------
None.
"""
try:
formattedInputNames = ""
for modelFile in modelFiles:
vdkError = convertContext.AddItem(modelFile)
formattedInputNames += "\t {}\n".format(modelFile)
vdkError = convertContext.Output(outFile)
print("Converting files:\n {} to {}".format(formattedInputNames,outFile))
convertContext.DoConvert()
print("done")
except vault.VdkException as err:
err.printout();
#######################################################
######################## Main #########################
#######################################################
if __name__ == "__main__":
if len(argv)<3:
print("Usage: {} VaultUserName VaultPassword [--merge] [inputFiles]".format(argv[0]))
try:
argv.remove("--merge")
merge = True
except ValueError:
merge = False
#mass convert, single directory, individual output files
if len(argv) >= 3:
userName = argv[1]
userPass = argv[2]
if len(argv) >= 4:
modelFiles = argv[3:]
else:
print("No model specified, falling back to example uds at {}".format(modelFiles[0]))
vault_login()
if merge:
outFile = abspath("./mergedUDS/"+os.path.basename(modelFiles[0])+".uds")
convert_model(modelFiles,outFile)
else:
for modelFile in modelFiles:
outFile = os.path.splitext(modelFile)[0]
outFile = abspath("./convertedUDS/"+os.path.basename(outFile)+".uds")
convert_model([modelFile], outFile)
vault_logout()