def main():
    print('main()')

    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    main_controller = MainController(app)
    context = engine.rootContext()
    context.setContextProperty("main", main_controller)
    script_directory = os.path.dirname(os.path.abspath(__file__))
    engine.load(os.path.join(script_directory, 'qml/main.qml'))

    # hook into SIGINT signal to shutdown the application when commanded
    def sig_int_handler(signal, frame):
        logger.info('SIGINT received')
        main_controller.shutdown()
    signal.signal(signal.SIGINT, sig_int_handler)

    # Python cannot handle signals while the Qt event loop is running
    # So we'll let the python interpreter run periodically so any
    # SIGINT signals can be processed
    timer = QTimer()
    timer.start(500)  # You may change this if you wish.
    timer.timeout.connect(lambda: None)

    main_controller.start()

    sys.exit(app.exec_())
Example #2
0
    def volume_render(self, min_depth, max_depth, is_bronchioles_mode, is_no_contrast_mode, is_advanced_mode):
        if min_depth >= max_depth:
            MainController.display_message_box(QMessageBox.Warning, "Error",
                                               "Minimal depth must be less then maximal depth.")
            return

        if self._model._images_directory == '':
            MainController.display_message_box(QMessageBox.Warning, "Error", "Load images first.")
            return

        if is_advanced_mode:
            mlab.options.backend = 'envisage'
        else:
            mlab.options.backend = 'auto'
        mlab.figure('Volume render')

        images = np.zeros(shape=(len(self._model._images), 512, 512), dtype="float32")
        for index in range(0, len(self._model.images)):
            img = image.load_img(os.path.join(self._model._images_directory, self._model.images[index].name),
                                 target_size=(512, 512), color_mode='grayscale')
            images[index] = img

        s = images[:, min_depth:max_depth, :]
        s = s[:, :, ::-1]
        vol = mlab.pipeline.volume(mlab.pipeline.scalar_field(s))

        otf = PiecewiseFunction()
        if is_bronchioles_mode and not is_no_contrast_mode:
            otf.add_point(0, 0.0)
            otf.add_point(99, 0.0)
            otf.add_point(100, 0.1)
            otf.add_point(190, 0.1)
            otf.add_point(191, 0.0)
            otf.add_point(255, 0)
        elif not is_no_contrast_mode:
            otf.add_point(0, 0.0)
            otf.add_point(139, 0.0)
            otf.add_point(140, 0.1)
            otf.add_point(200, 0.1)
            otf.add_point(255, 1)
        elif is_bronchioles_mode:
            otf.add_point(0, 0.0)
            otf.add_point(1, 0.2)
            otf.add_point(30, 0.2)
            otf.add_point(30, 0.0)
            otf.add_point(255, 0.0)
        else:
            otf.add_point(0, 0.0)
            otf.add_point(1, 0.1)
            otf.add_point(50, 1.0)

        vol._otf = otf
        vol._volume_property.set_scalar_opacity(otf)

        mlab.show()
Example #3
0
    def slice_render(self, axis):
        if self._model._images_directory == '':
            MainController.display_message_box(QMessageBox.Warning, "Error", "Load images first.")
            return
        images = np.zeros(shape=(len(self._model._images), 512, 512), dtype="float32")
        for index in range(0, len(self._model.images)):
            img = image.load_img(os.path.join(self._model._images_directory, self._model.images[index].name),
                                 target_size=(512, 512), color_mode='grayscale')
            images[index] = img

        mlab.figure('Slice render')
        volume_slice(images, plane_orientation= axis + '_axes', colormap='black-white')

        mlab.options.backend = 'auto'
        mlab.show()
def main():
    print('main()')

    qmlRegisterType(MatplotlibController, "Matplot", 1, 0, "Matplot")

    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    main_controller = MainController(app)
    context = engine.rootContext()
    context.setContextProperty("main", main_controller)
    script_directory = os.path.dirname(os.path.abspath(__file__))
    engine.load(os.path.join(script_directory, 'qml/main.qml'))

    main_controller.start()

    sys.exit(app.exec_())
Example #5
0
 def __init__(self, sys_argv):
     super(App, self).__init__(sys_argv)
     self.model = Model()
     self.main_controller = MainController(self.model)
     self.volume_render_controller = RenderController(self.model)
     self.main_view = MainView(self.model, self.main_controller,
                               self.volume_render_controller)
     self.main_view.show()
Example #6
0
def main():
    init_db()
    MainController()
Example #7
0
    return response


def load_modules():
    print("Loading modules...")

    modules = {
        "keyboard": {
            "template": "keyboard.html",
            "instance": KeyboardModule(socketio)
        },
        "tv": {  # Monitor
            "template": "monitor.html",
            "instance": MonitorModule(socketio)
        }
    }

    return modules


modules = load_modules()
print(f"Modules loaded: {modules.keys()}")

app.add_url_rule("/main",
                 view_func=MainController.as_view("main", modules=modules))
app.add_url_rule("/detect",
                 view_func=DetectionController.as_view("detection",
                                                       modules=modules))

if __name__ == "__main__":
    socketio.run(app, host="0.0.0.0", debug=True)
Example #8
0
def main():
    return MainController().index()