<commit_before># emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
'''
Miscellaneous algorithms for 2D contours and 3D triangularized meshes handling

    Change directory to provide relative paths for doctests
    >>> import os
    >>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
    >>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
    >>> os.chdir(datadir)

'''


import numpy as np
from numpy import linalg as nla
import os.path as op
from nipype.external import six

from .. import logging

from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
                               BaseInterfaceInputSpec)
from warnings import warn
iflogger = logging.getLogger('interface')


class WarpPointsInputSpec(BaseInterfaceInputSpec):
    points = File(exists=True, mandatory=True,
                  desc=('file containing the point set'))
    warp = File(exists=True, mandatory=True,
                desc=('dense deformation field to be applied'))
    interp = traits.Enum('cubic', 'nearest', 'linear', usedefault=True,
                         mandatory=True, desc='interpolation')
    out_points = File(name_source='points', name_template='%s_warped',
                      output_name='out_points', keep_extension=True,
                      desc='the warped point set')


class WarpPointsOutputSpec(TraitedSpec):
    out_points = File(desc='the warped point set')


class WarpPoints(BaseInterface):

    """
    Applies a displacement field to a point set in vtk

    Example
    -------

    >>> from nipype.algorithms.mesh import WarpPoints
    >>> wp = WarpPoints()
    >>> wp.inputs.points = 'surf1.vtk'
    >>> wp.inputs.warp = 'warpfield.nii'
    >>> res = wp.run() # doctest: +SKIP
    """
    input_spec = WarpPointsInputSpec
    output_spec = WarpPointsOutputSpec
    _redirect_x = True

    def _gen_fname(self, in_file, suffix='generated', ext=None):
        import os.path as op

        fname, fext = op.splitext(op.basename(in_file))

        if fext == '.gz':
            fname, fext2 = op.splitext(fname)
            fext = fext2+fext

        if ext is None:
            ext = fext

        if ext[0] == '.':
            ext = ext[1:]
        return op.abspath('%s_%s.%s' % (fname, suffix, ext))

    def _run_interface(self, runtime):<commit_msg>describe the input displacement field<commit_after># emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
'''
Miscellaneous algorithms for 2D contours and 3D triangularized meshes handling

    Change directory to provide relative paths for doctests
    >>> import os
    >>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
    >>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
    >>> os.chdir(datadir)

'''


import numpy as np
from numpy import linalg as nla
import os.path as op
from nipype.external import six

from .. import logging

from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
                               BaseInterfaceInputSpec)
from warnings import warn
iflogger = logging.getLogger('interface')


class WarpPointsInputSpec(BaseInterfaceInputSpec):
    points = File(exists=True, mandatory=True,
                  desc=('file containing the point set'))
    warp = File(exists=True, mandatory=True,
                desc=('dense deformation field to be applied'))
    interp = traits.Enum('cubic', 'nearest', 'linear', usedefault=True,
                         mandatory=True, desc='interpolation')
    out_points = File(name_source='points', name_template='%s_warped',
                      output_name='out_points', keep_extension=True,
                      desc='the warped point set')


class WarpPointsOutputSpec(TraitedSpec):
    out_points = File(desc='the warped point set')


class WarpPoints(BaseInterface):

    """
    Applies a displacement field to a point set given in vtk format.
    Any discrete deformation field, given in physical coordinates and
    which volume covers the extent of the vtk point set, is a valid
    ``warp`` file. FSL interfaces are compatible, for instance any
    field computed with :class:`nipype.interfaces.fsl.utils.ConvertWarp`.

    Example
    -------

    >>> from nipype.algorithms.mesh import WarpPoints
    >>> wp = WarpPoints()
    >>> wp.inputs.points = 'surf1.vtk'
    >>> wp.inputs.warp = 'warpfield.nii'
    >>> res = wp.run() # doctest: +SKIP
    """
    input_spec = WarpPointsInputSpec
    output_spec = WarpPointsOutputSpec
    _redirect_x = True

    def _gen_fname(self, in_file, suffix='generated', ext=None):
        import os.path as op

        fname, fext = op.splitext(op.basename(in_file))

        if fext == '.gz':
            fname, fext2 = op.splitext(fname)
            fext = fext2+fext

        if ext is None:
            ext = fext

        if ext[0] == '.':
            ext = ext[1:]
        return op.abspath('%s_%s.%s' % (fname, suffix, ext))

    def _run_interface(self, runtime):
{'fraction_non_alphanumeric': 0.11813349084465447, 'fraction_numerical': 0.0043315613309706635, 'mean_word_length': 2.7769516728624537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3069046', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1528, 'n_words': 422}