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

import typing
import pathlib
from styxdefs import *
import dataclasses

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


@dataclasses.dataclass
class MetricToVolumeMappingRibbonConstrained:
    """
    use ribbon constrained mapping algorithm.
    """
    inner_surf: InputPathType
    """the inner surface of the ribbon"""
    outer_surf: InputPathType
    """the outer surface of the ribbon"""
    opt_voxel_subdiv_subdiv_num: int | None = None
    """voxel divisions while estimating voxel weights: number of subdivisions,
    default 3"""
    opt_greedy: bool = False
    """instead of antialiasing partial-volumed voxels, put full metric values
    (legacy behavior)"""
    opt_thick_columns: bool = False
    """use overlapping columns (legacy method)"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-ribbon-constrained")
        cargs.append(execution.input_file(self.inner_surf))
        cargs.append(execution.input_file(self.outer_surf))
        if self.opt_voxel_subdiv_subdiv_num is not None:
            cargs.extend([
                "-voxel-subdiv",
                str(self.opt_voxel_subdiv_subdiv_num)
            ])
        if self.opt_greedy:
            cargs.append("-greedy")
        if self.opt_thick_columns:
            cargs.append("-thick-columns")
        return cargs


class MetricToVolumeMappingOutputs(typing.NamedTuple):
    """
    Output object returned when calling `metric_to_volume_mapping(...)`.
    """
    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(
    metric: InputPathType,
    surface: InputPathType,
    volume_space: InputPathType,
    volume_out: str,
    opt_nearest_vertex_distance: float | None = None,
    ribbon_constrained: MetricToVolumeMappingRibbonConstrained | None = None,
    runner: Runner | None = None,
) -> MetricToVolumeMappingOutputs:
    """
    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: Washington University School of Medicin
    
    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`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_TO_VOLUME_MAPPING_METADATA)
    cargs = []
    cargs.append("wb_command")
    cargs.append("-metric-to-volume-mapping")
    cargs.append(execution.input_file(metric))
    cargs.append(execution.input_file(surface))
    cargs.append(execution.input_file(volume_space))
    cargs.append(volume_out)
    if opt_nearest_vertex_distance is not None:
        cargs.extend([
            "-nearest-vertex",
            str(opt_nearest_vertex_distance)
        ])
    if ribbon_constrained is not None:
        cargs.extend(ribbon_constrained.run(execution))
    ret = MetricToVolumeMappingOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(volume_out),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "METRIC_TO_VOLUME_MAPPING_METADATA",
    "MetricToVolumeMappingOutputs",
    "MetricToVolumeMappingRibbonConstrained",
    "metric_to_volume_mapping",
]
