Exemple #1
0
def _import_builtin_asset(asset_name):
    r"""Single builtin asset (mesh or landmark) importer.

    Imports the relevant builtin asset from the ./data directory that
    ships with Menpo3d.

    Parameters
    ----------
    asset_name : `str`
        The filename of a builtin asset (see :map:`ls_builtin_assets`
        for allowed values)

    Returns
    -------
    asset
        An instantiated :map:`LandmarkGroup` or :map:`TriMesh` asset.
    """
    asset_path = data_path_to(asset_name)
    # Import could be either a mesh or a set of landmarks, so we try
    # importing them both separately.
    try:
        return _import(asset_path,
                       mesh_types,
                       landmark_ext_map=mesh_landmark_types)
    except ValueError:
        return _import(asset_path, mesh_landmark_types)
Exemple #2
0
def _import_builtin_asset(asset_name, **kwargs):
    r"""Single builtin asset (mesh or landmark) importer.

    Imports the relevant builtin asset from the ./data directory that
    ships with Menpo3d.

    Parameters
    ----------
    asset_name : `str`
        The filename of a builtin asset (see :map:`ls_builtin_assets`
        for allowed values)

    Returns
    -------
    asset
        An instantiated :map:`LandmarkGroup` or :map:`TriMesh` asset.
    """
    asset_path = data_path_to(asset_name)
    # Import could be either a mesh or a set of landmarks, so we try
    # importing them both separately.
    try:
        return _import(asset_path, mesh_types,
                       landmark_ext_map=mesh_landmark_types,
                       landmark_attach_func=_import_object_attach_landmarks,
                       importer_kwargs=kwargs)
    except ValueError:
        return _import(asset_path, mesh_landmark_types,
                       importer_kwargs=kwargs)
Exemple #3
0
def import_mesh(filepath,
                landmark_resolver=same_name_landmark,
                texture_resolver=same_name_texture):
    r"""Single mesh (and associated landmarks and texture) importer.

    Iff an mesh file is found at `filepath`, returns a :map:`TriMesh`
    representing it. Landmark files sharing the same filename
    will be imported and attached too. If texture coordinates and a suitable
    texture are found the object returned will be a :map:`TexturedTriMesh`.

    Parameters
    ----------
    filepath : `str`
        A relative or absolute filepath to an image file.
    landmark_resolver : `function`, optional
        This function will be used to find landmarks for the
        mesh. The function should take one argument (the mesh itself) and
        return a dictionary of the form ``{'group_name': 'landmark_filepath'}``
        Default finds landmarks with the same name as the mesh file.
    texture : `bool`, optional
        If ``False``, don't search for textures.

    Returns
    -------
    trimesh : :map:`TriMesh`
        An instantiated :map:`TriMesh` (or subclass thereof)
    """
    kwargs = {'texture_resolver': texture_resolver}
    return _import(filepath,
                   mesh_types,
                   landmark_resolver=landmark_resolver,
                   landmark_ext_map=mesh_landmark_types,
                   landmark_attach_func=_import_object_attach_landmarks,
                   importer_kwargs=kwargs)
Exemple #4
0
def import_mesh(filepath, landmark_resolver=same_name, texture=True):
    r"""Single mesh (and associated landmarks and texture) importer.

    Iff an mesh file is found at `filepath`, returns a :map:`TriMesh`
    representing it. Landmark files sharing the same filename
    will be imported and attached too. If texture coordinates and a suitable
    texture are found the object returned will be a :map:`TexturedTriMesh`.

    Parameters
    ----------
    filepath : `str`
        A relative or absolute filepath to an image file.
    landmark_resolver : `function`, optional
        This function will be used to find landmarks for the
        mesh. The function should take one argument (the mesh itself) and
        return a dictionary of the form ``{'group_name': 'landmark_filepath'}``
        Default finds landmarks with the same name as the mesh file.
    texture : `bool`, optional
        If ``False``, don't search for textures.

    Returns
    -------
    trimesh : :map:`TriMesh`
        An instantiated :map:`TriMesh` (or subclass thereof)
    """
    kwargs = {'texture': texture}
    return _import(filepath, mesh_types,
                   landmark_resolver=landmark_resolver,
                   landmark_ext_map=mesh_landmark_types,
                   landmark_attach_func=_import_object_attach_landmarks,
                   importer_kwargs=kwargs)
Exemple #5
0
def import_lsfm_model(filepath):
    r"""Import a LSFM Morphable Model


    Parameters
    ----------
    filepath : `str`
        A relative or absolute filepath to a LSFM model mat file.

    Returns
    -------
    :map:`PCAModel`
        The 3DMM contained in the LSFM mat file.

    """
    return _import(filepath, lsfm_types, landmark_resolver=None)
Exemple #6
0
def import_lsfm_model(filepath):
    r"""Import a LSFM Morphable Model


    Parameters
    ----------
    filepath : `str`
        A relative or absolute filepath to a LSFM model mat file.

    Returns
    -------
    :map:`PCAModel`
        The 3DMM contained in the LSFM mat file.

    """
    return _import(filepath, lsfm_types,
                   landmark_resolver=None)
Exemple #7
0
def import_landmark_file(filepath, landmark_resolver=same_name):
    r"""Single landmark group importer.

    Iff an landmark file is found at `filepath`, returns a :map:`LandmarkGroup`
    representing it.

    Parameters
    ----------
    filepath : `str`
        A relative or absolute filepath to an landmark file.

    Returns
    -------
    :map:`LandmarkGroup`
        The :map:`LandmarkGroup` that the file format represents.

    """
    return _import(filepath, mesh_landmark_types, landmark_resolver=landmark_resolver)
Exemple #8
0
def import_landmark_file(filepath, landmark_resolver=same_name):
    r"""Single landmark group importer.

    Iff an landmark file is found at `filepath`, returns a :map:`LandmarkGroup`
    representing it.

    Parameters
    ----------
    filepath : `str`
        A relative or absolute filepath to an landmark file.

    Returns
    -------
    :map:`LandmarkGroup`
        The :map:`LandmarkGroup` that the file format represents.

    """
    return _import(filepath,
                   mesh_landmark_types,
                   landmark_resolver=landmark_resolver)
Exemple #9
0
def _import_builtin_asset(asset_name):
    r"""Single builtin asset (mesh or image) importer.

    Imports the relevant builtin asset from the ./data directory that
    ships with Menpo3d.

    Parameters
    ----------
    asset_name : `str`
        The filename of a builtin asset (see :map:`ls_builtin_assets`
        for allowed values)

    Returns
    -------
    asset
        An instantiated :map:`Image` or :map:`TriMesh` asset.

    """
    asset_path = data_path_to(asset_name)
    return _import(asset_path,
                   mesh_types,
                   landmark_ext_map=mesh_landmark_types)