VR-Vantage 2.5 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleCreator

The exampleCreator example uses the creator pattern to cause a derived channel to get created when the display engine creates a channel. Here is the object class:

class MyExampleChannel : public DtOsgChannel
{
public:
friend class MyExampleChannelCreator;
virtual ~MyExampleChannel()
{
}
protected:
MyExampleChannel( DtDe& de, DtOsgWindow* window, DtChannelConfiguration& channelConfig )
: DtOsgChannel( de, window, channelConfig )
{
// Do nothing. This is an example of registering a class using the creator pattern.
// osgViewer::View* view = view();
// osg::Camera* camera = camera();
}
};

Notice the protected constructor. This is because we are going to use a creator to create our channel. Here is the creator for the object class:

class MyExampleChannelCreator : public DtChannelCreator
{
public:
virtual DtChannel* create( DtDe& de, DtWindow* window,
DtChannelConfiguration& config )
{
DtOsgWindow* osgWindow = dynamic_cast<DtOsgWindow*>(window);
if (!osgWindow)
{
return 0;
}
MyExampleChannel* myExampleChannel = new MyExampleChannel(de, osgWindow, config);
// initialize the channel to create the view, root node, observer object,
// setup cameras, etc.
if (myExampleChannel->initialize())
{
return myExampleChannel;
}
else
{
return 0;
}
}
};

This creator is derived from the DtChannelCreator (DtChannel.h):

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/exampleCreator.exe (on Windows) or ./bin64/exampleCreator (on Linux). For more information about running examples, please see Running Applications and Examples.


exampleCreator.cxx

/*****************************************************************************
* Copyright (c) 2012 MaK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <boost/bind.hpp>
// Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace.
using namespace makVrv;
// An example derived channel.
// This shows how to create and register your own channel with the DtDisplayEngine.
// This example demonstrates the Creator Pattern.
class MyExampleChannel : public DtOsgChannel
{
public:
friend class MyExampleChannelCreator;
virtual ~MyExampleChannel()
{
}
protected:
MyExampleChannel( DtDe& de, DtOsgWindow* window, DtChannelConfiguration& channelConfig )
: DtOsgChannel( de, window, channelConfig )
{
// Do nothing. This is an example of registering a class using the creator pattern.
// osgViewer::View* view = view();
// osg::Camera* camera = camera();
}
};
class MyExampleChannelCreator : public DtChannelCreator
{
public:
virtual DtChannel* create( DtDe& de, DtWindow* window,
{
DtOsgWindow* osgWindow = dynamic_cast<DtOsgWindow*>(window);
if (!osgWindow)
{
return 0;
}
MyExampleChannel* myExampleChannel = new MyExampleChannel(de, osgWindow, config);
// initialize the channel to create the view, root node, observer object,
// setup cameras, etc.
if (myExampleChannel->initialize())
{
return myExampleChannel;
}
else
{
return 0;
}
}
};
// A DtVrvApplication wraps up all the components required to build a complete
// VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a
// DtVrvApplicationConfiguration).
//
// This derived application simply overrides the postLoadPluginModules() call
// to register our example channel after the plugins are loaded.
class MyExampleApplication : public DtVrvApplication
{
public:
MyExampleApplication()
{
&MyExampleApplication::postLoadPluginModules, this, _1, _2, _3 );
installPostPluginTransform( functor, "postPluginTransform" );
}
protected:
virtual void postLoadPluginModules( DtDeInitializer& deInit, DtDe& de,
{
// Register the channel creator
DtChannelCreator::registerInstance( *myDe, new MyExampleChannelCreator() );
}
};
int main( int argc,char* argv[] )
{
// Create the example application class.
MyExampleApplication application;
// This causes the plugin manager to load plugins, cause a Display Configuration
// to be realized, creates the default environment, etc.
application.initialize(argc, argv);
// Creates an event loop and begins running it, causing the creation of frames.
application.run();
return 0;
}


Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)