def capture_mobjects(self, mobjects, **kwargs): mobjects = self.get_mobjects_to_display(mobjects, **kwargs) # Organize this list into batches of the same type, and # apply corresponding function to those batches type_func_pairs = [ (VMobject, self.display_multiple_vectorized_mobjects), (PMobject, self.display_multiple_point_cloud_mobjects), (AbstractImageMobject, self.display_multiple_image_mobjects), (Mobject, lambda batch, pa: batch), # Do nothing ] def get_mobject_type(mobject): for mobject_type, func in type_func_pairs: if isinstance(mobject, mobject_type): return mobject_type raise Exception( "Trying to display something which is not of type Mobject" ) batch_type_pairs = batch_by_property(mobjects, get_mobject_type) # Display in these batches for batch, batch_type in batch_type_pairs: # check what the type is, and call the appropriate function for mobject_type, func in type_func_pairs: if batch_type == mobject_type: func(batch, self.pixel_array)
def display_multiple_vectorized_mobjects(self, vmobjects, pixel_array): if len(vmobjects) == 0: return batch_file_pairs = batch_by_property( vmobjects, lambda vm: vm.get_background_image_file() ) for batch, file_name in batch_file_pairs: if file_name: self.display_multiple_background_colored_vmobject(batch, pixel_array) else: self.display_multiple_non_background_colored_vmobjects(batch, pixel_array)
def capture(self, *mobjects, **kwargs): self.refresh_shader_uniforms() shader_infos = it.chain( *[mob.get_shader_info_list() for mob in mobjects]) batches = batch_by_property(shader_infos, shader_info_to_id) for info_group, sid in batches: if len(info_group) == 1: data = info_group[0]["data"] else: data = np.hstack([info["data"] for info in info_group]) shader = self.get_shader(info_group[0]) render_primative = int(info_group[0]["render_primative"]) self.render(shader, data, render_primative)
def display(self, *cvmobjects): batch_image_file_pairs = batch_by_property( cvmobjects, lambda cv: cv.get_background_image_file()) curr_array = None for batch, image_file in batch_image_file_pairs: background_array = self.get_background_array(image_file) pixel_array = self.pixel_array self.camera.display_multiple_non_background_colored_vmobjects( batch, pixel_array) new_array = np.array( (background_array * pixel_array.astype('float') / 255), dtype=self.camera.pixel_array_dtype) if curr_array is None: curr_array = new_array else: curr_array = np.maximum(curr_array, new_array) self.reset_pixel_array() return curr_array
def get_shader_info_list(self): if self.shader_data_is_locked: return self.saved_shader_info_list shader_infos = it.chain( [self.get_shader_info()], *[ submob.get_shader_info_list() for submob in self.submobjects ] ) batches = batch_by_property(shader_infos, shader_info_to_id) result = [] for info_group, sid in batches: shader_info = shader_id_to_info(sid) shader_info["data"] = np.hstack([info["data"] for info in info_group]) if is_valid_shader_info(shader_info): result.append(shader_info) return result
def display(self, *cvmobjects): batch_image_file_pairs = batch_by_property( cvmobjects, lambda cv: cv.get_background_image_file() ) curr_array = None for batch, image_file in batch_image_file_pairs: background_array = self.get_background_array(image_file) pixel_array = self.pixel_array self.camera.display_multiple_non_background_colored_vmobjects( batch, pixel_array ) new_array = np.array( (background_array * pixel_array.astype('float') / 255), dtype=self.camera.pixel_array_dtype ) if curr_array is None: curr_array = new_array else: curr_array = np.maximum(curr_array, new_array) self.reset_pixel_array() return curr_array