Beispiel #1
0
def test_line_from_two_planes_invalid_input():
    """
    Test the fault case for the intersection of two planes
    """
    plane = Plane()
    with pytest.raises(TypeError):
        plane.intersection_line("not a plane")
Beispiel #2
0
def test_point_from_line_plane_bad_input():
    """
    Test bad inputs to line plane intersection
    """
    plane = Plane()
    with pytest.raises(TypeError):
        plane.intersection_point("not a line.")
Beispiel #3
0
def test_point_from_line_plane_parallel():
    """
    Check that a runtime error is raised if the line lies in the plane.
    """
    plane = Plane()
    line = Line([0, 0, 0], [1, 0, 0])
    with pytest.raises(RuntimeError):
        plane.intersection_point(line)
Beispiel #4
0
def test_point_from_line_plane_good():
    """
    Test that line/plane intersection.
    """
    plane = Plane([1, 1, 10], [0, 0, 1])
    line = Line([1, 1, 0], [1, 1, 1])

    assert pytest.approx(plane.intersection_point(line)) == [11, 11, 10]
Beispiel #5
0
def test_bad_input_size_initializer():
    """
    Test incorrect dimension of input arguements.
    """
    with pytest.raises(TypeError):
        Plane(point_on_plane=5.0)
    with pytest.raises(TypeError):
        Plane(normal=[5.0, 2.0])
Beispiel #6
0
def test_line_from_two_planes_working():
    """
    Test the generation of a line from two planes.
    """
    plane1 = Plane([0, 0, 0], [0, 0, 1])
    plane2 = Plane([0, 0, 0], [1, 0, 0])

    line = plane1.intersection_line(plane2)

    assert [0, 1, 0] == pytest.approx(line.direction)
    assert [0, 0, 0] == pytest.approx(line.point)
Beispiel #7
0
def test_line_from_two_planes_parallel():
    """
    Test the fault case for two planes not intersecting / parallel
    """
    plane1 = Plane()
    plane2 = Plane()
    with pytest.raises(RuntimeError):
        plane1.intersection_line(plane2)

    plane1 = Plane(point_on_plane=[1, 1, 50], normal=[1, 0, 1])
    plane2 = Plane(point_on_plane=[50, 2, -5], normal=[-1, 0, -1])
    with pytest.raises(RuntimeError):
        plane1.intersection_line(plane2)
Beispiel #8
0
def test_file_saving_loading():
    """
    Test the file saving and loading.
    """
    with tempfile.NamedTemporaryFile() as fid:
        plane = Plane(point_on_plane=np.array([1.0, 1.1, 1.2]),
                      normal=np.array([1., -1., 0.]))
        plane.write_file(fid.name)
        new_object = Plane.read_json_file(fid.name)
        assert isinstance(new_object, Plane)
        assert [1.0, 1.1, 1.2] == pytest.approx(new_object.point)
        assert [1.0 / np.sqrt(2), -1.0 / np.sqrt(2),
                0.0] == pytest.approx(new_object.normal)
Beispiel #9
0
def test_default_initializer():
    """
    Defaults test
    """
    plane = Plane()
    assert [0, 0, 0] == pytest.approx(plane.point)
    assert [0, 0, 1] == pytest.approx(plane.normal)
Beispiel #10
0
def laser_calibration():
    """
    Method for getting and setting the laser cal file.
    """
    success = True
    message = ""
    if request.method == "POST":
        cal_file = request.json
        try:
            laser_cal = json.loads(cal_file, JSONDecoder=decode_plane_settings)
            laser_cal.write_file(LASER_CAL_FILE)
        except:
            success = False
            message = "Failed to parse passed laser calibration."
        return jsonify({"success": success, "message": message})
    else:
        try:
            plane = Plane.read_json_file(LASER_CAL_FILE)
        except:
            plane = None
            success = False
            message = "Failed to load laser xml file."
        return jsonify({
            "laser_cal_file": plane,
            "success": success,
            "message": message
        })
Beispiel #11
0
def test_good_initialization():
    """
    Test initializer with non-default values.
    """
    plane = Plane(point_on_plane=np.array([1.0, 1.1, 1.2]),
                  normal=np.array([1., -1., 0.]))
    assert [1.0, 1.1, 1.2] == pytest.approx(plane.point)
    assert [1.0 / np.sqrt(2), -1.0 / np.sqrt(2),
            0.0] == pytest.approx(plane.normal)
Beispiel #12
0
def test_transform_plane():
    """
    Test transfroming a simple plane. 
    """ 
    rot_90_x = [np.pi/2, 0, 0]
    trans = [1, 2, -1]
    transform = Transform(translation = trans, rotation = rot_90_x)
    plane = Plane()

    new_plane = transform.transform_plane(plane)

    np.testing.assert_array_almost_equal(trans, new_plane.point)
    np.testing.assert_array_almost_equal([0, -1, 0], new_plane.normal)
Beispiel #13
0
def laser_calibration():
    """
    return a plane calibration file in json.
    """
    if request.method == "GET":
        if 'laser_plane' not in session:
            session['laser_plane'] = Plane()
        return jsonify(session['laser_plane'])
    else:
        json_object = request.get_json()
        if "__plane__" in json_object and json_object['__plane__']:
            session['laser_plane'] = json_object
        return jsonify({"success": True})
Beispiel #14
0
def test_plane_initialization_bad_normal():
    """
    Test plane initializer with bad normal (0)
    """
    with pytest.raises(ZeroDivisionError):
        Plane(normal=[0, 0, 0])
Beispiel #15
0
import sys
from volteracamera.analysis.undistort import Undistort
from volteracamera.analysis.plane import Plane
from volteracamera.analysis.laser_line_finder import LaserProcessingServer

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("camera_parameters", type=str, help="json file containing undistortion class.")
    parser.add_argument("laser_plane", type=str, help="json file containing laser plane class.")
    parser.add_argument("-o", "--output_file", type=str, help="optional output file for the laser data, saved in csv format.")

    args = parser.parse_args()

    #load in the calibration files
    cam_params = Undistort.read_json_file(args.camera_parameters)
    laser_plane = Plane.read_json_file(args.laser_plane)

    output_file = args.output_file

    if cam_params is None:
        print ("Failed to load camera parameters. Exiting...")
        sys.exit()
    if laser_plane is None:
        print ("Failed to load laser plane parameters. Exiting...")
        sys.exit()

    laser_processor = LaserProcessingServer (cam_params, laser_plane)

    if output_file:
        laser_processor.save_data (output_file)
    laser_processor.start()