vkit.engine.char_mask.default
1# Copyright 2022 vkit-x Administrator. All Rights Reserved. 2# 3# This project (vkit-x/vkit) is dual-licensed under commercial and SSPL licenses. 4# 5# The commercial license gives you the full rights to create and distribute software 6# on your own terms without any SSPL license obligations. For more information, 7# please see the "LICENSE_COMMERCIAL.txt" file. 8# 9# This project is also available under Server Side Public License (SSPL). 10# The SSPL licensing is ideal for use cases such as open source projects with 11# SSPL distribution, student/academic purposes, hobby projects, internal research 12# projects without external distribution, or other projects where all SSPL 13# obligations can be met. For more information, please see the "LICENSE_SSPL.txt" file. 14from typing import Optional 15import attrs 16from numpy.random import Generator as RandomGenerator 17 18from vkit.element import Mask 19from ..interface import ( 20 Engine, 21 EngineExecutorFactory, 22 NoneTypeEngineInitResource, 23) 24from .type import CharMaskEngineRunConfig, CharMask 25 26 27@attrs.define 28class CharMaskDefaultEngineInitConfig: 29 pass 30 31 32class CharMaskDefaultEngine( 33 Engine[ 34 CharMaskDefaultEngineInitConfig, 35 NoneTypeEngineInitResource, 36 CharMaskEngineRunConfig, 37 CharMask, 38 ] 39): # yapf: disable 40 41 @classmethod 42 def get_type_name(cls) -> str: 43 return 'default' 44 45 def run( 46 self, 47 run_config: CharMaskEngineRunConfig, 48 rng: Optional[RandomGenerator] = None, 49 ) -> CharMask: 50 combined_chars_mask = Mask.from_shape((run_config.height, run_config.width)) 51 for char_polygon in run_config.char_polygons: 52 char_polygon.fill_mask(combined_chars_mask, keep_max_value=True) 53 return CharMask(combined_chars_mask=combined_chars_mask) 54 55 56char_mask_default_engine_executor_factory = EngineExecutorFactory(CharMaskDefaultEngine)
class
CharMaskDefaultEngineInitConfig:
class
CharMaskDefaultEngine(vkit.engine.interface.Engine[vkit.engine.char_mask.default.CharMaskDefaultEngineInitConfig, vkit.engine.interface.NoneTypeEngineInitResource, vkit.engine.char_mask.type.CharMaskEngineRunConfig, vkit.engine.char_mask.type.CharMask]):
33class CharMaskDefaultEngine( 34 Engine[ 35 CharMaskDefaultEngineInitConfig, 36 NoneTypeEngineInitResource, 37 CharMaskEngineRunConfig, 38 CharMask, 39 ] 40): # yapf: disable 41 42 @classmethod 43 def get_type_name(cls) -> str: 44 return 'default' 45 46 def run( 47 self, 48 run_config: CharMaskEngineRunConfig, 49 rng: Optional[RandomGenerator] = None, 50 ) -> CharMask: 51 combined_chars_mask = Mask.from_shape((run_config.height, run_config.width)) 52 for char_polygon in run_config.char_polygons: 53 char_polygon.fill_mask(combined_chars_mask, keep_max_value=True) 54 return CharMask(combined_chars_mask=combined_chars_mask)
Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows::
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
def
run( self, run_config: vkit.engine.char_mask.type.CharMaskEngineRunConfig, rng: Union[numpy.random._generator.Generator, NoneType] = None) -> vkit.engine.char_mask.type.CharMask:
46 def run( 47 self, 48 run_config: CharMaskEngineRunConfig, 49 rng: Optional[RandomGenerator] = None, 50 ) -> CharMask: 51 combined_chars_mask = Mask.from_shape((run_config.height, run_config.width)) 52 for char_polygon in run_config.char_polygons: 53 char_polygon.fill_mask(combined_chars_mask, keep_max_value=True) 54 return CharMask(combined_chars_mask=combined_chars_mask)