# Examples from pyvista.examples.downloads.download_whole_body_ct_female
# ======================================================================

# Load the dataset.
from pyvista import examples
import pyvista as pv
dataset = examples.download_whole_body_ct_female()

# Get the names of the dataset's blocks.
dataset.keys()

# Get the CT image.
ct_image = dataset['ct']
ct_image

# Get the segmentation label names and show the first three.
segmentations = dataset['segmentations']
label_names = segmentations.keys()
label_names[:3]

# Get the label map and show its data range.
label_map = dataset['label_map']
label_map.get_data_range()

# Show the `'names_to_colors'` dictionary with RGB colors for each segment.
dataset.user_dict['names_to_colors']

# Show the `'names_to_ids'` dictionary with a mapping from segment names to segment ids.
dataset.user_dict['names_to_ids']

# Create a surface mesh of the segmentation labels.
labels_mesh = label_map.contour_labels()

# Color the surface using `color_labels()`. Use the
# `'ids_to_colors'` dictionary included with the dataset to map the colors.
colored_mesh = labels_mesh.color_labels(
    colors=dataset.user_dict['ids_to_colors']
)

# Plot the CT image and segmentation labels together.
pl = pv.Plotter()
_ = pl.add_volume(
    ct_image,
    cmap='bone',
    opacity='sigmoid_7',
    show_scalar_bar=False,
)
_ = pl.add_mesh(colored_mesh)
pl.view_zx()
pl.camera.up = (0, 0, 1)
pl.camera.zoom(1.3)
pl.show()

# SEE ALSO:
#     Visualize Anatomical Groups https://docs.pyvista.org/examples/99-advanced/anatomical_groups.html#anatomical-groups-example
#     Additional examples using this dataset.
#     Whole Body Ct Female Dataset https://docs.pyvista.org/api/examples/dataset_gallery.html#whole-body-ct-female-dataset
#     See this dataset in the Dataset Gallery for more info.
#     Whole Body Ct Male Dataset https://docs.pyvista.org/api/examples/dataset_gallery.html#whole-body-ct-male-dataset
#     Similar dataset of a male subject.
#     Medical Datasets https://docs.pyvista.org/api/examples/dataset_gallery.html#medical-dataset-gallery
#     Browse other medical datasets.
#     Crop Labeled ImageData https://docs.pyvista.org/examples/01-filter/crop_labeled.html#crop-labeled-example
#     Example cropping this dataset using a segmentation mask.
#     Volume With Segmentation Mask https://docs.pyvista.org/examples/02-plot/volume_rendering.html#volume-with-mask-example
#     See additional examples using this dataset.

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code

