VR-Vantage 3.0 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exampleExtendVisualizerPage

Table of Contents

Overview

This example show how to extend the state model visualizer and turn all the entities in XR mode to red.

Expected Result

exampleExtendVisualizer.png
Extend Visualizer Result

Example details

In this example we derived from the class DtEntityArticulatedStateModelVisualizer to create a new class MyEntityArticulatedStateModelVisualizer. This class overrides the visualizer initialize method to force the entity's id for colorization. This will show that it is overriding the original visualizer. To see the effect switch to XR mode to see all the entities in red.

Note that the extended visualizer must be registered with the DtStateVisualizerFactory in exampleExtendVisualizerPlugin.cxx

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/exampleExtendVisualizer_stealth.bat (on Windows) or ./bin64/exampleExtendVisualizer_stealth.sh (on Linux). Any terrain can be used, but to replicate the image above: Open MaK Data logger and open Raid2021-DIS.lgr. Once Vantage is started, load the Ala Moana terrain, connect to a DIS connection; then switch the observer to "XR" and all the entities will be red.

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

Example Source Files


exampleExtendVisualizerPlugin.cxx

/******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <iostream>
using namespace makVrv;
namespace exampleExtendVisualizer
{
void postInitializeWork(DtDe* de)
{
// We're done with the signal, so disconnect from it
de->signal_postInitialize.disconnect(boost::bind(&postInitializeWork, de));
// Added this to override the DtVrlinkEntityArticulatedStateModelVisualizer
}
void init(DtDe& de)
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
if (de.isInMasterMode())
{
// The custom state visualizer must be registered after the DE's initialization
// is finished, to make sure the default state visualizers have been registered.
de.signal_postInitialize.connect(boost::bind(&postInitializeWork, &de));
}
}
}
{
// Setup the plug-in. Normally, the init function and functionality
// should be in its own library.
return true;
}

exampleExtendVisualizerPlugin.h

/******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEEXTENDVISUALIZER
// Declare & export the plugin initialization function (bool initDeModule(DtDe* de))
namespace makVrv { class DtDe; }

MyEntityArticulatedStateModelVisualizer.h

/******************************************************************************
** Copyright (c) 2022 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
namespace makVrv
{
class DT_DLL_EXAMPLEEXTENDVISUALIZER MyEntityArticulatedStateModelVisualizer :
public DtEntityArticulatedStateModelVisualizer
{
public:
MyEntityArticulatedStateModelVisualizer(DtBaseConnection& simulation,
DtStateListener& listener, int modelSet);
MyEntityArticulatedStateModelVisualizer( DtBaseConnection& simulation,
DtStateListener& listener, DtSceneObjectAgent* sceneObject, int modelSet );
virtual ~MyEntityArticulatedStateModelVisualizer();
virtual void initialize() override;
protected:
};
typedef DtStateVisualizerCreatorTemplate<MyEntityArticulatedStateModelVisualizer>
}

MyEntityArticulatedStateModelVisualizer.cxx

/******************************************************************************
** Copyright (c) 2022 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
namespace makVrv
{
DtBaseConnection& simulation, DtStateListener& listener, int modelSet)
: DtEntityArticulatedStateModelVisualizer(simulation, listener, modelSet)
{
// intentional NOP - visualizers get initialized in initialize()
}
MyEntityArticulatedStateModelVisualizer::MyEntityArticulatedStateModelVisualizer( DtBaseConnection& simulation,
DtStateListener& listener, DtSceneObjectAgent* sceneObject, int modelSet )
: DtEntityArticulatedStateModelVisualizer( simulation, listener, sceneObject, modelSet )
{
// intentional NOP - visualizers get initialized in initialize()
}
MyEntityArticulatedStateModelVisualizer::~MyEntityArticulatedStateModelVisualizer()
{
}
void MyEntityArticulatedStateModelVisualizer::initialize()
{
DtEntityArticulatedStateModelVisualizer::initialize();
std::cout << "MyEntityArticulatedStateModelVisualizer initialized! " << std::endl;
DtEntityArticulatedStateModelVisualizer::setColorizedColor( 1.0, 0.0, 0.0, 1.0 );
}
}

[<< Examples] [Home] [Top of Page]



Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)