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

This file is deprecated. See `summary_v2.py` instead.
    N)metadata)plugin_data_pb2)
summary_v2c              	   C   s`   t j|d}|j }dd |D }tj| ||||||d}	t jjjj	t
| |||	|d}
|
S )aZ  Creates a tensor summary with summary metadata.

    Args:
      name: Uniquely identifiable name of the summary op. Could be replaced by
        combination of name and type to make it unique even outside of this
        summary.
      display_name: Will be used as the display name in TensorBoard.
        Defaults to `tag`.
      description: A longform readable description of the summary data. Markdown
        is supported.
      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.
      collections: List of collections to add this summary to.

    Returns:
      Tensor summary with metadata.
    )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.py
<listcomp>A       z'_get_tensor_summary.<locals>.<listcomp>json_config)summary_metadatacollections)tfconvert_to_tensorshapeas_listr   create_summary_metadatacompatv1summarytensor_summaryget_instance_name)namedisplay_namedescriptiontensorcontent_type
componentsr   r   r   tensor_metadatar   r	   r	   r   _get_tensor_summary    s&   

	
r%   c                 C   s   |du r| S |S )z0Returns display_name from display_name and name.Nr	   )r   r   r	   r	   r   _get_display_nameT   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_config[   s   r+   c                 C   s   t | |}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 ]}|	t| |||j|j||| q;tjjjj|	|| d}|S )a  Creates a TensorFlow summary op for mesh rendering.

    DEPRECATED: see `summary_v2.py` instead.

    Args:
      name: A name for this summary operation.
      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.
      display_name: If set, will be used as the display name in TensorBoard.
        Defaults to `name`.
      description: A longform readable description of the summary data. Markdown
        is supported.
      collections: Which TensorFlow graph collections to add the summary op to.
        Defaults to `['summaries']`. Can usually be ignored.
      config_dict: Dictionary with ThreeJS classes names and configuration.

    Returns:
      Merged summary for mesh/point cloud representation.
    c                 S      g | ]	}|j d ur|qS Ndatar   r!   r	   r	   r   r          zop.<locals>.<listcomp>c                 S      g | ]}|j qS r	   r"   r0   r	   r	   r   r          )r   r   )r&   r+   r   
MeshTensorr   MeshPluginDataVERTEXr   float32FACEint32COLORuint8get_components_bitmaskappendr%   r/   r"   r   r   r   merge)r   verticesfacescolorsr   r    r   r*   r   	summariestensorsr#   r!   all_summariesr	   r	   r   opc   sD   
!
rF   c              
   C   s&  t | |}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 ]4}|jj}dd |D }tjjj|j|jd}tj| ||j|
|||d}t| |j}||||f q;tjj }|D ]\}}}tjjj| }|jj|||d qx|S )a8  Create a mesh summary to save in pb format.

    DEPRECATED: see `summary_v2.py` instead.

    Args:
      name: A name for this summary operation.
      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.
      display_name: If set, will be used as the display name in TensorBoard.
        Defaults to `name`.
      description: A longform readable description of the summary data. Markdown
        is supported.
      config_dict: Dictionary with ThreeJS classes names and configuration.

    Returns:
      Instance of tf.Summary class.
    c                 S   r,   r-   r.   r0   r	   r	   r   r      r1   zpb.<locals>.<listcomp>c                 S   r2   r	   r3   r0   r	   r	   r   r      r4   c                 S   r   r   r	   r
   r	   r	   r   r      r   )dtyper   )tagr   r!   )r&   r+   r   r5   r   r6   r7   r   r8   r9   r:   r;   r<   r=   r/   r   r   r   make_tensor_proto	data_typer   r"   r   r>   SummarySummaryMetadata
FromStringSerializeToStringr   add)r   r@   rA   rB   r   r    r*   r   rC   rD   r#   r!   r   tensor_protor   rH   r   tf_summary_metadatar	   r	   r   pb   sV   
	
rR   )NNNNNN)NNNNN)__doc__r(   
tensorflowr   tensorboard.plugins.meshr   r   r   meshmesh_pbr%   r&   r+   rF   rR   r	   r	   r	   r   <module>   s0   4
P