RegionToCropBoxAndNormals.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 '''
4 Copyright (c) 2016, Aumann Florian, Borella Jocelyn, Heller Florian, Meissner Pascal, Schleicher Ralf, Stoeckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 
9 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14 
15 4. The use is explicitly not permitted to any application which deliberately try to kill or do harm to any living creature.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 '''
19 
20 import csv
21 import sys, getopt
22 
23 class Cropbox:
24 
25  def __init__(self):
26  self.Region = []
27  self.Normals = []
28 
29  def __repr__(self):
30  return "Region: " + str(self.Region) + "\nNormals: " + str(self.Normals)
31 
32 def get_max_point(point):
33  return [(point[3]-point[0]),(point[4]-point[1]),(point[5]-point[2])]
34 
35 def get_translation(point):
36  return [point[0],point[1],point[2]]
37 
38 def main():
39 
40  Cropboxes = []
41  i = 0
42 
43  inputfile = ''
44  outputfile = ''
45  try:
46  opts, args = getopt.getopt(sys.argv[1:],"hi:o:",["ifile=","ofile="])
47  except getopt.error:
48  print 'RegionToCropBox.py -i <inputfile>.csv -o <outputfile>.xml'
49  sys.exit(2)
50  for opt, arg in opts:
51  if opt == '-h':
52  print 'RegionToCropBox.py -i <inputfile>.csv -o <outputfile>.xml'
53  sys.exit()
54  elif opt in ("-i", "--ifile"):
55  inputfile = arg
56  elif opt in ("-o", "--ofile"):
57  outputfile = arg
58  print 'Input file is "', inputfile
59  print 'Output file is "', outputfile
60 
61  with open(inputfile, 'rb') as csvfile:
62  spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
63  cropbox = Cropbox()
64  isFirst = True
65  isNormalsRead = False
66  for row in spamreader:
67  if len(row) != 0 and str(row[0]).startswith('#'):
68  continue
69  if len(row) == 0 and isFirst is True:
70  continue
71  isFirst = False
72  if len(row) == 0:
73  isNormalsRead = False
74  Cropboxes.append(cropbox)
75  cropbox = Cropbox()
76  continue
77 
78  if isNormalsRead is False:
79  region = []
80  for elt in row:
81  region.append(float(elt))
82  cropbox.Region = region
83  isNormalsRead = True
84  else:
85  normal = []
86  for elt in row:
87  normal.append(float(elt))
88  cropbox.Normals.append(normal)
89 
90  returnString = '<CropBoxList name="Map">'
91  for c in Cropboxes:
92  returnString += '<CropBox name="Region_'+str(i)+'">'
93  returnString += '<min_pt x="0" y="0" z="0"/>'
94  max_point = get_max_point(c.Region)
95  if max_point[0] < 0.0 or max_point[1] < 0.0 or max_point[2] < 0.0:
96  print "ABORTING: Max values must be positive for PCL crop box filtering."
97  return
98  returnString += '<max_pt x="'+str(max_point[0])+'" y="'+str(max_point[1])+'" z="'+str(max_point[2])+'"/>'
99  returnString += '<rotation x="0" y="0" z="0"/>'
100  translation = get_translation(c.Region)
101  returnString += ' <translation x="'+str(translation[0])+'" y="'+str(translation[1])+'" z="'+str(translation[2])+'"/>'
102  j = 0
103  for n in c.Normals:
104  returnString += ' <normal_' + str(j) + ' x="'+str(n[0])+'" y="'+str(n[1])+'" z="'+str(n[2])+'"/>'
105  j += 1
106  returnString += '</CropBox>'
107  i += 1
108 
109  returnString += '</CropBoxList>'
110 
111  f = open(outputfile, 'r+')
112  f.truncate()
113  f.write(returnString)
114  f.close()
115 
116  print returnString
117 
118 if __name__ == '__main__':
119  main()


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18