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

import typing
import pathlib
from styxdefs import *
import dataclasses

GREEDY_METADATA = Metadata(
    id="fa0c2cc85074ae69ac2d7bc0d952e7394fbf5077.boutiques",
    name="greedy",
    package="greedy",
    container_image_tag="pyushkevich/itksnap:v3.8.2",
)


class GreedyOutputs(typing.NamedTuple):
    """
    Output object returned when calling `greedy_(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType | None
    """Output file from affine"""
    reslice_output_file: OutputPathType | None
    """Resliced output image"""


def greedy_(
    dimensions: int,
    threads: int | None = None,
    metric: typing.Literal["SSD", "MI", "NMI", "NCC", "MAHAL"] | None = None,
    affine: bool = False,
    affine_dof: int | None = None,
    ia_identity: bool = False,
    iterations: str | None = None,
    fixed_mask: InputPathType | None = None,
    moving_mask: InputPathType | None = None,
    input_images: list[InputPathType] | None = None,
    output: str | None = None,
    fixed_reslicing_image: InputPathType | None = None,
    reslice_moving_image: InputPathType | None = None,
    reslice_output_image: str | None = None,
    reslice: InputPathType | None = None,
    verbosity: int | None = None,
    runner: Runner | None = None,
) -> GreedyOutputs:
    """
    Paul's greedy diffeomorphic registration implementation.
    
    Args:
        dimensions: Number of image dimensions.
        threads: Number of allowed concurrent threads.
        metric: Metric for the entire registration.
        affine: Perform affine registration and save to output (-o).
        affine_dof: Degrees of freedom for affine registration.
        ia_identity: initialize affine matrix based on NIFTI headers.
        iterations: Number of iterations per level of multi-res.
        fixed_mask: Fixed image mask.
        moving_mask: Moving image mask.
        input_images: Image pair (may be repeated).
        output: Output file.
        fixed_reslicing_image: fixed image for reslicing.
        reslice_moving_image: Moving image reslice file.
        reslice_output_image: Output image reslice file.
        reslice: Reslice images instead of doing registration.
        verbosity: Verbosity level.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GreedyOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(GREEDY_METADATA)
    cargs = []
    cargs.append("greedy")
    if threads is not None:
        cargs.extend([
            "-threads",
            str(threads)
        ])
    cargs.extend([
        "-d",
        str(dimensions)
    ])
    if metric is not None:
        cargs.extend([
            "-m",
            metric
        ])
    if affine:
        cargs.append("-a")
    if affine_dof is not None:
        cargs.extend([
            "-dof",
            str(affine_dof)
        ])
    if ia_identity:
        cargs.append("-ia-identity")
    if iterations is not None:
        cargs.extend([
            "-n",
            iterations
        ])
    if fixed_mask is not None:
        cargs.extend([
            "-gm",
            execution.input_file(fixed_mask)
        ])
    if moving_mask is not None:
        cargs.extend([
            "-mm",
            execution.input_file(moving_mask)
        ])
    if input_images is not None:
        cargs.extend([
            "-i",
            *[execution.input_file(f) for f in input_images]
        ])
    if output is not None:
        cargs.extend([
            "-o",
            output
        ])
    if fixed_reslicing_image is not None:
        cargs.extend([
            "-rf",
            execution.input_file(fixed_reslicing_image)
        ])
    if reslice_moving_image is not None:
        cargs.extend([
            "-rm",
            execution.input_file(reslice_moving_image)
        ])
    if reslice_output_image is not None:
        cargs.append(reslice_output_image)
    if reslice is not None:
        cargs.extend([
            "-r",
            execution.input_file(reslice)
        ])
    if verbosity is not None:
        cargs.extend([
            "-V",
            str(verbosity)
        ])
    ret = GreedyOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(output) if (output is not None) else None,
        reslice_output_file=execution.output_file(reslice_output_image) if (reslice_output_image is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "GREEDY_METADATA",
    "GreedyOutputs",
    "greedy_",
]
