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 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: 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)
def display_multiple_vectorized_mobjects(self, vmobjects): 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) else: self.display_multiple_non_background_colored_vmobjects(batch)
def display_multiple_vectorized_mobjects(self, vmobjects): 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) else: self.display_multiple_non_background_colored_vmobjects(batch)
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 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) for cvmobject in batch: self.camera.display_vectorized(cvmobject, self.canvas) self.canvas.flush() new_array = np.array( (background_array * self.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.pixel_array[:, :] = 0 self.reset_canvas() return curr_array
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) for cvmobject in batch: self.camera.display_vectorized(cvmobject, self.canvas) self.canvas.flush() new_array = np.array( (background_array * self.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.pixel_array[:, :] = 0 self.reset_canvas() return curr_array