Skip to content

webcache

This module provides three utility functions that are used in combination with the DB interface to create downsized versions of images, point clouds, and mesh resources. The resources are identified using the Scan, Fileset, and File IDs. The downsized versions are cached in the 'webcache' directory in the scan directory.

The following size specifications are available:

  • Images: 'thumb' (max. 150x150), 'large' (max. 1500x1500), and 'orig' (original size).
  • Point clouds: 'preview' (max. 10k points), and 'orig' (original size).
  • Mesh: 'orig' (original size). TODO: add remeshing

Examples:

>>> from plantdb.server import webcache
>>> from os import environ
>>> from plantdb.commons.fsdb.core import FSDB
>>> db = FSDB(environ.get('ROMI_DB', "/data/ROMI/DB/"))
>>> db.connect()
>>> # Get the path to the original image:
>>> webcache.image_path(db,'sango36','images','00000_rgb','orig')
>>> # Get the path to the thumb image (resized and cached):
>>> webcache.image_path(db,'sango36','images','00000_rgb','thumb')
>>> # Get the path to the original pointcloud:
>>> webcache.pointcloud_path(db,'sango_90_300_36','PointCloud_1_0_0_0_10_0_ca07eb2790','PointCloud','orig')
>>> # Get the path to the preview pointcloud (resized and cached):
>>> webcache.pointcloud_path(db,'sango_90_300_36','PointCloud_1_0_0_0_10_0_ca07eb2790','PointCloud','preview')
>>> # Get the path to a downsampled pointcloud (resized and cached):
>>> webcache.pointcloud_path(db,'sango_90_300_36','PointCloud_1_0_0_0_10_0_ca07eb2790','PointCloud','2.3')
>>> db.disconnect()

__file_path Link

__file_path(db, scan_id, fileset_id, file_id, **kwargs)

Return the path to a file.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

Returns:

Type Description
Path

The path to the file.

Source code in plantdb/server/webcache.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def __file_path(db, scan_id, fileset_id, file_id, **kwargs) -> Path:
    """Return the path to a file.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.

    Returns
    -------
    pathlib.Path
        The path to the file.
    """
    scan = db.get_scan(scan_id, **kwargs)
    fs = scan.get_fileset(fileset_id)
    f = fs.get_file(file_id)
    return db.basedir / scan.id / fs.id / f.filename

__hash Link

Create a hash for a resource.

Parameters:

Name Type Description Default

resource_type Link

str

The name of the resource type, e.g. "image" or "pointcloud".

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str

The requested size.

required

Returns:

Type Description
str

The hash of the resource.

Source code in plantdb/server/webcache.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def __hash(resource_type, scan_id, fileset_id, file_id, size) -> str:
    """Create a hash for a resource.

    Parameters
    ----------
    resource_type : str
        The name of the resource type, *e.g.* "image" or "pointcloud".
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str
        The requested size.

    Returns
    -------
    str
        The hash of the resource.
    """
    m = hashlib.sha1()
    key = f"{resource_type}|{scan_id}|{fileset_id}|{file_id}|{size}"
    m.update(key.encode('utf-8'))
    return m.hexdigest()

__image_cache Link

__image_cache(db, scan_id, fileset_id, file_id, size, **kwargs)

Create a cache for an image resource.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | int

If an integer, use it as the size of the cached image to create and return. Else, it should be a string from ['orig', 'large', 'thumb'].

required

Returns:

Type Description
Path

The path to the cached image.

Source code in plantdb/server/webcache.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
def __image_cache(db, scan_id, fileset_id, file_id, size, **kwargs):
    """Create a cache for an image resource.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | int, optional
        If an integer, use it as the size of the cached image to create and return.
        Else, it should be a string from ``['orig', 'large', 'thumb']``.

    Returns
    -------
    pathlib.Path
        The path to the cached image.
    """
    # Get the path to the original image:
    src = __file_path(db, scan_id, fileset_id, file_id, **kwargs)

    # Get the path to the 'webcache' directory:
    cache_dir = __webcache_path(db, scan_id)
    dst = cache_dir / __image_hash(scan_id, fileset_id, file_id, size)

    # Load the image and resize it:
    image = Image.open(src)
    image.load()
    if isinstance(size, int):
        maxsize = size
    else:
        maxsize = IMG_RESOLUTIONS.get(size)
    image = __image_resize(image, maxsize)
    # Make sure we have an RGB image to be able to save in this format:
    if image.mode != "RGB":
        image = image.convert(mode="RGB")
    save_kwargs = {'quality': 84, 'optimize': True}
    # Save the resized image in the "webcache" directory:
    image.save(dst, **save_kwargs)
    logger.info(f"Converted '{src}' to '{dst}', using size '{maxsize}'")

    return dst

__image_cached_path Link

__image_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs)

Get The path to the cached image.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | int

If an integer, use it as the size of the cached image to create and return. Else, it should be a string from ['orig', 'large', 'thumb'].

required

Returns:

Type Description
Path

The path to the cached image.

Source code in plantdb/server/webcache.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
def __image_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs):
    """Get The path to the cached image.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | int, optional
        If an integer, use it as the size of the cached image to create and return.
        Else, it should be a string from ``['orig', 'large', 'thumb']``.

    Returns
    -------
    pathlib.Path
        The path to the cached image.
    """
    cache_dir = __webcache_path(db, scan_id)
    img_path = cache_dir / __image_hash(scan_id, fileset_id, file_id, size)
    if not img_path.is_file():
        __image_cache(db, scan_id, fileset_id, file_id, size, **kwargs)
    return img_path

__image_hash Link

__image_hash(scan_id, fileset_id, file_id, size)

Create a file name for an image resource using a hash value.

Parameters:

Name Type Description Default

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | int

If an integer, use it as the size of the cached image to create and return. Else, it should be a string from ['orig', 'large', 'thumb'].

required

Returns:

Type Description
str

The image resource file name.

Source code in plantdb/server/webcache.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def __image_hash(scan_id, fileset_id, file_id, size) -> str:
    """Create a file name for an image resource using a hash value.

    Parameters
    ----------
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | int, optional
        If an integer, use it as the size of the cached image to create and return.
        Else, it should be a string from ``['orig', 'large', 'thumb']``.

    Returns
    -------
    str
        The image resource file name.
    """
    return __hash("image", scan_id, fileset_id, file_id, size) + ".jpeg"

__image_resize Link

__image_resize(img, max_size)

Resize a Pillow image.

Parameters:

Name Type Description Default

img Link

Image

A Pillow image to resize.

required

max_size Link

int

The requested max width or height size, in pixels.

required

Returns:

Type Description
Image

The resized image.

Source code in plantdb/server/webcache.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __image_resize(img, max_size) -> Image.Image:
    """Resize a ``Pillow`` image.

    Parameters
    ----------
    img : PIL.Image.Image
        A ``Pillow`` image to resize.
    max_size : int
        The requested max width or height size, in pixels.

    Returns
    -------
    PIL.Image.Image
        The resized image.
    """
    img.thumbnail((max_size, max_size))
    return img

__mesh_cache Link

__mesh_cache(db, scan_id, fileset_id, file_id, size, **kwargs)

Create a cache for a mesh resource.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | float

The requested size of the mesh. Use 'orig' (default) to preserve the original mesh. Use 'preview' to resize the mesh to a 1.8 voxel size. A float value will resize the mesh to a given voxel size.

required

Returns:

Type Description
Path

The path to the cached mesh.

Source code in plantdb/server/webcache.py
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
def __mesh_cache(db, scan_id, fileset_id, file_id, size, **kwargs):
    """Create a cache for a mesh resource.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | float
        The requested size of the mesh.
        Use 'orig' (default) to preserve the original mesh.
        Use 'preview' to resize the mesh to a `1.8` voxel size.
        A float value will resize the mesh to a given voxel size.

    Returns
    -------
    pathlib.Path
        The path to the cached mesh.
    """
    read_mesh = o3d.io.read_triangle_mesh
    write_mesh = o3d.io.write_triangle_mesh
    # Get the path to the 'webcache' directory:
    cache_dir = __webcache_path(db, scan_id)
    dst = cache_dir / __mesh_hash(scan_id, fileset_id, file_id, size)

    # Load the mesh and resize it:
    src = __file_path(db, scan_id, fileset_id, file_id, **kwargs)
    mesh = read_mesh(str(src))
    mesh_npts = len(mesh.vertices)  # get the number of vertices

    if isinstance(size, float):
        vxs = size
    else:
        vxs = 1.8
    mesh_lowres = __mesh_resize(mesh, vxs)
    mesh_lowres_npts = len(mesh_lowres.vertices)  # get the number of vertices

    write_mesh(str(dst), mesh_lowres)

    logger.info(f"Converted '{src}' to '{dst}', using voxelsize '{vxs}'")
    logger.info(f"  - Original number of vertices: {mesh_npts}")
    logger.info(f"  - Resized number of vertices: {mesh_lowres_npts}")

    return dst

__mesh_cached_path Link

__mesh_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs)

Get The path to the cached mesh.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | float

The requested size of the mesh. Use 'orig' (default) to preserve the original mesh. Use 'preview' to resize the mesh to a 1.8 voxel size. A float value will resize the mesh to a given voxel size.

required

Returns:

Type Description
Path

The path to the cached mesh.

Source code in plantdb/server/webcache.py
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
def __mesh_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs):
    """Get The path to the cached mesh.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | float
        The requested size of the mesh.
        Use 'orig' (default) to preserve the original mesh.
        Use 'preview' to resize the mesh to a `1.8` voxel size.
        A float value will resize the mesh to a given voxel size.

    Returns
    -------
    pathlib.Path
        The path to the cached mesh.
    """
    cache_dir = __webcache_path(db, scan_id)
    mesh_path = cache_dir / __mesh_hash(scan_id, fileset_id, file_id, size)
    if not mesh_path.is_file():
        __mesh_cache(db, scan_id, fileset_id, file_id, size, **kwargs)
    return mesh_path

__mesh_hash Link

__mesh_hash(scan_id, fileset_id, file_id, size)

Create a hash for a mesh resource.

Parameters:

Name Type Description Default

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str

The requested size ('orig' or 'preview').

required

Returns:

Type Description
str

The hash of the mesh resource.

Source code in plantdb/server/webcache.py
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
def __mesh_hash(scan_id, fileset_id, file_id, size):
    """Create a hash for a mesh resource.

    Parameters
    ----------
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str
        The requested size ('orig' or 'preview').

    Returns
    -------
    str
        The hash of the mesh resource.
    """
    return __hash("mesh", scan_id, fileset_id, file_id, size) + ".ply"

__mesh_resize Link

__mesh_resize(mesh, voxel_size)

Resize a mesh to given voxelsize within vertices are pooled.

Parameters:

Name Type Description Default

mesh Link

TriangleMesh

A mesh to resize to given voxelsize.

required

voxel_size Link

float

The voxelsize to use for resampling.

required

Returns:

Type Description
TriangleMesh

The resized mesh.

Source code in plantdb/server/webcache.py
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
def __mesh_resize(mesh, voxel_size):
    """Resize a mesh to given voxelsize within vertices are pooled.

    Parameters
    ----------
    mesh : open3d.geometry.TriangleMesh
        A mesh to resize to given voxelsize.
    voxel_size : float
        The voxelsize to use for resampling.

    Returns
    -------
    open3d.geometry.TriangleMesh
        The resized mesh.
    """
    # Use vertex clustering for meshes
    return mesh.simplify_vertex_clustering(voxel_size)

__pointcloud_cache Link

__pointcloud_cache(db, scan_id, fileset_id, file_id, size, **kwargs)

Create a cache for a pointcloud resource.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | float

The requested size of the point cloud. Use 'orig' (default) to preserve the original point cloud. Use 'preview' to resize the point cloud to a 1.8 voxel size. A float value will resize the point cloud to a given voxel size.

required
See Also

__pointcloud_resize

Returns:

Type Description
Path

The path to the cached pointcloud.

Source code in plantdb/server/webcache.py
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def __pointcloud_cache(db, scan_id, fileset_id, file_id, size, **kwargs):
    """Create a cache for a pointcloud resource.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | float
        The requested size of the point cloud.
        Use 'orig' (default) to preserve the original point cloud.
        Use 'preview' to resize the point cloud to a `1.8` voxel size.
        A float value will resize the point cloud to a given voxel size.

    See Also
    --------
    __pointcloud_resize

    Returns
    -------
    pathlib.Path
        The path to the cached pointcloud.
    """
    read_pointcloud = o3d.io.read_point_cloud
    write_pointcloud = o3d.io.write_point_cloud
    # Get the path to the 'webcache' directory:
    cache_dir = __webcache_path(db, scan_id)
    dst = cache_dir / __pointcloud_hash(scan_id, fileset_id, file_id, size)

    # Load the pointcloud and resize it:
    src = __file_path(db, scan_id, fileset_id, file_id, **kwargs)
    pcd = read_pointcloud(str(src))
    pcd_npts = len(pcd.points)  # get the number of points
    if isinstance(size, float):
        vxs = size
    else:
        vxs = 1.8
    pcd_lowres = __pointcloud_resize(pcd, vxs)
    pcd_lowres_npts = len(pcd_lowres.points)  # get the number of points
    write_pointcloud(str(dst), pcd_lowres)

    logger.info(f"Converted '{src}' to '{dst}', using voxelsize '{vxs}'")
    logger.info(f"  - Original number of points: {pcd_npts}")
    logger.info(f"  - Resized number of points: {pcd_lowres_npts}")

    return dst

__pointcloud_cached_path Link

__pointcloud_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs)

Get The path to the cached pointcloud.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | float

The requested size of the point cloud. Use 'orig' (default) to preserve the original point cloud. Use 'preview' to resize the point cloud to a 1.8 voxel size. A float value will resize the point cloud to a given voxel size.

required

Returns:

Type Description
Path

The path to the cached pointcloud.

Source code in plantdb/server/webcache.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
def __pointcloud_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs):
    """Get The path to the cached pointcloud.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | float
        The requested size of the point cloud.
        Use 'orig' (default) to preserve the original point cloud.
        Use 'preview' to resize the point cloud to a `1.8` voxel size.
        A float value will resize the point cloud to a given voxel size.

    Returns
    -------
    pathlib.Path
        The path to the cached pointcloud.
    """
    cache_dir = __webcache_path(db, scan_id)
    pcd_path = cache_dir / __pointcloud_hash(scan_id, fileset_id, file_id, size)
    if not pcd_path.is_file():
        __pointcloud_cache(db, scan_id, fileset_id, file_id, size, **kwargs)
    return pcd_path

__pointcloud_hash Link

__pointcloud_hash(scan_id, fileset_id, file_id, size)

Create a hash for a pointcloud resource.

Parameters:

Name Type Description Default

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str

The requested size ('orig' or 'preview').

required

Returns:

Type Description
str

The hash of the pointcloud resource.

Source code in plantdb/server/webcache.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def __pointcloud_hash(scan_id, fileset_id, file_id, size):
    """Create a hash for a pointcloud resource.

    Parameters
    ----------
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str
        The requested size ('orig' or 'preview').

    Returns
    -------
    str
        The hash of the pointcloud resource.
    """
    return __hash("pointcloud", scan_id, fileset_id, file_id, size) + ".ply"

__pointcloud_resize Link

__pointcloud_resize(pointcloud, voxel_size)

Resize a pointcloud to given voxelsize.

Parameters:

Name Type Description Default

pointcloud Link

PointCloud

A pointcloud to resize to given voxelsize.

required

voxel_size Link

float

The voxelsize to use for resampling.

required

Returns:

Type Description
PointCloud

The resized pointcloud.

Source code in plantdb/server/webcache.py
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
def __pointcloud_resize(pointcloud, voxel_size):
    """Resize a pointcloud to given voxelsize.

    Parameters
    ----------
    pointcloud : open3d.geometry.PointCloud
        A pointcloud to resize to given voxelsize.
    voxel_size : float
        The voxelsize to use for resampling.

    Returns
    -------
    open3d.geometry.PointCloud
        The resized pointcloud.
    """
    return pointcloud.voxel_down_sample(voxel_size)

__webcache_path Link

__webcache_path(db, scan_id)

Creates a 'webcache' directory in the scan directory.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

Returns:

Type Description
Path

The path to the 'webcache' directory for the given scan.

Source code in plantdb/server/webcache.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def __webcache_path(db, scan_id: str) -> Path:
    """Creates a 'webcache' directory in the scan directory.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.

    Returns
    -------
    pathlib.Path
        The path to the 'webcache' directory for the given scan.
    """
    directory = db.basedir / scan_id / "webcache"
    directory.mkdir(exist_ok=True)
    return directory

image_path Link

image_path(db, scan_id, fileset_id, file_id, size='orig', **kwargs)

Get the path to an image file.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | int

If an integer, use it as the size of the cached image to create and return. Else, it should be a string from ['orig', 'large', 'thumb'], where:

  • 'thumb': image max width and height to 150.
  • 'large': image max width and height to 1500;
  • 'orig': original image, no chache;
'orig'

Returns:

Type Description
Path

The path to the original or cached image.

Examples:

>>> from plantdb.server.webcache import image_path
>>> from plantdb.commons.test_database import test_database
>>> db = test_database('real_plant_analyzed')
>>> db.connect()
>>> db.login('guest', 'guest')
>>> # Example 1: Get the original image:
>>> image_path(db, 'real_plant_analyzed', 'images', '00000_rgb', 'orig')
PosixPath('/tmp/ROMI_DB/real_plant_analyzed/images/00000_rgb.jpg')
>>> # Example 2: Get a thumbnail of the image:
>>> image_path(db, 'real_plant_analyzed', 'images', '00000_rgb', 'thumb')
PosixPath('/tmp/ROMI_DB/real_plant_analyzed/webcache/6fbae08f195837c511af7c2864d075dd5cd153bc.jpeg')
>>> db.disconnect()
Source code in plantdb/server/webcache.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
def image_path(db, scan_id, fileset_id, file_id, size='orig', **kwargs):
    """Get the path to an image file.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | int, optional
        If an integer, use  it as the size of the cached image to create and return.
        Else, it should be a string from ``['orig', 'large', 'thumb']``, where: 

          - `'thumb'`: image max width and height to `150`.
          - `'large'`: image max width and height to `1500`;
          - `'orig'`: original image, no chache;

    Returns
    -------
    pathlib.Path
        The path to the original or cached image.

    Examples
    --------
    >>> from plantdb.server.webcache import image_path
    >>> from plantdb.commons.test_database import test_database
    >>> db = test_database('real_plant_analyzed')
    >>> db.connect()
    >>> db.login('guest', 'guest')
    >>> # Example 1: Get the original image:
    >>> image_path(db, 'real_plant_analyzed', 'images', '00000_rgb', 'orig')
    PosixPath('/tmp/ROMI_DB/real_plant_analyzed/images/00000_rgb.jpg')
    >>> # Example 2: Get a thumbnail of the image:
    >>> image_path(db, 'real_plant_analyzed', 'images', '00000_rgb', 'thumb')
    PosixPath('/tmp/ROMI_DB/real_plant_analyzed/webcache/6fbae08f195837c511af7c2864d075dd5cd153bc.jpeg')
    >>> db.disconnect()
    """
    try:
        size = int(size)
    except ValueError:
        pass

    if size == "orig":
        return __file_path(db, scan_id, fileset_id, file_id, **kwargs)
    elif size == "large" or size == "thumb" or isinstance(size, int):
        return __image_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs)
    else:
        raise ValueError(f"Unknown image size specification: {size}")

mesh_path Link

mesh_path(db, scan_id, fileset_id, file_id, size='orig', **kwargs)

Get the path to a mesh file.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | float

The requested size of the mesh. Use 'orig' (default) to preserve the original mesh. Use 'preview' to resize the mesh to a 1.8 voxel size. A float value will resize the mesh to a given voxel size.

'orig'

Returns:

Type Description
Path

The path to the original or cached mesh.

Examples:

>>> from plantdb.server.webcache import mesh_path
>>> from plantdb.commons.test_database import test_database
>>> db = test_database('real_plant_analyzed')
>>> db.connect()
>>> # Example 1: Get the original mesh:
>>> mesh_path(db, 'real_plant_analyzed', 'TriangleMesh_9_most_connected_t_open3d_00e095c359', 'TriangleMesh', 'orig')
PosixPath('/tmp/ROMI_DB/real_plant_analyzed/TriangleMesh_9_most_connected_t_open3d_00e095c359/TriangleMesh.ply')
>>> # Example 2: Get a down-sampled version of the mesh:
>>> mesh_path(db, 'real_plant_analyzed', 'TriangleMesh_9_most_connected_t_open3d_00e095c359', 'TriangleMesh', 'preview')
PosixPath('/tmp/ROMI_DB/real_plant_analyzed/webcache/77e25820ddd8facd7d7a4bc5b17ad3c81046becc.ply')
>>> db.disconnect()
Source code in plantdb/server/webcache.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
def mesh_path(db, scan_id, fileset_id, file_id, size='orig', **kwargs):
    """Get the path to a mesh file.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | float
        The requested size of the mesh.
        Use 'orig' (default) to preserve the original mesh.
        Use 'preview' to resize the mesh to a `1.8` voxel size.
        A float value will resize the mesh to a given voxel size.

    Returns
    -------
    pathlib.Path
        The path to the original or cached mesh.

    Examples
    --------
    >>> from plantdb.server.webcache import mesh_path
    >>> from plantdb.commons.test_database import test_database
    >>> db = test_database('real_plant_analyzed')
    >>> db.connect()
    >>> # Example 1: Get the original mesh:
    >>> mesh_path(db, 'real_plant_analyzed', 'TriangleMesh_9_most_connected_t_open3d_00e095c359', 'TriangleMesh', 'orig')
    PosixPath('/tmp/ROMI_DB/real_plant_analyzed/TriangleMesh_9_most_connected_t_open3d_00e095c359/TriangleMesh.ply')
    >>> # Example 2: Get a down-sampled version of the mesh:
    >>> mesh_path(db, 'real_plant_analyzed', 'TriangleMesh_9_most_connected_t_open3d_00e095c359', 'TriangleMesh', 'preview')
    PosixPath('/tmp/ROMI_DB/real_plant_analyzed/webcache/77e25820ddd8facd7d7a4bc5b17ad3c81046becc.ply')
    >>> db.disconnect()
    """
    if size == "orig":
        logger.info("Using original mesh file")
        return __file_path(db, scan_id, fileset_id, file_id, **kwargs)
    elif size == "preview":
        logger.info("Using cached mesh file")
        return __mesh_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs)
    else:
        try:
            path = __mesh_cached_path(db, scan_id, fileset_id, file_id, float(size), **kwargs)
        except ValueError:
            raise ValueError(f"Unknown mesh size specification: {size}")
        else:
            return path

pointcloud_path Link

pointcloud_path(db, scan_id, fileset_id, file_id, size='orig', **kwargs)

Get the path to a point cloud file.

Parameters:

Name Type Description Default

db Link

FSDB

The database object.

required

scan_id Link

str

The ID of the scan in the database.

required

fileset_id Link

str

The ID of the fileset in the scan.

required

file_id Link

str

The ID of the file in the fileset.

required

size Link

str | float

The requested size of the point cloud. Use 'orig' (default) to preserve the original point cloud. Use 'preview' to resize the point cloud to a 1.8 voxel size. A float value will resize the point cloud to a given voxel size.

'orig'

Returns:

Type Description
Path

The path to the original or cached pointcloud.

Examples:

>>> from plantdb.server.webcache import pointcloud_path
>>> from plantdb.commons.test_database import test_database
>>> db = test_database('real_plant_analyzed')
>>> db.connect()
>>> # Example 1: Get the original pointcloud:
>>> pointcloud_path(db, 'real_plant_analyzed', 'PointCloud_1_0_1_0_10_0_7ee836e5a9', 'PointCloud', 'orig')
PosixPath('/tmp/ROMI_DB/real_plant_analyzed/PointCloud_1_0_1_0_10_0_7ee836e5a9/PointCloud.ply')
>>> # Example 2: Get a down-sampled version of the pointcloud:
>>> pointcloud_path(db, 'real_plant_analyzed', 'PointCloud_1_0_1_0_10_0_7ee836e5a9', 'PointCloud', 'preview')
PosixPath('/tmp/ROMI_DB/real_plant_analyzed/webcache/77e25820ddd8facd7d7a4bc5b17ad3c81046becc.ply')
>>> db.disconnect()
Source code in plantdb/server/webcache.py
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
def pointcloud_path(db, scan_id, fileset_id, file_id, size='orig', **kwargs):
    """Get the path to a point cloud file.

    Parameters
    ----------
    db : plantdb.commons.fsdb.core.FSDB
        The database object.
    scan_id : str
        The ID of the scan in the database.
    fileset_id : str
        The ID of the fileset in the scan.
    file_id : str
        The ID of the file in the fileset.
    size : str | float
        The requested size of the point cloud.
        Use 'orig' (default) to preserve the original point cloud.
        Use 'preview' to resize the point cloud to a `1.8` voxel size.
        A float value will resize the point cloud to a given voxel size.

    Returns
    -------
    pathlib.Path
        The path to the original or cached pointcloud.

    Examples
    --------
    >>> from plantdb.server.webcache import pointcloud_path
    >>> from plantdb.commons.test_database import test_database
    >>> db = test_database('real_plant_analyzed')
    >>> db.connect()
    >>> # Example 1: Get the original pointcloud:
    >>> pointcloud_path(db, 'real_plant_analyzed', 'PointCloud_1_0_1_0_10_0_7ee836e5a9', 'PointCloud', 'orig')
    PosixPath('/tmp/ROMI_DB/real_plant_analyzed/PointCloud_1_0_1_0_10_0_7ee836e5a9/PointCloud.ply')
    >>> # Example 2: Get a down-sampled version of the pointcloud:
    >>> pointcloud_path(db, 'real_plant_analyzed', 'PointCloud_1_0_1_0_10_0_7ee836e5a9', 'PointCloud', 'preview')
    PosixPath('/tmp/ROMI_DB/real_plant_analyzed/webcache/77e25820ddd8facd7d7a4bc5b17ad3c81046becc.ply')
    >>> db.disconnect()
    """
    if size == "orig":
        logger.info("Using original pointcloud file")
        return __file_path(db, scan_id, fileset_id, file_id, **kwargs)
    elif size == "preview":
        logger.info("Using cached pointcloud file")
        return __pointcloud_cached_path(db, scan_id, fileset_id, file_id, size, **kwargs)
    else:
        try:
            path = __pointcloud_cached_path(db, scan_id, fileset_id, file_id, float(size), **kwargs)
        except ValueError:
            raise ValueError(f"Unknown pointcloud size specification: {size}")
        else:
            return path