-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_02_simple_earth_sun_camera_system.py
More file actions
117 lines (97 loc) · 3.43 KB
/
test_02_simple_earth_sun_camera_system.py
File metadata and controls
117 lines (97 loc) · 3.43 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
#! python3
# -*- coding: utf-8 -*-
"""
SurRender script
Script : SCR_02 Simple Earth-Sun-Camera system
(C) 2019 Airbus copyright all rights reserved
"""
import sys
from surrender.surrender_client import surrender_client
import numpy as np
from PIL import Image
try:
from surrender_test.util import config, with_pytest, s, script_dir
except Exception as e:
print(e)
#--[CONSTANTS]---------------------------
SUN_RADIUS = 696342000.0 #m
EARTH_RADIUS = 6478137.0 #m
EARTH_SUN_DISTANCE = 149597870000.0 #m
#-----------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------
def test_render(with_pytest: bool, config, s, script_dir):
#--[Connection to server]--------------------------------
if not with_pytest:
s = surrender_client()
s.setVerbosityLevel(1)
s.connectToServer("127.0.0.1", 5151)
print("----------------------------------------")
print("SCRIPT : %s"%sys.argv[0])
print("SurRender version: "+s.version())
print("----------------------------------------")
#--[Initialisation]--------------------------
s.closeViewer()
s.setConventions(s.XYZ_SCALAR_CONVENTION,s.Z_FRONTWARD)
s.enableDoublePrecisionMode( True )
s.enableRaytracing( True )
s.setNbSamplesPerPixel(1)
#--[Objects creation]---------------------
# Earth
s.createBRDF("mate", "mate.brdf", {})
s.createShape("earth_shape", "sphere.shp", {'radius': EARTH_RADIUS})
s.createBody("earth", "earth_shape", "mate", ["earth.jpg"])
# Earth position
xEarthPos = 0
yEarthPos = 0
zEarthPos = -(EARTH_RADIUS + 2*np.power(10,7))
s.setObjectPosition("earth", (xEarthPos, yEarthPos, zEarthPos))
# Sun
s.createBRDF("sun", "sun.brdf", {})
s.createShape("sun_shape", "sphere.shp", {'radius':SUN_RADIUS})
s.createBody("sun", "sun_shape", "sun", [])
# Sun position
xSunPos = 0
ySunPos = 0
zSunPos = EARTH_SUN_DISTANCE-zEarthPos
s.setObjectPosition("sun", (xSunPos, ySunPos, zSunPos))
# Sun illumination
p = EARTH_SUN_DISTANCE * EARTH_SUN_DISTANCE * np.pi
s.setSunPower(np.array([p,p,p,p]))
#--[Camera position]-----------------------
xCamPos = 0
yCamPos = 0
zCamPos = 0
s.setObjectPosition( "camera", ( xCamPos, yCamPos, zCamPos ) )
#--[Image size (4/3)]------------------------
imWidth = 640
imHeight = 480
s.setImageSize(imWidth, imHeight)
#--[FOV configuration (4/3)]------------------------
xFOV = 40.0 #deg
yFOV = 30.0 #deg
s.setCameraFOVDeg(xFOV,yFOV)
#--[Rendering]------------------------
s.render()
#--[Image recovery]------------------------
# Gray
if with_pytest:
image = s.getImageRGBA8()
from surrender_test.check import check_img_error_hist
check_img_error_hist(config, image[...,:3], f"{script_dir}/../../surrender-nonreg-test/user_manual/control/SCR02_ref.png")
else:
image = s.getImageGray8()
Image.fromarray(image).save('SCR02_imageGray.png')
# Color
imageRGBA = s.getImageRGBA8()
Image.fromarray(imageRGBA).save('SCR02_imageRGBA.png')
# get rid of the alpha channel
r,g,b,a = Image.fromarray(imageRGBA).split()
imageRGB = Image.merge("RGB", (r, g, b))
imageRGB.save('SCR02_imageRGB.png')
print("SCR_02: done.")
print("----------------------------------------")
if __name__ == "__main__":
test_render(False, None, None, None)
#-----------------------------------------------------------------------
# End