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

import typing
import pathlib
from styxdefs import *

ANTSUSE_LANDMARK_IMAGES_TO_GET_AFFINE_TRANSFORM_METADATA = Metadata(
    id="bf03b521899d77cb41c538f595ad6ed7f0d4440c.boutiques",
    name="ANTSUseLandmarkImagesToGetAffineTransform",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsuseLandmarkImagesToGetAffineTransformParamsDictNoTag = typing.TypedDict('_AntsuseLandmarkImagesToGetAffineTransformParamsDictNoTag', {
    "fixed_image": InputPathType,
    "moving_image": InputPathType,
    "transform_type": typing.Literal["rigid", "affine"],
    "output_affine": str,
})
AntsuseLandmarkImagesToGetAffineTransformParamsDictTagged = typing.TypedDict('AntsuseLandmarkImagesToGetAffineTransformParamsDictTagged', {
    "@type": typing.Literal["ants/ANTSUseLandmarkImagesToGetAffineTransform"],
    "fixed_image": InputPathType,
    "moving_image": InputPathType,
    "transform_type": typing.Literal["rigid", "affine"],
    "output_affine": str,
})
AntsuseLandmarkImagesToGetAffineTransformParamsDict = _AntsuseLandmarkImagesToGetAffineTransformParamsDictNoTag | AntsuseLandmarkImagesToGetAffineTransformParamsDictTagged


class AntsuseLandmarkImagesToGetAffineTransformOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsuseLandmarkImagesToGetAffineTransformParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    affine_transform_matrix: OutputPathType
    """The output is the affine transformation matrix file."""


def antsuse_landmark_images_to_get_affine_transform_params(
    fixed_image: InputPathType,
    moving_image: InputPathType,
    transform_type: typing.Literal["rigid", "affine"],
    output_affine: str,
) -> AntsuseLandmarkImagesToGetAffineTransformParamsDictTagged:
    """
    Build parameters.
    
    Args:
        fixed_image: The fixed image containing labeled landmarks (N-ary\
            image).
        moving_image: The moving image containing labeled landmarks (N-ary\
            image).
        transform_type: Type of transform to compute: 'rigid' or 'affine'.
        output_affine: The output file for the affine transform matrix (e.g.,\
            OutAffine.txt).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/ANTSUseLandmarkImagesToGetAffineTransform",
        "fixed_image": fixed_image,
        "moving_image": moving_image,
        "transform_type": transform_type,
        "output_affine": output_affine,
    }
    return params


def antsuse_landmark_images_to_get_affine_transform_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsuseLandmarkImagesToGetAffineTransformParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("fixed_image", None) is None:
        raise StyxValidationError("`fixed_image` must not be None")
    if not isinstance(params["fixed_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`fixed_image` has the wrong type: Received `{type(params.get("fixed_image", None))}` expected `InputPathType`')
    if params.get("moving_image", None) is None:
        raise StyxValidationError("`moving_image` must not be None")
    if not isinstance(params["moving_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`moving_image` has the wrong type: Received `{type(params.get("moving_image", None))}` expected `InputPathType`')
    if params.get("transform_type", None) is None:
        raise StyxValidationError("`transform_type` must not be None")
    if not isinstance(params["transform_type"], str):
        raise StyxValidationError(f'`transform_type` has the wrong type: Received `{type(params.get("transform_type", None))}` expected `typing.Literal["rigid", "affine"]`')
    if params["transform_type"] not in ["rigid", "affine"]:
        raise StyxValidationError("Parameter `transform_type` must be one of [\"rigid\", \"affine\"]")
    if params.get("output_affine", None) is None:
        raise StyxValidationError("`output_affine` must not be None")
    if not isinstance(params["output_affine"], str):
        raise StyxValidationError(f'`output_affine` has the wrong type: Received `{type(params.get("output_affine", None))}` expected `str`')


def antsuse_landmark_images_to_get_affine_transform_cargs(
    params: AntsuseLandmarkImagesToGetAffineTransformParamsDict,
    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("ANTSUseLandmarkImagesToGetAffineTransform")
    cargs.append(execution.input_file(params.get("fixed_image", None)))
    cargs.append(execution.input_file(params.get("moving_image", None)))
    cargs.append(params.get("transform_type", None))
    cargs.append(params.get("output_affine", None))
    return cargs


def antsuse_landmark_images_to_get_affine_transform_outputs(
    params: AntsuseLandmarkImagesToGetAffineTransformParamsDict,
    execution: Execution,
) -> AntsuseLandmarkImagesToGetAffineTransformOutputs:
    """
    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 = AntsuseLandmarkImagesToGetAffineTransformOutputs(
        root=execution.output_file("."),
        affine_transform_matrix=execution.output_file(params.get("output_affine", None)),
    )
    return ret


def antsuse_landmark_images_to_get_affine_transform_execute(
    params: AntsuseLandmarkImagesToGetAffineTransformParamsDict,
    runner: Runner | None = None,
) -> AntsuseLandmarkImagesToGetAffineTransformOutputs:
    """
    ANTSUseLandmarkImagesToGetAffineTransform
    
    This tool computes an affine transform (rigid or affine) from labeled
    landmark images. It requires input images to be N-ary, in the same physical
    space as the images you want to register, and to have the same landmark
    points defined within them. Landmarks are defined from the center of mass of
    the labels in the input images. ITK-snap can be used to generate the label
    images.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsuseLandmarkImagesToGetAffineTransformOutputs`).
    """
    antsuse_landmark_images_to_get_affine_transform_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTSUSE_LANDMARK_IMAGES_TO_GET_AFFINE_TRANSFORM_METADATA)
    params = execution.params(params)
    cargs = antsuse_landmark_images_to_get_affine_transform_cargs(params, execution)
    ret = antsuse_landmark_images_to_get_affine_transform_outputs(params, execution)
    execution.run(cargs)
    return ret


def antsuse_landmark_images_to_get_affine_transform(
    fixed_image: InputPathType,
    moving_image: InputPathType,
    transform_type: typing.Literal["rigid", "affine"],
    output_affine: str,
    runner: Runner | None = None,
) -> AntsuseLandmarkImagesToGetAffineTransformOutputs:
    """
    ANTSUseLandmarkImagesToGetAffineTransform
    
    This tool computes an affine transform (rigid or affine) from labeled
    landmark images. It requires input images to be N-ary, in the same physical
    space as the images you want to register, and to have the same landmark
    points defined within them. Landmarks are defined from the center of mass of
    the labels in the input images. ITK-snap can be used to generate the label
    images.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        fixed_image: The fixed image containing labeled landmarks (N-ary\
            image).
        moving_image: The moving image containing labeled landmarks (N-ary\
            image).
        transform_type: Type of transform to compute: 'rigid' or 'affine'.
        output_affine: The output file for the affine transform matrix (e.g.,\
            OutAffine.txt).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsuseLandmarkImagesToGetAffineTransformOutputs`).
    """
    params = antsuse_landmark_images_to_get_affine_transform_params(
        fixed_image=fixed_image,
        moving_image=moving_image,
        transform_type=transform_type,
        output_affine=output_affine,
    )
    return antsuse_landmark_images_to_get_affine_transform_execute(params, runner)


__all__ = [
    "ANTSUSE_LANDMARK_IMAGES_TO_GET_AFFINE_TRANSFORM_METADATA",
    "AntsuseLandmarkImagesToGetAffineTransformOutputs",
    "AntsuseLandmarkImagesToGetAffineTransformParamsDict",
    "AntsuseLandmarkImagesToGetAffineTransformParamsDictTagged",
    "antsuse_landmark_images_to_get_affine_transform",
    "antsuse_landmark_images_to_get_affine_transform_execute",
    "antsuse_landmark_images_to_get_affine_transform_params",
]
