forked from tudelft3d/City3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_generate_buildings.sh
executable file
·155 lines (121 loc) · 4.46 KB
/
03_generate_buildings.sh
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
#!/usr/bin/env bash
# This scripts generates building using City3D and parrallel to speed things up
# and automatically kill hanging process after a certain timeout
#############
# Variables #
#############
EXECUTABLE_PATH="./Release/bin/CLI_IGN_LIDAR_Footprints"
DATA_DIR="data/IGN/"
LIDAR_DIR=$DATA_DIR"point_cloud_extracts_ply_shifted/"
OBJ_DIR=$DATA_DIR"footprints_obj_below_pcd_shifted/"
RESULTS_DIR_NAME="results/"
ORIGIN_DIR_NAME="origin_shift/"
RESULTS_DIR=$DATA_DIR$RESULTS_DIR_NAME
ORIGIN_DIR=$DATA_DIR$ORIGIN_DIR_NAME
INPUT_CSV_FILE="params_generate.csv"
JOBLOG_FILE="city3d.csv"
TIMEOUT_FILE="reconstruction_timeout.txt"
ERROR_FILE="reconstruction_error.txt"
SERVER_DIR="/var/www/html/data/"
TIMEOUT_SECONDS=7200
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
##############################
# Parameters file generation #
##############################
rm $INPUT_CSV_FILE 2> /dev/null
for f in "$LIDAR_DIR"*
do
INPUT_PCD_FILE="$(pwd)"/$f
FILENAME=$(basename "$INPUT_PCD_FILE" .ply)
INPUT_FOOTPRINT_FILE="$(pwd)"/"$OBJ_DIR$FILENAME".obj
RESULT_FILE="$(pwd)"/"$RESULTS_DIR$FILENAME".obj
echo "$INPUT_PCD_FILE","$INPUT_FOOTPRINT_FILE","$RESULT_FILE" >> $INPUT_CSV_FILE
done
#############################
# Recreate output directory #
#############################
if [ -d "$RESULTS_DIR" ]
then
rm -rf $RESULTS_DIR
fi
mkdir $RESULTS_DIR
###########################
# Launch city3d processes #
###########################
# remove existing log files
rm $JOBLOG_FILE 2> /dev/null
rm $TIMEOUT_FILE 2> /dev/null
rm $ERROR_FILE 2> /dev/null
START=$(date +%s.%N)
# Launch city3D in parallel jobs to speed things up
cat $INPUT_CSV_FILE | parallel --timeout $TIMEOUT_SECONDS --colsep ',' --jobs $(nproc) --joblog $JOBLOG_FILE $EXECUTABLE_PATH {1} {2} {3} >> /dev/null 2>&1
DURATION=$(echo "$(date +%s.%N) - $START" | bc)
EXECUTION_TIME=`printf "%.2f seconds" ${DURATION/./,}`
#########################
# List failed processes #
#########################
echo "==============================="
echo " POINT CLOUD COULD NOT BE READ "
echo "==============================="
while IFS=$'\t' read -r Seq Host Starttime JobRuntime Send Receive Exitval Signal Command
do
if [ "$Exitval" -eq "10" ]
then
BUILDING_FAILURE=$(echo $Command | awk '{print $NF}' | xargs basename | cut -d '.' -f 1)
echo $BUILDING_FAILURE
fi
done < <(tail -n +2 $JOBLOG_FILE)
echo "============================="
echo " FOOTPRINT COULD NOT BE READ "
echo "============================="
while IFS=$'\t' read -r Seq Host Starttime JobRuntime Send Receive Exitval Signal Command
do
if [ "$Exitval" -eq "11" ]
then
BUILDING_FAILURE=$(echo $Command | awk '{print $NF}' | xargs basename | cut -d '.' -f 1)
echo $BUILDING_FAILURE
fi
done < <(tail -n +2 $JOBLOG_FILE)
echo "======================="
echo " RECONSTRUCTION ERRROR "
echo "======================="
while IFS=$'\t' read -r Seq Host Starttime JobRuntime Send Receive Exitval Signal Command
do
if [ "$Exitval" -eq "13" ] || [ "$Signal" -ne "0" ]
then
BUILDING_FAILURE=$(echo $Command | awk '{print $NF}' | xargs basename | cut -d '.' -f 1)
echo $BUILDING_FAILURE
echo $BUILDING_FAILURE >> $ERROR_FILE
fi
done < <(tail -n +2 $JOBLOG_FILE)
echo "========================"
echo " RECONSTRUCTION TIMEOUT "
echo "========================"
while IFS=$'\t' read -r Seq Host Starttime JobRuntime Send Receive Exitval Signal Command
do
if [ "$Exitval" -eq "-1" ]
then
BUILDING_FAILURE=$(echo $Command | awk '{print $NF}' | xargs basename | cut -d '.' -f 1)
echo $BUILDING_FAILURE
echo $BUILDING_FAILURE >> $TIMEOUT_FILE
fi
done < <(tail -n +2 $JOBLOG_FILE)
echo "========================"
echo " COULD NOT WRITE RESULT "
echo "========================"
while IFS=$'\t' read -r Seq Host Starttime JobRuntime Send Receive Exitval Signal Command
do
if [ "$Exitval" -eq "12" ]
then
BUILDING_FAILURE=$(echo $Command | awk '{print $NF}' | xargs basename | cut -d '.' -f 1)
echo $BUILDING_FAILURE
fi
done < <(tail -n +2 $JOBLOG_FILE)
##############################
# Create archive and copy it #
##############################
TAR_NAME="results_$(date +%s).tar.gz"
tar czf $TAR_NAME -C $DATA_DIR $RESULTS_DIR_NAME $ORIGIN_DIR_NAME -C $SCRIPT_DIR $JOBLOG_FILE $ERROR_FILE $TIMEOUT_FILE
cp $TAR_NAME $SERVER_DIR
rm $TAR_NAME
echo "City3D Execution Time: $EXECUTION_TIME"