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

import typing
import pathlib
from styxdefs import *

SURFACE_SPHERE_PROJECT_UNPROJECT_METADATA = Metadata(
    id="ec00569346766fa83a8b274b19856b08f237baba.boutiques",
    name="surface-sphere-project-unproject",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


SurfaceSphereProjectUnprojectParameters = typing.TypedDict('SurfaceSphereProjectUnprojectParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/surface-sphere-project-unproject"]],
    "sphere_in": InputPathType,
    "sphere_project_to": InputPathType,
    "sphere_unproject_from": InputPathType,
    "sphere_out": str,
})
SurfaceSphereProjectUnprojectParametersTagged = typing.TypedDict('SurfaceSphereProjectUnprojectParametersTagged', {
    "@type": typing.Literal["workbench/surface-sphere-project-unproject"],
    "sphere_in": InputPathType,
    "sphere_project_to": InputPathType,
    "sphere_unproject_from": InputPathType,
    "sphere_out": str,
})


class SurfaceSphereProjectUnprojectOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceSphereProjectUnprojectParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    sphere_out: OutputPathType
    """the output sphere"""


def surface_sphere_project_unproject_params(
    sphere_in: InputPathType,
    sphere_project_to: InputPathType,
    sphere_unproject_from: InputPathType,
    sphere_out: str,
) -> SurfaceSphereProjectUnprojectParametersTagged:
    """
    Build parameters.
    
    Args:
        sphere_in: a sphere with the desired output mesh.
        sphere_project_to: a sphere that aligns with sphere-in.
        sphere_unproject_from: <sphere-project-to> deformed to the desired\
            output space.
        sphere_out: the output sphere.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-sphere-project-unproject",
        "sphere_in": sphere_in,
        "sphere_project_to": sphere_project_to,
        "sphere_unproject_from": sphere_unproject_from,
        "sphere_out": sphere_out,
    }
    return params


def surface_sphere_project_unproject_cargs(
    params: SurfaceSphereProjectUnprojectParameters,
    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("-surface-sphere-project-unproject")
    cargs.append(execution.input_file(params.get("sphere_in", None)))
    cargs.append(execution.input_file(params.get("sphere_project_to", None)))
    cargs.append(execution.input_file(params.get("sphere_unproject_from", None)))
    cargs.append(params.get("sphere_out", None))
    return cargs


def surface_sphere_project_unproject_outputs(
    params: SurfaceSphereProjectUnprojectParameters,
    execution: Execution,
) -> SurfaceSphereProjectUnprojectOutputs:
    """
    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 = SurfaceSphereProjectUnprojectOutputs(
        root=execution.output_file("."),
        sphere_out=execution.output_file(params.get("sphere_out", None)),
    )
    return ret


def surface_sphere_project_unproject_execute(
    params: SurfaceSphereProjectUnprojectParameters,
    runner: Runner | None = None,
) -> SurfaceSphereProjectUnprojectOutputs:
    """
    surface-sphere-project-unproject
    
    Copy registration deformations to different sphere.
    
    Background: A surface registration starts with an input sphere, and moves
    its vertices around on the sphere until it matches the template data. This
    means that the registration deformation is actually represented as the
    difference between two separate files - the starting sphere, and the
    registered sphere. Since the starting sphere of the registration may not
    have vertex correspondence to any other sphere (often, it is a native
    sphere), it can be inconvenient to manipulate or compare these deformations
    across subjects, etc.
    
    The purpose of this command is to be able to apply these deformations onto a
    new sphere of the user's choice, to make it easier to compare or manipulate
    them. Common uses are to concatenate two successive separate registrations
    (e.g. Human to Chimpanzee, and then Chimpanzee to Macaque) or inversion (for
    dedrifting or symmetric registration schemes).
    
    <sphere-in> must already be considered to be in alignment with one of the
    two ends of the registration (if your registration is Human to Chimpanzee,
    <sphere-in> must be in register with either Human or Chimpanzee). The
    'project-to' sphere must be the side of the registration that is aligned
    with <sphere-in> (if your registration is Human to Chimpanzee, and
    <sphere-in> is aligned with Human, then 'project-to' should be the original
    Human sphere). The 'unproject-from' sphere must be the remaining sphere of
    the registration (original vs deformed/registered). The output is as if you
    had run the same registration with <sphere-in> as the starting sphere, in
    the direction of deforming the 'project-to' sphere to create the
    'unproject-from' sphere.
    
    Note that this command cannot check for you what spheres are aligned with
    other spheres, and using the wrong spheres or in the incorrect order will
    not necessarily cause an error message. In some cases, it may be useful to
    use a new, arbitrary sphere as the input, which can be created with the
    -surface-create-sphere command.
    
    Example 1: You have a Human to Chimpanzee registration, and a Chimpanzee to
    Macaque registration, and want to combine them. If you use the Human sphere
    registered to Chimpanzee as sphere-in, the Chimpanzee standard sphere as
    project-to, and the Chimpanzee sphere registered to Macaque as
    unproject-from, the output will be the Human sphere in register with the
    Macaque.
    
    Example 2: You have a Human to Chimpanzee registration, but what you really
    want is the inverse, that is, the sphere as if you had run the registration
    from Chimpanzee to Human. If you use the Chimpanzee standard sphere as
    sphere-in, the Human sphere registered to Chimpanzee as project-to, and the
    standard Human sphere as unproject-from, the output will be the Chimpanzee
    sphere in register with the Human.
    
    Technical details: Each vertex of <sphere-in> is projected to a triangle of
    <sphere-project-to>, and its new position is determined by the position of
    the corresponding triangle in <sphere-unproject-from>. The output is a
    sphere with the topology of <sphere-in>, but coordinates shifted by the
    deformation from <sphere-project-to> to <sphere-unproject-from>.
    <sphere-project-to> and <sphere-unproject-from> must have the same topology
    as each other, but <sphere-in> may have any topology.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceSphereProjectUnprojectOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_SPHERE_PROJECT_UNPROJECT_METADATA)
    params = execution.params(params)
    cargs = surface_sphere_project_unproject_cargs(params, execution)
    ret = surface_sphere_project_unproject_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_sphere_project_unproject(
    sphere_in: InputPathType,
    sphere_project_to: InputPathType,
    sphere_unproject_from: InputPathType,
    sphere_out: str,
    runner: Runner | None = None,
) -> SurfaceSphereProjectUnprojectOutputs:
    """
    surface-sphere-project-unproject
    
    Copy registration deformations to different sphere.
    
    Background: A surface registration starts with an input sphere, and moves
    its vertices around on the sphere until it matches the template data. This
    means that the registration deformation is actually represented as the
    difference between two separate files - the starting sphere, and the
    registered sphere. Since the starting sphere of the registration may not
    have vertex correspondence to any other sphere (often, it is a native
    sphere), it can be inconvenient to manipulate or compare these deformations
    across subjects, etc.
    
    The purpose of this command is to be able to apply these deformations onto a
    new sphere of the user's choice, to make it easier to compare or manipulate
    them. Common uses are to concatenate two successive separate registrations
    (e.g. Human to Chimpanzee, and then Chimpanzee to Macaque) or inversion (for
    dedrifting or symmetric registration schemes).
    
    <sphere-in> must already be considered to be in alignment with one of the
    two ends of the registration (if your registration is Human to Chimpanzee,
    <sphere-in> must be in register with either Human or Chimpanzee). The
    'project-to' sphere must be the side of the registration that is aligned
    with <sphere-in> (if your registration is Human to Chimpanzee, and
    <sphere-in> is aligned with Human, then 'project-to' should be the original
    Human sphere). The 'unproject-from' sphere must be the remaining sphere of
    the registration (original vs deformed/registered). The output is as if you
    had run the same registration with <sphere-in> as the starting sphere, in
    the direction of deforming the 'project-to' sphere to create the
    'unproject-from' sphere.
    
    Note that this command cannot check for you what spheres are aligned with
    other spheres, and using the wrong spheres or in the incorrect order will
    not necessarily cause an error message. In some cases, it may be useful to
    use a new, arbitrary sphere as the input, which can be created with the
    -surface-create-sphere command.
    
    Example 1: You have a Human to Chimpanzee registration, and a Chimpanzee to
    Macaque registration, and want to combine them. If you use the Human sphere
    registered to Chimpanzee as sphere-in, the Chimpanzee standard sphere as
    project-to, and the Chimpanzee sphere registered to Macaque as
    unproject-from, the output will be the Human sphere in register with the
    Macaque.
    
    Example 2: You have a Human to Chimpanzee registration, but what you really
    want is the inverse, that is, the sphere as if you had run the registration
    from Chimpanzee to Human. If you use the Chimpanzee standard sphere as
    sphere-in, the Human sphere registered to Chimpanzee as project-to, and the
    standard Human sphere as unproject-from, the output will be the Chimpanzee
    sphere in register with the Human.
    
    Technical details: Each vertex of <sphere-in> is projected to a triangle of
    <sphere-project-to>, and its new position is determined by the position of
    the corresponding triangle in <sphere-unproject-from>. The output is a
    sphere with the topology of <sphere-in>, but coordinates shifted by the
    deformation from <sphere-project-to> to <sphere-unproject-from>.
    <sphere-project-to> and <sphere-unproject-from> must have the same topology
    as each other, but <sphere-in> may have any topology.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        sphere_in: a sphere with the desired output mesh.
        sphere_project_to: a sphere that aligns with sphere-in.
        sphere_unproject_from: <sphere-project-to> deformed to the desired\
            output space.
        sphere_out: the output sphere.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceSphereProjectUnprojectOutputs`).
    """
    params = surface_sphere_project_unproject_params(
        sphere_in=sphere_in,
        sphere_project_to=sphere_project_to,
        sphere_unproject_from=sphere_unproject_from,
        sphere_out=sphere_out,
    )
    return surface_sphere_project_unproject_execute(params, runner)


__all__ = [
    "SURFACE_SPHERE_PROJECT_UNPROJECT_METADATA",
    "SurfaceSphereProjectUnprojectOutputs",
    "surface_sphere_project_unproject",
    "surface_sphere_project_unproject_execute",
    "surface_sphere_project_unproject_params",
]
