Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#if defined(WITH_OSGEARTH) && defined(INET_WITH_VISUALIZATIONOSG)
#include <osg/PositionAttitudeTransform>
#include <osgEarth/GeoTransform>
#include "qtenv/osg/osgscenehandle.h" // omnetpp::getOsgRoot()
#endif

namespace inet {
Expand Down Expand Up @@ -49,7 +50,7 @@ Define_Module(OsgGeographicCoordinateSystem);
void OsgGeographicCoordinateSystem::initialize(int stage)
{
if (stage == INITSTAGE_LOCAL) {
auto mapScene = getParentModule()->getOsgCanvas()->getScene();
auto mapScene = omnetpp::getOsgRoot(getParentModule()->getOsgCanvas()->getScene());
mapNode = osgEarth::MapNode::findMapNode(mapScene);
if (mapNode == nullptr)
throw cRuntimeError("Count not find map node in the scene");
Expand Down
4 changes: 3 additions & 1 deletion src/inet/visualizer/osg/base/SceneOsgVisualizerBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <osg/ShapeDrawable>
#include <osgDB/ReadFile>

#include "qtenv/osg/osgscenehandle.h" // omnetpp::createScene3DNode(osg::Node*)

#include "inet/common/ModuleAccess.h"
#include "inet/visualizer/osg/scene/NetworkNodeOsgVisualizer.h"
#include "inet/visualizer/osg/util/OsgScene.h"
Expand All @@ -28,7 +30,7 @@ void SceneOsgVisualizerBase::initializeScene()
throw cRuntimeError("OSG canvas scene at '%s' has been already initialized", visualizationTargetModule->getFullPath().c_str());
else {
auto topLevelScene = new inet::osg::TopLevelScene();
osgCanvas->setScene(topLevelScene);
osgCanvas->setScene(omnetpp::createScene3DNode(topLevelScene));
const char *clearColor = par("clearColor");
if (*clearColor != '\0')
osgCanvas->setClearColor(cFigure::Color(clearColor));
Expand Down
3 changes: 2 additions & 1 deletion src/inet/visualizer/osg/scene/SceneOsgEarthVisualizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <osgDB/ReadFile>
#include <osgEarth/Capabilities>
#include <osgEarth/Viewpoint>
#include "qtenv/osg/osgscenehandle.h" // omnetpp::getOsgRoot()
#endif // ifdef WITH_OSGEARTH

namespace inet {
Expand Down Expand Up @@ -62,7 +63,7 @@ void SceneOsgEarthVisualizer::initializeScene()
throw cRuntimeError("Could not read earth map file '%s'", mapFileString.c_str());
auto osgCanvas = visualizationTargetModule->getOsgCanvas();
osgCanvas->setViewerStyle(cOsgCanvas::STYLE_EARTH);
auto topLevelScene = check_and_cast<inet::osg::TopLevelScene *>(osgCanvas->getScene());
auto topLevelScene = check_and_cast<inet::osg::TopLevelScene *>(omnetpp::getOsgRoot(osgCanvas->getScene()));
topLevelScene->addChild(mapScene);
mapNode = MapNode::findMapNode(mapScene);
if (mapNode == nullptr)
Expand Down
4 changes: 3 additions & 1 deletion src/inet/visualizer/osg/scene/SceneOsgVisualizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <osg/Group>
#include <osgDB/ReadFile>

#include "qtenv/osg/osgscenehandle.h" // omnetpp::getOsgRoot()

#include "inet/common/ModuleAccess.h"
#include "inet/visualizer/osg/util/OsgScene.h"
#include "inet/visualizer/osg/util/OsgUtils.h"
Expand Down Expand Up @@ -39,7 +41,7 @@ void SceneOsgVisualizer::initialize(int stage)
void SceneOsgVisualizer::initializeScene()
{
SceneOsgVisualizerBase::initializeScene();
auto topLevelScene = check_and_cast<inet::osg::TopLevelScene *>(visualizationTargetModule->getOsgCanvas()->getScene());
auto topLevelScene = check_and_cast<inet::osg::TopLevelScene *>(omnetpp::getOsgRoot(visualizationTargetModule->getOsgCanvas()->getScene()));
topLevelScene->addChild(new inet::osg::SimulationScene());
}

Expand Down
6 changes: 4 additions & 2 deletions src/inet/visualizer/osg/util/OsgScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "inet/visualizer/osg/util/OsgScene.h"

#include "qtenv/osg/osgscenehandle.h" // omnetpp::createScene3DNode(osg::Node*), getOsgRoot()

namespace inet {

namespace osg {
Expand Down Expand Up @@ -35,15 +37,15 @@ SimulationScene *TopLevelScene::getSimulationScene()
SimulationScene *TopLevelScene::getSimulationScene(cModule *module)
{
auto osgCanvas = module->getOsgCanvas();
auto topLevelScene = dynamic_cast<TopLevelScene *>(osgCanvas->getScene());
auto topLevelScene = dynamic_cast<TopLevelScene *>(omnetpp::getOsgRoot(osgCanvas->getScene()));
if (topLevelScene != nullptr)
return topLevelScene->getSimulationScene();
else {
auto simulationScene = new SimulationScene();
topLevelScene = new TopLevelScene();
topLevelScene->addChild(simulationScene);
// NOTE: these are the default values when there's no SceneOsgVisualizer
osgCanvas->setScene(topLevelScene);
osgCanvas->setScene(omnetpp::createScene3DNode(topLevelScene));
osgCanvas->setClearColor(cFigure::Color("#FFFFFF"));
osgCanvas->setZNear(0.1);
osgCanvas->setZFar(100000);
Expand Down
2 changes: 1 addition & 1 deletion src/inet/visualizer/vsg/scene/SceneVsgVisualizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void SceneVsgVisualizer::initializeScene()
{
SceneVsgVisualizerBase::initializeScene();
auto sceneNode = visualizationTargetModule->getOsgCanvas()->getScene();
auto topLevelScene = sceneNode != nullptr ? dynamic_cast<inet::vsg::TopLevelScene *>(sceneNode->getRoot().get()) : nullptr;
auto topLevelScene = dynamic_cast<inet::vsg::TopLevelScene *>(omnetpp::getVsgRoot(sceneNode).get());
Comment thread
tabgab marked this conversation as resolved.
if (topLevelScene == nullptr)
throw cRuntimeError("Cannot find the VSG top level scene");
topLevelScene->addChild(inet::vsg::SimulationScene::create());
Expand Down
2 changes: 1 addition & 1 deletion src/inet/visualizer/vsg/util/VsgScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SimulationScene *TopLevelScene::getSimulationScene(cModule *module)
// Under WITH_VSG the cOsgCanvas scene is an opaque omnetpp::cScene3DNode that
// wraps the VSG scene-root group; recover our TopLevelScene from its root.
auto sceneNode = osgCanvas->getScene();
::vsg::ref_ptr<Group> root = sceneNode != nullptr ? sceneNode->getRoot() : ::vsg::ref_ptr<Group>();
::vsg::ref_ptr<Group> root = omnetpp::getVsgRoot(sceneNode); // null / wrong-backend safe
auto topLevelScene = root ? dynamic_cast<TopLevelScene *>(root.get()) : nullptr;
if (topLevelScene != nullptr)
return topLevelScene->getSimulationScene();
Expand Down