raytrace to class attribute, save on multiple raytracing steps

This commit is contained in:
Daniel Mevec 2023-02-11 13:36:44 +01:00
parent 126be2e0e2
commit 908cd306c0

View file

@ -97,10 +97,21 @@ class NoInamge():
self.levels = 25 # [-1, 0, 1] self.levels = 25 # [-1, 0, 1]
self.torus = TorusWorld(rfrac_init) self.torus = TorusWorld(rfrac_init)
self.illumination = None
self.res = (50, 100)
self.update_illumination()
self.init_top_view() self.init_top_view()
self.init_side_view() self.init_side_view()
self.init_map_view() self.init_map_view()
def update_illumination(self):
# TODO: refactor TorusWorld.illumination() do use vectoization!!
phi = np.linspace(-np.pi, np.pi, self.res[0])
theta = np.linspace(-np.pi, np.pi, self.res[1])
self.illumination = np.array([[self.torus.illumination(ph, th) for th in theta] for ph in phi])
def init_map_view(self): def init_map_view(self):
self.lines['map_border'], = self.ax['map'].plot(*self._mantle_map(), 'k') self.lines['map_border'], = self.ax['map'].plot(*self._mantle_map(), 'k')
self.lines['pos_map'], = self.ax['map'].plot(*self._sunpos_map(), marker='o', color='r', markersize=10,) self.lines['pos_map'], = self.ax['map'].plot(*self._sunpos_map(), marker='o', color='r', markersize=10,)
@ -142,16 +153,14 @@ class NoInamge():
data = np.append(data, data[:, 0:1], axis=1) data = np.append(data, data[:, 0:1], axis=1)
return data return data
def _contour_map(self, n=100): def _contour_map(self):
theta = np.linspace(-np.pi, np.pi, n) phi = np.linspace(-np.pi, np.pi, self.res[0])
phi = np.linspace(-np.pi, np.pi, int(n*self.torus.r_min)) y = np.array([[w]*self.res[1] for w in self.torus.r_min*phi])
y = np.array([[w]*n for w in self.torus.r_min*phi])
func = (np.pi)*(self.torus.r_maj - self.torus.r_min*np.cos(phi)) func = (np.pi)*(self.torus.r_maj - self.torus.r_min*np.cos(phi))
x = np.array([np.linspace(-f, f, n) for f in func]) x = np.array([np.linspace(-f, f, self.res[1]) for f in func])
# x, y = np.meshgrid(np.linspace(-func[0], func[0], n), rmin*theta) # x, y = np.meshgrid(np.linspace(-func[0], func[0], n), rmin*theta)
z = np.array([[self.torus.illumination(ph, th) for th in theta] for ph in phi]) z = self.illumination
return x, y, z return x, y, z
@ -226,6 +235,7 @@ class NoInamge():
def update_torus(self, rfrac): def update_torus(self, rfrac):
self.torus.update(rfrac) self.torus.update(rfrac)
self.update_illumination()
self.redraw_plot(self.ax['map'], self.lines['map_border'], self._mantle_map) self.redraw_plot(self.ax['map'], self.lines['map_border'], self._mantle_map)
self.redraw_plot(self.ax['side'], self.lines['circles_side'], self._crossection) self.redraw_plot(self.ax['side'], self.lines['circles_side'], self._crossection)
self.redraw_plot(self.ax['side'], self.lines['path_side'], self._sunpath_side) self.redraw_plot(self.ax['side'], self.lines['path_side'], self._sunpath_side)
@ -237,6 +247,7 @@ class NoInamge():
def update_sun(self, phi, theta): def update_sun(self, phi, theta):
self.torus.put_sun(phi, theta) self.torus.put_sun(phi, theta)
self.update_illumination()
self.redraw_plot(self.ax['map'], self.lines['pos_map'], self._sunpos_map) self.redraw_plot(self.ax['map'], self.lines['pos_map'], self._sunpos_map)
self.redraw_plot(self.ax['side'], self.lines['pos_side'], self._sunpos_side) self.redraw_plot(self.ax['side'], self.lines['pos_side'], self._sunpos_side)
self.redraw_plot(self.ax['top'], self.lines['pos_top'], self._sunpos_top) self.redraw_plot(self.ax['top'], self.lines['pos_top'], self._sunpos_top)