• No results found

Consider a lazyflow operator that works on multiple images at once. An example would be a sum operator that adds more than two images. Implementing such an operator is simple if the number of images on which the operator works is fixed: just define as many input slots as needed. But if the operator should work with a variable number of inputs the situation is more complicated. To handle this use case lazyflow supports so-called higher level slots. These slots act as a list of inputs. A slot of level 1 consists of a list of input slots, a slot of level 2 consists of lists of lists of input slots. These higher level slots are defined like this:

from l a z y f l o w.gra ph i m p o r t Operator, InputSlot, O u t p u t S l o t

from l a z y f l o w.sty pe i m p o r t A r r a y L i k e

class S u m O p e r a t o r(O p e r a t o r) :

in put = I n p u t S l o t(le vel = 1) # note the l eve l k e y w o r d a r g u m e n t !

Accessing such higher level slots inside and outside an operator is simple since they behave like a Python list:

su mop = S u m O p e r a t o r()

su mop.in put[0] # this a c c e s s e s the f irs t slot i n s i d e the s umo p . i npu t h i g h e r le vel slot

Since higher level slots behave like a Python list they have a certain length or size. To resize a higher level slot to a specified number of elements the resize function can be used:

su mop.in put.r e s i z e(4) # r e s i z e the i npu t l eve l 1 slot to c o n t a i n 4 i npu t sl ots

Such resizing happens automatically when an input level 1 slot is connected to another output level 1 slot. In this case, the input slot is resized to match the number of elements in the output slot to which it is connected.

To allow the developer of an operator or graphical user interface to react to such resize events higher level slots support a wider range of notification events which we present now.

notifyResize

Calls the corresponding callback function before the slot is resized. Such a resize event can occur for example when connecting a slot to a slot of different size or when manually calling the

7.5 Higher level slots

resize method of a slot. The first argument of the function is the slot, the second argument is the old size and the third argument is the new size.

def c a l l b a c k(slot, old_size, n e w _ s i z e) :

# do s o m e t h i n g

pass

o p e r a t o r.l e v e l 1 s l o t.n o t i f y R e s i z e(c a l l b a c k)

notifyResized

Setting up this notification calls the corresponding callback function after the slot is resized. The first argument of the function is the slot, the second argument is the old size and the third argument is the new size.

def c a l l b a c k(slot, old_size, n e w _ s i z e) :

# do s o m e t h i n g

pass

o p e r a t o r.l e v e l 1 s l o t.n o t i f y R e s i z e d(c a l l b a c k)

notifyRemove

Lazyflow will call the specified callback function before a slot is removed. Such a slot removal can happen during a resize event of a slot when the size of the slot is decreased. The first argument of the function is the slot, the second argument is the old size and the third argument is the new size.

o p e r a t o r.l e v e l 1 s l o t.n o t i f y R e m o v e(c a l l b a c k)

notifyRemoved

Calls the given callback function after a slot is removed. The first argument of the function is the slot, the second argument is the old size and the third argument is the new size.

o p e r a t o r.l e v e l 1 s l o t.n o t i f y R e m o v e d(c a l l b a c k)

notifyInserted

Allows to specify a callback function which is called after a slot has been added. Such an event can occur during a resize operation when the size of a slot is increased. The first argument of the function is the slot, the second argument is the old size and the third argument is the new size.

Figure 7.3: Illustrations of the OperatorWrapper class. It replicates the input and outputs slots of a given operator (OperatorA) with a level of +1, i.e. for each slot it creates a list of slots. The slots of this list slots are forwarded to the inner slots of instances of the wrapped operator.

notifyPreInsertion

Calls the given callback function immediately before a slot is going to be inserted into a multi- slot. Same signature as the notifyInserted signal.

o p e r a t o r.l e v e l 1 s l o t.n o t i f y P r e I n s e r t i o n(c a l l b a c k)