VR-Vantage
Loading...
Searching...
No Matches
exampleEmbeddedSlave

Overview

This example shows how to create your own QT application and embed a VR-Vantage slave display engine in it. Use any master VR-Vantage application (VR-Vantage XR, VR-Vantage or VR-Vantage IG for example) to control the visuals embedded in this application.

Expected Result

Embedded Slave Result

Example details

Create and show the main application:

QApplication app(argc, argv);
mainWindow.showMaximized();
A main window class.
Definition exampleEmbeddedSlaveMainWindow.h:32

Run the application:

return app.exec();

The example application has a GUI derived from QMainWindow. This is a very common way of building QT applications.

The main window class owns some key VR-Vantage objects. It owns a DtDe (display engine), which is the core component for adding visualization to any application. It also owns a DtPluginManager, which is responsible for loading all the VR-Vantage plug-ins.

makVrv::DtDe * myDe
Definition exampleEmbeddedSlaveMainWindow.h:69
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
makVrv::DtPluginManager * myPluginManager
Definition exampleEmbeddedSlaveMainWindow.h:70
Loads plugins.
Definition DtPluginManager.h:27

The OpenGL graphics context needs to be owned and managed by the QT main window. We connect it the VR-Vantage display engine (and consequently OSG) via the DtOsgAdapterQtWidget.

makVrv::DtOsgAdapterQtWidget * myMainOSGWidget
Definition exampleEmbeddedSlaveMainWindow.h:47
DtOsgAdapterQtWidget provides the mechanism for embedding an OSG context into a Qt widget.
Definition DtOsgAdapterQtWidget.h:53

In addition, main window owns some QT widgets for menus and toolbars.

QMenu * myFileMenu
Definition exampleEmbeddedSlaveMainWindow.h:72
QAction * myExitAction
Definition exampleEmbeddedSlaveMainWindow.h:74
QToolBar * myFileToolBar
Definition exampleEmbeddedSlaveMainWindow.h:73

The real work begins in the constructor of the main window.

, myPluginManager(0)
, myDe(0)
, myMainOSGWidget(0)
{
createDisplayEngine();
buildGui();
preDisplayEngineInitialize();
initializeDisplayEngine();
postDisplayEngineInitialize();
}

First, create the display engine, prepare it to be put into slave mode, create a plug-in manager, and then initialize load the plug-ins.

void createDisplayEngine()
Non virtual since called from CTOR.
{
DtDeInitializer init;
// Configure DtDeInitializer
init.setDeMode(DtDeInitializer::SlaveMode);
DtLogFileInfo::instance().setAppName( "ExampleEmbeddedSlaveMainWindow" );
DtLogFileInfo::instance().setProtocol( DT_PROTOCOL_SHORT_NAME );
DtLogFileInfo::instance().setSvnRev( SVN_REV );
DtLogFileInfo::instance().setVersion(VANTAGE_VERSION_STRING);
init.setLogFileName( DtLogFileInfo::instance().getLogFileName() );
myDe = new DtDe();
myDe->setDeInitializer(init);
//create the log once we get the DeInitializer since we need this as early as possible
myDe->createDebugLog(init.logFileName(), init.notifyLevel());
myPluginManager = new DtPluginManager(*myDe);
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
#define VANTAGE_VERSION_STRING
Definition igVersion.h:12
#define SVN_REV
Definition svnRev.h:1
myPluginManager->initializePlugins();
}

Now we create the GUI. The interesting thing here is the DtQtIgTickerProvider. This provides us with a "ticker" that ticks the display engine as fast as the QT GUI will go. The rest of the function just sets up menus, toolbars, and the other things that would be part of this application.

{
// Create an IG ticker to tick during Qt's idle time.
DtQtDeTickerProvider& tickerProvider = DtQtDeTickerProvider::instance(*myDe);
tickerProvider.ticker(this);
setWindowTitle(tr("Embedded Slave Example"));
setWindowIcon(QIcon(":/images/Mak-de.png"));
createActions();
createMenus();
createToolBars();
createStatusBar();
}

During the call to preDisplayEngineInitialize(), we override the functionality set up by plug-ins. We want to create to use a DtOsgAdapterQtWidget to own the DtEmbeddedOsgWindow and we do that by installing a new creator with the DtWindowFactory.

// Set the display window creator function to create use the Adapter widget.
DtWindowFactory::instance(*myDe).setCreator(
DtWindowConfiguration::EmbeddedWindow,
Definition exampleEmbeddedSlaveMainWindow.h:78

We have to tell our application framework not to try and create a QApplication, which already exists. We also have to tell it not to create a main window, since that already exists too.

// Register the qApp with the DtQApplicationProvider.
DtQApplicationProvider::instance(*myDe).setQAppInstance(qApp);
// Register null with the DtIgMainWindowProvider so that no main window
// is ever created. This DtDe instance is embedded in a QMainWindow already.
DtDeMainWindowProvider::registerInstance(*myDe, NULL);

Finally, everything is all set up and we can initialize the display engine:

Building the Example

VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is an application. You can run it by running ./bin64/exampleEmbeddedSlave.exe (on Windows) or ./bin64/exampleEmbeddedSlave (on Linux). Start Vantage separatly, load ground_DB II terrain, connect the remote display engine by first enabling from the menu "view->Display Engine Configuration Editor Panel". In the "Display Engine Configuration Editor Panel" click on "Connect To Display Engine", set the host name (leave it to localhost if you are running both on the same PC), click connect. For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleEmbeddedSlaveMain.cxx

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
// Include this header before any Qt header.
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
//
// This example illustrates how to embed a slave display engine into a preexisting
// application.
//
QApplication app(argc, argv);
mainWindow.showMaximized();
//
// Notice how the preexisting applications event loop wasn't changed.
//
return app.exec();
}

exampleEmbeddedSlaveMainWindow.h

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#ifndef exampleEmbeddedSlaveMainWindow_H
#define exampleEmbeddedSlaveMainWindow_H
// Include this header before any Qt header.
#include <vrvCore/DtDe.h>
#include <vrvCore/DtWindow.h>
#include <QtWidgets/QMainWindow>
#include <osg/Group>
#include <osg/Node>
class QAction;
class QMenu;
{
Q_OBJECT
public:
// The adapter widgets. These will become owned and
// deleted by MainWindow.
public slots:
protected:
void buildGui();
virtual void closeEvent(QCloseEvent *event);
void createActions();
void createMenus();
protected:
};
{
public:
{
myWindow = window;
}
protected:
};
#endif
Contains makVrv::DtDe class.
Contains DtQtOSGAdapterWidget class.
Contains DtPluginManager class.
Contains makVrv::DtVrvApplication implementation.
Contains makVrv::DtIgView class.
Contains makVrv::DtWindowConfiguration class.
virtual makVrv::DtWindow * create(makVrv::DtDe &, makVrv::DtWindowConfiguration &)
Create an de window instance.
ExampleEmbeddedSlaveMainWindowCreator(ExampleEmbeddedSlaveMainWindow *window)
Definition exampleEmbeddedSlaveMainWindow.h:80
ExampleEmbeddedSlaveMainWindow * myWindow
Definition exampleEmbeddedSlaveMainWindow.h:89
virtual ~ExampleEmbeddedSlaveMainWindow()
DTOR.
virtual void closeEvent(QCloseEvent *event)
This owns a list of channel configurations.
Definition DtWindowConfiguration.h:27
A creator class for DtWindow instances.
Definition DtWindow.h:131
Abstract Base class.
Definition DtWindow.h:26

exampleEmbeddedSlaveMainWindow.cxx

/******************************************************************************
** Copyright (c) 2023 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
// Include this header before any Qt header.
#include <vrvOsg/vrvOsg.h>
#include <QtWidgets/QApplication>
#include <QtWidgets/QtWidgets>
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <vrvCore/svnRev.h>
#include <vlutil/vlLogFileInfo.h>
using namespace makVrv;
, myPluginManager(0)
, myDe(0)
, myMainOSGWidget(0)
{
createDisplayEngine();
buildGui();
preDisplayEngineInitialize();
initializeDisplayEngine();
postDisplayEngineInitialize();
}
{
{
}
delete myDe;
myDe = 0;
}
{
// Configure DtDeInitializer
DtLogFileInfo::instance().setAppName( "ExampleEmbeddedSlaveMainWindow" );
DtLogFileInfo::instance().setProtocol( DT_PROTOCOL_SHORT_NAME );
DtLogFileInfo::instance().setSvnRev( SVN_REV );
DtLogFileInfo::instance().setVersion(VANTAGE_VERSION_STRING);
init.setLogFileName( DtLogFileInfo::instance().getLogFileName() );
myDe = new DtDe();
//create the log once we get the DeInitializer since we need this as early as possible
myDe->createDebugLog(init.logFileName(), init.notifyLevel());
#ifndef _WIN32
// DI-Guy links in Qt 3, which is incompatible with Qt 4 based applications.
// The following code will exclude the DI-Guy plugin for Linux:
std::list<std::string> excludePlugins;
excludePlugins.push_back("../plugins/release/libvrvDiGuyPlugin.so");
#endif
}
{
// Create an IG ticker to tick during Qt's idle time.
DtQtDeTickerProvider& tickerProvider = DtQtDeTickerProvider::instance(*myDe);
tickerProvider.ticker(this);
setWindowTitle(tr("Embedded Slave Example"));
setWindowIcon(QIcon(":/images/Mak-de.png"));
}
{
// Override Display Engine Functionality
// Set the display window creator function to create use the Adapter widget.
DtWindowFactory::instance(*myDe).setCreator(
DtWindowConfiguration::EmbeddedWindow,
new ExampleEmbeddedSlaveMainWindowCreator(this));
vrvCoreQt::init(*myDe);
vrvOsg::init(*myDe);
// Register the qApp with the DtQApplicationProvider.
DtQApplicationProvider::instance(*myDe).setQAppInstance(qApp);
// Register null with the DtIgMainWindowProvider so that no main window
// is ever created. This DtDe instance is embedded in a QMainWindow already.
DtDeMainWindowProvider::registerInstance(*myDe, NULL);
}
{
myDe->initialize();
}
{
}
{
event->accept();
}
{
DtEmbeddedOsgWindow* pWindow = 0;
DtOsgAdapterQtWidget* pAdapter = 0;
osg::GraphicsContext* sharedContext = 0;
if(de.display())
{
const DtWindowManager::WindowList& windows = de.display()->windowManager().windows();
if(windows.size() > 0)
{
DtOsgWindow* osgView = dynamic_cast<DtOsgWindow*>(windows.front());
if(osgView)
{
sharedContext = osgView->graphicsContext();
}
}
}
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();
traits->sharedContext = sharedContext;
const DtDeInitializer& deInit = de.deInitializer();
traits->doubleBuffer = deInit.doubleBuffer();
traits->vsync = deInit.vsync();
traits->depth = deInit.numDepthBits();
traits->stencil = deInit.numStencilBits();
unsigned short level = deInit.antiAliasingLevel();
if (level == 2 || level == 4 || level == 8 || level == 16 || level == 32)
{
traits->sampleBuffers = 1;
traits->samples = level;
}
else
{
traits->sampleBuffers = 0;
traits->samples = 0;
}
if(wc.name() == "Window 1")
{
// Set the main OSG widget as the central widget.
myWindow->myMainOSGWidget =
DtOsgAdapterQtWidgetCreator::instance( de ).create( de, traits.get(),
DtOsgAdapterQtWidget::createFormatFromTraits(traits.get()),myWindow, 0 );
myWindow->setCentralWidget(myWindow->myMainOSGWidget);
pAdapter = myWindow->myMainOSGWidget;
}
if(pAdapter)
{
pWindow = new DtEmbeddedOsgWindow(de, wc, pAdapter);
if(pWindow)
{
pAdapter->setView(pWindow);
}
}
return pWindow;
}
{
myExitAction = new QAction(QIcon(":/images/exit.png"),tr("E&xit"), this);
myExitAction->setStatusTip(tr("Exit the application"));
connect(myExitAction, SIGNAL(triggered()), this, SLOT(close()));
}
{
myFileMenu = this->menuBar()->addMenu(tr("&File"));
myFileMenu->addAction(myExitAction);
}
{
myFileToolBar = this->addToolBar(tr("File"));
}
{
this->statusBar()->showMessage(tr("Ready"));
}
Contains makVrv::DtDeSharedState class.
Contains makVrv::DtEmbeddedOsgWindow class.
Contains makVrv::DtEventLoop class.
Interaction makVrv::DtModelDefinition class.
Contains makVrv::DtQApplicationProvider class.
Contains makVrv::DtQtDeMainWindow class.
Contains makVrv::DtQtDeTicker class.
Contains makVrv::DtScene class.
Contains makVrv::DtSceneDriver class.
Contains makVrv::DtStaticFileDialog class.
Contains makVrv::DtTerrain class.
Contains makVrv::DtTerrainPatch class.
Contains makVrv::DtViewFactory class.
Contains makVrv::DtWindowManager class.
virtual const std::string & name() const
Get the configuration name.
virtual void setDeInitializer(const DtDeInitializer &initializer)
Set the Display Engine initializer used to initialize the Display Engine. This call will do nothing i...
virtual DtDisplay * display()
DtDisplay accessor. The returned pointer will be NULL before initialize is called,...
virtual void createDebugLog(const std::string &fileName, DtDebugLog::PrintLevel level)
create the debug log for logging information to a file
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
The initialization configuration for the makVrv::DtDe.
Definition DtDeInitializer.h:40
unsigned short numStencilBits() const
unsigned short numDepthBits() const
bool doubleBuffer() const
@ SlaveMode
Definition DtDeInitializer.h:47
unsigned short antiAliasingLevel() const
virtual DtWindowManager & windowManager()
DtWindowManager accessor.
void setView(DtWindow *window)
Set the osg window to forward off events such as resize.
virtual osg::GraphicsContext * graphicsContext()
Get the OSG Graphics Context for the window.
void setExcludedPluginFiles(const std::list< std::string > &files)
void initializePlugins()
Loads libraries in plugin directory. Initialized plugins.
virtual DtQtDeTicker * ticker(QObject *parent)
virtual WindowList & windows()
Get the window list.
Contains necessary ig version information.
DT_DLL_VRVCORE DtTaitBryan level(const DtCoordinateSystem &cs, const DtVector &localOrigin, double topoHeading)
Returns a level orientation with the topographic heading.
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
Contains DLL export macros.
Contains DLL export macros.