123 lines
4.1 KiB
Python
123 lines
4.1 KiB
Python
import math
|
|
import argparse
|
|
|
|
#input config file format: x,y,z,id,filename,angleoffset
|
|
#angleoffset is 0 when center of 360 image points to the right, positive rotation means image center in pointing more CCW. value in degrees
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog = 'File Edit Script',
|
|
description = 'Read content of text file and write to file',
|
|
epilog = '')
|
|
|
|
parser.add_argument('filename') # positional argument
|
|
parser.add_argument('-o', '--output') # option that takes a value
|
|
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
|
|
|
|
args = parser.parse_args()
|
|
print(args.filename, args.output, args.verbose)
|
|
|
|
def distance(x1,y1,x2,y2):
|
|
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
|
return dist
|
|
|
|
|
|
print("Loading Templates")
|
|
template_panellum=None
|
|
with open("template_panellum.txt",'r') as rf:
|
|
template_panellum=rf.readlines()
|
|
|
|
template_scenes=None
|
|
with open("template_scenes.txt",'r') as rf:
|
|
template_scenes=rf.readlines()
|
|
|
|
template_hotspots=None
|
|
with open("template_hotspots.txt",'r') as rf:
|
|
template_hotspots=rf.readlines()
|
|
|
|
|
|
linesinput=None
|
|
with open(args.filename,'r') as rf:
|
|
linesinput=rf.readlines()
|
|
|
|
linesinput=[x.rstrip() for x in linesinput] #remove newline and whitespaces at end
|
|
|
|
output_scenes=[]
|
|
|
|
first_sceneId=None
|
|
|
|
for iline1,line1 in enumerate(linesinput):
|
|
|
|
x1,y1,z1,id1,filename1,angleoffset1=line1.split(',')
|
|
x1,y1,z1=(float(x1),float(y1),float(z1))
|
|
angleoffset1=float(angleoffset1)
|
|
|
|
if first_sceneId is None:
|
|
first_sceneId=id1 #take first entry as start scene
|
|
|
|
# ### Set information for scene ###
|
|
current_scene=template_scenes
|
|
current_scene=[x.replace('<id>',id1) for x in current_scene]
|
|
current_scene=[x.replace('<title>',id1) for x in current_scene]
|
|
current_scene=[x.replace('<filename>',filename1) for x in current_scene]
|
|
|
|
output_hotspots=[]
|
|
|
|
for iline2,line2 in enumerate(linesinput):
|
|
x2,y2,z2,id2,filename2,angleoffset2=line2.split(',')
|
|
x2,y2,z2=(float(x2),float(y2),float(z2))
|
|
angleoffset2=float(angleoffset2)
|
|
|
|
|
|
|
|
if id1!=id2:
|
|
print()
|
|
print("from "+str(x1)+", "+str(y1)+" : "+id1)
|
|
print("to "+str(x2)+", "+str(y2)+" : "+id2)
|
|
|
|
print("dist="+str(distance(x1,y1,x2,y2)))
|
|
angle=math.degrees(math.atan2(y2-y1, x2-x1)) #in degrees
|
|
print("angle="+str(angle)+" offset1="+str(angleoffset1)+" offset2="+str(angleoffset2))
|
|
angle+=angleoffset1 #correct hotspot position by rotation of scene image
|
|
print("angle final="+str(angle))
|
|
|
|
pitch=-math.degrees(math.atan(z1/distance(x1,y1,x2,y2))) #from current looking to hotspot. 0deg=straight, 90deg=down
|
|
pitch=pitch/2 #manual correction
|
|
|
|
|
|
# ### Set information for target/hotspot ###
|
|
current_hotspot=template_hotspots
|
|
current_hotspot=[x.replace('<id>',id2) for x in current_hotspot]
|
|
current_hotspot=[x.replace('<yaw>',str(angle)) for x in current_hotspot]
|
|
current_hotspot=[x.replace('<pitch>',str(pitch)) for x in current_hotspot]
|
|
|
|
output_hotspots.append(current_hotspot)
|
|
|
|
|
|
output_hotspots_string=""
|
|
for _ihotspot,_hotspot in enumerate(output_hotspots):
|
|
if _ihotspot>0:
|
|
output_hotspots_string+=",\n" #separate blocks with comma
|
|
for _hotspotline in _hotspot:
|
|
output_hotspots_string+=_hotspotline
|
|
|
|
current_scene=[x.replace('<hotspot>',output_hotspots_string) for x in current_scene]
|
|
|
|
output_scenes.append(current_scene)
|
|
|
|
|
|
|
|
|
|
output_scenes_string=""
|
|
for _iscene,_scene in enumerate(output_scenes):
|
|
if _iscene>0:
|
|
output_scenes_string+=",\n" #separate blocks with comma
|
|
for _sceneline in _scene:
|
|
output_scenes_string+=_sceneline
|
|
|
|
output=template_panellum
|
|
output=[x.replace('<firstScene>',first_sceneId) for x in output]
|
|
output=[x.replace('<scene>',output_scenes_string) for x in output]
|
|
|
|
with open(args.output, 'w') as wf:
|
|
wf.writelines(output)
|