# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_EXTRACT_LARGEST_CC_METADATA = Metadata(
    id="d482ce41fdae770a9397038906daba39eebb0541.boutiques",
    name="mri_extract_largest_CC",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriExtractLargestCcOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_extract_largest_cc(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_volume_file: OutputPathType
    """The output volume with the largest connected component extracted."""


def mri_extract_largest_cc(
    input_volume: InputPathType,
    output_volume: str,
    threshold: float | None = None,
    hemisphere: typing.Literal["lh", "rh"] | None = None,
    largest_cc_in_bg: bool = False,
    original_volume: InputPathType | None = None,
    label_value: float | None = None,
    runner: Runner | None = None,
) -> MriExtractLargestCcOutputs:
    """
    This program extracts the largest connected component of the input volume.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Input volume.
        output_volume: Output volume.
        threshold: Threshold for object.
        hemisphere: Set the target value corresponding to lh (255) or rh (127).
        largest_cc_in_bg: Find the largest CC in the background.
        original_volume: Clone values from original volume into output (used\
            with -I).
        label_value: Perform connected components on voxels with specified\
            label value.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriExtractLargestCcOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_EXTRACT_LARGEST_CC_METADATA)
    cargs = []
    cargs.append("mri_extract_largest_CC")
    cargs.append(execution.input_file(input_volume))
    cargs.append(output_volume)
    if threshold is not None:
        cargs.extend([
            "-T",
            str(threshold)
        ])
    if hemisphere is not None:
        cargs.extend([
            "-hemi",
            hemisphere
        ])
    if largest_cc_in_bg:
        cargs.append("-I")
    if original_volume is not None:
        cargs.extend([
            "-O",
            execution.input_file(original_volume)
        ])
    if label_value is not None:
        cargs.extend([
            "-L",
            str(label_value)
        ])
    ret = MriExtractLargestCcOutputs(
        root=execution.output_file("."),
        output_volume_file=execution.output_file(output_volume),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_EXTRACT_LARGEST_CC_METADATA",
    "MriExtractLargestCcOutputs",
    "mri_extract_largest_cc",
]
