-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVolvox_Python.py
185 lines (150 loc) · 7.39 KB
/
Volvox_Python.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"""
This creates a command line link to CloudCompare.
www.CloudComapare.org
http://www.danielgm.net/cc/doc/wiki/index.php5?title=CommandLine
"""
import sys
import System.IO
sys.path.append(str(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory())) + '\Plug-ins\IronPython\Lib')
import subprocess
import os
import shutil
import glob
import clr
clr.AddReferenceToFileAndPath(os.path.join(System.IO.Directory.GetCurrentDirectory(), 'RhinoCommon.dll'))
import Rhino as rc
class CloudCompare:
def __init__(self):
self.dir = os.path.normpath('C:\\Program Files\\CloudCompare')
def open(self, filePath):
"""
Open in CloudCompare.
"""
if os.path.isdir(self.dir) == True:
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare ' + filePath
P = subprocess.Popen(Args , cwd=self.dir)
#P.wait()
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir
def CCcommand(self, commands):
"""
write commands for CloudCompare.
"""
if os.path.isdir(self.dir) == True:
#create command string
command = str()
for com in commands:
command = command + com + ' '
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare ' + command
P = subprocess.Popen(Args , cwd=self.dir)
P.wait()
return 'Done. Find the output next to the input file.'
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir
def CCcommandE57(self, filePath, commands, outName):
"""
write commands for CloudCompare.
"""
if os.path.isdir(self.dir) == True:
#create command string
command = str()
for com in commands:
command = command + com + ' '
print command
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare -SILENT -O ' + filePath + ' -NO_TIMESTAMP -C_EXPORT_FMT E57 -AUTO_SAVE OFF ' + command + ' -SAVE_CLOUDS ALL_AT_ONCE'
P = subprocess.Popen(Args , cwd=self.dir)
P.wait()
#filePath for output file of CloudCommpare
tmpFilePath = os.path.join(os.path.dirname(filePath), 'AllClouds.e57')
#outputFilePath
outputFilePath = os.path.join(os.path.dirname(filePath), outName + '.e57')
#Rename (and move) tmpFilePath
shutil.move(tmpFilePath, outputFilePath)
return outputFilePath
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir
def CCcommandXYZ(self, filePath, commands, outName):
"""
write commands for CloudCompare.
"""
if os.path.isdir(self.dir) == True:
#create command string
command = str()
for com in commands:
command = command + com + ' '
print command
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare -SILENT -O ' + filePath + ' -NO_TIMESTAMP -C_EXPORT_FMT ASC -EXT xyz -AUTO_SAVE OFF -MERGE_CLOUDS ' + command + ' -SAVE_CLOUDS'
P = subprocess.Popen(Args , cwd=self.dir)
P.wait()
#filePath for output file of CloudCommpare
tmpFilePath = max(glob.iglob(os.path.splitext(filePath)[0]+'*.xyz'), key=os.path.getctime)
#outputFilePath
outputFilePath = os.path.join(os.path.dirname(filePath), outName + '.xyz')
#Rename (and move) tmpFilePath
shutil.move(tmpFilePath, outputFilePath)
return outputFilePath
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir
def toXYZ(self, filePath):
"""
Merge and exports an XYZ file through CloudCompare.
"""
if os.path.isdir(self.dir) == True:
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare -SILENT -O ' + filePath + ' -NO_TIMESTAMP -C_EXPORT_FMT ASC -EXT xyz -MERGE_CLOUDS'
P = subprocess.Popen(Args , cwd=self.dir)
P.wait()
#filePath for output file of CloudCommpare
tmpFilePath = os.path.splitext(filePath)[0] + '_MERGED.xyz'
#outputFilePath
outputFilePath = os.path.splitext(filePath)[0] + '.xyz' #os.path.join(os.path.dirname(filePath), outName + '.xyz')
#Rename (and move) tmpFilePath
shutil.move(tmpFilePath, outputFilePath)
return outputFilePath
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir
def SubsampleSpatial(self, filePath, distance, outName):
"""
Spatially subsamples point cloud through CloudCompare and outputs a filepath.
Args: filePath: file to subsample. dist: Distance between points to aim for through the subsampling. outName: name for new file
Returns: filePath: file path to new in same directory as input file
"""
if os.path.isdir(self.dir) == True:
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare -SILENT -O ' + filePath + ' -NO_TIMESTAMP -C_EXPORT_FMT E57 -AUTO_SAVE OFF -SS SPATIAL ' + str(distance) + ' -SAVE_CLOUDS ALL_AT_ONCE'
P = subprocess.Popen(Args , cwd=self.dir)
P.wait()
#filePath for output file of CloudCommpare
tmpFilePath = os.path.join(os.path.dirname(filePath), 'AllClouds.e57')
#outputFilePath
outputFilePath = os.path.join(os.path.dirname(filePath), outName + '.e57')
#Rename (and move) tmpFilePath
shutil.move(tmpFilePath, outputFilePath)
return outputFilePath
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir
def SubsampleRandom(self, filePath, amount, outName):
"""
Randomly subsamples point cloud through CloudCompare and outputs a filepath
Args: filePath: file to subsample. amount: Amount of points per scan. outName: name for new file
Returns: filePath: file path to new in same directory as input file
"""
if os.path.isdir(self.dir) == True:
#run CloudCompare cmd line
Args = self.dir + '\CloudCompare -SILENT -O ' + filePath + ' -NO_TIMESTAMP -C_EXPORT_FMT E57 -AUTO_SAVE OFF -SS RANDOM ' + str(amount) + ' -SAVE_CLOUDS ALL_AT_ONCE'
P = subprocess.Popen(Args , cwd=self.dir)
P.wait()
#filePath for output file of CloudCommpare
tmpFilePath = os.path.join(os.path.dirname(filePath), 'AllClouds.e57')
#outputFilePath
outputFilePath = os.path.join(os.path.dirname(filePath), outName + '.e57')
#Rename (and move) tmpFilePath
shutil.move(tmpFilePath, outputFilePath)
#Output
return outputFilePath
else:
return 'CloudCompare missing. Install CloudCompare in ' + self.dir