Fixing various in ZoomedScene

This commit is contained in:
Grant Sanderson
2018-05-10 19:20:18 -07:00
parent 7ee85faadd
commit 8703e2336c
3 changed files with 15 additions and 11 deletions

View File

@ -312,8 +312,7 @@ class Camera(object):
# points = self.adjust_out_of_range_points(points)
if len(points) == 0:
continue
aligned_points = self.align_points_to_camera(points)
coords = self.points_to_pixel_coords(aligned_points)
coords = self.points_to_pixel_coords(points)
coord_strings = coords.flatten().astype(str)
# Start new path string with M
coord_strings[0] = "M" + coord_strings[0]
@ -353,7 +352,6 @@ class Camera(object):
def display_point_cloud(self, points, rgbas, thickness):
if len(points) == 0:
return
points = self.align_points_to_camera(points)
pixel_coords = self.points_to_pixel_coords(points)
pixel_coords = self.thickened_coordinates(
pixel_coords, thickness
@ -441,10 +439,6 @@ class Camera(object):
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):
if not np.any(points > self.max_allowable_norm):
return points
@ -461,6 +455,8 @@ class Camera(object):
return points
def points_to_pixel_coords(self, points):
shifted_points = points - self.space_center
result = np.zeros((len(points), 2))
ph, pw = self.pixel_shape
sh, sw = self.frame_shape
@ -471,8 +467,8 @@ class Camera(object):
# Flip on y-axis as you go
height_mult *= -1
result[:, 0] = points[:, 0] * width_mult + width_add
result[:, 1] = points[:, 1] * height_mult + height_add
result[:, 0] = shifted_points[:, 0] * width_mult + width_add
result[:, 1] = shifted_points[:, 1] * height_mult + height_add
return result.astype('int')
def on_screen_pixels(self, pixel_coords):

View File

@ -27,6 +27,7 @@ class MultiCamera(MovingCamera):
# A silly method to have right now, but maybe there are things
# we want to guarantee about any imfc's added later.
imfc = image_mobject_from_camera
assert(isinstance(imfc.camera, MovingCamera))
self.image_mobjects_from_cameras.append(imfc)
def update_sub_cameras(self):
@ -47,6 +48,12 @@ class MultiCamera(MovingCamera):
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):
# Make sure all frames are in mobjects? Or not?
self.update_sub_cameras()
@ -58,3 +65,4 @@ class MultiCamera(MovingCamera):
)
imfc.camera.capture_mobjects(to_add, **kwargs)
MovingCamera.capture_mobjects(self, mobjects, **kwargs)

View File

@ -55,7 +55,7 @@ class ZoomedScene(Scene):
self.zoomed_camera = zoomed_camera
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
zoomed_camera = self.zoomed_camera
zoomed_display = self.zoomed_display
@ -63,7 +63,7 @@ class ZoomedScene(Scene):
to_add = [zoomed_camera.frame, zoomed_display]
if animate:
zoomed_display.save_state()
zoomed_display.save_state(use_deepcopy=True)
zoomed_display.replace(zoomed_camera.frame)
full_frame_height, full_frame_width = self.camera.frame_shape