|
14 | 14 | from wkw import wkw |
15 | 15 | from wkw.wkw import WKWException |
16 | 16 |
|
| 17 | +from wkcuber.api.dataset import Dataset, DatasetViewConfiguration |
17 | 18 | from wkcuber.api.bounding_box import BoundingBox |
18 | | -from wkcuber.api.dataset import Dataset |
19 | 19 | from os import makedirs |
20 | 20 |
|
21 | | -from wkcuber.api.layer import Layer, LayerCategories, SegmentationLayer |
| 21 | +from wkcuber.api.layer import ( |
| 22 | + Layer, |
| 23 | + LayerCategories, |
| 24 | + SegmentationLayer, |
| 25 | + LayerViewConfiguration, |
| 26 | +) |
22 | 27 | from wkcuber.api.mag_view import MagView |
23 | 28 | from wkcuber.api.properties.dataset_properties import Properties |
24 | 29 | from wkcuber.api.properties.layer_properties import SegmentationLayerProperties |
25 | 30 | from wkcuber.api.properties.resolution_properties import Resolution |
26 | 31 | from wkcuber.api.view import View |
27 | 32 | from wkcuber.compress import compress_mag_inplace |
28 | 33 | from wkcuber.mag import Mag |
29 | | -from wkcuber.utils import get_executor_for_args, named_partial |
| 34 | +from wkcuber.utils import get_executor_for_args, named_partial, _snake_to_camel_case |
30 | 35 |
|
31 | 36 | TESTDATA_DIR = Path("testdata") |
32 | 37 | TESTOUTPUT_DIR = Path("testoutput") |
@@ -1398,6 +1403,123 @@ def test_compression(tmp_path: Path) -> None: |
1398 | 1403 | ) |
1399 | 1404 |
|
1400 | 1405 |
|
| 1406 | +def test_dataset_view_configuration(tmp_path: Path) -> None: |
| 1407 | + ds1 = Dataset.create(tmp_path, scale=(2, 2, 1)) |
| 1408 | + default_view_configuration = ds1.get_view_configuration() |
| 1409 | + assert default_view_configuration is None |
| 1410 | + |
| 1411 | + ds1.set_view_configuration(DatasetViewConfiguration(four_bit=True)) |
| 1412 | + default_view_configuration = ds1.get_view_configuration() |
| 1413 | + assert default_view_configuration is not None |
| 1414 | + assert default_view_configuration.four_bit == True |
| 1415 | + assert default_view_configuration.interpolation == None |
| 1416 | + assert default_view_configuration.render_missing_data_black == None |
| 1417 | + assert default_view_configuration.loading_strategy == None |
| 1418 | + assert default_view_configuration.segmentation_pattern_opacity == None |
| 1419 | + assert default_view_configuration.zoom == None |
| 1420 | + assert default_view_configuration.position == None |
| 1421 | + assert default_view_configuration.rotation == None |
| 1422 | + |
| 1423 | + # Test if only the set parameters are stored in the properties |
| 1424 | + assert ds1.properties.default_view_configuration == {"fourBit": True} |
| 1425 | + |
| 1426 | + ds1.set_view_configuration( |
| 1427 | + DatasetViewConfiguration( |
| 1428 | + four_bit=True, |
| 1429 | + interpolation=False, |
| 1430 | + render_missing_data_black=True, |
| 1431 | + loading_strategy="PROGRESSIVE_QUALITY", |
| 1432 | + segmentation_pattern_opacity=40, |
| 1433 | + zoom=0.1, |
| 1434 | + position=(12, 12, 12), |
| 1435 | + rotation=(1, 2, 3), |
| 1436 | + ) |
| 1437 | + ) |
| 1438 | + default_view_configuration = ds1.get_view_configuration() |
| 1439 | + assert default_view_configuration is not None |
| 1440 | + assert default_view_configuration.four_bit == True |
| 1441 | + assert default_view_configuration.interpolation == False |
| 1442 | + assert default_view_configuration.render_missing_data_black == True |
| 1443 | + assert default_view_configuration.loading_strategy == "PROGRESSIVE_QUALITY" |
| 1444 | + assert default_view_configuration.segmentation_pattern_opacity == 40 |
| 1445 | + assert default_view_configuration.zoom == 0.1 |
| 1446 | + assert default_view_configuration.position == (12, 12, 12) |
| 1447 | + assert default_view_configuration.rotation == (1, 2, 3) |
| 1448 | + |
| 1449 | + # Test if the data is persisted to disk |
| 1450 | + ds2 = Dataset(tmp_path) |
| 1451 | + default_view_configuration = ds2.get_view_configuration() |
| 1452 | + assert default_view_configuration is not None |
| 1453 | + assert default_view_configuration.four_bit == True |
| 1454 | + assert default_view_configuration.interpolation == False |
| 1455 | + assert default_view_configuration.render_missing_data_black == True |
| 1456 | + assert default_view_configuration.loading_strategy == "PROGRESSIVE_QUALITY" |
| 1457 | + assert default_view_configuration.segmentation_pattern_opacity == 40 |
| 1458 | + assert default_view_configuration.zoom == 0.1 |
| 1459 | + assert default_view_configuration.position == (12, 12, 12) |
| 1460 | + assert default_view_configuration.rotation == (1, 2, 3) |
| 1461 | + |
| 1462 | + # Test camel case |
| 1463 | + view_configuration_dict = ds2.properties.default_view_configuration |
| 1464 | + assert view_configuration_dict is not None |
| 1465 | + for k in view_configuration_dict.keys(): |
| 1466 | + assert _snake_to_camel_case(k) == k |
| 1467 | + |
| 1468 | + |
| 1469 | +def test_layer_view_configuration(tmp_path: Path) -> None: |
| 1470 | + ds1 = Dataset.create(tmp_path, scale=(2, 2, 1)) |
| 1471 | + layer1 = ds1.add_layer("color", LayerCategories.COLOR_TYPE) |
| 1472 | + default_view_configuration = layer1.get_view_configuration() |
| 1473 | + assert default_view_configuration is None |
| 1474 | + |
| 1475 | + layer1.set_view_configuration(LayerViewConfiguration(color=(255, 0, 0))) |
| 1476 | + default_view_configuration = layer1.get_view_configuration() |
| 1477 | + assert default_view_configuration is not None |
| 1478 | + assert default_view_configuration.color == (255, 0, 0) |
| 1479 | + assert default_view_configuration.alpha is None |
| 1480 | + assert default_view_configuration.intensity_range is None |
| 1481 | + assert default_view_configuration.is_inverted is None |
| 1482 | + # Test if only the set parameters are stored in the properties |
| 1483 | + assert ds1.properties.data_layers["color"].default_view_configuration == { |
| 1484 | + "color": (255, 0, 0) |
| 1485 | + } |
| 1486 | + |
| 1487 | + layer1.set_view_configuration( |
| 1488 | + LayerViewConfiguration( |
| 1489 | + color=(255, 0, 0), |
| 1490 | + alpha=1.0, |
| 1491 | + min=55.0, |
| 1492 | + intensity_range=(-12.3e1, 123), |
| 1493 | + is_inverted=True, |
| 1494 | + ) |
| 1495 | + ) |
| 1496 | + default_view_configuration = layer1.get_view_configuration() |
| 1497 | + assert default_view_configuration is not None |
| 1498 | + assert default_view_configuration.color == (255, 0, 0) |
| 1499 | + assert default_view_configuration.alpha == 1.0 |
| 1500 | + assert default_view_configuration.intensity_range == (-12.3e1, 123) |
| 1501 | + assert default_view_configuration.is_inverted == True |
| 1502 | + assert default_view_configuration.min == 55.0 |
| 1503 | + |
| 1504 | + # Test if the data is persisted to disk |
| 1505 | + ds2 = Dataset(tmp_path) |
| 1506 | + default_view_configuration = ds2.get_layer("color").get_view_configuration() |
| 1507 | + assert default_view_configuration is not None |
| 1508 | + assert default_view_configuration.color == (255, 0, 0) |
| 1509 | + assert default_view_configuration.alpha == 1.0 |
| 1510 | + assert default_view_configuration.intensity_range == (-12.3e1, 123) |
| 1511 | + assert default_view_configuration.is_inverted == True |
| 1512 | + assert default_view_configuration.min == 55.0 |
| 1513 | + |
| 1514 | + # Test camel case |
| 1515 | + view_configuration_dict = ds2.properties.data_layers[ |
| 1516 | + "color" |
| 1517 | + ].default_view_configuration |
| 1518 | + assert view_configuration_dict is not None |
| 1519 | + for k in view_configuration_dict.keys(): |
| 1520 | + assert _snake_to_camel_case(k) == k |
| 1521 | + |
| 1522 | + |
1401 | 1523 | def test_get_largest_segment_id(tmp_path: Path) -> None: |
1402 | 1524 | ds = Dataset.create(tmp_path, scale=(1, 1, 1)) |
1403 | 1525 |
|
|
0 commit comments