def roll(**kwargs): """ Roll :param cursor: the 3d world coordinate of a cursor, like [1,1,2], you should pass it like `'1,1,2'` :param width: width of viewport :param height: height of viewport :param focus_view: current focused view, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal :param display_view: need to displayed on screen, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal, 'all' for all view :return: rgb image data """ try: cursor = kwargs['cursor'].split(',') cursor = [float(cursor[0]), float(cursor[1]), float(cursor[2])] width = int(kwargs['width']) height = int(kwargs['height']) focus_view = get_view_index(kwargs['focus_view']) display_view = get_view_index(kwargs['display_view']) except Exception as err: return response(success=False, message=err.message) server.set_cursor(cursor) imgs = server.get_images(display_view, width, height) return response(json.dumps(imgs))
def rotate(**kwargs): """ Rotate :param pos_pre: :param pos_cur: :param focus_view: current focused view, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal :return: rgb image data """ try: pos_pre = string_int_trans(kwargs['pos_pre'].split(','), 's2i') pos_cur = string_int_trans(kwargs['pos_cur'].split(','), 's2i') focus_view = get_view_index(kwargs['focus_view']) log.dev_info("=== enter rotate ===") except Exception as err: return response(success=False, message=err.message) try: views = imageentity.get_children_views() size = views[focus_view].get_scene().get_display_size() angle = cal_angle(size, pos_pre, pos_cur) imageentity.rotate(focus_view, angle) imageentity.updater().update(RefreshType.All) result = imageentity.updater().get_result() return response(json.dumps(result)) except Exception as e: return response(success=False, message='rotate failed')
def get_multi_images(self, display_view_array): data = {} for display_view in display_view_array: width, height = self.view_size[display_view] display_view = get_view_index(display_view) img = self.get_images(display_view, width, height) data.update(img) return data
def color(**kwargs): """ Pseudo-color :param colormode: 0 for grayscale, 1 for red, 2 for green, 3 for blue, 4 for jet color, 5 for color config :param width: width of viewport :param height: height of viewport :param focus_view: current focused view, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal :param display_view: need to displayed on screen, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal, 'all' for all view :return: rgb image data """ try: colormode = int(kwargs['colormode']) width = int(kwargs['width']) height = int(kwargs['height']) focus_view = get_view_index(kwargs['focus_view']) display_view = get_view_index(kwargs['display_view']) except Exception as err: return response(success=False, message=err.message) server.set_colormode(colormode) imgs = server.get_images(display_view, width, height) return response(json.dumps(imgs))
def get_point2d(**kwargs): try: index = get_view_index('transverse') view = imageentity.get_children_views()[index] scene = view.get_scene() vol = scene.volume contour = kwargs['contour'] cps = [] for cp in contour: cp = vol.voxel_to_world(cp) pt2d = translate_from_world_to_screen(scene, cp) cps.append(pt2d.tolist()) return response(json.dumps({'contour': cps})) except Exception as e: log.dev_info('---------------->', e.message) return response(success=False, message=e.message)
def locate(**kwargs): try: focus_view = get_view_index(kwargs['focus_view']) cursor_2D = kwargs['cross_point'].split(",") except Exception as err: return response(success=False, message=err.message) try: success, msg = imageentity.locate(focus_view, cursor_2D) if not success: return response(success=False, message=msg) imageentity.updater().update(RefreshType.All) result = imageentity.updater().get_result() result = view_filter(result, focus_view) return response(json.dumps(result)) except Exception as e: return response(success=False, message=e.message)
def get_point3d(**kwargs): try: index = get_view_index('transverse') contours = kwargs['contours'] view = imageentity.get_children_views()[index] scene = view.get_scene() vol = scene.volume cps_list = {'contours': []} for contour in contours: cps = [] for cp in contour: pt3d = translate_from_screen_to_world(scene, [cp['x'], cp['y']]) pt3d = vol.world_to_voxel(pt3d) cps.append([int(pt3d[0]), int(pt3d[1]), int(pt3d[2])]) cps_list['contours'].append(cps) return response(json.dumps(cps_list)) except Exception as e: log.dev_info('---------------->', e.message) return response(success=False, message=e.message)
def zoom(**kwargs): """ zoom :param kwargs: :return: """ try: zoom_factor = kwargs['zoom_factor'] focus_view = get_view_index(kwargs['focus_view']) except Exception as err: return response(success=False, message=err.message) try: zoom_factor = float(zoom_factor) imageentity.zoom(focus_view, zoom_factor) imageentity.updater().update(RefreshType.All) result = imageentity.updater().get_result() return response(json.dumps(result)) except Exception as e: return response(success=False, message='zoom failed')
def page(**kwargs): """ Page turning :param delta: cursor delta :param focus_view: current focused view, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal :return: png base64 image data """ try: delta = int(kwargs['delta']) focus_view = get_view_index(kwargs['focus_view']) except Exception as err: return response(success=False, message=err.message) imageentity.page(focus_view, delta) imageentity.updater().update(RefreshType.All) result = imageentity.updater().get_result() filter_view = get_page_filter_view(focus_view) result = view_filter(result, filter_view) return response(json.dumps(result))
def pan(**kwargs): """ Pan :param pos_pre: :param pos_cur: :param focus_view: current focused view, 'transverse' for transverse, 'saggital' for saggital, 'coronal' for coronal :return: rgb image data """ try: pos_pre = string_int_trans(kwargs['pos_pre'].split(','), 's2i') pos_cur = string_int_trans(kwargs['pos_cur'].split(','), 's2i') focus_view = get_view_index(kwargs['focus_view']) except Exception as err: return response(success=False, message=err.message) try: imageentity.pan(focus_view, pos_pre, pos_cur) imageentity.updater().update(RefreshType.All) result = imageentity.updater().get_result() return response(json.dumps(result)) except Exception as e: return response(success=False, message='pan failed')