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

Overview

This DtDistributedDraw driver owns a DtExampleDrawObject, and is responsible for keeping track of the draw object's state and creating or destroying it when the driver is started or stopped.

Expected Result

Distributed Draw Result

Example details

DtExampleDrawObject is the implementation of the distributed draw object. When a DtExampleDrawObjectAgent is created on the master, an exampleDrawObject is created locally on each display engine.

Building the Example

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

Running the Example

This example is a plug-in. You can run it by running ./bin64/exampleDistributedDraw_stealth.bat and ./bin64/exampleDistributedDraw_slave.bat (on Windows) or ./bin64/exampleDistributedDraw_stealth.sh and ./bin64/exampleDistributedDraw_slave.sh (on Linux). In Vantage, load Ground_DB II terrain than from the "Observer Views" panel click on "import and append views" and select "exampleDrawObjectsGroundDbView.osrx" then click on "remoteGraphicsView". If you also started "exampleDistributedDraw_slave", 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. Press the "F" key to create a sphere and see it display on both window.

For more information about running examples, please see Running Applications and Examples.

Example Source Files


DtExampleShaderManager.cxx

// /******************************************************************************
// ** Copyright (c) 2019 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#ifndef DtDistributedDrawDriver_H_
#define DtDistributedDrawDriver_H_
using namespace makVrv;
// This driver owns a DtExampleDrawObject, and is responsible for keeping track of
// the draw object's state & creating or destroying it when the driver is started or stopped.
{
public:
const std::string& instanceName);
virtual const std::string& className() const;
virtual void drawRandomSphere();
protected:
virtual bool onStart();
virtual bool onStop();
virtual void slot_displayEngineAdded( const DtDeRecord& igRecord );
virtual bool onTick();
virtual void updateSphere();
};
#endif
Contains makVrv:DtAgentManager class.
Contains makVrv:DtDriver class.
Definition DtDistributedDrawDriver.h:21
virtual void updateSphere()
Utility function add a sphere at location x,y,z in the scene.
virtual bool onTick()
Stub implementation since this driver doesn't have anything that needs updating.
virtual bool onStart()
DtDistributedDrawDriver(DtAgentManager &agentManager, const std::string &instanceName)
CTOR.
DtExampleDrawObjectAgent * myDrawAgent
The draw agent that draws the sphere.
Definition DtDistributedDrawDriver.h:62
virtual bool onStop()
Called when the driver is stopped by the display engine.
bool mySphereInScene
Whether or not a sphere is displayed.
Definition DtDistributedDrawDriver.h:68
virtual void slot_displayEngineAdded(const DtDeRecord &igRecord)
Called when a display engine is connected; restarts the driver.
virtual void drawRandomSphere()
double mySphereZ
Definition DtDistributedDrawDriver.h:65
double mySphereY
Definition DtDistributedDrawDriver.h:65
double mySphereX
Saved location of the sphere.
Definition DtDistributedDrawDriver.h:65
virtual ~DtDistributedDrawDriver()
Virtual DTOR.
virtual const std::string & className() const
Get the class name as a string.
The DtAgentManager manages the distributed scene object framework. This includes the objects and upda...
Definition DtAgentManager.h:39
A Record of an IG instance.
Definition DtDeRecord.h:25
The DtDriver is an abstract class. Developers derive from this to create logic that "directs" things ...
Definition DtDriver.h:32
virtual const std::string & instanceName() const
Get this driver's instance name.
DtAgentManager & agentManager()
Get the master scene for this host. Do not create drivers using this agentManager,...
Agent class for the scene object class: DtExampleDrawObject.
Definition DtExampleDrawObjectAgent.hpp:23
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16

DtExampleShaderManager.h

// /******************************************************************************
// ** Copyright (c) 2019 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#ifndef DtExampleDrawObject_H_
#define DtExampleDrawObject_H_
#include <vrvCore/DtDe.h>
#include <osg/Node>
#include <string>
namespace makVrv
{
{
public:
DtExampleDrawObject(DtDe& de, DtUniqueID id);
void drawSphere(double x, double y, double z, double r);
protected:
// Keep track of the node drawSphere creates so that it will be cleaned up properly
osg::ref_ptr<osg::Node> myNode;
};
}
#endif
Contains makVrv::DtDe class.
Contains makVrv::DtUniqueID type.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
Definition DtExampleDrawObject.h:24
void drawSphere(double x, double y, double z, double r)
Draw a sphere centered at x,y,z with radius r.
osg::ref_ptr< osg::Node > myNode
Definition DtExampleDrawObject.h:45
void removeChildFromAllRoots()
Removes the child from all model set roots.
DtExampleDrawObject(DtDe &de, DtUniqueID id)
The Constructor for a distributed object must take a DtDe and a Unique Id.
DtDe & myDe
Definition DtExampleDrawObject.h:42
virtual ~DtExampleDrawObject()
DTOR.

exampleCustomShaders.cxx

exampleCustomShaders.h

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <boost/bind/bind.hpp>
using namespace makVrv;
static vrvSignalsLib::connection postInitializeConnection;
void init(DtDe& de)
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
// We only want to create the example driver if we're running in master mode:
if (de.isInMasterMode())
{
// The driver must be created after the DE's initialization is finished,
// to make sure all the objects it uses exist.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(
&loadDriver, &de));
}
}
{
// Setup the plugin. Normally, the init function and functionality
// should be in its own library.
init(*de);
return true;
}
void loadDriver(DtDe* de)
{
// We're done with the signal, so disconnect from it
postInitializeConnection.disconnect();
// Create the driver that will manage the DtExampleDrawObjectAgents
de->agentManager(), "drawDriver1");
// After the driver is added to the display engine below, the DE will manage
// its memory. The driver will be started automatically when added since we
// set the autoStart property in its CTOR
de->driverManager().addDriver(driver);
// Add a key binding that calls the example driver's draw function:
// The input driver responds to input events by calling key functions. To
// bind a key to an arbitrary function, there are two steps:
// 1. Create a KeyFunction that calls the desired function and add it
// to the input driver
// 2. Add a key binding from some key to the KeyFunction defined in step 1
// to the keymap
// Create the KeyFunction
DtInputDriver& inputDriver = de->driverManager().inputDriver();
keyMapManager.addKeyFunction( "Draw Sphere", boost::bind(
// Bind the above key function to the 'f' key in the default
// ("Observer Frame") key map
DtKeyMap* obsFrame = keyMapManager.findKeyMap( "Observer Frame" );
if ( obsFrame )
{
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_F, "Draw Sphere" );
}
}
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains DtDistributedDrawDriver class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtInputDriver class.
Contains makVrv::DtKeyMap and related classes.
Contains makVrv::DtKeyMapManager class.
DtAgentManager & agentManager()
Get the scene manager.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
This class's main responsibility is to handle keyboard and mouse events from OSG (Qt events are route...
Definition DtInputDriver.h:46
void addKeyBinding(DtKeyMap *map, DtKeyState::KeyType key, const std::string &functionName, DtKeyState::KeyModifier modifiers=DtKeyState::NO_MODIFIER, bool replace=false, DtKeyEvent::KeyEventType eventType=DtKeyEvent::KEY_DOWN)
bind a key down or key up event (possibly modified) to a function name
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
@ Rendering
Definition DtKeyMapManager.h:43
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * findKeyMap(const std::string &mapName)
look up a key map
@ KEY_F
Definition DtKeyState.h:61
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
void loadDriver(DtDe *de)
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)

DtExampleDrawObject.cxx

// /******************************************************************************
// ** Copyright (c) 2024 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#include <osg/Group>
#include <osg/Node>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Material>
namespace makVrv
{
: myDe(de)
, myNode()
{
}
{
// Clear out myNode from the scene
if (myNode.valid())
{
removeChildFromAllRoots();
}
}
{
const DtModelSetRealizationManager& manager = myDe.sharedState().modelSetRealizationManager();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator iter = manager.modelSetRealizations().begin();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator end = manager.modelSetRealizations().end();
while (iter != end)
{
if (iter->second)
{
// Remove the object from the scene graph.
((DtOsgRenderer&)myDe.renderer()).removeNodeFromRoot( myNode.get(),
DtOsgRenderer::visualizerTypeRoot( iter->first, 0 ) );
}
++iter;
}
myNode = 0;
}
void DtExampleDrawObject::drawSphere(double x, double y, double z, double r)
{
// Clear out myNode from the scene if it was there already
if (myNode.valid())
{
removeChildFromAllRoots();
myNode = 0;
}
// Create a sphere with specified radius at the specified location
osg::Geode* geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(x,y,z), r)));
myNode = geode;
// Setting up the diffuse and ambient material properties.
// We are setting up these properties to enable shading on the sphere.
osg::Material* mat = new osg::Material();
mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.25f, 0.40f, 0.55f, 1.0f));
mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.5f, 0.8f, 0.35f, 1.0f));
// Add material properties that are already setup to the sphere.
geode->getOrCreateStateSet()->setAttributeAndModes(mat);
const DtModelSetRealizationManager& manager = myDe.sharedState().modelSetRealizationManager();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator iter = manager.modelSetRealizations().begin();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator end = manager.modelSetRealizations().end();
while (iter != end)
{
if (iter->second)
{
// Add the object to the root of the scene graph.
((DtOsgRenderer&)myDe.renderer()).addNodeToRoot( myNode.get(),
DtOsgRenderer::visualizerTypeRoot( iter->first, 0 ) );
}
++iter;
}
}
}
Contains makVrv::DtChannelSpecificGroup class.
Contains makVrv::DtDeSharedState class.
Contains makVrv::DtModelSetRealizationManager class.
Contains makVrv::DtOsgRenderer class.
DtModelSetRealizationManager is responsible for tracking which model sets are currently realized....
Definition DtModelSetRealizationManager.h:38
const ModelSetRealizations & modelSetRealizations() const
get the realizations map
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition DtOsgRenderer.h:93
static DtSceneRoot visualizerTypeRoot(DtModelSetId modelSet, int visualizerType)
Definition DtOsgRenderer.h:404

DtDistributedDrawDriver.cxx

// /******************************************************************************
// ** Copyright (c) 2008 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
//
#include <stdlib.h>
DtDistributedDrawDriver::DtDistributedDrawDriver( DtAgentManager& agentManager, const std::string& instanceName )
: DtDriver(agentManager, instanceName)
, myDrawAgent(0)
, mySphereInScene(false)
, mySphereX(0.0)
, mySphereY(0.0)
, mySphereZ(0.0)
{
// Tell the driver to start automatically when added to the DE
setAutoStart(true);
// This driver can't be started or stopped from the GUI; myUserControllableFlag sets this property
myUserControllableFlag = false;
}
{
// Don't need to delete myAgent, since the driver manager guarantees
// that onStop will be called before the driver is deleted.
}
const std::string& DtDistributedDrawDriver::className() const
{
// name must be static, since it's returned by reference
static std::string name("DtDistributedDrawDriver");
return name;
}
{
// Create the distributed draw agent, which will create a DtExampleDrawObject
// on each connected display engine.
// Restore the state of the driver's agent if necessary
{
}
return true;
}
{
// Shutdown cleanly:
{
delete myDrawAgent;
}
return true;
}
{
// Does nothing
return true;
}
{
// When a new display engine is added, we need to restart the driver so that everything is
// correctly created on the new DE.
if (DtDriver::myStartedFlag)
{
stop();
start();
}
}
{
mySphereX = rand() % 1000;
mySphereY = rand() % 1000;
mySphereZ = rand() % 1000;
}
{
// This call will queue the drawSphere function, and during the object update phase
// drawSphere will be called on the DtExampleDrawObject instances.
// Make a note that there's a sphere in the scene so that the driver
// can restore its state correctly if stopped and restarted
}
DtAgentManager & myAgentManager
Definition DtDriver.h:190
void start()
Start the driver. Called by the Master Scene. Calls installAccessories().
void stop()
Stop the driver. Called by the Master Scene. Calls uninstallAccessories().
static DtExampleDrawObjectAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.