mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 14:03:59 +08:00
Fixing various in ZoomedScene
This commit is contained in:
@ -312,8 +312,7 @@ class Camera(object):
|
|||||||
# points = self.adjust_out_of_range_points(points)
|
# points = self.adjust_out_of_range_points(points)
|
||||||
if len(points) == 0:
|
if len(points) == 0:
|
||||||
continue
|
continue
|
||||||
aligned_points = self.align_points_to_camera(points)
|
coords = self.points_to_pixel_coords(points)
|
||||||
coords = self.points_to_pixel_coords(aligned_points)
|
|
||||||
coord_strings = coords.flatten().astype(str)
|
coord_strings = coords.flatten().astype(str)
|
||||||
# Start new path string with M
|
# Start new path string with M
|
||||||
coord_strings[0] = "M" + coord_strings[0]
|
coord_strings[0] = "M" + coord_strings[0]
|
||||||
@ -353,7 +352,6 @@ class Camera(object):
|
|||||||
def display_point_cloud(self, points, rgbas, thickness):
|
def display_point_cloud(self, points, rgbas, thickness):
|
||||||
if len(points) == 0:
|
if len(points) == 0:
|
||||||
return
|
return
|
||||||
points = self.align_points_to_camera(points)
|
|
||||||
pixel_coords = self.points_to_pixel_coords(points)
|
pixel_coords = self.points_to_pixel_coords(points)
|
||||||
pixel_coords = self.thickened_coordinates(
|
pixel_coords = self.thickened_coordinates(
|
||||||
pixel_coords, thickness
|
pixel_coords, thickness
|
||||||
@ -441,10 +439,6 @@ class Camera(object):
|
|||||||
Image.alpha_composite(self.get_image(), image)
|
Image.alpha_composite(self.get_image(), image)
|
||||||
)
|
)
|
||||||
|
|
||||||
def align_points_to_camera(self, points):
|
|
||||||
# This is where projection should live
|
|
||||||
return points - self.space_center
|
|
||||||
|
|
||||||
def adjust_out_of_range_points(self, points):
|
def adjust_out_of_range_points(self, points):
|
||||||
if not np.any(points > self.max_allowable_norm):
|
if not np.any(points > self.max_allowable_norm):
|
||||||
return points
|
return points
|
||||||
@ -461,6 +455,8 @@ class Camera(object):
|
|||||||
return points
|
return points
|
||||||
|
|
||||||
def points_to_pixel_coords(self, points):
|
def points_to_pixel_coords(self, points):
|
||||||
|
shifted_points = points - self.space_center
|
||||||
|
|
||||||
result = np.zeros((len(points), 2))
|
result = np.zeros((len(points), 2))
|
||||||
ph, pw = self.pixel_shape
|
ph, pw = self.pixel_shape
|
||||||
sh, sw = self.frame_shape
|
sh, sw = self.frame_shape
|
||||||
@ -471,8 +467,8 @@ class Camera(object):
|
|||||||
# Flip on y-axis as you go
|
# Flip on y-axis as you go
|
||||||
height_mult *= -1
|
height_mult *= -1
|
||||||
|
|
||||||
result[:, 0] = points[:, 0] * width_mult + width_add
|
result[:, 0] = shifted_points[:, 0] * width_mult + width_add
|
||||||
result[:, 1] = points[:, 1] * height_mult + height_add
|
result[:, 1] = shifted_points[:, 1] * height_mult + height_add
|
||||||
return result.astype('int')
|
return result.astype('int')
|
||||||
|
|
||||||
def on_screen_pixels(self, pixel_coords):
|
def on_screen_pixels(self, pixel_coords):
|
||||||
|
@ -27,6 +27,7 @@ class MultiCamera(MovingCamera):
|
|||||||
# A silly method to have right now, but maybe there are things
|
# A silly method to have right now, but maybe there are things
|
||||||
# we want to guarantee about any imfc's added later.
|
# we want to guarantee about any imfc's added later.
|
||||||
imfc = image_mobject_from_camera
|
imfc = image_mobject_from_camera
|
||||||
|
assert(isinstance(imfc.camera, MovingCamera))
|
||||||
self.image_mobjects_from_cameras.append(imfc)
|
self.image_mobjects_from_cameras.append(imfc)
|
||||||
|
|
||||||
def update_sub_cameras(self):
|
def update_sub_cameras(self):
|
||||||
@ -47,6 +48,12 @@ class MultiCamera(MovingCamera):
|
|||||||
int(pixel_width * imfc.get_width() / frame_width),
|
int(pixel_width * imfc.get_width() / frame_width),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
for imfc in self.image_mobjects_from_cameras:
|
||||||
|
imfc.camera.reset()
|
||||||
|
MovingCamera.reset(self)
|
||||||
|
return self
|
||||||
|
|
||||||
def capture_mobjects(self, mobjects, **kwargs):
|
def capture_mobjects(self, mobjects, **kwargs):
|
||||||
# Make sure all frames are in mobjects? Or not?
|
# Make sure all frames are in mobjects? Or not?
|
||||||
self.update_sub_cameras()
|
self.update_sub_cameras()
|
||||||
@ -58,3 +65,4 @@ class MultiCamera(MovingCamera):
|
|||||||
)
|
)
|
||||||
imfc.camera.capture_mobjects(to_add, **kwargs)
|
imfc.camera.capture_mobjects(to_add, **kwargs)
|
||||||
MovingCamera.capture_mobjects(self, mobjects, **kwargs)
|
MovingCamera.capture_mobjects(self, mobjects, **kwargs)
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class ZoomedScene(Scene):
|
|||||||
self.zoomed_camera = zoomed_camera
|
self.zoomed_camera = zoomed_camera
|
||||||
self.zoomed_display = zoomed_display
|
self.zoomed_display = zoomed_display
|
||||||
|
|
||||||
def activate_zooming(self, animate=False, run_times=[3, 2]):
|
def activate_zooming(self, animate=False, run_times=[2, 1]):
|
||||||
self.zoom_activated = True
|
self.zoom_activated = True
|
||||||
zoomed_camera = self.zoomed_camera
|
zoomed_camera = self.zoomed_camera
|
||||||
zoomed_display = self.zoomed_display
|
zoomed_display = self.zoomed_display
|
||||||
@ -63,7 +63,7 @@ class ZoomedScene(Scene):
|
|||||||
|
|
||||||
to_add = [zoomed_camera.frame, zoomed_display]
|
to_add = [zoomed_camera.frame, zoomed_display]
|
||||||
if animate:
|
if animate:
|
||||||
zoomed_display.save_state()
|
zoomed_display.save_state(use_deepcopy=True)
|
||||||
zoomed_display.replace(zoomed_camera.frame)
|
zoomed_display.replace(zoomed_camera.frame)
|
||||||
|
|
||||||
full_frame_height, full_frame_width = self.camera.frame_shape
|
full_frame_height, full_frame_width = self.camera.frame_shape
|
||||||
|
Reference in New Issue
Block a user