-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_01_rendering_a_sphere.py
More file actions
112 lines (92 loc) · 3.22 KB
/
test_01_rendering_a_sphere.py
File metadata and controls
112 lines (92 loc) · 3.22 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
#! python3
# -*- coding: utf-8 -*-
"""
SurRender script
Script : SCR_01 Rendering a sphere (using default value)
(C) 2019 Airbus copyright all rights reserved
"""
import sys
from surrender.surrender_client import surrender_client
import numpy as np
import matplotlib.pyplot as plot
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 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 ) )
#--[FOV configuration]------------------------
xFOV = 30.0 #deg
yFOV = 30.0 #deg
s.setCameraFOVDeg(xFOV,yFOV)
#--[Rendering]------------------------
s.render()
#--[Image recovery]------------------------
image = s.getImageGray8()
if with_pytest:
from surrender_test.check import check_img_error_hist
check_img_error_hist(config, image, f"{script_dir}/../../surrender-nonreg-test/user_manual/control/SCR01_ref.png")
else:
# Matplotlib viewer and saver
plot.ioff()
plot.imshow(image,cmap='gray')
plot.savefig('SCR01_plotGray.png')
plot.imshow(image)
plot.savefig('SCR01_plot.png')
# Pillow saver
Image.fromarray(image).save('SCR01_imageGray.tif')
print("SCR_01: done.")
print("----------------------------------------")
if __name__ == "__main__":
test_render(False, None, None, None)
#-----------------------------------------------------------------------
# End