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

Overview

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

Expected Result

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) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <iostream>
using namespace makVrv;
namespace exampleExtendVisualizer
{
static vrvSignalsLib::connection postInitializeConnection;
void postInitializeWork(DtDe* de)
{
// We're done with the signal, so disconnect from it
postInitializeConnection.disconnect();
// Added this to override the DtVrlinkEntityArticulatedStateModelVisualizer
DtStateVisualizerFactory::instance(*de).addStateVisualizerCreator(*de,
}
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.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(&postInitializeWork, &de));
}
}
}
{
// Setup the plug-in. Normally, the init function and functionality
// should be in its own library.
exampleExtendVisualizer::init(*de);
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::DtStateVisualizerFactory class.
MyEntityArticulatedStateModelVisualizer 2021 Update - This example no longer uses protocol dependant ...
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
static DtStateVisualizerFactory & instance(DtDe &de)
Get the instance of the factory from its owner de.
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtStateVisualizerCreatorTemplate< MyEntityArticulatedStateModelVisualizer > MyEntityArticulatedStateModelVisualizerCreator
Creator type definition.
Definition MyEntityArticulatedStateModelVisualizer.h:39

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; }
Contains DLL export macros.

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, DtSceneObjectAgent* sceneObject, DtModelSetId modelSet );
virtual ~MyEntityArticulatedStateModelVisualizer();
virtual void initialize() override;
protected:
};
typedef DtStateVisualizerCreatorTemplate<MyEntityArticulatedStateModelVisualizer>
}
Contains makVrv:DtEntityArticulatedStateModelVisualizer class to visualize articulated models....
Contains makVrv:DtEntityStateListener class.
Contains the DtSharedEntityDisplaySettings class declaration.
#define DT_DLL_EXAMPLEEXTENDVISUALIZER
Definition exampleExtendVisualizer.h:18

MyEntityArticulatedStateModelVisualizer.cxx

/******************************************************************************
** Copyright (c) 2022 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
namespace makVrv
{
DtStateListener& listener, DtSceneObjectAgent* sceneObject, DtModelSetId modelSet )
: DtEntityArticulatedStateModelVisualizer( simulation, listener, sceneObject, modelSet )
{
// intentional NOP - visualizers get initialized in initialize()
}
{
}
{
std::cout << "MyEntityArticulatedStateModelVisualizer initialized! " << std::endl;
}
}
Contains makVrv::DtEntityAppearanceMapper class.
The DtBaseConnection is an abstract class.
Definition DtBaseConnection.h:36
State visualizer for entities with articulated models.
Definition DtEntityArticulatedStateModelVisualizer.h:33
virtual void initialize() override
Initialize the visualizer.
virtual void setColorizedColor(float r, float g, float b, float alpha)
Set the color of the model.
Agent class for the scene object class: DtSceneObject.
Definition DtSceneObjectAgent.hpp:32
The DtStateListener is an abstract class. Subclasses implement functionality that will allow data to ...
Definition DtStateListener.h:27
MyEntityArticulatedStateModelVisualizer(DtBaseConnection &simulation, DtStateListener &listener, DtSceneObjectAgent *sceneObject, DtModelSetId modelSet)
CTOR.
virtual void initialize() override
Initialize override.