Using Axl from another application

In this section, we illustrate how Axl library and data can be used from an external application. The corresponding file is axl/test/axlExpl/torus.cpp.

Header files

To define the plugin manager and the objects to be used, some header files need to be included:

#include <axl-config.h>        // For AXL_PLUGIN_DIR, AXL_DATA_DIR
#include <axlCore/axlReader.h>  // Generic data reader
#include <axlCore/axlWriter.h>  // Generic data writer
#include <axlCore/axlFactoryRegister.h>      // Factory of data
#include <dtkCoreSupport/dtkPluginManager.h> // Plugin manager
#include <axlCore/axlPoint.h>  // Definition of axlPoint
#include <axlCore/axlTorus.h>  // Definition of axlTorus

The file axl-config.h define the macro AXL_PLUGIN_DIR corresponding to the folder of the plugins and AXL_DATA_DIR corresponding to the folder of the data.

Loading the plugins

We set up the plugin manager and load the plugins:

//    // Loading of Axel plugins
//    dtkPluginManager::instance()->setPath(AXL_PLUGIN_DIR);
//    dtkPluginManager::instance()->initializeApplication();
//    dtkPluginManager::instance()->initialize();
//    axlFactoryRegister::initialized();

Reading data

We read the file torus.axl from the folder AXL_DATA_DIR:

    //Reading input file
    qDebug()<<"Reading file"<<QString(AXL_DATA_DIR)+"/torus.axl";
    axlReader *obj_reader = new axlReader();
    obj_reader->read(QString(AXL_DATA_DIR)+"/torus.axl");
    QList<axlAbstractData *> list = obj_reader->dataSet();

The list of objects, which have been read, is list.

Manipulating data

We output the description of the first object in the read list, which should be a torus. We cast it into an axlTorus and get its center. The color of the center point and its size are changed:

    // Print description of list[0]
    qDebug()<<list.at(0)->description();

    //Convertion of generic object to a Torus
    axlTorus* axltorus = dynamic_cast<axlTorus*>(list.at(0));
    axlPoint* P= axltorus->centerPoint();
    P->setColor(1.0,0,0);
    P->setSize(0.08);
    qDebug()<< " Point:"<<P->x()<<P->y()<<P->z();

Saving data

In the last steps, we save all the objects, which have been read and the center point in the file tmp.axl:

    //Writing output file
    axlWriter *obj_writer = new axlWriter();
    foreach(axlAbstractData* o, list)
        obj_writer->addDataToWrite(o);
    obj_writer->addDataToWrite(P);