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

import typing
import pathlib
from styxdefs import *

METRIC_TO_VOLUME_MAPPING_METADATA = Metadata(
    id="4a17edeb9af7773ec08dedde028a48523ef336b2.boutiques",
    name="metric-to-volume-mapping",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricToVolumeMappingRibbonConstrainedParameters = typing.TypedDict('MetricToVolumeMappingRibbonConstrainedParameters', {
    "@type": typing.NotRequired[typing.Literal["ribbon_constrained"]],
    "inner_surf": InputPathType,
    "outer_surf": InputPathType,
    "opt_voxel_subdiv_subdiv_num": typing.NotRequired[int | None],
    "opt_greedy": bool,
    "opt_thick_columns": bool,
})
MetricToVolumeMappingRibbonConstrainedParametersTagged = typing.TypedDict('MetricToVolumeMappingRibbonConstrainedParametersTagged', {
    "@type": typing.Literal["ribbon_constrained"],
    "inner_surf": InputPathType,
    "outer_surf": InputPathType,
    "opt_voxel_subdiv_subdiv_num": typing.NotRequired[int | None],
    "opt_greedy": bool,
    "opt_thick_columns": bool,
})


MetricToVolumeMappingParameters = typing.TypedDict('MetricToVolumeMappingParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-to-volume-mapping"]],
    "metric": InputPathType,
    "surface": InputPathType,
    "volume_space": InputPathType,
    "volume_out": str,
    "opt_nearest_vertex_distance": typing.NotRequired[float | None],
    "ribbon_constrained": typing.NotRequired[MetricToVolumeMappingRibbonConstrainedParameters | None],
})
MetricToVolumeMappingParametersTagged = typing.TypedDict('MetricToVolumeMappingParametersTagged', {
    "@type": typing.Literal["workbench/metric-to-volume-mapping"],
    "metric": InputPathType,
    "surface": InputPathType,
    "volume_space": InputPathType,
    "volume_out": str,
    "opt_nearest_vertex_distance": typing.NotRequired[float | None],
    "ribbon_constrained": typing.NotRequired[MetricToVolumeMappingRibbonConstrainedParameters | None],
})


def metric_to_volume_mapping_ribbon_constrained_params(
    inner_surf: InputPathType,
    outer_surf: InputPathType,
    opt_voxel_subdiv_subdiv_num: int | None = None,
    opt_greedy: bool = False,
    opt_thick_columns: bool = False,
) -> MetricToVolumeMappingRibbonConstrainedParametersTagged:
    """
    Build parameters.
    
    Args:
        inner_surf: the inner surface of the ribbon.
        outer_surf: the outer surface of the ribbon.
        opt_voxel_subdiv_subdiv_num: voxel divisions while estimating voxel\
            weights: number of subdivisions, default 3.
        opt_greedy: instead of antialiasing partial-volumed voxels, put full\
            metric values (legacy behavior).
        opt_thick_columns: use overlapping columns (legacy method).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ribbon_constrained",
        "inner_surf": inner_surf,
        "outer_surf": outer_surf,
        "opt_greedy": opt_greedy,
        "opt_thick_columns": opt_thick_columns,
    }
    if opt_voxel_subdiv_subdiv_num is not None:
        params["opt_voxel_subdiv_subdiv_num"] = opt_voxel_subdiv_subdiv_num
    return params


def metric_to_volume_mapping_ribbon_constrained_cargs(
    params: MetricToVolumeMappingRibbonConstrainedParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-ribbon-constrained")
    cargs.append(execution.input_file(params.get("inner_surf", None)))
    cargs.append(execution.input_file(params.get("outer_surf", None)))
    if params.get("opt_voxel_subdiv_subdiv_num", None) is not None:
        cargs.extend([
            "-voxel-subdiv",
            str(params.get("opt_voxel_subdiv_subdiv_num", None))
        ])
    if params.get("opt_greedy", False):
        cargs.append("-greedy")
    if params.get("opt_thick_columns", False):
        cargs.append("-thick-columns")
    return cargs


class MetricToVolumeMappingOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricToVolumeMappingParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    volume_out: OutputPathType
    """the output volume file"""


def metric_to_volume_mapping_params(
    metric: InputPathType,
    surface: InputPathType,
    volume_space: InputPathType,
    volume_out: str,
    opt_nearest_vertex_distance: float | None = None,
    ribbon_constrained: MetricToVolumeMappingRibbonConstrainedParameters | None = None,
) -> MetricToVolumeMappingParametersTagged:
    """
    Build parameters.
    
    Args:
        metric: the input metric file.
        surface: the surface to use coordinates from.
        volume_space: a volume file in the desired output volume space.
        volume_out: the output volume file.
        opt_nearest_vertex_distance: use the value from the vertex closest to\
            the voxel center: how far from the surface to map values to voxels, in\
            mm.
        ribbon_constrained: use ribbon constrained mapping algorithm.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-to-volume-mapping",
        "metric": metric,
        "surface": surface,
        "volume_space": volume_space,
        "volume_out": volume_out,
    }
    if opt_nearest_vertex_distance is not None:
        params["opt_nearest_vertex_distance"] = opt_nearest_vertex_distance
    if ribbon_constrained is not None:
        params["ribbon_constrained"] = ribbon_constrained
    return params


def metric_to_volume_mapping_cargs(
    params: MetricToVolumeMappingParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("wb_command")
    cargs.append("-metric-to-volume-mapping")
    cargs.append(execution.input_file(params.get("metric", None)))
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(execution.input_file(params.get("volume_space", None)))
    cargs.append(params.get("volume_out", None))
    if params.get("opt_nearest_vertex_distance", None) is not None:
        cargs.extend([
            "-nearest-vertex",
            str(params.get("opt_nearest_vertex_distance", None))
        ])
    if params.get("ribbon_constrained", None) is not None:
        cargs.extend(metric_to_volume_mapping_ribbon_constrained_cargs(params.get("ribbon_constrained", None), execution))
    return cargs


def metric_to_volume_mapping_outputs(
    params: MetricToVolumeMappingParameters,
    execution: Execution,
) -> MetricToVolumeMappingOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = MetricToVolumeMappingOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume_out", None)),
    )
    return ret


def metric_to_volume_mapping_execute(
    params: MetricToVolumeMappingParameters,
    runner: Runner | None = None,
) -> MetricToVolumeMappingOutputs:
    """
    metric-to-volume-mapping
    
    Map metric file to volume.
    
    Maps values from a metric file into a volume file. You must specify exactly
    one mapping method option. The -nearest-vertex method uses the value from
    the vertex closest to the voxel center (useful for integer values). The
    -ribbon-constrained method uses the same method as in
    -volume-to-surface-mapping, then uses the weights in reverse. Mapping to
    lower resolutions than the mesh may require a larger -voxel-subdiv value in
    order to have all of the surface data participate.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricToVolumeMappingOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_TO_VOLUME_MAPPING_METADATA)
    params = execution.params(params)
    cargs = metric_to_volume_mapping_cargs(params, execution)
    ret = metric_to_volume_mapping_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_to_volume_mapping(
    metric: InputPathType,
    surface: InputPathType,
    volume_space: InputPathType,
    volume_out: str,
    opt_nearest_vertex_distance: float | None = None,
    ribbon_constrained: MetricToVolumeMappingRibbonConstrainedParameters | None = None,
    runner: Runner | None = None,
) -> MetricToVolumeMappingOutputs:
    """
    metric-to-volume-mapping
    
    Map metric file to volume.
    
    Maps values from a metric file into a volume file. You must specify exactly
    one mapping method option. The -nearest-vertex method uses the value from
    the vertex closest to the voxel center (useful for integer values). The
    -ribbon-constrained method uses the same method as in
    -volume-to-surface-mapping, then uses the weights in reverse. Mapping to
    lower resolutions than the mesh may require a larger -voxel-subdiv value in
    order to have all of the surface data participate.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        metric: the input metric file.
        surface: the surface to use coordinates from.
        volume_space: a volume file in the desired output volume space.
        volume_out: the output volume file.
        opt_nearest_vertex_distance: use the value from the vertex closest to\
            the voxel center: how far from the surface to map values to voxels, in\
            mm.
        ribbon_constrained: use ribbon constrained mapping algorithm.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricToVolumeMappingOutputs`).
    """
    params = metric_to_volume_mapping_params(
        metric=metric,
        surface=surface,
        volume_space=volume_space,
        volume_out=volume_out,
        opt_nearest_vertex_distance=opt_nearest_vertex_distance,
        ribbon_constrained=ribbon_constrained,
    )
    return metric_to_volume_mapping_execute(params, runner)


__all__ = [
    "METRIC_TO_VOLUME_MAPPING_METADATA",
    "MetricToVolumeMappingOutputs",
    "metric_to_volume_mapping",
    "metric_to_volume_mapping_execute",
    "metric_to_volume_mapping_params",
    "metric_to_volume_mapping_ribbon_constrained_params",
]
