Cache
Bases:
SyncManager
- streamlit_pyvista.helpers.cache.get_decimated_content(pv_mesh_instance, file_ext)[source]
This function extract the String that represent a mesh.
- Parameters:
pv_mesh_instance (DataSet) – The mesh from which you want to get the String representation.
file_ext (str) – The file extension of the mesh.
- Returns:
A string representing the mesh.
- Return type:
str
Note
It could be then be written in a file and read by pv.read function. This function is mainly copied from pv.DataDet.save method.
- streamlit_pyvista.helpers.cache.decimated_mesh_from_file(mesh, save_dir, decimation_factor=0.5)[source]
Decimate a mesh and store it in a file.
- Parameters:
mesh (pv.DataSet) – The mesh you want to decimate.
save_dir (str) – The directory in which to save the decimated mesh.
decimation_factor (float, optional) – The reduction factor to aim for. Defaults to 0.5. E.g., if decimation_factor = 0.25 and the initial mesh has 1000 cells, the resulting mesh will have 750 cells.
- Returns:
The path to the decimated mesh.
- Return type:
str
Note
For more information about decimation using PyVista, see: https://docs.pyvista.org/version/stable/examples/01-filter/decimate#decimate-example
- streamlit_pyvista.helpers.cache.compute_decimation_factor(current_nbr_points, target_nbr_points)[source]
Compute the decimation reduction factor required to get to a target size number of points.
- Parameters:
current_nbr_points (float) – The number of points of the initial mesh.
target_nbr_points (float) – The number of points aimed after decimation.
- Returns:
The decimation_factor required to reach the target
- Return type:
float
- streamlit_pyvista.helpers.cache.save_file_content(file_content, save_path, ttl_minutes=10, process_func=None, process_args=None)[source]
Save file content to a cache, optionally process it, and return the path.
- Parameters:
file_content (bytes) – Content of the file to save in the cache
save_path (str) – {Cache directory}/{filename} to ideally store the content. The checksum will be added to
filename (the)
ttl_minutes (int) – Time to live of the element in the cache
process_func (Optional[Callable]) – Optional function to process the file (e.g., decimation for meshes)
process_args (Optional[dict]) – Optional arguments for the process_func
- Returns:
The path to the saved file or its processed version
- Return type:
tuple[str, Optional[str]]
Note
- The cache works as follows:
The hash of content passed as argument is computed. If one entry with the same hash exists already in the cache json, we take the file that was stored in it (we try to take the processed one if it exists) and we update the last access time to avoid deleting it if it was recently used
If the hash is not in the cache then a new entry is created and the content is processed with the function passed as parameter if there is one
Then the function return the path to the processed file in priority and to the original file if no processing happened
- streamlit_pyvista.helpers.cache.process_mesh(file_path, save_dir, decimation_factor, decimation_threshold)[source]
Decimate a mesh and store it in a file
- Parameters:
file_path (str) – The path to the mesh to decimate
save_dir (str) – The directory in which we should save the decimated mesh
decimation_factor (float) – The reduction factor to aim. e.g. decimation_factor = 0.25, initial mesh number of
cells (cells 1000 -> resulting mesh will have 750)
decimation_threshold (int) – The threshold under which we don’t decimate the mesh
- Returns:
the path to the decimated mesh or None if the mesh is under the decimation threshold
- Return type:
Optional[str]
- streamlit_pyvista.helpers.cache.save_mesh_content(mesh_content, save_dir, ttl_minutes=10, decimation_factor=None, decimation_threshold=6000)[source]
Save mesh content to a cache, optionally decimate it, and return the path.
- Parameters:
mesh_content (bytes) – content of the mesh
save_dir (str) – {Cache directory}/{filename} to ideally store the content. The checksum will be added to the
filename.
ttl_minutes (int) – Time to live of the element in the cache
decimation_factor (float) – The reduction factor to aim. e.g. decimation_factor = 0.25, initial mesh number of
1000 (cells) – -> resulting mesh will have 750 cells
decimation_threshold (int) – The threshold under which we don’t decimate the mesh
- Return type:
tuple[str,Optional[str]]
- Returns
str: The path to file decimated or not (depending on the threshold) in the cache
- streamlit_pyvista.helpers.cache.save_mesh_content_from_url(url, save_path, ttl_minutes=10, decimation_factor=None, decimation_threshold=6000)[source]
Save mesh content from a URL to a cache, optionally decimate it, and return the path.
- Parameters:
url (str) – URL to the mesh
save_path (str) – {Cache directory}/{filename} to ideally store the content. The checksum will be added to
filename (the)
ttl_minutes (int) – Time to live of the element in the cache
decimation_factor (float) – The reduction factor to aim. e.g. decimation_factor = 0.25, initial mesh number of
cells (cells 1000 -> resulting mesh will have 750)
decimation_threshold (int) – The threshold under which we don’t decimate the mesh
- Return type:
tuple[Optional[str],Optional[str]]
- Returns
Optional[str]: The path to file decimated or not (depending on the threshold) in the cache
- streamlit_pyvista.helpers.cache.save_mesh_content_from_file(path, save_path, ttl_minutes=10, decimation_factor=None, decimation_threshold=6000)[source]
Save mesh content from a file to a cache, optionally decimate it, and return the path.
- Parameters:
path (str) – Path to the mesh file
save_path (str) – {Cache directory}/{filename} to ideally store the content. The checksum will be added to
filename (the)
ttl_minutes (str) – Time to live of the element in the cache
decimation_factor (float) – The reduction factor to aim. e.g. decimation_factor = 0.25, initial mesh number of
cells (cells 1000 -> resulting mesh will have 750)
decimation_threshold (int) – The threshold under which we don’t decimate the mesh
- Return type:
tuple[Optional[str],Optional[str]]
- Returns
Optional[str]: The path to file decimated or not (depending on the threshold) in the cache