webcache
plantdb.server.webcache Link
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 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)
Return the path to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
__hash Link
__hash(resource_type, scan_id, fileset_id, file_id, size)
Create a hash for a resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_type
|
str
|
The name of the resource type, e.g. "image" or "pointcloud". |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
str
|
The requested size. |
required |
Returns:
Type | Description |
---|---|
str
|
The hash of the resource. |
Source code in plantdb/server/webcache.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
__image_cache Link
__image_cache(db, scan_id, fileset_id, file_id, size)
Create a cache for an image resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return. Else, should be a string in the given list. |
'orig'
|
Returns:
Type | Description |
---|---|
Path
|
The path to the cached image. |
Source code in plantdb/server/webcache.py
187 188 189 190 191 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 |
|
__image_cached_path Link
__image_cached_path(db, scan_id, fileset_id, file_id, size)
Get The path to the cached image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return. Else, should be a string in the given list. |
'orig'
|
Returns:
Type | Description |
---|---|
Path
|
The path to the cached image. |
Source code in plantdb/server/webcache.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
__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
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return. Else, should be a string in the given list. |
'orig'
|
Returns:
Type | Description |
---|---|
str
|
The image resource file name. |
Source code in plantdb/server/webcache.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
__image_resize Link
__image_resize(img, max_size)
Resize a Pillow
image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
Image
|
A |
required |
max_size
|
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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
__pointcloud_cache Link
__pointcloud_cache(db, scan_id, fileset_id, file_id, size)
Create a cache for a pointcloud resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, preview)
|
The requested size of the point cloud.
Obviously 'orig' preserve the original point cloud.
'preview' will resize the point cloud to a |
'orig'
|
See Also
__pointcloud_resize
Returns:
Type | Description |
---|---|
Path
|
The path to the cached pointcloud. |
Source code in plantdb/server/webcache.py
360 361 362 363 364 365 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 |
|
__pointcloud_cached_path Link
__pointcloud_cached_path(db, scan_id, fileset_id, file_id, size)
Get The path to the cached pointcloud.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, preview)
|
The requested size of the point cloud.
Obviously 'orig' preserve the original point cloud.
'preview' will resize the point cloud to a |
'orig'
|
Returns:
Type | Description |
---|---|
Path
|
The path to the cached pointcloud. |
Source code in plantdb/server/webcache.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
|
__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
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, preview)
|
The requested size ('orig' or 'preview'). |
'orig'
|
Returns:
Type | Description |
---|---|
str
|
The hash of the pointcloud resource. |
Source code in plantdb/server/webcache.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
__pointcloud_resize Link
__pointcloud_resize(pointcloud, voxel_size)
Resize a pointcloud to given voxelsize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pointcloud
|
PointCloud
|
A pointcloud to resize to given voxelsize. |
required |
voxel_size
|
float
|
The voxelsize to use for resampling. |
required |
Returns:
Type | Description |
---|---|
PointCloud
|
The resized pointcloud. |
Source code in plantdb/server/webcache.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
__webcache_path Link
__webcache_path(db, scan_id)
Creates a 'webcache' directory in the scan directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
image_path Link
image_path(db, scan_id, fileset_id, file_id, size='orig')
Get the path to an image file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, large, thumb)
|
If an integer, use it as the size of the cached image to create and return.
Otherwise, should be one of the following strings, default to
|
'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()
>>> # 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
264 265 266 267 268 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 |
|
mesh_path Link
mesh_path(db, scan_id, fileset_id, file_id, size='orig')
Get the path to a mesh file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
any
|
UNUSED. |
'orig'
|
Returns:
Type | Description |
---|---|
Path
|
The path to the original 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 pointcloud:
>>> 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')
>>> db.disconnect()
Source code in plantdb/server/webcache.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
|
pointcloud_path Link
pointcloud_path(db, scan_id, fileset_id, file_id, size='orig')
Get the path to a point cloud file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
FSDB
|
The database object. |
required |
scan_id
|
str
|
The ID of the scan in the database. |
required |
fileset_id
|
str
|
The ID of the fileset in the scan. |
required |
file_id
|
str
|
The ID of the file in the fileset. |
required |
size
|
(orig, preview)
|
The requested size of the point cloud.
Obviously 'orig' preserve the original point cloud.
'preview' will 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
444 445 446 447 448 449 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 |
|