The DtTerrainPageSignaler has signals that are triggered when pages from a database page in and out. The signaler will raise signals for anything that is derived from osg::PagedLOD, for example TerraPage (TXPPagedLOD). It also works with DtHierarchicalPagedLod (which does not derive from osg::PagedLOD). This example demonstrates how to listen in on DtTerrainPageSignaler signals and do some custom processing on those pages.
This example is best run with a database that has Proxy Nodes (external references) in it. This can be MetaFlight, TerraPage, etc. When a child of a Page pages in (that is, data for it has been loaded from the disk and the child added to the scenegraph as child of the page), we look for proxy nodes underneath the child. Then, we register the proxy nodes with the page in a map (if it has not been registered already)
When the children are about to page out (i.e. are going to be removed from underneath the page, and hence the scenegraph), we look for proxy nodes again, and remove them from the map.
Looking for proxy nodes is just an illustration. One can look for other types of nodes (e.g. grab at light point nodes and turn them on/off), track what pages are paged in/out, etc.
This example is a plug-in. You can run it by running ./bin64/exampleOsgTerrainPaging_stealth.bat (on Windows) or ./bin64/exampleOsgTerrainPaging_stealth.sh (on Linux). Once Vantage is started, load a MetaFlight terrain database (for example BDesign3dNevada.mft from the supplemental data package).
#include <vlutil/vlPerformanceStats.h>
#include <boost/bind/bind.hpp>
#include <unordered_set>
#include <unordered_map>
#include <osg/ProxyNode>
class PagedLODsProcessor
{
public:
PagedLODsProcessor();
~PagedLODsProcessor();
void printDetails(void);
void printDetailsTimed(void);
private:
void slot_childPagedIn(const osg::Group* page, const osg::Node* child);
void slot_childAboutToPageOut(const osg::Group* page, const osg::Node* child);
typedef std::vector<vrvSignalsLib::connection> Connections;
Connections myConnections;
typedef std::unordered_set<osg::ProxyNode*> SetProxyNodes;
typedef std::unordered_map<osg::Node*, SetProxyNodes> MapLODsToProxyNodes;
MapLODsToProxyNodes myMapLODsToProxyNodes;
void connectSignals(void);
DtTimedSection myTimer;
};
PagedLODsProcessor::PagedLODsProcessor()
: myDe(0)
{
}
void PagedLODsProcessor::printDetails(void)
{
unsigned int count = 0;
for(MapLODsToProxyNodes::const_iterator it = myMapLODsToProxyNodes.begin(); it != myMapLODsToProxyNodes.end();++it)
{
const SetProxyNodes& proxyNodes = it->second;
count += proxyNodes.size();
}
std::cout<<"Num of Pages: "<<myMapLODsToProxyNodes.size()<<std::endl;
std::cout<<"Num of Proxy Nodes:"<<count<<std::endl;
}
void PagedLODsProcessor::printDetailsTimed()
{
static const float duration = 2.0;
static double elapsedTime = 0;
static double lastTime = 0;
double curr = myDe->simulationTime();
elapsedTime += (curr-lastTime);
lastTime = curr;
if (elapsedTime>duration)
{
printDetails();
elapsedTime = 0;
}
}
PagedLODsProcessor::~PagedLODsProcessor()
{
for(auto& conn : myConnections)
{
conn.disconnect();
}
myConnections.clear();
printDetails();
}
void PagedLODsProcessor::init(
DtDe* de)
{
myDe = de;
connectSignals();
}
void PagedLODsProcessor::connectSignals()
{
myConnections.push_back(signaler.
signal_childPagedIn.connect(boost::bind(&PagedLODsProcessor::slot_childPagedIn,
this, boost::placeholders::_1, boost::placeholders::_2)));
myConnections.push_back(signaler.
signal_childAboutToPageOut.connect(boost::bind(&PagedLODsProcessor::slot_childAboutToPageOut,
this, boost::placeholders::_1, boost::placeholders::_2)));
}
void PagedLODsProcessor::slot_childPagedIn(const osg::Group* page, const osg::Node* child)
{
osg::Group* pageNonConst = const_cast<osg::Group*>(page);
osg::Node* childNonConst = const_cast<osg::Node*>(child);
if (myMapLODsToProxyNodes.find(pageNonConst) == myMapLODsToProxyNodes.end())
{
myMapLODsToProxyNodes.insert(std::make_pair(pageNonConst, SetProxyNodes()));
}
childNonConst->accept(visitor);
for(ProxyNodes::const_iterator it = proxyNodes.begin(); it != proxyNodes.end(); ++it)
{
osg::ProxyNode* node = *it;
if (node->getNumFileNames()>0)
{
std::cout<<"Proxy node filename: "<< myDe->dePathConfiguration().resolvePath( node->getFileName(0) ) <<std::endl;
}
myMapLODsToProxyNodes[pageNonConst].insert(node);
}
}
void PagedLODsProcessor::slot_childAboutToPageOut(const osg::Group* page, const osg::Node* child)
{
osg::Group* pageNonConst = const_cast<osg::Group*>(page);
osg::Node* childNonConst = const_cast<osg::Node*>(child);
ASSERT_PREDICATE(myMapLODsToProxyNodes.find(pageNonConst) != myMapLODsToProxyNodes.end());
if (myMapLODsToProxyNodes.find(pageNonConst) == myMapLODsToProxyNodes.end())
{
std::cout<<"Page not registered"<<std::endl;
return;
}
childNonConst->accept(visitor);
for(ProxyNodes::const_iterator it = proxyNodes.begin(); it != proxyNodes.end(); ++it)
{
osg::ProxyNode* node = *it;
ASSERT_PREDICATE(myMapLODsToProxyNodes[pageNonConst].find(node) != myMapLODsToProxyNodes[pageNonConst].end());
if (myMapLODsToProxyNodes[pageNonConst].find(node) != myMapLODsToProxyNodes[pageNonConst].end())
{
myMapLODsToProxyNodes[pageNonConst].erase(node);
}
}
}
static PagedLODsProcessor processor;
{
processor.init(de);
std::cout<<"Initialized Osg Terrain Paging Callbacks!!"<<std::endl;
de->
signal_postTick.connect(boost::bind(&PagedLODsProcessor::printDetailsTimed, &processor));
}
{
{
}
}
{
{
return true;
}
return false;
}
#define ASSERT_PREDICATE(p)
Definition DtAssert.h:28
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::DtHierarchicalPagedLod class.
Contains makVrv::DtOsgNodeObserver class.
Base class to provide boost signal/slot management.
Contains makVrv::DtTerrainPageSignaler class.
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_postTick
Definition DtDe.h:549
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
bool featureSupported(DeFeatures feature) const
Check to see if a feature is supported.
@ Features_3D
Definition DtDeInitializer.h:58
Definition DtTerrainPageSignaler.h:31
boost::signalslib::signal< void(const osg::Group *page, const osg::Node *child)> signal_childAboutToPageOut
Definition DtTerrainPageSignaler.h:57
static DtTerrainPageSignaler & instance(DtDe &)
Get the global instance for this signaler.
boost::signalslib::signal< void(const osg::Group *page, const osg::Node *child)> signal_childPagedIn
signal when a child is paged in (i.e. added to the scenegraph)
Definition DtTerrainPageSignaler.h:53
Utility class to find all proxy nodes nodes underneath a node.
Definition exampleNodeVisitor.h:24
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains declarations for plugin initialization functions.
void initCallbacks(makVrv::DtDe *de)
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)