a
    
dT                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ dZdZ	ej
ddG d	d
 d
Zdd Zdd Zdd ZdddZdd ZdS )z+Internal information about the mesh plugin.    N)Any)summary_pb2)plugin_data_pb2ZmeshT)frozenc                   @   s.   e Zd ZU dZeed< ejjed< eed< dS )
MeshTensora  A mesh tensor.

    Attributes:
      data: Tensor of shape `[dim_1, ..., dim_n, 3]` representing the mesh data
        of one of the following:
          - 3D coordinates of vertices
          - Indices of vertices within each triangle
          - Colors for each vertex
      content_type: Type of the mesh plugin data content.
      data_type: Data type of the elements in the tensor.
    datacontent_typeZ	data_typeN)	__name__
__module____qualname____doc__r   __annotations__r   MeshPluginDataContentType r   r   j/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/tensorboard/plugins/mesh/metadata.pyr      s   
r   c                 C   s2   d}| D ]$}|t jjkr td|d|> B }q|S )zCreates bitmask for all existing components of the summary.

    Args:
      content_type: list of plugin_data_pb2.MeshPluginData.ContentType,
        representing all components related to the summary.
    Returns: bitmask based on passed tensors.
    r   z.Cannot include UNDEFINED content type in mask.   )r   r   	UNDEFINED
ValueError)Zcontent_types
componentsr   r   r   r   get_components_bitmask2   s    r   c                   C   s   t S )z%Returns current verions of the proto.)_PROTO_VERSIONr   r   r   r   get_current_versionB   s    r   c                 C   s   d| t jj|f S )zKReturns a unique instance name for a given summary related to the
    mesh.z%s_%s)r   r   r   Name)namer   r   r   r   get_instance_nameG   s    r   c           	      C   sX   t |dkrtdt| tjt | ||||d}| }tj||tjj	t
|ddS )a  Creates summary metadata which defined at MeshPluginData proto.

    Arguments:
      name: Original merged (summaries of different types) summary name.
      display_name: The display name used in TensorBoard.
      content_type: Value from MeshPluginData.ContentType enum describing data.
      components: Bitmask representing present parts (vertices, colors, etc.) that
        belong to the summary.
      shape: list of dimensions sizes of the tensor.
      description: The description to show in TensorBoard.
      json_config: A string, JSON-serialized dictionary of ThreeJS classes
        configuration.

    Returns:
      A `summary_pb2.SummaryMetadata` protobuf object.
       z2Tensor shape should be of shape BxNx3, but got %s.)versionr   r   r   shapejson_config)Zplugin_namecontent)display_nameZsummary_descriptionZplugin_data)lenr   strr   r   r   ZSerializeToStringr   ZSummaryMetadataZ
PluginDataPLUGIN_NAME)	r   r!   r   r   r   descriptionr   Zmesh_plugin_datar    r   r   r   create_summary_metadataP   s(    
r&   c                 C   sH   t | tstdtj| }|jdkrDttjjtjj	tjj
g|_|S )a"  Parse summary metadata to a Python object.

    Arguments:
      content: The `content` field of a `SummaryMetadata` proto
        corresponding to the mesh plugin.

    Returns:
      A `MeshPluginData` protobuf object.
    Raises: Error if the version of the plugin is not supported.
    zContent type must be bytes.r   )
isinstancebytes	TypeErrorr   r   Z
FromStringr   r   ZVERTEXZFACEZCOLOR)r    resultr   r   r   parse_plugin_metadata   s    

r+   )NN)r   Zdataclassestypingr   Ztensorboard.compat.protor   Ztensorboard.plugins.meshr   r$   r   Z	dataclassr   r   r   r   r&   r+   r   r   r   r   <module>   s   
  
1