Skip to content

Xaval v0.5

Pre-release
Pre-release
Compare
Choose a tag to compare
@habbes habbes released this 03 Jun 21:17
· 133 commits to master since this release

Xaval v0.5 Release

Xaval library reorganized

The Xaval "standard" library has been reorganised around a root xaval module.

The image source and image viewer are now accessible under the io submodule: xaval.io.imageViewer and xaval.io.imageSource and the widget manager is directly accessible as xaval.widgets.

The entire module looks like this:

Reference Description
xaval.cv OpenCv module
xaval.widgets widget manager
xaval.io.imageViewer image viewer
xaval.io.imageSource image source
xaval.core.widget.createWidgetTemplate widget template factory function

Note: While cv is part of the xaval module, it's also still accessible from the global scope.

Note: This organisation might change in future releases as I'm still thinking of better ways to go about it.

WidgetManager's new API

Changes were made to the WidgetManager to make it more useful in managing widgets on the screen. Here's the new API:

Method Description
widgets.define(name, opts) creates and registers a new template. Returns the created template
widgets.setTemplate(name, tpl) registers a widget template
widgets.getTemplate(name) gets the template registered with the specified name
widgets.create(name) creates a new widget from the specified template and adds the template to manager. Returns the widget's id.
widgets.add(widget) Adds a widget instance to the manager and returns the widget's assigned id. Displays the widget on screen.
widgets.get(id) gets a widget by its assigned id
widgets.hide(id) hides widget with the specified id
widgets.hideAll() hides all widgets in the manager
widgets.show(id) displays widget with the specified id
widgets.showAll() shows all widgets in the manager
widgets.remove(id) remove widget with specified id (also removes from DOM)
widgets.removeAll() removes all widgets in the manager

ImageViewer is now a DataSink

The ImageViewer implements the DataSink interface, this basically means that it has a next(value) method and it can there for be piped to a DataSource or used as an Observer.
If the value passed to ImageViewer.next(value) is cv.Mat object, it will be deleted to clean up memory. This assumes that the image viewer is used as the last node in a pipeline.

Improved widgets I/O

Multiple outputs

Widgets now support multiple outputs. Ouputs now have to be declared similar to how inputs are declared. And consequently the onUpdate callback must return an object which a key for each output:

widgets.define('Example', {
   // ... other opts
   outputs: ['output1', 'output2'],
   onUpdate (ctx) {
      // do stuff ...
      return {
         output1: something,
         output2: somthingElse
     }
}

Widgets data sources and sinks for pipeline support

Widgets inputs and outputs now expose DataSinks and DataSources respectively. You can pipe some source or observable to a widget's input and pipe a widget's output to some destination data sink or observer.

For example:

someSource.pipe(widget.inputs.image);
widget.outputs.image.pipe(imageViewer);

To achieve this, there's widget.inputs object that map inputs to objects implementing the next(value) method allowing them to be used as data sinks or observers. Similarly widget.outputs maps outputs to data sources, implementing pipe(dest), subscribe(observer) and exposing an observable property.

The following table summarises the changes and additions made to the WidgetModel's API:

Method/Property Description
widget.observable now emits the entire outputs object returned from onUpdate(ctx)
widget.pipe(dest) pipes the outputs object to the destination whenever an update occurs. Returns the dest object to enable chaining: widget.pipe(dest).pipe(otherDest)
widget.subscribe(observer) shortcut for widget.observable.subscribe(observer)
widget.inputs[name] DataSink attached to the specified input
widget.inputs[name].next(value) pushes the value to the specified input (and updates the widget)
widget.outputs[name] DataSource attached to the specified output
widget.outputs[name].pipe(dest) pipes the specified output to the specified DataSink. Returns the dest object.
widget.outputs[name].observable observable attached to the output
widget.outputs[name].subscribe(observer) shortcut for widget.outputs[name].observable.subscribe(observer)