def test_import_asset_bunny(): mesh = mio.import_builtin_asset("bunny.obj") assert isinstance(mesh, TriMesh) assert isinstance(mesh.points, np.ndarray) assert mesh.points.shape[1] == 3 assert isinstance(mesh.trilist, np.ndarray) assert mesh.trilist.shape[1] == 3
def test_import_asset_bunny(): mesh = mio.import_builtin_asset('bunny.obj') assert(isinstance(mesh, TriMesh)) assert(isinstance(mesh.points, np.ndarray)) assert(mesh.points.shape[1] == 3) assert(isinstance(mesh.trilist, np.ndarray)) assert(mesh.trilist.shape[1] == 3)
def test_import_asset_bunny(): mesh = mio.import_builtin_asset('bunny.obj') assert (isinstance(mesh, TriMesh)) assert (isinstance(mesh.points, np.ndarray)) assert (mesh.points.shape[1] == 3) assert (isinstance(mesh.trilist, np.ndarray)) assert (mesh.trilist.shape[1] == 3)
def test_json_landmarks_bunny(): mesh = mio.import_builtin_asset("bunny.obj") assert "LJSON" in mesh.landmarks.group_labels lms = mesh.landmarks["LJSON"] labels = {"reye", "mouth", "nose", "leye"} assert len(labels - set(lms.labels)) == 0 assert_allclose(lms["leye"].points, bunny_leye, atol=1e-7) assert_allclose(lms["reye"].points, bunny_reye, atol=1e-7) assert_allclose(lms["nose"].points, bunny_nose, atol=1e-7) assert_allclose(lms["mouth"].points, bunny_mouth, atol=1e-7)
def test_import_asset_template(): mesh = mio.import_builtin_asset("template.ply") assert isinstance(mesh, ColouredTriMesh) assert isinstance(mesh.points, np.ndarray) assert mesh.points.shape[1] == 3 assert isinstance(mesh.trilist, np.ndarray) assert mesh.trilist.shape[1] == 3 assert isinstance(mesh.colours, np.ndarray) assert mesh.colours.shape[1] == 3 assert mesh.colours.max() == 1.0
def test_json_landmarks_bunny(): mesh = mio.import_builtin_asset("bunny.obj") assert "LJSON" in mesh.landmarks.group_labels lms = mesh.landmarks["LJSON"] labels = {"reye", "mouth", "nose", "leye"} assert len(labels - set(lms.labels)) == 0 assert_allclose(lms.with_labels("leye").points, bunny_leye, atol=1e-7) assert_allclose(lms.with_labels("reye").points, bunny_reye, atol=1e-7) assert_allclose(lms.with_labels("nose").points, bunny_nose, atol=1e-7) assert_allclose(lms.with_labels("mouth").points, bunny_mouth, atol=1e-7)
def test_json_landmarks_bunny(): mesh = mio.import_builtin_asset('bunny.obj') assert ('LJSON' in mesh.landmarks.group_labels) lms = mesh.landmarks['LJSON'] labels = {'reye', 'mouth', 'nose', 'leye'} assert (len(labels - set(lms.labels)) == 0) assert_allclose(lms.with_labels('leye').points, bunny_leye, atol=1e-7) assert_allclose(lms.with_labels('reye').points, bunny_reye, atol=1e-7) assert_allclose(lms.with_labels('nose').points, bunny_nose, atol=1e-7) assert_allclose(lms.with_labels('mouth').points, bunny_mouth, atol=1e-7)
def test_import_asset_james(): mesh = mio.import_builtin_asset('james.obj') assert (isinstance(mesh, TexturedTriMesh)) assert (isinstance(mesh.points, np.ndarray)) assert (mesh.points.shape[1] == 3) assert (isinstance(mesh.trilist, np.ndarray)) assert (mesh.trilist.shape[1] == 3) assert (isinstance(mesh.texture, Image)) assert (isinstance(mesh.tcoords, PointCloud)) assert (mesh.tcoords.points.shape[1] == 2)
def test_json_landmarks_bunny(): mesh = mio.import_builtin_asset('bunny.obj') assert('LJSON' in mesh.landmarks.group_labels) lms = mesh.landmarks['LJSON'] labels = {'reye', 'mouth', 'nose', 'leye'} assert(len(labels - set(lms.labels)) == 0) assert_allclose(lms['leye'].points, bunny_leye, atol=1e-7) assert_allclose(lms['reye'].points, bunny_reye, atol=1e-7) assert_allclose(lms['nose'].points, bunny_nose, atol=1e-7) assert_allclose(lms['mouth'].points, bunny_mouth, atol=1e-7)
def test_import_asset_james(): mesh = mio.import_builtin_asset('james.obj') assert(isinstance(mesh, TexturedTriMesh)) assert(isinstance(mesh.points, np.ndarray)) assert(mesh.points.shape[1] == 3) assert(isinstance(mesh.trilist, np.ndarray)) assert(mesh.trilist.shape[1] == 3) assert(isinstance(mesh.texture, Image)) assert(isinstance(mesh.tcoords, PointCloud)) assert(mesh.tcoords.points.shape[1] == 2)
frag_shader = """#version 330 #extension GL_ARB_explicit_attrib_location : require uniform sampler2D textureImage; smooth in vec2 tcoord; smooth in vec3 linearMappingCoord; layout(location = 0) out vec4 outputColor; layout(location = 1) out vec3 outputLinearMapping; void main() { outputColor = texture(textureImage, tcoord); outputLinearMapping = linearMappingCoord; } """ import numpy as np import menpo3d.io as mio from cyrasterize import CyRasterizer from cyrasterize import FragmentShader import sip sip.setapi('QString', 2) sip.setapi('QVariant', 2) mesh = mio.import_builtin_asset('james.obj') CyRasterizer() shader = FragmentShader(frag_shader) print(shader)
def test_import_incorrect_built_in(): mio.import_builtin_asset('adskljasdlkajd.obj')
from mock import patch, PropertyMock, MagicMock import menpo3d.io as mio test_obj = mio.import_builtin_asset('james.obj') test_lg = mio.import_landmark_file(mio.data_path_to('bunny.ljson')) @patch('menpo3d.io.output.base.Path.exists') @patch('{}.open'.format(__name__), create=True) def test_export_mesh_obj(mock_open, exists): exists.return_value = False fake_path = '/fake/fake.obj' with open(fake_path) as f: type(f).name = PropertyMock(return_value=fake_path) mio.export_mesh(test_obj, f, extension='obj') @patch('menpo.image.base.PILImage') @patch('menpo3d.io.output.base.Path.exists') @patch('menpo.io.output.base.Path.open') def test_export_mesh_obj_textured(mock_open, exists, PILImage): exists.return_value = False mock_open.return_value = MagicMock() fake_path = '/fake/fake.obj' mio.export_textured_mesh(test_obj, fake_path, extension='obj') assert PILImage.fromarray.called @patch('menpo.io.output.landmark.json.dump') @patch('menpo3d.io.output.base.Path.exists')
import contextlib import os import tempfile from mock import patch, PropertyMock, MagicMock import menpo3d.io as mio test_obj = mio.import_builtin_asset('james.obj') test_lg = mio.import_landmark_file(mio.data_path_to('bunny.ljson')) @contextlib.contextmanager def _temporary_path(extension): # Create a temporary file and remove it fake_path = tempfile.NamedTemporaryFile(delete=False, suffix=extension) fake_path.close() fake_path = fake_path.name os.unlink(fake_path) yield fake_path if os.path.exists(fake_path): os.unlink(fake_path) @patch('menpo3d.io.output.base.Path.exists') @patch('{}.open'.format(__name__), create=True) def test_export_mesh_obj(mock_open, exists): exists.return_value = False fake_path = '/fake/fake.obj' with open(fake_path) as f: type(f).name = PropertyMock(return_value=fake_path) mio.export_mesh(test_obj, f, extension='obj')
import contextlib import os import tempfile from unittest.mock import MagicMock, PropertyMock, patch import menpo3d.io as mio test_obj = mio.import_builtin_asset("james.obj") test_lg = mio.import_landmark_file(mio.data_path_to("bunny.ljson")) @contextlib.contextmanager def _temporary_path(extension): # Create a temporary file and remove it fake_path = tempfile.NamedTemporaryFile(delete=False, suffix=extension) fake_path.close() fake_path = fake_path.name os.unlink(fake_path) yield fake_path if os.path.exists(fake_path): os.unlink(fake_path) @patch("menpo3d.io.output.base.Path.exists") @patch("{}.open".format(__name__), create=True) def test_export_mesh_obj(mock_open, exists): exists.return_value = False fake_path = "/fake/fake.obj" with open(fake_path) as f: type(f).name = PropertyMock(return_value=fake_path) mio.export_mesh(test_obj, f, extension="obj")
def test_import_incorrect_built_in(): with raises(ValueError): mio.import_builtin_asset("adskljasdlkajd.obj")