Delete deprecated camera classes

This commit is contained in:
Grant Sanderson 2021-01-12 12:26:08 -10:00
parent c4f190cfc4
commit 7c8162a6f7
3 changed files with 0 additions and 252 deletions

View file

@ -1,113 +0,0 @@
import numpy as np
from manimlib.camera.camera import Camera
from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.utils.config_ops import DictAsObject
from manimlib.utils.config_ops import digest_config
# TODO: Add an attribute to mobjects under which they can specify that they should just
# map their centers but remain otherwise undistorted (useful for labels, etc.)
# TODO, this class is deprecated
class MappingCamera(Camera):
CONFIG = {
"mapping_func": lambda p: p,
"min_num_curves": 50,
"allow_object_intrusion": False
}
def points_to_pixel_coords(self, points):
return Camera.points_to_pixel_coords(self, np.apply_along_axis(self.mapping_func, 1, points))
def capture_mobjects(self, mobjects, **kwargs):
mobjects = self.get_mobjects_to_display(mobjects, **kwargs)
if self.allow_object_intrusion:
mobject_copies = mobjects
else:
mobject_copies = [mobject.copy() for mobject in mobjects]
for mobject in mobject_copies:
if isinstance(mobject, VMobject) and \
0 < mobject.get_num_curves() < self.min_num_curves:
mobject.insert_n_curves(self.min_num_curves)
Camera.capture_mobjects(
self, mobject_copies,
excluded_mobjects=None,
)
# Note: This allows layering of multiple cameras onto the same portion of the pixel array,
# the later cameras overwriting the former
#
# TODO: Add optional separator borders between cameras (or perhaps peel this off into a
# CameraPlusOverlay class)
# TODO, the classes below should likely be deleted
class OldMultiCamera(Camera):
def __init__(self, *cameras_with_start_positions, **kwargs):
self.shifted_cameras = [
DictAsObject(
{
"camera": camera_with_start_positions[0],
"start_x": camera_with_start_positions[1][1],
"start_y": camera_with_start_positions[1][0],
"end_x": camera_with_start_positions[1][1] + camera_with_start_positions[0].get_pixel_width(),
"end_y": camera_with_start_positions[1][0] + camera_with_start_positions[0].get_pixel_height(),
})
for camera_with_start_positions in cameras_with_start_positions
]
Camera.__init__(self, **kwargs)
def capture_mobjects(self, mobjects, **kwargs):
for shifted_camera in self.shifted_cameras:
shifted_camera.camera.capture_mobjects(mobjects, **kwargs)
self.pixel_array[
shifted_camera.start_y:shifted_camera.end_y,
shifted_camera.start_x:shifted_camera.end_x] \
= shifted_camera.camera.pixel_array
def set_background(self, pixel_array, **kwargs):
for shifted_camera in self.shifted_cameras:
shifted_camera.camera.set_background(
pixel_array[
shifted_camera.start_y:shifted_camera.end_y,
shifted_camera.start_x:shifted_camera.end_x],
**kwargs
)
def set_pixel_array(self, pixel_array, **kwargs):
Camera.set_pixel_array(self, pixel_array, **kwargs)
for shifted_camera in self.shifted_cameras:
shifted_camera.camera.set_pixel_array(
pixel_array[
shifted_camera.start_y:shifted_camera.end_y,
shifted_camera.start_x:shifted_camera.end_x],
**kwargs
)
def init_background(self):
Camera.init_background(self)
for shifted_camera in self.shifted_cameras:
shifted_camera.camera.init_background()
# A OldMultiCamera which, when called with two full-size cameras, initializes itself
# as a splitscreen, also taking care to resize each individual camera within it
class SplitScreenCamera(OldMultiCamera):
def __init__(self, left_camera, right_camera, **kwargs):
digest_config(self, kwargs)
self.left_camera = left_camera
self.right_camera = right_camera
half_width = self.get_pixel_width() / 2
for camera in [self.left_camera, self.right_camera]:
# TODO: Round up on one if width is odd
camera.reset_pixel_shape(half_width, camera.get_pixel_height())
OldMultiCamera.__init__(
self,
(left_camera, (0, 0)),
(right_camera, (0, half_width)),
)

View file

@ -1,82 +0,0 @@
from manimlib.camera.camera import Camera
from manimlib.constants import FRAME_HEIGHT
from manimlib.constants import FRAME_WIDTH
from manimlib.constants import ORIGIN
from manimlib.constants import WHITE
from manimlib.mobject.frame import ScreenRectangle
from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.utils.config_ops import digest_config
# Depricated?
class MovingCamera(Camera):
"""
Stays in line with the height, width and position of it's 'frame', which is a Rectangle
"""
CONFIG = {
"fixed_dimension": 0, # width
"default_frame_stroke_color": WHITE,
"default_frame_stroke_width": 0,
}
def __init__(self, frame=None, **kwargs):
"""
frame is a Mobject, (should almost certainly be a rectangle)
determining which region of space the camera displys
"""
digest_config(self, kwargs)
if frame is None:
frame = ScreenRectangle(height=FRAME_HEIGHT)
frame.set_stroke(
self.default_frame_stroke_color,
self.default_frame_stroke_width,
)
self.frame = frame
Camera.__init__(self, **kwargs)
# TODO, make these work for a rotated frame
def get_frame_height(self):
return self.frame.get_height()
def get_frame_width(self):
return self.frame.get_width()
def get_frame_center(self):
return self.frame.get_center()
def set_frame_height(self, frame_height):
self.frame.stretch_to_fit_height(frame_height)
def set_frame_width(self, frame_width):
self.frame.stretch_to_fit_width(frame_width)
def set_frame_center(self, frame_center):
self.frame.move_to(frame_center)
# Since the frame can be moving around, the cairo
# context used for updating should be regenerated
# at each frame. So no caching.
def get_cached_cairo_context(self, pixel_array):
return None
def cache_cairo_context(self, pixel_array, ctx):
pass
# def reset_frame_center(self):
# self.frame_center = self.frame.get_center()
# def realign_frame_shape(self):
# height, width = self.frame_shape
# if self.fixed_dimension == 0:
# self.frame_shape = (height, self.frame.get_width())
# else:
# self.frame_shape = (self.frame.get_height(), width)
# self.resize_frame_shape(fixed_dimension=self.fixed_dimension)
def get_mobjects_indicating_movement(self):
"""
Returns all mobjets whose movement implies that the camera
should think of all other mobjects on the screen as moving
"""
return [self.frame]

View file

@ -1,57 +0,0 @@
from manimlib.camera.moving_camera import MovingCamera
from manimlib.utils.iterables import list_difference_update
class MultiCamera(MovingCamera):
CONFIG = {
"allow_cameras_to_capture_their_own_display": False,
}
def __init__(self, *image_mobjects_from_cameras, **kwargs):
self.image_mobjects_from_cameras = []
for imfc in image_mobjects_from_cameras:
self.add_image_mobject_from_camera(imfc)
MovingCamera.__init__(self, **kwargs)
def add_image_mobject_from_camera(self, image_mobject_from_camera):
# 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):
""" Reshape sub_camera pixel_arrays """
for imfc in self.image_mobjects_from_cameras:
pixel_height, pixel_width = self.get_pixel_array().shape[:2]
imfc.camera.frame_shape = (
imfc.camera.frame.get_height(),
imfc.camera.frame.get_width(),
)
imfc.camera.reset_pixel_shape(
int(pixel_width * imfc.get_width() / self.get_frame_width()),
int(pixel_height * imfc.get_height() / self.get_frame_height()),
)
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):
self.update_sub_cameras()
for imfc in self.image_mobjects_from_cameras:
to_add = list(mobjects)
if not self.allow_cameras_to_capture_their_own_display:
to_add = list_difference_update(
to_add, imfc.get_family()
)
imfc.camera.capture_mobjects(to_add, **kwargs)
MovingCamera.capture_mobjects(self, mobjects, **kwargs)
def get_mobjects_indicating_movement(self):
return [self.frame] + [
imfc.camera.frame
for imfc in self.image_mobjects_from_cameras
]