Skip to content

HighLevelAPI

thorbenk edited this page Aug 3, 2011 · 11 revisions

How to create layers

From numpy arrays

source = ArraySource(npy_array)
rgb    = ArraySource(npy_rgbarray)

ArraySource wraps the numpy array to provide an asynchronous interface similiar to what the lazyflow graph needs. Currently, npy_array must be 5D with axis order t x y z c.

layerstack = LayerStackModel()

layer1 = GrayscaleLayer( source )
layer1.name = "Raw Data"
layerstack.append(layer1)    

layer2 = RGBALayer(red=rgb[..., 0], green=rgb[..., 1], alpha=rgb[..., 2])
layer2.name = "RGB Layer"
layer2.opacity = 0.5
layerstack.append(layer1)

We define a stack of layers. Currently, tested layer classes are RGBALayer and GrayscaleLayer.

From a lazyflow output slot

nucleisrc   = LazyflowSource(operator1, slot="Data")
membranesrc = LazyflowSource(operator4, slot="Output")

The results are compatible to source and rgb above. LazyflowSource provides the unidirectional interface between the graph and the Qt side.

#Instantiate the volumeeditor

We make an VolumeEditor object, which is a pre-made assembly of all the parts to make a 5D viewer (without the layouting of the widgets), and an VolumeEditorWidget widget, which provides the layout (quad splitter) in addition.

app = QApplication(sys.argv)
self.editor = VolumeEditor(shape, layerstack)
self.widget = VolumeEditorWidget( self.editor )
self.widget.show()
app.exec_()

This is how we can use the internal model of the VolumeEditor object to manipulate the view right from the source code

def randomMove():
    # slicingPos only refers to the spacial axes x, y and z  
    self.editor.posModel.slicingPos = [numpy.random.randint(0,self.data.shape[i]) for i in range(3)]

# move to a random viewing position every second
t = QTimer(self)
t.setInterval(1000)
t.timeout.connect(randomMove)
t.start()

For a full example, see https://github.com/Ilastik/volumeeditor/blob/master/volumeeditor/volumeEditorWidget.py#L258

Clone this wiki locally