Пример #1
0
    def test_model(self):
        viewer = IntegrableViewer()
        orig_model = viewer.model
        viewer.model = Model()
        new_model = viewer.model

        assert orig_model is not new_model
Пример #2
0
    def test_screen_to_ndc(self):
        viewer = IntegrableViewer()
        viewer.resize(800, 600)
        ndc = viewer.screen_to_ndc(400, 150, 0)

        expected = [0.0, 0.5, 1.0]
        assert self.equal_list(expected, ndc)
Пример #3
0
    def test_unproject(self):
        viewer = IntegrableViewer()

        expected = [0.0, 0.0, -1.0]
        unproject = viewer.unproject(0, 0, 0)
        assert self.equal_list(expected, unproject)

        assert viewer.unproject(0.5, 0.0, 0)[0] > 0.0
        assert viewer.unproject(-0.5, 0.0, 0)[0] < 0.0
Пример #4
0
    def test_clear(self):
        viewer = IntegrableViewer()

        viewer.load_mesh(path=f'{TEST_FILES_FOLDER_PATH}/caseron.off')
        viewer.load_blocks(path=f'{TEST_FILES_FOLDER_PATH}/mini.csv')
        viewer.load_points(path=f'{TEST_FILES_FOLDER_PATH}/mini.csv')

        assert viewer.drawable_collection.size() == 3
        viewer.clear()
        assert viewer.drawable_collection.size() == 0
Пример #5
0
    def test_last_drawable(self):
        viewer = IntegrableViewer()
        assert viewer.last_id == -1

        mesh = viewer.mesh(x=[-1, 1, 0],
                           y=[0, 0, 1],
                           z=[0, 0, 0],
                           indices=[[0, 1, 2]])
        assert viewer.last_id == 0
        assert viewer.last_drawable is mesh
Пример #6
0
    def test_slice_meshes(self):
        viewer = IntegrableViewer()
        mesh = viewer.load_mesh(f'{TEST_FILES_FOLDER_PATH}/caseron.dxf')
        mesh.hide()

        origin = mesh.center
        normal = [0.0, 0.6, 0.8]
        slices = viewer.slice_meshes(origin, normal, include_hidden=False)
        assert len(slices) == 0

        slices = viewer.slice_meshes(origin, normal, include_hidden=True)
        assert len(slices) > 0
Пример #7
0
    def test_slice_blocks(self):
        viewer = IntegrableViewer()
        blocks = viewer.load_blocks(f'{TEST_FILES_FOLDER_PATH}/mini.csv')
        blocks.hide()

        origin = blocks.center
        normal = [0.0, 0.6, -0.8]
        slices = viewer.slice_blocks(origin, normal, include_hidden=False)
        assert len(slices) == 0

        slices = viewer.slice_blocks(origin, normal, include_hidden=True)
        assert len(slices) > 0
Пример #8
0
    def test_generate_slice_description(self):
        def on_description(description: dict):
            assert 'origin' in description.keys()
            assert 'normal' in description.keys()
            assert 'up' in description.keys()

        viewer = IntegrableViewer()
        viewer.signal_slice_description.connect(on_description)

        viewer.generate_slice_description(origin_list=[[0.0, 0.0, 0.0],
                                                       [100.0, 0.0, 0.0]],
                                          ray_list=[[-0.5, 0.0, -0.7],
                                                    [+0.5, 0.0, -0.7]])
Пример #9
0
    def test_load_elements(self):
        viewer = IntegrableViewer()

        mesh = viewer.mesh(x=[-1, 1, 0],
                           y=[0, 0, 1],
                           z=[-3, -3, -3],
                           color=[0.0, 0.0, 1.0],
                           indices=[[0, 1, 2]],
                           alpha=0.4,
                           name='mesh_name',
                           extension='dxf')

        assert viewer.last_id == 0

        blocks = viewer.blocks(x=[-3, 3, 0],
                               y=[0, 0, 5],
                               z=[0, 0, 0],
                               block_size=[1.0, 1.0, 1.0],
                               values=[0.5, 1.0, 1.5])

        assert viewer.last_id == 1

        points = viewer.points(vertices=[[-3, 2, 0], [0, 2, 1], [3, 2, 2]],
                               point_size=10.0,
                               values=[1.5, 1.0, 0.5])

        assert viewer.last_id == 2

        lines = viewer.lines(x=[-0.5, 0.5],
                             y=[-2.0, 1.5],
                             z=[-2.0, -2.0],
                             color=[0.2, 0.8, 0.8])

        assert viewer.last_id == 3

        tubes = viewer.tubes(x=[0.5, -0.5, 1.5, 1.5],
                             y=[-2.0, 1.8, 1.8, 0.0],
                             z=[-1.5, -1.5, -1.5, -1.5],
                             color=[0.9, 0.2, 0.2],
                             radius=0.2,
                             resolution=15)

        assert viewer.last_id == 4

        assert viewer.drawable_collection.size() == 5

        assert viewer.get_drawable(0) is mesh
        assert viewer.get_drawable(1) is blocks
        assert viewer.get_drawable(2) is points
        assert viewer.get_drawable(3) is lines
        assert viewer.get_drawable(4) is tubes
Пример #10
0
    def test_init(self):
        viewer = IntegrableViewer()

        assert viewer.model
        assert viewer.post_collection
        assert viewer.pre_collection
        assert viewer.drawable_collection

        assert viewer.axis
        assert viewer.background

        assert len(viewer.controllers) > 0

        expected = [0.0, 0.0, 0.0]
        assert self.equal_list(expected, viewer.rotation_angle)
        assert self.equal_list(expected, viewer.rotation_center)

        expected = [0.0, 0.0, 200.0]
        assert self.equal_list(expected, viewer.camera_position)

        assert viewer.fov == 45.0
        assert viewer.smoothness == 2.0
        assert viewer.current_projection == 'Perspective'

        assert viewer.last_id == -1
        assert viewer.last_drawable is None
Пример #11
0
    def test_controller_modes(self):
        viewer = IntegrableViewer()
        assert type(viewer.current_controller) is NormalController

        viewer.set_slice_controller()
        assert type(viewer.current_controller) is SliceController

        viewer.set_detection_controller()
        assert type(viewer.current_controller) is DetectionController

        viewer.set_normal_controller()
        assert type(viewer.current_controller) is NormalController
Пример #12
0
    def test_ray_from_click(self):
        viewer = IntegrableViewer()
        viewer.resize(800, 600)

        # Perspective: Ray deviates when click is not at center
        expected = [0.0, 0.0, -1.0]
        ray = viewer.ray_from_click(400, 300, 0)
        assert self.equal_list(expected, ray)

        ray = viewer.ray_from_click(100, 100, 0)
        assert not self.equal_list(expected, ray)

        # Orthographic: Ray always has the same direction
        viewer.orthographic_projection()
        ray = viewer.ray_from_click(400, 300, 0)
        assert self.equal_list(expected, ray)

        ray = viewer.ray_from_click(100, 100, 0)
        assert self.equal_list(expected, ray)
Пример #13
0
    def test_turbo_rendering(self):
        viewer = IntegrableViewer()
        viewer.mesh(x=[-1, 1, 0],
                    y=[0, 0, 1],
                    z=[0, 0, 0],
                    indices=[[0, 1, 2]])

        assert not viewer.last_drawable.is_boostable
        viewer.set_turbo_rendering(True)
        assert viewer.last_drawable.is_boostable

        viewer.set_turbo_rendering(False)
        assert not viewer.last_drawable.is_boostable
Пример #14
0
    def test_origin_from_click(self):
        viewer = IntegrableViewer()
        viewer.resize(800, 600)

        # Perspective: The origin doesn't change, only the ray
        expected = [0.0, 0.0, 0.0]
        origin = viewer.origin_from_click(100, 100, 0)
        assert self.equal_list(expected, origin)

        # Orthographic: The ray doesn't change, but the origin does
        viewer.orthographic_projection()
        origin = viewer.origin_from_click(100, 100, 0)
        assert not self.equal_list(expected, origin)
Пример #15
0
    def test_update_drawable(self):
        viewer = IntegrableViewer()
        mesh = viewer.mesh(x=[-1, 1, 0],
                           y=[0, 0, 1],
                           z=[0, 0, 0],
                           indices=[[0, 1, 2]])
        viewer.update_drawable(mesh.id)
        viewer.update_all()

        assert mesh
Пример #16
0
 def test_projections(self):
     viewer = IntegrableViewer()
     assert viewer.current_projection == 'Perspective'
     viewer.orthographic_projection()
     assert viewer.current_projection == 'Orthographic'
     viewer.perspective_projection()
     assert viewer.current_projection == 'Perspective'
Пример #17
0
    def test_resize_gl(self):
        viewer = IntegrableViewer()

        expected = viewer.proj_matrix.data()
        assert self.equal_list(expected, viewer.proj_matrix.data())

        viewer.resizeGL(10, 10)
        perspective = viewer.proj_matrix.data()
        assert not self.equal_list(expected, perspective)

        viewer.orthographic_projection()
        viewer.resizeGL(10, 10)
        orthographic = viewer.proj_matrix.data()

        assert not self.equal_list(expected, orthographic)
        assert not self.equal_list(perspective, orthographic)
Пример #18
0
    def test_angles_from_vectors(self):
        viewer = IntegrableViewer()

        # Make the normal face the camera
        default = [0.0, 0.0, 0.0]
        expected = [-90.0, 0.0, -90.0]

        normal = [1.0, 0.0, 0.0]
        up = [0.0, 0.0, 1.0]
        angles = viewer.angles_from_vectors(normal, up)
        assert self.equal_list(expected, angles)

        assert self.equal_list(default, viewer.get_rotation_angle())
        viewer.set_camera_from_vectors(normal, up)
        assert self.equal_list(expected, viewer.get_rotation_angle())
Пример #19
0
    def test_plan_north_east_view(self):
        viewer = IntegrableViewer()

        # Default
        expected = [0.0, 0.0, 0.0]
        assert self.equal_list(expected, viewer.rotation_angle)

        # Plan
        viewer.plan_view()
        expected = [0.0, 0.0, 0.0]
        assert self.equal_list(expected, viewer.rotation_angle)

        # North
        viewer.north_view()
        expected = [270.0, 0.0, 270.0]
        assert self.equal_list(expected, viewer.rotation_angle)

        # East
        viewer.east_view()
        expected = [270.0, 0.0, 0.0]
        assert self.equal_list(expected, viewer.rotation_angle)
Пример #20
0
    def test_load_multiple(self):
        viewer = IntegrableViewer()
        path = f'{TEST_FILES_FOLDER_PATH}/caseron.dxf'
        path_list = 3 * [path]

        meshes = viewer.load_multiple([], viewer.load_mesh)
        assert len(meshes) == 0
        assert len(viewer.get_all_ids()) == 0

        meshes = viewer.load_multiple(path_list, viewer.load_mesh)
        assert len(path_list) == len(meshes)
        assert len(viewer.get_all_ids()) == len(path_list)

        for mesh in meshes:
            assert type(mesh) is MeshGL
Пример #21
0
    def test_load_folder(self):
        viewer = IntegrableViewer()
        successes = []
        failures = []

        successes += viewer.load_mesh_folder(f'{TEST_FILES_FOLDER_PATH}')
        assert len(successes) > 0
        failures += viewer.load_blocks_folder(
            f'{TEST_FILES_FOLDER_PATH}/../blastsight')
        assert len(failures) == 0
        failures += viewer.load_points_folder(
            f'{TEST_FILES_FOLDER_PATH}/../blastsight')
        assert len(failures) == 0
        failures += viewer.load_lines_folder(
            f'{TEST_FILES_FOLDER_PATH}/../blastsight')
        assert len(failures) == 0
        failures += viewer.load_tubes_folder(
            f'{TEST_FILES_FOLDER_PATH}/../blastsight')
        assert len(failures) == 0

        assert viewer.drawable_collection.size() == len(successes) > 0
        assert viewer.drawable_collection.size(
        ) == len(failures) + len(successes)
Пример #22
0
    def test_get_normal(self):
        viewer = IntegrableViewer()

        # Auto-generates a normal from 2 rays and 2 origins
        normal = viewer.get_normal(origin_list=[[0.0, 0.0, 0.0],
                                                [100.0, 0.0, 0.0]],
                                   ray_list=[[-0.5, 0.0, -0.7],
                                             [+0.5, 0.0, -0.7]])

        # Perspective: We only need the rays
        expected = [0.0, -1.0, 0.0]
        assert self.equal_list(expected, normal)

        # Orthographic: A origin is needed to make differences between the rays
        viewer.orthographic_projection()
        normal = viewer.get_normal(origin_list=[[0.0, 100.0, 0.0],
                                                [100.0, 0.0, 0.0]],
                                   ray_list=[[-0.5, 0.0, -0.7],
                                             [+0.5, 0.0, -0.7]])

        assert not self.equal_list(expected, normal)
Пример #23
0
    def test_camera_position(self):
        viewer = IntegrableViewer()

        # Translate camera
        translation = [5.0, 10.0, 15.0]

        assert self.equal_list([0.0, 0.0, 200.0], viewer.get_camera_position())
        viewer.translate(*translation)
        assert self.equal_list([5.0, 10.0, 215.0],
                               viewer.get_camera_position())
        viewer.translate(*translation)
        assert self.equal_list([10.0, 20.0, 230.0],
                               viewer.get_camera_position())

        viewer.set_camera_position(translation)
        assert self.equal_list(translation, viewer.get_camera_position())
Пример #24
0
    def test_add_wrong_elements(self):
        viewer = IntegrableViewer()

        assert viewer.mesh() is None
        assert viewer.blocks() is None
        assert viewer.points() is None
        assert viewer.lines() is None
        assert viewer.tubes() is None

        assert viewer.load_mesh('') is None
        assert viewer.load_blocks('') is None
        assert viewer.load_points('') is None
        assert viewer.load_lines('') is None
        assert viewer.load_tubes('') is None

        assert len(viewer.get_all_drawables()) == 0
Пример #25
0
    def test_drawable_visibility(self):
        viewer = IntegrableViewer()
        viewer.mesh(x=[-1, 1, 0],
                    y=[0, 0, 1],
                    z=[0, 0, 0],
                    indices=[[0, 1, 2]])
        viewer.blocks(x=[-1, 1, 0], y=[0, 0, 1], z=[0, 0, 0], values=[0, 1, 2])

        assert viewer.get_drawable(0).is_visible
        assert viewer.get_drawable(1).is_visible

        viewer.hide_drawable(1)

        assert viewer.get_drawable(0).is_visible
        assert not viewer.get_drawable(1).is_visible

        viewer.hide_drawable(0)
        viewer.show_drawable(1)

        assert not viewer.get_drawable(0).is_visible
        assert viewer.get_drawable(1).is_visible

        viewer.show_drawable(0)
        viewer.show_drawable(1)

        assert viewer.get_drawable(0).is_visible
        assert viewer.get_drawable(1).is_visible
Пример #26
0
    def test_delete_drawable(self):
        viewer = IntegrableViewer()
        viewer.mesh(x=[-1, 1, 0],
                    y=[0, 0, 1],
                    z=[0, 0, 0],
                    indices=[[0, 1, 2]])
        viewer.blocks(x=[-1, 1, 0], y=[0, 0, 1], z=[0, 0, 0], values=[0, 1, 2])

        assert viewer.drawable_collection.size() == 2

        viewer.delete(-1)
        assert viewer.drawable_collection.size() == 2

        viewer.delete(0)
        assert viewer.drawable_collection.size() == 1

        with pytest.raises(Exception):
            viewer.delete(0)

        viewer.delete(1)
        assert viewer.drawable_collection.size() == 0
Пример #27
0
    def test_export(self):
        viewer = IntegrableViewer()

        mesh = viewer.load_mesh(path=f'{TEST_FILES_FOLDER_PATH}/caseron.off')
        blocks = viewer.load_blocks(path=f'{TEST_FILES_FOLDER_PATH}/mini.csv')

        viewer.export_element(
            f'{TEST_FILES_FOLDER_PATH}/caseron_model_export.h5m', mesh.id)
        viewer.export_element(
            f'{TEST_FILES_FOLDER_PATH}/mini_model_export_blocks.h5p',
            blocks.id)
        viewer.export_element(
            f'{TEST_FILES_FOLDER_PATH}/mini_model_export_points.h5p',
            blocks.id)
        viewer.export_element(
            f'{TEST_FILES_FOLDER_PATH}/mini_model_export_lines.h5p', blocks.id)
        viewer.export_element(
            f'{TEST_FILES_FOLDER_PATH}/mini_model_export_tubes.h5p', blocks.id)

        # Failure deliberate
        viewer.export_element('a.asdf', -1)

        # Cleanup
        os.remove(f'{TEST_FILES_FOLDER_PATH}/caseron_model_export.h5m')
        os.remove(f'{TEST_FILES_FOLDER_PATH}/mini_model_export_blocks.h5p')
        os.remove(f'{TEST_FILES_FOLDER_PATH}/mini_model_export_points.h5p')
        os.remove(f'{TEST_FILES_FOLDER_PATH}/mini_model_export_lines.h5p')
        os.remove(f'{TEST_FILES_FOLDER_PATH}/mini_model_export_tubes.h5p')

        with pytest.raises(Exception):
            os.remove('a.asdf')
Пример #28
0
    def test_camera_rotation(self):
        viewer = IntegrableViewer()

        # Rotate camera
        rotation = [90.0, 10.0, 45.0]

        assert self.equal_list([0.0, 0.0, 0.0], viewer.get_rotation_angle())
        viewer.rotate(*rotation)
        assert self.equal_list([90.0, 10.0, 45.0], viewer.get_rotation_angle())
        viewer.rotate(*rotation)
        assert self.equal_list([180.0, 20.0, 90.0],
                               viewer.get_rotation_angle())

        viewer.set_rotation_angle(rotation)
        assert self.equal_list(rotation, viewer.get_rotation_angle())
Пример #29
0
from blastsight.view.integrableviewer import IntegrableViewer
"""
In this demo, we'll show how you can embed BlastSight in
an PyQt5/PySide2 application.
"""

if __name__ == '__main__':
    app = QApplication(sys.argv)
    central_widget = QWidget()
    central_widget.setWindowTitle(
        'Embedding BlastSight in a PyQt5/PySide2 Application')
    layout = QGridLayout(central_widget)
    """
    IntegrableViewer inherits from QOpenGLWidget, so you can insert it as any QWidget.
    """
    viewer = IntegrableViewer(central_widget)
    viewer.setSizePolicy(QSizePolicy.MinimumExpanding,
                         QSizePolicy.MinimumExpanding)

    label_list = []
    for i in range(3):
        for j in range(3):
            if i == j == 1:
                continue

            label = QLabel(central_widget)
            label.setText('Other QWidget at (%d, %d)' % (i, j))
            label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
            layout.addWidget(label, i, j)
            label_list.append(label)
Пример #30
0
    def test_fit_camera(self):
        viewer = IntegrableViewer()

        expected = [0.0, 0.0, 200.0]
        assert self.equal_list(expected, viewer.off_center)
        viewer.fit_to_screen()  # No drawables, no fit
        assert self.equal_list(expected, viewer.off_center)

        viewer.mesh(x=[-1, 1, 0],
                    y=[0, 0, 1],
                    z=[0, 0, 0],
                    indices=[[0, 1, 2]])

        viewer.fit_to_screen()  # One drawable, auto-fit
        assert not self.equal_list(expected, viewer.off_center)

        viewer.camera_position = expected
        viewer.camera_at(viewer.last_id)
        viewer.current_projection = 'orthographic'

        viewer.fit_to_bounds(*viewer.last_drawable.element.bounding_box)
        assert not self.equal_list(expected, viewer.off_center)