a
    d=ic                     @   st   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   s   g | ]}|d ur|ndqS N .0dimr   r   q/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/tensorboard/plugins/mesh/summary.py
<listcomp>A       z'_get_tensor_summary.<locals>.<listcomp>json_config)summary_metadatacollections)tfZ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   Z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||| qvt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   s   g | ]}|j d ur|qS Ndatar
   r   r   r   r   r      r   zop.<locals>.<listcomp>c                 S   s   g | ]
}|j qS r   r    r,   r   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   Zall_summariesr   r   r   opc   sD    !

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 ]h}|jj}dd |D }tjjj|j|jd}tj| ||j|
|||d}t| |j}||||f qvtjj }|D ]0\}}}tjjj| }|jj|||d q|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   s   g | ]}|j d ur|qS r)   r*   r,   r   r   r   r      r   zpb.<locals>.<listcomp>c                 S   s   g | ]
}|j qS r   r-   r,   r   r   r   r      r   c                 S   s   g | ]}|d ur|ndqS r   r   r	   r   r   r   r      r   )Zdtyper   )tagr   r   )r#   r(   r   r.   r   r/   r0   r   r1   r2   r3   r4   r5   r6   r+   r   r   r   Zmake_tensor_proto	data_typer   r    r   r7   SummaryZSummaryMetadataZ
FromStringZSerializeToStringr   add)r   r9   r:   r;   r   r   r'   r   r<   r=   r!   r   r   Ztensor_protor   r?   r   Ztf_summary_metadatar   r   r   pb   sV    
	
rC   )NNNNNN)NNNNN)__doc__r%   Z
tensorflowr   Ztensorboard.plugins.meshr   r   r   ZmeshZmesh_pbr"   r#   r(   r>   rC   r   r   r   r   <module>   s.   4      
P     