How to use the generic.log function in generic

To help you get started, we’ve selected a few generic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikedh / trimesh / tests / regression.py View on Github external
def typical_application():
    # make sure we can load everything we think we can
    # while getting a list of meshes to run tests on
    meshes = g.get_meshes(raise_error=True)
    g.log.info('Running tests on %d meshes', len(meshes))

    for mesh in meshes:
        g.log.info('Testing %s', mesh.metadata['file_name'])
        assert len(mesh.faces) > 0
        assert len(mesh.vertices) > 0

        assert len(mesh.edges) > 0
        assert len(mesh.edges_unique) > 0
        assert len(mesh.edges_sorted) > 0
        assert len(mesh.edges_face) > 0
        assert isinstance(mesh.euler_number, int)

        if not mesh.is_volume:
            continue

        assert len(mesh.facets) == len(mesh.facets_area)
github mikedh / trimesh / tests / test_bounds.py View on Github external
def test_obb_mesh(self):
        """
        Test the OBB functionality in attributes of Trimesh objects
        """
        for m in self.meshes:
            g.log.info('Testing OBB of %s', m.metadata['file_name'])
            for i in range(6):
                # on the first run through don't transform the points to see
                # if we succeed in the meshes original orientation
                matrix = g.np.eye(4)
                if i > 0:
                    # get repeatable transforms
                    matrix = g.transforms[i]
                    m.apply_transform(matrix)

                box_ext = m.bounding_box_oriented.primitive.extents.copy()
                box_t = m.bounding_box_oriented.primitive.transform.copy()

                m.apply_transform(g.np.linalg.inv(box_t))

                test = m.bounds / (box_ext / 2.0)
                test_ok = g.np.allclose(test, [[-1, -1, -1], [1, 1, 1]])
github mikedh / trimesh / tests / test_dae.py View on Github external
def test_shoulder(self):
        if collada is None:
            g.log.error('no pycollada to test!')
            return

        scene = g.get_mesh('shoulder.zae')
        assert len(scene.geometry) == 3
        assert len(scene.graph.nodes_geometry) == 3
github mikedh / trimesh / tests / test_convex.py View on Github external
g.np.median(volume),
                                 atol=mesh.bounding_box.volume / 1000)

            if g.platform.system() == 'Linux':
                # on linux the convex hulls are pretty robust
                close_ok = close.all()
            else:
                # on windows sometimes there is flaky numerical weirdness
                # which causes spurious CI failures, so use softer metric
                # for success: here of 90% of values are close to the median
                # then declare everything hunky dory
                ratio = close.sum() / float(len(close))
                close_ok = ratio > .9

            if not close_ok:
                g.log.error('volume inconsistent: {}'.format(volume))
                raise ValueError('volume is inconsistent on {}'.format(
                    mesh.metadata['file_name']))
            assert min(volume) > 0.0

            if not all(i.is_winding_consistent for i in hulls):
                raise ValueError(
                    'mesh %s reported bad winding on convex hull!',
                    mesh.metadata['file_name'])

            if not all(i.is_convex for i in hulls):
                raise ValueError('mesh %s reported non-convex convex hull!',
                                 mesh.metadata['file_name'])
github mikedh / trimesh / tests / test_paths.py View on Github external
body.identifier

            if len(d.root) == 1:
                d.apply_obb()

            # store the X values of bounds
            ori = d.bounds.copy()
            # apply a translation
            d.apply_translation([10, 0])
            # X should have translated by 10.0
            assert g.np.allclose(d.bounds[:, 0] - 10, ori[:, 0])
            # Y should not have moved
            assert g.np.allclose(d.bounds[:, 1], ori[:, 1])

            if len(d.polygons_full) > 0 and len(d.vertices) < 150:
                g.log.info('Checking medial axis on %s',
                           d.metadata['file_name'])
                m = d.medial_axis()
                assert len(m.entities) > 0

            # shouldn't crash
            d.fill_gaps()

            # transform to first quadrant
            d.rezero()
            # run process manually
            d.process()
github mikedh / trimesh / tests / test_boolean.py View on Github external
if not d.is_volume:
                d.show()
            self.assertTrue(d.is_volume)
            self.assertTrue(self.is_zero(d.volume -
                                         self.truth['difference']))

            i = a.intersection(b, engine=engine)
            self.assertTrue(i.is_volume)
            self.assertTrue(self.is_zero(i.volume -
                                         self.truth['intersection']))

            u = a.union(b, engine=engine)
            self.assertTrue(u.is_volume)
            self.assertTrue(self.is_zero(u.volume - self.truth['union']))

            g.log.info('booleans succeeded with %s', engine)
github mikedh / trimesh / tests / test_integrate.py View on Github external
def test_integrate(self):
        from trimesh.integrate import symbolic_barycentric
        import sympy as sp
        m = g.get_mesh('featuretype.STL')

        integrator, expr = symbolic_barycentric('1')
        self.assertTrue(g.np.allclose(integrator(m).sum(), m.area))

        x, y, z = sp.symbols('x y z')
        functions = [x**2 + y**2, x + y + z]

        for f in functions:
            integrator, expr = symbolic_barycentric(f)
            integrator_p, expr_p = symbolic_barycentric(str(f))

            g.log.debug('expression %s was integrated to %s',
                        str(f),
                        str(expr))

            summed = integrator(m).sum()
            summed_p = integrator_p(m).sum()
            self.assertTrue(g.np.allclose(summed,
                                          summed_p))
            self.assertFalse(g.np.allclose(summed, 0.0))
github mikedh / trimesh / tests / test_mesh.py View on Github external
section = mesh.section(plane_normal=[0, 0, 1],  # NOQA
                                   plane_origin=mesh.centroid)

            sample = mesh.sample(1000)
            even_sample = g.trimesh.sample.sample_surface_even(mesh, 100)  # NOQA
            assert sample.shape == (1000, 3)
            g.log.info('finished testing meshes')

            # make sure vertex kdtree and triangles rtree exist

            t = mesh.kdtree
            assert hasattr(t, 'query')
            g.log.info('Creating triangles tree')
            r = mesh.triangles_tree
            assert hasattr(r, 'intersection')
            g.log.info('Triangles tree ok')

            # face angles should have same
            assert mesh.face_angles.shape == mesh.faces.shape
            assert len(mesh.vertices) == len(mesh.vertex_defects)
            assert len(mesh.principal_inertia_components) == 3

            # collect list of cached properties that are writeable
            writeable = []
            # we should have built up a bunch of stuff into
            # our cache, so make sure all numpy arrays cached
            # are read-only and not crazy
            for name, cached in mesh._cache.cache.items():
                # only check numpy arrays
                if not isinstance(cached, g.np.ndarray):
                    continue
github mikedh / trimesh / tests / test_decomposition.py View on Github external
def test_convex_decomposition(self):
        mesh = g.get_mesh('quadknot.obj')

        engines = [('vhacd', g.trimesh.interfaces.vhacd.exists)]

        for engine, exists in engines:
            if not exists:
                g.log.warning(
                    'skipping convex decomposition engine %s', engine)
                continue

            g.log.info('Testing convex decomposition with engine %s', engine)
            meshes = mesh.convex_decomposition(engine=engine)
            self.assertTrue(len(meshes) > 1)
            for m in meshes:
                self.assertTrue(m.is_watertight)

            g.log.info('convex decomposition succeeded with %s', engine)
github mikedh / trimesh / tests / test_collision.py View on Github external
def test_collision(self):
        # Ensure that FCL is importable
        try:
            g.trimesh.collision.CollisionManager()
        except ValueError:
            g.log.warning('skipping collision tests, no FCL installed')
            return

        cube = g.get_mesh('unit_cube.STL')

        tf1 = g.np.eye(4)
        tf1[:3, 3] = g.np.array([5, 0, 0])

        tf2 = g.np.eye(4)
        tf2[:3, 3] = g.np.array([-5, 0, 0])

        # Test one-to-many collision checking
        m = g.trimesh.collision.CollisionManager()
        m.add_object('cube0', cube)
        m.add_object('cube1', cube, tf1)

        ret = m.in_collision_single(cube)