
    1Vh{                     t    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 Zd	 Z	 	 	 	 	 dd
Z	 ddZy)zFMesh summaries and TensorFlow operations to create them.

V2 versions
    N)tf2)summary_pb2)metadata)plugin_data_pb2)tensor_utilc           	      8   t        j                  |      }|j                  j                         }|D cg c]  }||nd
 }}t	        j
                  | d|||||      }	t         j                  j                  t	        j                  | |      |||	      S c c}w )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.
    )valueN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   dimtensor_metadatas
             S/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/plugins/mesh/summary_v2.py_write_summaryr      s    . !!/FLL  "E7<=COS+=E=66O ::&&t\: 	    >s   Bc                 <    d}| t        j                  | d      }|S )z6Parses and returns JSON string from python dictionary.z{}T)	sort_keys)jsondumps)config_dictr   s     r   _get_json_configr%   H   s#    Kjj=    c                 X   t        |      }t        j                  |t        j                  j
                  t        j                        t        j                  |t        j                  j                  t        j                        t        j                  |t        j                  j                  t        j                        g}|D 	cg c]  }	|	j                  |	 }}	t        j                  |D 	cg c]  }	|	j                   c}	      }
t        t        j                   j"                  dd      xs t        j                   j$                  }d} || d|      5  |D ]+  }	|xr% t'        | ||	j                  |	j                  |
||      }- 	 ddd       |S c c}	w c c}	w # 1 sw Y   |S xY w)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.
    Nsummary_scopeTmesh_summary)values)r%   r   
MeshTensorr   MeshPluginDataVERTEXr   float32FACEint32COLORuint8dataget_components_bitmaskr   getattrr   experimentalr(   r   )r   verticesfacescolorsr$   r   r   r   tensorsr   r   r(   all_successs                r   meshr<   P   sx   > #;/K 	o44;;RZZ	
 	?1166	
 	O2288"((	

G %,G&v{{/FvGGG00+23		3J
 	

''$? 	$::##  K	t^G	< 
 		F% .##+K		
 / H 	4
 s   FF1F1FF)c           
          t        |      }g }t        j                  |t        j                  j
                  t        j                        t        j                  |t        j                  j                  t        j                        t        j                  |t        j                  j                  t        j                        g}|D 	cg c]  }	|	j                  |	 }}	t        j                  |D 	cg c]  }	|	j                   c}	      }
|D ]  }	|	j                  j                  }|D cg c]  }||nd
 }}t!        j"                  |	j                  |	j$                        }t        j&                  | d|	j                  |
|||      }t        j(                  | |	j                        }|j+                  |||f        t-        j.                         }|D ]$  \  }}}|j0                  j3                  |||       & |S c c}	w c c}	w c c}w )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.
    Nr
   )dtyper   )r   r   r   )r%   r   r+   r   r,   r-   r   r.   r/   r0   r1   r2   r3   r4   r   r   r   make_tensor_proto	data_typer   r   appendr   Summaryr	   add)r   r7   r8   r9   r$   r   r   	summariesr:   r   r   r   r   tensor_protosummary_metadatainstance_tagr   s                    r   mesh_pbrH      s   ( #;/KIo44;;RZZ	
 	?1166	
 	O2288"((	

G %,G&v{{/FvGGG00+23		3J  I!!;@ACR/AA"44KKv//
 $;;#
  11#v7J7JK,(8,GH!I$ !!#G8A 
4&'7 	 	

 N7 H3 Bs   HH3H,H)NNNNN)NNNN)__doc__r"   tensorboard.compatr   r   tensorboard.compat.protor   tensorboard.plugins.meshr   r   tensorboard.utilr   r   r%   r<   rH    r&   r   <module>rO      sM   
  ( 0 - 4 ((V 	FT KO=r&   