def image_view_cache_load(self, il): key = id(il) if key not in self.image_view_cache: iv = ImageView(il) iv.initGL(self.gls) self.image_view_cache[key] = iv return self.image_view_cache[key]
def image_view_cache_load(self, il: 'ImageLayer') -> ImageView: key = id(il) if key not in self.image_view_cache: iv = ImageView(il) iv.initGL(self.gls) self.image_view_cache[key] = iv return self.image_view_cache[key]
def get_iv(self, il): if il is self.iv.il: return self.iv if il not in self.iv_cache: iv = ImageView(il) iv.initGL(self.gls) self.iv_cache[il] = iv return self.iv_cache[il]
def get_imageview(self, il: ImageLayer) -> None: """For an imagelayer, return an ImageView that can draw it""" if il is self.iv.il: return self.iv if il not in self.iv_cache: iv = ImageView(il) iv.initGL(self.gls) self.iv_cache[il] = iv return self.iv_cache[il]
def __init__(self, vis_model, il, model): BaseViewWidget.__init__(self) self.il = il self.iv = ImageView(il) self.model = model self.vis_model = vis_model self.overlays = set() self.active_overlays = set() self.setFocusPolicy(QtCore.Qt.StrongFocus) self.viewState.transform = scale(0.80) self.originView = OriginView() self.text_batch = TextBatcher(self.gls.text)
def __init__(self, vis_model: VisibilityModelRoot, il: ImageLayer, model) -> None: BaseViewWidget.__init__(self) self.il = il self.iv = ImageView(il) self.model = model self.vis_model = vis_model self.overlays: Set[OverlayProtocol] = set() self.active_overlays: Set[OverlayProtocol] = set() self.setFocusPolicy(QtCore.Qt.StrongFocus) self.viewState.set_scale(0.80) self.originView = OriginView() self.text_batch = TextBatcher(self.gls.text)
class AlignmentViewWidget(BaseViewWidget): def __init__(self, vis_model, il, model): BaseViewWidget.__init__(self) self.il = il self.iv = ImageView(il) self.model = model self.vis_model = vis_model self.overlays = set() self.active_overlays = set() self.setFocusPolicy(QtCore.Qt.StrongFocus) self.viewState.transform = scale(0.80) self.originView = OriginView() self.text_batch = TextBatcher(self.gls.text) def reinit(self): self.iv.initGL(self.gls) self.iv_cache = {} for ov in self.overlays: ov.initializeGL(self.gls) self.originView.initializeGL(self.gls) self.text_batch.initializeGL() def get_iv(self, il): if il is self.iv.il: return self.iv if il not in self.iv_cache: iv = ImageView(il) iv.initGL(self.gls) self.iv_cache[il] = iv return self.iv_cache[il] def get_flattened(self, n=None, l=None): if l is None: l = [] if n is None: n = self.vis_model for i in n.children: if hasattr(i, "_il_obj") and i.visible: l.append(i._il_obj) else: self.get_flattened(i, l) return l def render(self): self.text_batch.restart() GL.glEnable(GL.GL_BLEND) if self.model.align_by == ALIGN_BY_DIMENSIONS: if self.model.view_mode == VIEW_MODE_UNALIGNED: self.iv.mat = numpy.identity(3) else: self.iv.mat = self.model.ra.image_matrix else: if self.model.view_mode == VIEW_MODE_UNALIGNED: self.iv.mat = numpy.identity(3) else: self.iv.mat = self.model.kp.image_matrix # Render the base image if self.model.view_mode == VIEW_MODE_UNALIGNED: self.iv.render(self.viewState.glMatrix) else: # Draw all visible layers bottom to top all_ils = list(reversed(self.get_flattened())) for il in all_ils: iv = self.get_iv(il) iv.render(self.viewState.glMatrix) for ovl in self.active_overlays: ovl.render(self.viewState) self.text_batch.render() def keyPressEvent(self, evt): if self.interactionDelegate: self.interactionDelegate.keyPressEvent(evt) def focusNextPrevChild(self, next): found = False if self.interactionDelegate: found = self.interactionDelegate.next_prev_child(next) if not found: return super(AlignmentViewWidget, self).focusNextPrevChild(next) return True def focusOutEvent(self, evt): if self.interactionDelegate: self.interactionDelegate.focusOutEvent(evt)
class AlignmentViewWidget(BaseViewWidget): def __init__(self, vis_model: VisibilityModelRoot, il: ImageLayer, model) -> None: BaseViewWidget.__init__(self) self.il = il self.iv = ImageView(il) self.model = model self.vis_model = vis_model self.overlays: Set[OverlayProtocol] = set() self.active_overlays: Set[OverlayProtocol] = set() self.setFocusPolicy(QtCore.Qt.StrongFocus) self.viewState.set_scale(0.80) self.originView = OriginView() self.text_batch = TextBatcher(self.gls.text) def reinit(self) -> None: """Reinitialize self render state and subview render state""" self.iv.initGL(self.gls) self.iv_cache = {} for ov in self.overlays: ov.initializeGL(self.gls) self.originView.initializeGL(self.gls) self.text_batch.initializeGL() def get_imageview(self, il: ImageLayer) -> None: """For an imagelayer, return an ImageView that can draw it""" if il is self.iv.il: return self.iv if il not in self.iv_cache: iv = ImageView(il) iv.initGL(self.gls) self.iv_cache[il] = iv return self.iv_cache[il] def get_flattened(self, n: 'VisibilityNode' = None, l: List = None) -> List[Any]: if l is None: l = [] if n is None: n = self.vis_model for i in n.children: if i.visible == Visible.YES and i.obj is not None: l.append(i.obj) else: self.get_flattened(i, l) return l def render(self): self.text_batch.restart() GL.glEnable(GL.GL_BLEND) if self.model.align_by == AlignBy.Dimensions: if self.model.view_mode == ViewMode.UnAligned: self.iv.mat = numpy.identity(3) else: self.iv.mat = self.model.ra.image_matrix else: if self.model.view_mode == ViewMode.UnAligned: self.iv.mat = numpy.identity(3) else: self.iv.mat = self.model.kp.image_matrix # Render the base image if self.model.view_mode == ViewMode.UnAligned: self.iv.render(self.viewState.glMatrix) else: # Draw all visible layers bottom to top all_ils = list(reversed(self.get_flattened())) for il in all_ils: iv = self.get_imageview(il) iv.render(self.viewState.glMatrix) for ovl in self.active_overlays: ovl.render(self.viewState) self.text_batch.render() def focusNextPrevChild(self, next) -> bool: found = False if self.interactionDelegate: found = self.interactionDelegate.next_prev_child(next) if not found: return super(AlignmentViewWidget, self).focusNextPrevChild(next) return True def focusOutEvent(self, evt) -> None: if self.interactionDelegate: self.interactionDelegate.focusOutEvent(evt)