Exemple #1
0
    def buildOps(self, filename, win):
        # Check if the state contains a recipe as we can't continue without it since the order (graph) is unknown
        if not State.hasKey('/recipe'): return

        # Get the recipe and available ops
        recipe = State.getKey('/recipe')
        registeredOps = Registry.getRegisteredOps()

        # Go through the recipe in order
        for op in recipe:
            opName, opType = op

            # Look up the corresponding State data and check if the type corresponds to a registered Op
            opTypeKey = opName + '/type'
            if not State.hasKey(opName) or not State.hasKey(opTypeKey): return
            opType_state = State.getKey(opTypeKey)[1:]
            if opType_state not in registeredOps: continue

            # Get the Op from the registration factory and create the op (without duplicating the State entry)
            self._addOp(registeredOps[opType_state],
                        win,
                        initialiseState=False,
                        name=opName)

        self.interface.reset()
        self.cookOps(win, self.getFrame(), forceRecook=True)

        if win:
            win.updateGL()
            win.updateLayers()
Exemple #2
0
def add_image(img, shp=None):
    if shp is None: shp = get_predictor()['ref_shape']
    if not State.hasKey('/images') or not State.hasKey(
            '/shapes') or not State.hasKey('/labels'):
        State.setKey('/images', [])
        State.setKey('/shapes', [])
        State.setKey('/labels', [])
    fi = len(State.getKey('/images'))
    lbl = np.zeros(len(shp), dtype=np.int32)  # unlabelled
    set_frame_image(fi, img)
    set_frame_markup(fi, shp)
    set_frame_labels(fi, lbl)
    State.push('add image')
Exemple #3
0
	def updateFieldKey(self, key):
		#print 'updateFieldKey',key 
		if not State.hasKey(key): return # TODO maybe need to remove something from UI
		sel = State.getSel()
		if sel is None: return self.qfields.setKeyValue(key, State.getKey(key))
		s = '/%s/attrs/'%sel.strip('/')
		#print 'updateFieldKey',s,key
		if key.startswith(s): self.qfields.setKeyValue(key[len(s):], State.getKey(key))
Exemple #4
0
    def getAttr(self,
                attrName,
                defaultValue=None,
                location=None,
                onlyDirty=False):
        if location is None: location = self.name
        if not State.hasKey(location): return defaultValue
        op = State.getKey(location)
        if not op or 'attrs' not in op: return defaultValue

        attrs = op['attrs']
        if not attrName in attrs: return defaultValue
        if onlyDirty and not self.isDirty(attrName, location):
            return defaultValue

        return attrs[attrName]
Exemple #5
0
        State.setKey('/flip', flip)
        State.setKey('/vnames', vnames)
        shapes = State.getKey('/shapes')
        labels = State.getKey('/labels')
        shapes = list(np.float32(shapes)[:, subset])
        labels = list(np.int32(labels)[:, subset])
        State.setKey('/shapes', shapes)
        State.setKey('/labels', labels)

    img_vs = np.float32([[-1000, -1000, 0], [1000, -1000, 0], [1000, 1000, 0],
                         [-1000, 1000, 0]])
    img_fs = np.int32([[0, 1, 2, 3]])
    img_ts = np.float32([[1, 0, 0, 0], [0, 1, 0, 1000], [0, 0, 1, 0]])
    img_vts = np.float32([[0, 1], [1, 1], [1, 0], [0, 0]])

    if not State.hasKey('/edges') or not State.hasKey('/tris'):
        retriangulate()

    template_vs = get_predictor()['ref_shape'] * 100
    size = len(template_vs)
    markup_x2ds = np.zeros((size, 3), dtype=np.float32)
    ref_vs = np.zeros((size, 3), dtype=np.float32)
    ref_vs[:, :2] = template_vs

    markup_mesh = GLPoints3D(vertices=markup_x2ds,
                             edges=None,
                             names=[],
                             colour=[0, 1, 0, 1],
                             edgeColour=[1, 1, 1, 1])
    ref_mesh = GLPoints3D(vertices=ref_vs,
                          edges=State.getKey('/edges', None),