def handleEditorRightClick(self, position5d, win_coord):
        debug = ilastik_config.getboolean("ilastik", "debug")

        obj, time = self.get_object(position5d)
        if obj == 0:
            menu = TitledMenu(["Background"])
            if debug:
                menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear")))
            menu.exec_(win_coord)
            return
        
        # Get color and track from hypotheses graph (which is a slot in the new operator)
        # TODO: Remove pgmlink section after old operator is phased out
        if WITH_HYTRA:
            hypothesesGraph = self.mainOperator.HypothesesGraph.value
    
            if hypothesesGraph == None:
                color = None
                track = None
            else:
                color = hypothesesGraph.getLineageId(time, obj)
                track = hypothesesGraph.getTrackId(time, obj)
        else:
            try:
                extra = self.mainOperator.extra_track_ids
            except (IndexError, KeyError):
                extra = {}
    
            # if this is a resolved merger, find which of the merged IDs we actually clicked on
            if time in extra and obj in extra[time]:
                colors = [self.mainOperator.label2color[time][t] for t in extra[time][obj]]
                tracks = [self.mainOperator.track_id[time][t] for t in extra[time][obj]]
                selected_track = self.get_color(position5d)
                idx = colors.index(selected_track)
                color = colors[idx]
                track = tracks[idx]
            else:
                try:
                    color = self.mainOperator.label2color[time][obj]
                    track = [self.mainOperator.track_id[time][obj]][0]
                except (IndexError, KeyError):
                    color = None
                    track = []

        children = None 
        parents = None

        menu = TitledMenu([
            "Object {} of lineage id {}".format(obj, color),
            "Track id: " + (str(track) or "None"),
        ])

        if not debug:
            menu.exec_(win_coord)
            return

        if any(IPCFacade().sending):

            obj_sub_menu = menu.addMenu("Hilite Object")
            for mode in Protocol.ValidHiliteModes:
                where = Protocol.simple("and", ilastik_id=obj, time=time)
                cmd = Protocol.cmd(mode, where)
                obj_sub_menu.addAction(mode.capitalize(), IPCFacade().broadcast(cmd))

            sub_menus = [
                ("Tracks", Protocol.simple_in, tracks),
                ("Parents", Protocol.simple_in, parents),
                ("Children", Protocol.simple_in, children)
            ]
            for name, protocol, args in sub_menus:
                if args:
                    sub = menu.addMenu("Hilite {}".format(name))
                    for mode in Protocol.ValidHiliteModes[:-1]:
                        mode = mode.capitalize()
                        where = protocol("track_id*", args)
                        cmd = Protocol.cmd(mode, where)
                        sub.addAction(mode, IPCFacade().broadcast(cmd))
                else:
                    sub = menu.addAction("Hilite {}".format(name))
                    sub.setEnabled(False)

            menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear")))
        else:
            menu.addAction("Open IPC Server Window", IPCFacade().show_info)
            menu.addAction("Start IPC Server", IPCFacade().start)

        menu.exec_(win_coord)
Example #2
0
    def handleEditorRightClick(self, position5d, globalWindowCoordinate):
        layer = self.getLayer('Labels')
        obj = self._getObject(layer.segmentationImageSlot, position5d)
        if obj == 0:
            return

        menu = QMenu(self)
        text = "Print info for object {} in the terminal".format(obj)
        menu.addAction(text)

        # IPC stuff
        if ilastik_config.getboolean("ilastik", "debug"):
            menu.addSeparator()
            if any(IPCFacade().sending):
                time = position5d[0]

                sub = menu.addMenu("Hilite Object")
                for mode in Protocol.ValidHiliteModes[:-1]:
                    where = Protocol.simple("and", time=time, ilastik_id=obj)
                    cmd = Protocol.cmd(mode, where)
                    sub.addAction(mode.capitalize(),
                                  IPCFacade().broadcast(cmd))
                menu.addAction("Clear Hilite",
                               IPCFacade().broadcast(Protocol.cmd("clear")))
            else:
                menu.addAction("Open IPC Server Window", IPCFacade().show_info)
                menu.addAction("Start All IPC Servers", IPCFacade().start)

        menu.addSeparator()
        clearlabel = "Clear label for object {}".format(obj)
        menu.addAction(clearlabel)
        numLabels = self.labelListData.rowCount()
        label_actions = []
        for l in range(numLabels):
            color_icon = self.labelListData.createIconForLabel(l)
            act_text = 'Label object {} as "{}"'.format(
                obj, self.labelListData[l].name)
            act = QAction(color_icon, act_text, menu)
            act.setIconVisibleInMenu(True)
            label_actions.append(act_text)
            menu.addAction(act)

        action = menu.exec_(globalWindowCoordinate)
        if action is None:
            return
        if action.text() == text:
            numpy.set_printoptions(precision=4)
            print(
                "------------------------------------------------------------")
            print("object:         {}".format(obj))

            t = position5d[0]
            labels = self.op.LabelInputs([t]).wait()[t]
            if len(labels) > obj:
                label = int(labels[obj])
            else:
                label = "none"
            print("label:          {}".format(label))

            print('features:')
            feats = self.op.ObjectFeatures([t]).wait()[t]
            selected = self.op.SelectedFeatures([]).wait()
            for plugin in sorted(feats.keys()):
                if plugin == default_features_key or plugin not in selected:
                    continue
                print("Feature category: {}".format(plugin))
                for featname in sorted(feats[plugin].keys()):
                    if featname not in selected[plugin]:
                        continue
                    value = feats[plugin][featname]
                    ft = numpy.asarray(value.squeeze())[obj]
                    print("{}: {}".format(featname, ft))

            if len(selected) > 0:
                pred = 'none'
                if self.op.Predictions.ready():
                    preds = self.op.Predictions([t]).wait()[t]
                    if len(preds) >= obj:
                        pred = int(preds[obj])

                prob = 'none'
                if self.op.Probabilities.ready():
                    probs = self.op.Probabilities([t]).wait()[t]
                    if len(probs) >= obj:
                        prob = probs[obj]

                print("probabilities:  {}".format(prob))
                print("prediction:     {}".format(pred))

                uncertainty = 'none'
                if self.op.UncertaintyEstimate.ready():
                    uncertainties = self.op.UncertaintyEstimate([t]).wait()[t]
                    if len(uncertainties) >= obj:
                        uncertainty = uncertainties[obj]

                print("uncertainty:    {}".format(uncertainty))

            print(
                "------------------------------------------------------------")
        elif action.text() == clearlabel:
            topLevelOp = self.topLevelOperatorView.viewed_operator()
            imageIndex = topLevelOp.LabelInputs.index(
                self.topLevelOperatorView.LabelInputs)
            self.topLevelOperatorView.assignObjectLabel(
                imageIndex, position5d, 0)

        #todo: remove old
        elif self.applet.connected_to_knime:
            if action.text() == knime_hilite:
                data = {'command': 0, 'objectid': 'Row' + str(obj)}
                self.applet.sendMessageToServer('knime', data)
            elif action.text() == knime_unhilite:
                data = {'command': 1, 'objectid': 'Row' + str(obj)}
                self.applet.sendMessageToServer('knime', data)
            elif action.text() == knime_clearhilite:
                data = {'command': 2}
                self.applet.sendMessageToServer('knime', data)

        else:
            try:
                label = label_actions.index(action.text())
            except ValueError:
                return
            topLevelOp = self.topLevelOperatorView.viewed_operator()
            imageIndex = topLevelOp.LabelInputs.index(
                self.topLevelOperatorView.LabelInputs)
            self.topLevelOperatorView.assignObjectLabel(
                imageIndex, position5d, label + 1)
    def handleEditorRightClick(self, position5d, win_coord):
        debug = ilastik_config.getboolean("ilastik", "debug")

        obj, time = self.get_object(position5d)
        if obj == 0:
            menu = TitledMenu(["Background"])
            if debug:
                menu.addAction("Clear Hilite",
                               IPCFacade().broadcast(Protocol.cmd("clear")))
            menu.exec_(win_coord)
            return

        try:
            color = self.mainOperator.label2color[time][obj]
            tracks = [self.mainOperator.track_id[time][obj]]
            extra = self.mainOperator.extra_track_ids
        except (IndexError, KeyError):
            color = None
            tracks = []
            extra = {}

        if time in extra and obj in extra[time]:
            tracks.extend(extra[time][obj])
        if tracks:
            children, parents = self.mainOperator.track_family(tracks[0])
        else:
            children, parents = None, None

        menu = TitledMenu([
            "Object {} of lineage id {}".format(obj, color),
            "Track ids: " + (", ".join(map(str, set(tracks))) or "None"),
        ])

        if not debug:
            menu.exec_(win_coord)
            return

        if any(IPCFacade().sending):

            obj_sub_menu = menu.addMenu("Hilite Object")
            for mode in Protocol.ValidHiliteModes:
                where = Protocol.simple("and", ilastik_id=obj, time=time)
                cmd = Protocol.cmd(mode, where)
                obj_sub_menu.addAction(mode.capitalize(),
                                       IPCFacade().broadcast(cmd))

            sub_menus = [("Tracks", Protocol.simple_in, tracks),
                         ("Parents", Protocol.simple_in, parents),
                         ("Children", Protocol.simple_in, children)]
            for name, protocol, args in sub_menus:
                if args:
                    sub = menu.addMenu("Hilite {}".format(name))
                    for mode in Protocol.ValidHiliteModes[:-1]:
                        mode = mode.capitalize()
                        where = protocol("track_id*", args)
                        cmd = Protocol.cmd(mode, where)
                        sub.addAction(mode, IPCFacade().broadcast(cmd))
                else:
                    sub = menu.addAction("Hilite {}".format(name))
                    sub.setEnabled(False)

            menu.addAction("Clear Hilite",
                           IPCFacade().broadcast(Protocol.cmd("clear")))
        else:
            menu.addAction("Open IPC Server Window", IPCFacade().show_info)
            menu.addAction("Start IPC Server", IPCFacade().start)

        menu.exec_(win_coord)
Example #4
0
    def handleEditorRightClick(self, position5d, win_coord):
        debug = ilastik_config.getboolean("ilastik", "debug")

        obj, time = self.get_object(position5d)
        if obj == 0:
            menu = TitledMenu(["Background"])
            if debug:
                menu.addAction("Clear Hilite",
                               IPCFacade().broadcast(Protocol.cmd("clear")))
            menu.exec_(win_coord)
            return

        hypothesesGraph = self.mainOperator.HypothesesGraph.value

        if hypothesesGraph == None:
            color = None
            track = None
        else:
            color = hypothesesGraph.getLineageId(time, obj)
            track = hypothesesGraph.getTrackId(time, obj)

        children = None
        parents = None

        menu = TitledMenu([
            "Object {} of lineage id {}".format(obj, color),
            "Track id: " + (str(track) or "None"),
        ])

        if not debug:
            menu.exec_(win_coord)
            return

        if any(IPCFacade().sending):

            obj_sub_menu = menu.addMenu("Hilite Object")
            for mode in Protocol.ValidHiliteModes:
                where = Protocol.simple("and", ilastik_id=obj, time=time)
                cmd = Protocol.cmd(mode, where)
                obj_sub_menu.addAction(mode.capitalize(),
                                       IPCFacade().broadcast(cmd))

            sub_menus = [("Tracks", Protocol.simple_in, tracks),
                         ("Parents", Protocol.simple_in, parents),
                         ("Children", Protocol.simple_in, children)]
            for name, protocol, args in sub_menus:
                if args:
                    sub = menu.addMenu("Hilite {}".format(name))
                    for mode in Protocol.ValidHiliteModes[:-1]:
                        mode = mode.capitalize()
                        where = protocol("track_id*", args)
                        cmd = Protocol.cmd(mode, where)
                        sub.addAction(mode, IPCFacade().broadcast(cmd))
                else:
                    sub = menu.addAction("Hilite {}".format(name))
                    sub.setEnabled(False)

            menu.addAction("Clear Hilite",
                           IPCFacade().broadcast(Protocol.cmd("clear")))
        else:
            menu.addAction("Open IPC Server Window", IPCFacade().show_info)
            menu.addAction("Start IPC Server", IPCFacade().start)

        menu.exec_(win_coord)
Example #5
0
def handshake(_, protocol, name, **address):
    from ilastik.shell.gui.ipcManager import IPCFacade
    if "host" in address and "port" in address:
        address = (address["host"], address["port"])
    IPCFacade().handshake(protocol, name, address)