o
    2h{                     @   s|   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	 Zd
d Z					dddZ	dddZdS )zFMesh summaries and TensorFlow operations to create them.

V2 versions
    N)tf2)summary_pb2)metadata)plugin_data_pb2)tensor_utilc           	   	   C   sX   t j|d}|j }dd |D }tj| d|||||d}t jjt| ||||dS )a  Creates a tensor summary with summary metadata.

    Args:
      name: A name for this summary. The summary tag used for TensorBoard will
        be this name prefixed by any active name scopes.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.
      tensor: Tensor to display in summary.
      content_type: Type of content inside the Tensor.
      components: Bitmask representing present parts (vertices, colors, etc.) that
        belong to the summary.
      json_config: A string, JSON-serialized dictionary of ThreeJS classes
        configuration.
      step: Explicit `int64`-castable monotonic step value for this summary. If
        omitted, this defaults to `tf.summary.experimental.get_step()`, which must
        not be None.

    Returns:
      A boolean indicating if summary was saved successfully or not.
    )valuec                 S      g | ]
}|d ur
|ndqS N .0dimr   r   ^/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/plugins/mesh/summary_v2.py
<listcomp>6       z"_write_summary.<locals>.<listcomp>Njson_config)tagtensorstepr   )	tfconvert_to_tensorshapeas_listr   create_summary_metadatasummarywriteget_instance_name)	namedescriptionr   content_type
componentsr   r   r   tensor_metadatar   r   r   _write_summary   s$   
	
r$   c                 C   s   d}| durt j| dd}|S )z6Parses and returns JSON string from python dictionary.z{}NT)	sort_keys)jsondumps)config_dictr   r   r   r   _get_json_configH   s   r)   c              
   C   s   t |}t|tjjtjt|tjjtj	t|tjj
tjg}dd |D }tdd |D }	ttjjddp=tjj}
d}|
| d|d |D ]}|oYt| ||j|j|	||}qJW d   |S 1 sfw   Y  |S )	a  Writes a TensorFlow mesh summary.

    Args:
      name: A name for this summary. The summary tag used for TensorBoard will
        be this name prefixed by any active name scopes.
      vertices: Tensor of shape `[dim_1, ..., dim_n, 3]` representing the 3D
        coordinates of vertices.
      faces: Tensor of shape `[dim_1, ..., dim_n, 3]` containing indices of
        vertices within each triangle.
      colors: Tensor of shape `[dim_1, ..., dim_n, 3]` containing colors for each
        vertex.
      config_dict: Dictionary with ThreeJS classes names and configuration.
      step: Explicit `int64`-castable monotonic step value for this summary. If
        omitted, this defaults to `tf.summary.experimental.get_step()`, which must
        not be None.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.

    Returns:
      True if all components of the mesh were saved successfully and False
        otherwise.
    c                 S      g | ]	}|j d ur|qS Ndatar   r   r   r   r   r          zmesh.<locals>.<listcomp>c                 S      g | ]}|j qS r   r!   r.   r   r   r   r          summary_scopeNTmesh_summary)values)r)   r   
MeshTensorr   MeshPluginDataVERTEXr   float32FACEint32COLORuint8get_components_bitmaskgetattrr   experimentalr3   r$   r-   r!   )r   verticesfacescolorsr(   r   r    r   tensorsr"   r3   all_successr   r   r   r   meshP   sF   
rF   c              
   C   s   t |}g }t|tjjtjt|tjjtj	t|tjj
tjg}dd |D }tdd |D }	|D ]2}
|
jj}dd |D }tj|
j|
jd}tj| d|
j|	|||d}t| |
j}||||f q6t }|D ]\}}}|jj|||d qo|S )	a  Create a mesh summary to save in pb format.

    Args:
      tag: String tag for the summary.
      vertices: numpy array of shape `[dim_1, ..., dim_n, 3]` representing the 3D
        coordinates of vertices.
      faces: numpy array of shape `[dim_1, ..., dim_n, 3]` containing indices of
        vertices within each triangle.
      colors: numpy array of shape `[dim_1, ..., dim_n, 3]` containing colors for
        each vertex.
      config_dict: Dictionary with ThreeJS classes names and configuration.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.

    Returns:
      Instance of tf.Summary class.
    c                 S   r*   r+   r,   r.   r   r   r   r      r/   zmesh_pb.<locals>.<listcomp>c                 S   r0   r   r1   r.   r   r   r   r      r2   c                 S   r   r	   r   r   r   r   r   r      r   )dtypeNr   )r   r   r   )r)   r   r6   r   r7   r8   r   r9   r:   r;   r<   r=   r>   r-   r   r   make_tensor_proto	data_typer   r!   r   appendr   Summaryr   add)r   rA   rB   rC   r(   r    r   	summariesrD   r"   r   r   tensor_protosummary_metadatainstance_tagr   r   r   r   mesh_pb   sN   	rQ   )NNNNN)NNNN)__doc__r&   tensorboard.compatr   r   tensorboard.compat.protor   tensorboard.plugins.meshr   r   tensorboard.utilr   r$   r)   rF   rQ   r   r   r   r   <module>   s"   +
J