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

import typing
import pathlib
from styxdefs import *
import dataclasses

SURF2VOL_METADATA = Metadata(
    id="f4ae5ac678a739e2426d3a890649ef1fbff288ef.boutiques",
    name="surf2vol",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class Surf2volOutputs(typing.NamedTuple):
    """
    Output object returned when calling `surf2vol(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType | None
    """Default output of the deformation process."""
    output_field: OutputPathType | None
    """Field output of the deformation process."""


def surf2vol(
    fixed_surface: InputPathType,
    moving_surface: InputPathType,
    fixed_mri: InputPathType,
    moving_mri: InputPathType,
    output_file: str | None = "out.mgz",
    output_field: str | None = "out_field.mgz",
    output_affine: str | None = None,
    output_surf: str | None = None,
    output_surf_affine: str | None = None,
    output_mesh: str | None = None,
    spacing_x: float | None = None,
    spacing_y: float | None = None,
    spacing_z: float | None = None,
    poisson_ratio: float | None = None,
    dirty_factor: float | None = None,
    debug_output: bool = False,
    cache_transform: str | None = None,
    runner: Runner | None = None,
) -> Surf2volOutputs:
    """
    Diffuse surface deformation to volumes using surface and MRI data.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        fixed_surface: File path for the main fixed surface.
        moving_surface: File path for the main moving surface.
        fixed_mri: Fixed volume file.
        moving_mri: Moving volume file.
        output_file: Output file for the result, default is out.mgz.
        output_field: Output field file, default is out_field.mgz.
        output_affine: Path for the output affine file.
        output_surf: Root file name for output surfaces which will have indices\
            appended for each surface.
        output_surf_affine: Root file name for output surfaces with affine\
            transformations.
        output_mesh: File path for the output mesh.
        spacing_x: Specifies the x spacing for the deformation grid.
        spacing_y: Specifies the y spacing for the deformation grid.
        spacing_z: Specifies the z spacing for the deformation grid.
        poisson_ratio: Poisson ratio for material properties, default is 0.3.
        dirty_factor: Factor for dirty regions, between 0 and 1.
        debug_output: Enable debug output, writing a morph file at each\
            iteration.
        cache_transform: Path to save transformation cache for reusing in\
            subsequent runs.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Surf2volOutputs`).
    """
    if poisson_ratio is not None and not (poisson_ratio <= 0.5): 
        raise ValueError(f"'poisson_ratio' must be less than x <= 0.5 but was {poisson_ratio}")
    if dirty_factor is not None and not (0 <= dirty_factor <= 1): 
        raise ValueError(f"'dirty_factor' must be between 0 <= x <= 1 but was {dirty_factor}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURF2VOL_METADATA)
    cargs = []
    cargs.append("surf2vol")
    cargs.extend([
        "-fixed_surf",
        execution.input_file(fixed_surface)
    ])
    cargs.extend([
        "-moving_surf",
        execution.input_file(moving_surface)
    ])
    cargs.extend([
        "-fixed_mri",
        execution.input_file(fixed_mri)
    ])
    cargs.extend([
        "-moving_mri",
        execution.input_file(moving_mri)
    ])
    if output_file is not None:
        cargs.extend([
            "-out",
            output_file
        ])
    if output_field is not None:
        cargs.extend([
            "-out_field",
            output_field
        ])
    if output_affine is not None:
        cargs.extend([
            "-out_affine",
            output_affine
        ])
    if output_surf is not None:
        cargs.extend([
            "-out_surf",
            output_surf
        ])
    if output_surf_affine is not None:
        cargs.extend([
            "-out_surf_affine",
            output_surf_affine
        ])
    if output_mesh is not None:
        cargs.extend([
            "-out_mesh",
            output_mesh
        ])
    if spacing_x is not None:
        cargs.extend([
            "-spacing_x",
            str(spacing_x)
        ])
    if spacing_y is not None:
        cargs.extend([
            "-spacing_y",
            str(spacing_y)
        ])
    if spacing_z is not None:
        cargs.extend([
            "-spacing_z",
            str(spacing_z)
        ])
    if poisson_ratio is not None:
        cargs.extend([
            "-poisson",
            str(poisson_ratio)
        ])
    if dirty_factor is not None:
        cargs.extend([
            "-dirty",
            str(dirty_factor)
        ])
    if debug_output:
        cargs.append("-dbg_output")
    if cache_transform is not None:
        cargs.extend([
            "-cache_transform",
            cache_transform
        ])
    ret = Surf2volOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(output_file) if (output_file is not None) else None,
        output_field=execution.output_file(output_field) if (output_field is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "SURF2VOL_METADATA",
    "Surf2volOutputs",
    "surf2vol",
]
