Package com.luciad.fusion.engine


package com.luciad.fusion.engine

This package provides the LuciadFusion engine. The LuciadFusion engine is the part of the LuciadFusion product that takes the original data as input and processes it, so that it can be later served by the LuciadFusion server part. This process is often referred to as the data fusion process, or fusion for short. The original data are the assets, each with one or more sources. The processed output data is a coverage. The role of the engine in a typical LuciadFusion setup is shown in the image below:

A typical LuciadFusion setup

The LuciadFusion engine is represented by the ALfnEngine class. To start fusing data with it, the necessary asset and coverage metadata need to be created first and added to the Tile Store, LuciadFusion's main data storage component. The asset metadata identifies your data sources,while the coverage metadata identifies the intended result of the data fusion process. Once this metadata is created, the engine can be started.

The example code illustrates these steps in more detail. Its main purpose is to illustrate the steps you need to take to fuse some data. For brevity, the sample does not perform any error checking, creates a new coverage to store the data, ... . The samples directory in the LuciadFusion release contains more elaborate samples which illustrate how to add all this functionality.

  public static void main(String[] aArgs) throws Exception {
    //Create the environments
    //These are expensive resources.
    //It is best to only create a single instance of each in your application
    ALfnEnvironment environment = ALfnEnvironment.newInstance();
    ALfnEngineEnvironment engineEnvironment = ALfnEngineEnvironment.newInstance(environment);
    ALfnClientEnvironment clientEnvironment = ALfnClientEnvironment.newInstance(environment);

    //Obtain a reference to the tile store
    ALfnTileStore tileStore = getTileStore(clientEnvironment);

    String rasterDataToFuse = "Data/Dted/Alps/dmed";

    // Create an asset.
    TLfnCompositeFormat compositeFormat = engineEnvironment.getCompositeFormat();
    ALfnAssetMetadata asset = compositeFormat.createAsset(rasterDataToFuse, tileStore.query(ASSET));

    // Put the asset in the Tile Store so it can be fused later on.
    asset = tileStore.putResourceMetadata(asset);

    // Create a new coverage containing the previously created asset.
    TLfnRasterCoverageMetadata coverageMetadata =
        TLfnRasterCoverageMetadata.newBuilder()
                                  .addAssetInfo(asset, STATUS_INCOMPLETE)
                                  .id("munchen")
                                  .name("Munchen")
                                  .type(ELfnDataType.IMAGE)
                                  .build();

    // Put the coverage on the Tile Store so it can be fused later on.
    coverageMetadata = tileStore.putRasterCoverageMetadata(coverageMetadata);

    // Create the engine and start fusing the data.
    TLfnEngineFactory engineFactory = new TLfnEngineFactory(engineEnvironment);
    ALfnEngine engine = engineFactory.createEngine(tileStore, coverageMetadata.getId());

    // Start asynchronous fusion.
    Future<Void> future = engine.fuse(null);

    // Report progress.
    Timer progressReporter = new Timer();
    progressReporter.scheduleAtFixedRate(new TimerTask() {
      @Override
      public void run() {
        TLfnProgress progress = engine.getProgress();
        System.out.println("Percentage done: " + progress.getAsFraction() * 100 + "%");
        if (engine.getStatus() == ELfnStatus.COMPLETED || engine.getStatus() == ELfnStatus.FAILED) {
          progressReporter.cancel();
        }
      }
    }, 0, 500);

    // Make sure the program does not exit before the fusion is done.
    future.get();
  }


  /**
   * Returns the tilestore.
   * When not yet available, this method will first create it.
   */
  private static ALfnTileStore getTileStore(ALfnClientEnvironment aClientEnvironment) throws IOException, TLfnServiceException {
    Path tileStorePath = Paths.get(System.getProperty("java.io.tmpdir"), "tilestore");
    URI tileStoreUri = tileStorePath.toUri();

    TLfnClientFactory clientFactory = new TLfnClientFactory(aClientEnvironment);
    TLfnTileStoreProvider tileStoreProvider = new TLfnTileStoreProvider(clientFactory, aClientEnvironment.getEnvironment());
    ALfnTileStore tileStore;
    try {
      tileStore = tileStoreProvider.getTileStore(tileStoreUri);
    } catch (FileNotFoundException e) {
      // When the Tile Store does not yet exists, we create one from scratch.
      TLfnTileStoreUtil.createTileStore(tileStorePath.toFile(), aClientEnvironment.getEnvironment());
      tileStore = tileStoreProvider.getTileStore(tileStoreUri);
    }
    return tileStore;
  }

This package not only provides the ALfnEngine class, but also the factory classes to create such an engine.

Since:
10.0