-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuildDenseCloud.py
More file actions
119 lines (104 loc) · 4.95 KB
/
Copy pathBuildDenseCloud.py
File metadata and controls
119 lines (104 loc) · 4.95 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
import PhotoScan, glob, sys, time
# BuildDenseCloud.py
# Justin Dowd, Clemson Center for Geospatial Technologies, www.clemsongis.org
# March 2018
# Email: jmdowd@g.clemson.edu
# Scripts submits a task that builds the dense cloud in our previously created project
#Create Command Line Argument Variable that reads arguments from the run command in submitAlignCameras.sh
args = sys.argv
# Open the argument file (arguments.txt)
argumentFile =open(args[1])
# Create a variable to hold the path to where the project will be saved and assign the first line
# of arguments.txt to this variable
path = argumentFile.readline()
# Strips the new line character at the end of the path name
path = path.strip('\n')
# Get the length of the path name
pathLen = len(path)
# Checks to see if a forward slash is at the end of the path name, if not one is added
if(path[pathLen-1] != '/'):
path = path + '/'
# Create a variable to hold the name of the project and assigns the second line of
# arguments.txt to this variable
docName = argumentFile.readline()
# Strips the new line character at the end of the path name
docName = docName.strip('\n')
# Get the length of the path name
docNameLen = len(docName)
# Removes the .psx extension from the project name if it exists
if('.psx' in docName):
docName = docName.replace('.psx', '')
# Adds the .psx extension to the end of the project name to ensure it is in the right place
if('.psx' not in docName):
docName = docName + '.psx'
# Skips over the next three lines of arguments.txt as they are not needed for this script
blank1 = argumentFile.readline()
blank2 = argumentFile.readline()
blank3 = argumentFile.readline()
# Create a variable to store the path to where the address.txt file (file containing IP Address of server node) is stored.
addrDir = argumentFile.readline()
# Close the argument file
argumentFile.close()
# Strip new line character at the end of the path name
addrDir = addrDir.strip('\n')
# Combine the path with the name of the address folder containing the IP Address (address.txt) and store it in the variable (addrDir)
# It will always be named address.txt becuase that is the name designated in initServerNode2.sh
addrDir = (addrDir + "/address.txt")
# Opens the address file
addr_file = open(addrDir, "r")
# Reads the IP Address and stores it in a variable
addr_str = addr_file.readline()
# Closes the address file
addr_file.close()
# Create a PhotoScan Network Client object named 'client'
client = PhotoScan.NetworkClient()
# Combines the path to where the project is to be saved with the name of the project in order to save, open, and access the project in the script
filePath = (path + docName)
# Create a PhotoScan Document object and name it 'doc'
doc = PhotoScan.app.document
# Open the document that was previously created by MatchPhotos.py using the filePath variable we created
doc.open(filePath)
# Set the read only variable to false in order to enable editing
doc.read_only = False
#Task 4 or Build Dense Cloud Task
# Create a PhotoScan Network Task object called 'task4'
task4 = PhotoScan.NetworkTask()
# Add all the chunks and frames(if applicable) to the network task so it has access to them
for c in doc.chunks:
task4.chunks.append(c.key)
task4.frames.append((c.key,0))
# Names the task
task4.name = "BuildDenseCloud"
# Applies the task to the chunks we added to the task
task4.params['apply'] = task4.chunks
# Set the processing quality to Ultra, which is the highest quality for PhotoScan
task4.params['downscale'] = int(PhotoScan.UltraQuality)
# Set filtering to not filter
task4.params['filter'] = int(PhotoScan.FilterMode.NoFiltering)
# Grants the task permission to distribute the processing onto our client
task4.params['network_distribute'] = True
# Connect to the IP Address of the PhotoScan server node we read in from address.txt
client.connect(addr_str)
# Create a batch to submit to the server node
batch_id4 = client.createBatch(filePath, [task4])
# Send the batch to the server node for processing
client.resumeBatch(batch_id4)
print("Job started...")
print("Building Dense Cloud...")
# Get the current status dictionary of the batch
stat = client.batchStatus(batch_id4)
# Print the status from the dictionary
print("Status: " + stat['status'])
# Continue to the run the script until the processing step has finished
while(stat['status'] == "inprogress" or stat['status'] == "working"):
stat = client.batchStatus(batch_id4)
# Makes the loop sleep for 5 minutes before checking the status again
# This is done to conserve memory as this step can take up large amounts of time and if
# the loop is constantly checking for the status and assigning the status to a variable
# the job on the Palmetto Cluster will eventually run out of memory and corrupt the project
time.sleep(500)
# Disconnect from the client and Save the project (Save is equivalent to a 'Save As' on windows
client.disconnect()
print("Dense Cloud Built")
print("All jobs complete")
doc.save(filePath)