class TestDistanceToVerticesCubeOutsideRandom():
    """Ranom location that is always outside the cube
    """
    pt_out = np.random.uniform(0.51 * np.sqrt(3), 1) * sphere.rand(2)
    v_cube, f_cube = wavefront.read_obj('./integration/cube.obj')
    ast = asteroid.Asteroid('castalia', 256, 'mat')
    ast = ast.loadmesh(v_cube, f_cube, 'cube')
    edge_vertex_map = ast.asteroid_grav['edge_vertex_map']
    edge_face_map = ast.asteroid_grav['edge_face_map']
    normal_face = ast.asteroid_grav['normal_face']
    vf_map = ast.asteroid_grav['vertex_face_map']

    D, P, V, E, F = wavefront.distance_to_vertices(pt_out, v_cube, f_cube,
                                                   normal_face,
                                                   edge_vertex_map,
                                                   edge_face_map, vf_map)

    def test_distance(self):
        np.testing.assert_allclose(np.isfinite(self.D), True)

    def test_point(self):
        np.testing.assert_allclose(len(self.P) >= 3, True)

    def test_vertex(self):
        np.testing.assert_allclose(np.isfinite(self.V), True)

    def test_edge(self):
        np.testing.assert_allclose(np.isfinite(self.E), True)

    def test_face(self):
        np.testing.assert_allclose(len(self.F) >= 1, True)
Exemple #2
0
def test_distance_to_mesh(pt=np.random.uniform(0.8, 1.5) * sphere.rand(2)):
    """Test out the point processing function
    """
    v, f = wavefront.read_obj('./integration/cube.obj')
    mesh_parameters = wavefront.polyhedron_parameters(v, f)
    D, P, V, E, F, primitive = wavefront.distance_to_mesh(
        pt, v, f, mesh_parameters)
    plot_data(pt, v, f, D, P, V, E, F, 'Min Primitive: ' + primitive)

    return D, P, V, E, F, primitive
Exemple #3
0
class TestPerturbedVector():

    q = sphere.rand(2)
    half_angle = 5
    qp = sphere.perturb_vec(q, half_angle)

    def test_angle(self):
        """Ensure the angle is always less than half_angle
        """
        angle = np.arccos(np.dot(self.q, self.qp)) * 180 / np.pi
        np.testing.assert_array_less(angle, self.half_angle)

    def test_norm(self):
        np.testing.assert_allclose(np.linalg.norm(self.qp), 1)
Exemple #4
0
def test_closest_edge_plot_asteroid(pt=np.random.uniform(0.8, 1.5) *
                                    sphere.rand(2)):
    ast = asteroid.Asteroid('itokawa', 0, 'obj')

    v, f = ast.asteroid_grav['V'], ast.asteroid_grav['F']
    edge_vertex_map = ast.asteroid_grav['edge_vertex_map']
    edge_face_map = ast.asteroid_grav['edge_face_map']
    normal_face = ast.asteroid_grav['normal_face']
    vf_map = ast.asteroid_grav['vertex_face_map']

    D, P, V, E, F = wavefront.distance_to_edges(pt, v, f, normal_face,
                                                edge_vertex_map, edge_face_map,
                                                vf_map)
    plot_data(pt, v, f, D, P, V, E, F, 'Closest Edge')
    return D, P, V, E, F
Exemple #5
0
def test_closest_edge_plot_cube(pt=np.random.uniform(0.9, 1.5) *
                                sphere.rand(2)):
    ast = asteroid.Asteroid('castalia', 256, 'mat')
    v, f = wavefront.read_obj('./integration/cube.obj')
    ast = ast.loadmesh(v, f, 'cube')

    edge_vertex_map = ast.asteroid_grav['edge_vertex_map']
    edge_face_map = ast.asteroid_grav['edge_face_map']
    normal_face = ast.asteroid_grav['normal_face']
    vf_map = ast.asteroid_grav['vertex_face_map']

    D, P, V, E, F = wavefront.distance_to_edges(pt, v, f, normal_face,
                                                edge_vertex_map, edge_face_map,
                                                vf_map)
    plot_data(pt, v, f, D, P, V, E, F, '')
    return D, P, V, E, F
Exemple #6
0
def test_point_insertion_random():

    num_points = 100
    nv, nf = wavefront.read_obj('./integration/cube.obj')

    # loop over random points and add them to the cube
    for ii in range(num_points):

        pt = np.random.uniform(0.6, 0.7) * sphere.rand(2)
        mesh_parameters = wavefront.polyhedron_parameters(nv, nf)
        D, P, V, E, F, primitive = wavefront.distance_to_mesh(
            pt, nv, nf, mesh_parameters)
        if primitive == 'vertex':
            nv, nf = wavefront.vertex_insertion(pt, nv, nf, D, P, V, E, F)
        elif primitive == 'edge':
            nv, nf = wavefront.edge_insertion(pt, nv, nf, D, P, V, E, F)
        elif primitive == 'face':
            nv, nf = wavefront.face_insertion(pt, nv, nf, D, P, V, E, F)

    mfig = graphics.mayavi_figure()
    mesh = graphics.mayavi_addMesh(mfig, nv, nf)
Exemple #7
0
def test_closest_face_plot_asteroid(pt=np.random.uniform(0.8, 1.5) *
                                    sphere.rand(2)):
    """Needs to be aligned with a face
    
        i.e. not in the corners
    """

    ast = asteroid.Asteroid('itokawa', 0, 'obj')

    v, f = ast.asteroid_grav['V'], ast.asteroid_grav['F']
    edge_vertex_map = ast.asteroid_grav['edge_vertex_map']
    edge_face_map = ast.asteroid_grav['edge_face_map']
    normal_face = ast.asteroid_grav['normal_face']
    vf_map = ast.asteroid_grav['vertex_face_map']

    D, P, V, E, F = wavefront.distance_to_faces(pt, v, f, normal_face,
                                                edge_vertex_map, edge_face_map,
                                                vf_map)
    plot_data(pt, v, f, D, P, V, E, F, 'Closest Face')

    return D, P, V, E, F
Exemple #8
0
def test_two_sphere_random_vector_norm():
    vec = sphere.rand(2)
    np.testing.assert_almost_equal(np.linalg.norm(vec), 1)
Exemple #9
0
def test_two_sphere_tangent_vector():
    vec = sphere.rand(2)
    vecd = sphere.tan_rand(vec, 9)

    np.testing.assert_almost_equal(np.dot(vec, vecd), 0)
Exemple #10
0
"""Test out creating and plotting a geodesic waypoint (great circle) on the 
sphere
"""
from point_cloud import wavefront
from kinematics import sphere
from visualization import graphics

from lib import geodesic, surface_mesh

import numpy as np

# generate a sphere for plotting
sphere_mesh = surface_mesh.SurfMesh(1, 1, 1, 10, 0.15, 0.5)
vs, fs = sphere_mesh.verts(), sphere_mesh.faces()

# create two random points on the sphere
initial_point_cartesian = sphere.rand(2)
final_point_cartesian = sphere.rand(2)

# compute waypoints inbetween
waypoints_cartesian = geodesic.sphere_waypoint(initial_point_cartesian,
                                               final_point_cartesian, 5)

# plot everythign on a mayavi figure
mfig = graphics.mayavi_figure()
graphics.mayavi_axes(mfig, [-1, 1, -1, 1, -1, 1])
graphics.mayavi_addMesh(mfig, vs, fs, color=(0, 0, 1), opacity=0.2)
graphics.mayavi_points3d(mfig, waypoints_cartesian, color=(0, 0, 1))
graphics.mayavi_addPoint(mfig, initial_point_cartesian, color=(0, 1, 0))
graphics.mayavi_addPoint(mfig, final_point_cartesian, color=(1, 0, 0))