Skip to content

Switch for application connections

Guillaume Pasero requested to merge switch-app-chain into develop

Summary

This MR proposes a mechanism to easily switch between in-memory and on-disk application connections.

Rationale

The goal is to facilitate the development of OTB processing chains in Python.

Implementation Details

Classes and files

With the function Application::ConnectImage(), a specific kind of connection has been implemented in InputImageParameter (the InputImageListParameter is also supported), it contains:

  • an Application pointer
  • a key for the OutputImageParameter to connect
  • a boolean to set the connection mode: in-memory / on-disk

It allows to build a kind of application pipeline, where we can propagate calls from the last application to the upstream applications. The method Application::Execute() has been modified to propagate Execute() calls. It follows a simple procedure:

  • Discover the list of upstream applications
  • Call Execute() on each of them
  • Handle the input images that have a connection:
    • in-memory mode: pass the image pointer from upstream application to InputImageParameter and disable the OutputImageParameter where it comes from
    • on-disk mode: pass the filename from upstream application to InputImageParameter and enable the OutputImageParameter where it comes from
  • Call WriteOutput() on each upstream application
  • Call our own Application::DoExecute()

This removes the need to call Execute() after each upstream application, we just call ExecuteAndWriteOutput() on the latest application.

The function Application::PropagateConnectMode(bool) has been added to switch between the in-memory (default) and on-disk modes. When no temporary filename has been given in the output image, the connection will always default to in-memory.

Here is a snippet of what we can do in Python:

# in-memory
app1 = otb.Registry.CreateApplication("Smoothing")
app2 = otb.Registry.CreateApplication("Smoothing")

app1.IN = input_image

app2.ConnectImage("in", app1, "out")
app2.OUT = output_image
app2.ExecuteAndWriteOutput()
# on-disk
app1 = otb.Registry.CreateApplication("Smoothing")
app2 = otb.Registry.CreateApplication("Smoothing")

app1.IN = input_image
app1.OUT = temp_image

app2.ConnectImage("in", app1, "out")
app2.OUT = output_image
app2.PropagateConnectMode(False)
app2.ExecuteAndWriteOutput()
Tests

The test pyTvConnectApplications has been updated to demonstrate the new features.

Documentation

TODO: the Python CookBook recipe needs to be updated

Additional notes

Some optional todos:

  • the function CompositeApplication::Connect() should be deprecated and renamed (perhaps Link(), or LinkParameter()) to avoid any confusion.

Copyright

The copyright owner is COPYRIGHT OWNER (OR OWNER'S AGENT) and has signed the ORFEO ToolBox Contributor License Agreement.


Check before merging:

  • All discussions are resolved
  • At least 2 👍 votes from core developers, no 👎 vote.
  • The feature branch is (reasonably) up-to-date with the base branch
  • Dashboard is green
  • Copyright owner has signed the ORFEO ToolBox Contributor License Agreement
Edited by Guillaume Pasero

Merge request reports

Loading