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

import typing
import pathlib
from styxdefs import *
import dataclasses

SMOOTH_DISPLACEMENT_FIELD_METADATA = Metadata(
    id="74242e4a08e876a4821008fd823b0b832ab0e019.boutiques",
    name="SmoothDisplacementField",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class SmoothDisplacementFieldOutputs(typing.NamedTuple):
    """
    Output object returned when calling `smooth_displacement_field(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    smoothed_field: OutputPathType
    """The output file containing the smoothed displacement field."""
    confidence_image_out: OutputPathType | None
    """The output file containing confidence information from the smoothing
    process."""


def smooth_displacement_field(
    image_dimension: int,
    input_field: InputPathType,
    output_field: InputPathType,
    variance_or_mesh_size_base_level: float,
    number_of_levels: int | None = 1,
    spline_order: int | None = 3,
    estimate_inverse: typing.Literal[0, 1] | None = 0,
    confidence_image: InputPathType | None = None,
    runner: Runner | None = None,
) -> SmoothDisplacementFieldOutputs:
    """
    SmoothDisplacementField applies smoothing to a displacement field over a
    specified number of levels with optional parameters for spline order, inverse
    estimation, and confidence image output.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the input displacement field.
        input_field: The input displacement field file.
        output_field: The output file for the smoothed displacement field.
        variance_or_mesh_size_base_level: The variance for Gaussian smoothing\
            or mesh size at the base level for B-spline smoothing.
        number_of_levels: The number of levels for multi-resolution smoothing.
        spline_order: The order of the spline for B-spline smoothing.
        estimate_inverse: Estimate the inverse of the displacement field if set\
            to 1.
        confidence_image: Optional confidence image output of the smoothing\
            process.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SmoothDisplacementFieldOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SMOOTH_DISPLACEMENT_FIELD_METADATA)
    cargs = []
    cargs.append("SmoothDisplacementField")
    cargs.append(str(image_dimension))
    cargs.append(execution.input_file(input_field))
    cargs.append(execution.input_file(output_field))
    cargs.append(str(variance_or_mesh_size_base_level))
    if number_of_levels is not None:
        cargs.append(str(number_of_levels))
    if spline_order is not None:
        cargs.append(str(spline_order))
    if estimate_inverse is not None:
        cargs.append(str(estimate_inverse))
    if confidence_image is not None:
        cargs.append(execution.input_file(confidence_image))
    ret = SmoothDisplacementFieldOutputs(
        root=execution.output_file("."),
        smoothed_field=execution.output_file(pathlib.Path(output_field).name),
        confidence_image_out=execution.output_file(pathlib.Path(confidence_image).name) if (confidence_image is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "SMOOTH_DISPLACEMENT_FIELD_METADATA",
    "SmoothDisplacementFieldOutputs",
    "smooth_displacement_field",
]
