Overview
This example shows how to create multiple windows and channels from a plug-in. It demonstrates the use of multiple windows with multiple channels each rendering the same scene, however each channel renders the scene differently.
Expected Result
Multiple Channels Result
Example details
A VR-Vantage application displays one or more windows: floating, embedded or full-screen. Each window is composed of one or more channels. Each channel renders a view into the scene. Each channel has its position, orientation, and other parameters controlled by an observer.
Channels can share observers to display the same view within the scene. However, to render different views into the same scene, different observer instances per channel are required. For this example, to demonstrate how to render different model sets in each channel, multiple channels are created, each with its own observer mode configuration. When creating an observer for a channel, the observer mode is a collection of settings assigned to an observer that will ultimately be used the the channel to render the scene (such as 3-D or 2-D perspective). Among other attributes defined by the observer mode is the model set to be rendered. A model set is a collection of models that are consistent with a given projection mode (2-D or 3-D) and style (out the window or XR, e.g.). Each channel is configured with an observer mode and the observer mode defines which model set is rendered in the channel.
When models are added into the scene, they are generally added to a scene object that manages the model for use as part of one model set. The scene object positions and orients the model in the scene. It is the scene object that defines the model set for the model. When a channel is rendering the scene objects in the scene, the channel's observer will cull out scene objects that do not have a matching model set for the channel. For example, if a channel is configured with the '3-D' observer mode, the channel will only render scene objects with model set 'ModelSet_3D' (0). Scene objects with other model sets will not be rendered within that channel.
The default observer mode configurations are read from a file named 'default_ObserverModes.omcx' located in the '.../appData/settings/stealth' directory.
The two important steps to rendering different scene objects in different channels are:
- Configure the channel with an observermode.
- Specify the model set in the scene object.
This example uses four helper functions to configure the display into multiple windows with multiple channels, each with a different observer (and different observer modes).
Configuration for a single channel Serialized and sent to remote displays as necessary to configure r...
Definition DtChannelConfiguration.h:27
makVrv::DtChannelConfiguration makeChannelConfiguration(makVrv::DtDe &de, double left=0, double right=100, double bottom=0, double top=100)
Helper function creates a channel-configuration with a default name. Channel parameter values are per...
makVrv::DtDe& de,
double left=0,
double right=100,
double bottom=0,
double top=100);
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
This owns a list of channel configurations.
Definition DtWindowConfiguration.h:27
makVrv::DtWindowConfiguration makeWindowConfiguration(makVrv::DtDe &de, int x, int y, unsigned int numChannels=1)
Helper function creates a window-configuration with a default name. The windows position must be spec...
makVrv::DtDe& de,
int x,
int y,
unsigned int numChannels=1);
This owns a list of window configurations.
Definition DtDisplayConfiguration.h:44
makVrv::DtDisplayConfiguration makeDisplayConfiguration(makVrv::DtDe &de, const std::string &name="My Display Configuration")
Helper function creates a display-configuration. This configuration creates multiple windows each wit...
makVrv::DtDe& de,
const std::string& name =
"My Display Configuration");
This owns a list of display engine configurations.
Definition DtVrvApplicationConfiguration.h:33
void makeObserverConfigurations(makVrv::DtVrvApplicationConfiguration &config, makVrv::DtDe &de, const makVrv::DtDisplayConfiguration &displayConfig)
Helper function creates observer configurations for each channel This function iterates through the c...
The helper function to create the channel configurations creates a configuration for each channel with a unique channel name.
std::string cName = DtChannelConfiguration::DefaultChannelString;
DtChannelConfiguration channelConfig(cName);
The channel's viewport is also defined.
channelConfig.setViewport(left, right, bottom, top);
return channelConfig;
The helper function to create the windows first creates a window configuration with a unique window name.
std::string wName = DtWindowConfiguration::DefaultWindowString;
DtWindowConfiguration windowConfig(wName);
Then the type of window, size, and position are set in the window's configuration.
windowConfig.setWindowType(DtWindowConfiguration::Window);
windowConfig.setPosition(x, y);
windowConfig.setSize(400, 300);
For each channel that the window displays, the window configuration is given a channel configuration by calling the helper function for channels.
DtChannelConfigurations& channelConfig = windowConfig.channelConfigurations();
return windowConfig;
The helper function to create the display configuration just creates a configuration and for each window displayed, and is given a window configuration by calling the helper function for windows.
DtDisplayConfiguration dc;
dc.setName(name);
return dc;
The helper function to create the observer configurations iterates through all of the channel configures created above. For each channel configuraiton, it first a creates an observer configuration with a unique observer name.
oName = DtObserverConfiguration::ObserverConfigurationString;
DtObserverConfiguration observerConfig(oName);
The observer mode is defined in the observer configuration.
The mode is a string matching one of the default observer modes read in at application configuration time. Then the configuration is added to the input driver's configuration (which will create all the observers based on the configuarations supplied).
observerConfig.setObserverMode(mode);
config.inputDriverConfiguration().observerConfigurations().add(observerConfig);
This example uses three helper functions to load the geometry files into models and assign those models to scene objects, each for a different model set.
std::string registerModelDefinition(makVrv::DtDe &de, const std::string &dataFile)
Helper function populates a makVrv::DtModelDefinitionManager with a model- description for later use....
void addModelToTheScene(makVrv::DtDe &de, const std::string &modelName)
Helper function to load a geometry file and add it to the scene. This function creates a makVrv::DtSc...
void loadTheScene(makVrv::DtDe &de)
Helper function to load all the models into the scene. For each model filename, this function creates...
The helper function to register the model definitions takes the name of a model geometry file, creates a definition with a unique name, and registers the definition with the display engine.
DtModelDefinition md(modelName.str());
md.setParameter("filename", dataFile);
de.sharedState().addModelDefinition(md);
return modelName.str();
The helper function to load a model into the scene creates a scene object with a unique ID, assigns a model set to the scene object, and adds a model to the scene object. The model is created with a previously registered model definition.
DtSceneObject* sceneObj = new DtSceneObject(de, id);
sceneObj->setModelSet(modelSet);
DtOsgSimpleModel* model = new DtOsgSimpleModel(de, id);
sceneObj->addModel(model, 0);
model->setModelDefinition(modelName);
When the model is added to the scene object, the model is loaded from disk using the model configuration.
The helper function to load the scene just iterates over a list of filenames for models, registering their definitions and generating scene objects for each.
std::vector<std::string>::const_iterator iter(modelFiles.begin());
This example creates a plug-in that will create a custom display layout with multiple windows and overwrites the initialized default.
It is important to note that the custom display configuration must be created and registered after the default application initialization of these configurations but before they are realized. There are two places that this can happen: either a post-plug-in transform or a post-assemble plug-in. After plug-ins are loaded, the post-plug-in transforms are run; after that, the GUI is assembled; then the post-assemble transforms are invoked. The display configurations are realized after the GUI is assembled, so either transform type will work. This example uses a post-plug-in transform (which is also the appropriate place to make changes to the GUI configuration before assembly.
The post-plug-in transform creates the display configurations; removes the default configurations created during application initialization; adds the new display configurations to the application configuration; and then creates and registers a new display engine initializer that will be used actually create the displays.
The plug-in also connects to the boost signal signal_postInitialize, which will fire after the display engine has completed its initialization (including the creation of the new display/windows/channels. The method connected to the post initialize signal will call the helper function loadTheScene(de). It then connects a postTick function to the signal signal_postTick. The post tick function will call inspectDisplayWindows(de), which prints information about the windows and channels (and their observers) to the console. This is called after the first tick to guarantee that the observers have been created and assigned to the channels (postInitialize would have been too soon for that).
Building the Example
VR-Vantage includes prebuilt 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 plugin. You can run the VR-Vantage with this plug-in included by running ./bin64/exampleMultipleChannels.bat (on Windows) or ./bin64/exampleMultipleChannels (on Linux). For more information about running examples, please see Running Applications and Examples.
Learn More
Example Source Files
exampleMultipleChannels.cxx
#include <string>
#include <sstream>
#include <iostream>
static vrvSignalsLib::connection postInitializeConnection;
static vrvSignalsLib::connection postTickConnection;
{
postTickConnection.disconnect();
}
void postInitialize(
DtDe& de)
{
postInitializeConnection.disconnect();
postTickConnection = de.
signal_postTick.connect(boost::bind(&postTick, std::ref(de)));
}
{
}
{
{
if (app)
{
}
}
}
{
return true;
}
Contains makVrv::DtDe class.
#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 makVrv::DtDisplayConfiguration class.
Contains makVrv::DtOsgEmptySceneLogo class.
Contains makVrv::DtVrvApplication implementation.
void destroyAll()
Destroys all channel configurations.
Definition DtConfigurationCollection.h:138
virtual ConfigurationType & add(const ConfigurationType &orig)
Add a Channel configuration.
Definition DtConfigurationCollection.h:68
virtual const std::string & name() const
Get the configuration name.
virtual DT_DECLARE_serialize_FUNCTIONS DtDisplayConfigurations & displayConfigurations()
Declare serialize functions Call via serialize(Archive ar, unsigned int version); Where Archive can b...
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual void setDeInitializer(const DtDeInitializer &initializer)
Set the Display Engine initializer used to initialize the Display Engine. This call will do nothing i...
boost::signalslib::signal< void()> signal_postTick
Definition DtDe.h:549
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
The initialization configuration for the makVrv::DtDe.
Definition DtDeInitializer.h:40
static void setEnabled(bool enabled)
This global method will enable or disable the use of an empty scene overlay for all uses of this clas...
DtDeConfiguration & deConfiguration()
Get the initial de configuration.
const UIConfiguration & masterModeUIConfiguration() const
DtDeInitializer buildInitializer()
Generate a DtDeInitializer from the app config state.
void setDisplayEngineName(const std::string &name)
Set the active local display engine configuration.
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
static DtVrvApplication * findFromDe(DtDe &)
virtual void installPostPluginTransform(const ApplicationTransform &transform, const std::string &id)
Add a transformer that runs after plug-ins are loaded.
boost::function< void(DtDeInitializer &, DtDe &, DtVrvApplicationConfiguration &)> ApplicationTransform
Definition DtVrvApplication.h:147
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
void inspectDisplayWindows(makVrv::DtDe &de)
Helper function to inspect the structure of the display, windows, channels and observers....
Prototypes of utility functions for exampleMultipleChannels.
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
bool myShowStartupScreen
Definition DtVrvApplicationConfiguration.h:42
multipleChannelUtilities.h
#pragma once
#include <string>
{
class DtDe;
class DtVrvApplicationConfiguration;
}
makVrv::DtDe& de,
double left=0,
double right=100,
double bottom=0,
double top=100);
makVrv::DtDe& de,
int x,
int y,
unsigned int numChannels=1);
makVrv::DtDe& de,
const std::string& name =
"My Display Configuration");
Contains makVrv::DtChannelConfiguration class.
Contains makVrv::DtWindowConfiguration class.
multipleChannelUtilities.cxx
#include <sstream>
#include <iostream>
#include <matrix/vlTaitBryan.h>
#include <matrix/vlVector.h>
typedef std::pair<std::string, int> ModeToModelSet;
const std::vector<ModeToModelSet> modesAndSets =
StdVectorCreator< ModeToModelSet >
(ModeToModelSet("3D", 0))
(ModeToModelSet("XR", 1))
(ModeToModelSet("Plan View", 5))
(ModeToModelSet("OTW", 0))
;
const std::string vehicles("/ModelData/Vehicles/Wheeled/");
const std::string boats("/ModelData/Vehicles/Surface/");
const std::string trees("/ModelData/Vegetation/Trees/");
const std::vector<std::string> modelFiles = StdVectorCreator< std::string >
(vehicles + "Fiat_124/Fiat_124.medf")
(vehicles + "SUVLarge/SUVLarge.medf")
(boats + "CruiseShip/CruiseShip.medf")
(vehicles + "ChevyCaprisPolice/Chevy_Capris_Police.medf")
;
DtDe& de,
double left,
double right,
double bottom,
double top)
{
static DtUniqueID id(1);
std::stringstream idName;
idName << " " << id;
cName += idName.str();
channelConfig.setViewport(left, right, bottom, top);
++id;
return channelConfig;
}
DtDe& de,
int x,
int y,
unsigned int numChannels)
{
static DtUniqueID id(1);
std::stringstream idName;
idName << " " << id;
wName += idName.str();
windowConfig.setPosition(x, y);
windowConfig.setSize(400, 300);
switch (numChannels)
{
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
++id;
return windowConfig;
}
{
DtUniqueID id(1);
std::stringstream idName;
std::string oName;
for ( ; wcIter != wcEndIter; ++wcIter )
{
for ( ; ccIter != ccEndIter; ++ccIter )
{
idName.str("");
idName << " " << id++;
oName += idName.str();
const std::string& mode(modesAndSets.at((id - 1) % modesAndSets.size()).first);
observerConfig.setObserverMode(mode);
}
}
}
{
return dc;
}
{
std::cerr << std::endl;
for (DtWindowManager::WindowList::const_iterator witer(windows.begin());
witer != windows.end(); ++witer)
{
std::cerr << "***** WINDOW : ["
<< win->configuration().name() << "]" << std::endl;
for (DtChannelManager::ChannelMap::const_iterator citer(cm.begin());
citer != cm.end(); ++citer)
{
std::cerr << "----- CHANNEL : ["
<< chan->configuration().name() << "]\t";
if (obs)
{
std::cerr << "Model-Set : " << (int)obs->modelSet();
}
else
{
std::cerr << "No observer at this time.";
}
std::cerr << std::endl;
}
std::cerr << std::endl;
}
}
{
static DtUniqueID id(1);
std::stringstream modelName;
modelName << "model " << id;
md.setParameter("filename", dataFile);
++id;
return modelName.str();
}
{
static DtUniqueID id(1);
if (id == 1)
{
}
else if (id == 2)
{
}
else if (id == 3)
{
sceneObj->
setPosition(0, DtVector(0.0f, 0.0f, 100.0f));
}
else if (id == 4)
{
}
osg::DegreesToRadians(-150.0f),
osg::DegreesToRadians(-30.0f),
osg::DegreesToRadians(-10.0f)));
DtModelSetId modelSet = (DtModelSetId)(modesAndSets.at((id - 1) % modesAndSets.size()).second);
++id;
}
{
std::vector<std::string>::const_iterator iter(modelFiles.begin());
std::vector<std::string>::const_iterator endr(modelFiles.end());
for (; iter != endr; ++iter)
{
std::cerr << "Adding Model: [" << modelName << "] " << sharedDataPath + *iter << std::endl;
}
}
Contains makVrv::DtChannel class.
Contains makVrv::DtChannelManager class.
Macros for constructing and initializing standard container classes.
Contains makVrv::DtDeSharedState class.
Contains makVrv:DtDisplay class.
Contains makVrv:DtMasterScene class.
Interaction makVrv::DtModelDefinition class.
Contains makVrv::DtModelInstance class.
Contains makVrv::DtObserverConfiguration class.
Contains makVrv::DtObserverObject class declaration.
Contains makVrv::DtOsgSimpleModel class.
Contains makVrv::DtSceneObject class.
Contains makVrv::DtIgView class.
Contains makVrv::DtWindowManager class.
virtual void setObserverName(const std::string &observerName)
Set the observer name.
static const char * DefaultChannelString
Definition DtChannelConfiguration.h:31
The abstract Channel Class.
Definition DtChannel.h:36
std::map< std::string, DtChannel * > ChannelMap
Definition DtChannelManager.h:42
Configurations::const_iterator const_iterator
Definition DtConfigurationCollection.h:29
Configurations::iterator iterator
Definition DtConfigurationCollection.h:28
iterator end()
Definition DtConfigurationCollection.h:116
iterator begin()
Definition DtConfigurationCollection.h:113
virtual void setName(const std::string &name)
Set the configuration name.
virtual const DtDePathConfiguration & dePathConfiguration() const
Return the DtDePathConfiguration.
virtual DtDisplay * display()
DtDisplay accessor. The returned pointer will be NULL before initialize is called,...
virtual DtDeSharedState & sharedState()
Returns the DtDeSharedState object.
virtual std::string sharedDataPath() const
virtual void addModelDefinition(const DtModelDefinition &definition)
DT_DECLARE_ALL_serialize_FUNCTIONS DtWindowConfigurations & windowConfigurations()
Declare serialize functions Call via serialize(Archive ar, unsigned int version); Where Archive can b...
virtual DtWindowManager & windowManager()
DtWindowManager accessor.
A model definition Interaction any number of named parameters, and also can be used to store cached d...
Definition DtModelDefinition.h:45
TODO: This class is used to encapsulate a set of default observer settings and parameters.
Definition DtObserverConfiguration.h:23
static const char * ObserverConfigurationString
Definition DtObserverConfiguration.h:27
This abstract base class defines the interface for OS-specific keyboard and mouse event listeners.
Definition DtObserverObject.h:36
This is a realization of DtModel. It is a model class that is used to create a simple,...
Definition DtOsgSimpleModel.h:39
virtual void setModelDefinition(const std::string &str)
Set the model definition.
A DtSceneObject represents an object that can be positioned in the scene by (possibly) attaching it t...
Definition DtSceneObject.h:45
void setOrientation(int vtx, const DtTaitBryan &orientation)
Sets the orientation of the object and all of it's models.
void setModelSet(DtModelSetId modelSet)
Set the model set this object uses; ignored if isProp is true Make sure this is set BEFORE element ID...
void addModel(DtModel *model, int visualizerType)
Add a model, and indicate the model's visualizerType. The visualizerType is ignored if the scene obje...
void setPosition(int vtx, const DtVector &position)
const DtInputDriverConfiguration & inputDriverConfiguration() const
Get the input driver configuration.
DtChannelConfigurations & channelConfigurations()
Get the channel configurations for this window.
static const char * DefaultWindowString
Definition DtWindowConfiguration.h:31
@ Window
Definition DtWindowConfiguration.h:36
Abstract Base class.
Definition DtWindow.h:26
std::list< DtWindow * > WindowList
Definition DtWindowManager.h:36
virtual WindowList & windows()
Get the window list.
DtConfigurationCollection< DtChannelConfiguration > DtChannelConfigurations
Definition DtWindowConfiguration.h:22