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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
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 | |
__hash
Link
__hash(resource_type, scan_id, fileset_id, file_id, size)
Create a hash for a resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the resource type, e.g. "image" or "pointcloud". |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 | |
__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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 |
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 | |
__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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 |
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 | |
__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 |
|---|---|---|---|
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 |
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 | |
__image_resize
Link
Resize a Pillow image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Image
|
A |
required |
|
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 | |
__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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
str | float
|
The requested size of the mesh.
Use 'orig' (default) to preserve the original mesh.
Use 'preview' to resize the mesh to a |
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 | |
__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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
str | float
|
The requested size of the mesh.
Use 'orig' (default) to preserve the original mesh.
Use 'preview' to resize the mesh to a |
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 | |
__mesh_hash
Link
__mesh_hash(scan_id, fileset_id, file_id, size)
Create a hash for a mesh resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 | |
__mesh_resize
Link
__mesh_resize(mesh, voxel_size)
Resize a mesh to given voxelsize within vertices are pooled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TriangleMesh
|
A mesh to resize to given voxelsize. |
required |
|
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 | |
__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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 |
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 | |
__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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 |
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 | |
__pointcloud_hash
Link
__pointcloud_hash(scan_id, fileset_id, file_id, size)
Create a hash for a pointcloud resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 | |
__pointcloud_resize
Link
__pointcloud_resize(pointcloud, voxel_size)
Resize a pointcloud to given voxelsize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
PointCloud
|
A pointcloud to resize to given voxelsize. |
required |
|
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 | |
__webcache_path
Link
Creates a 'webcache' directory in the scan directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
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 | |
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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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'
|
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 | |
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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
str | float
|
The requested size of the mesh.
Use 'orig' (default) to preserve the original mesh.
Use 'preview' to resize the mesh to a |
'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 | |
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 |
|---|---|---|---|
|
FSDB
|
The database object. |
required |
|
str
|
The ID of the scan in the database. |
required |
|
str
|
The ID of the fileset in the scan. |
required |
|
str
|
The ID of the file in the fileset. |
required |
|
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 |
'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 | |