0
votes

I am building a dynamic multi agent simulation in OMNeT and for this I have to create new modules at runtime. The module creation is working, however, the modules created at runtime are not appearing in the 3D visualization.

module "node" is created sucessfully

Does anyone know how to make the module appear in the visualization? Do I have to update the visualization module?

omnet.ini:

[General]
network = AgentNetwork

*.visualizer.osgVisualizer.typename = "IntegratedOsgVisualizer"
*.visualizer.*.mobilityVisualizer.animationSpeed = 1
*.visualizer.osgVisualizer.sceneVisualizer.typename = "SceneOsgEarthVisualizer"
*.visualizer.osgVisualizer.sceneVisualizer.mapFile = "hamburg.earth"

AgentSpawner:

void AgentSpawner::initialize()
{
    cMessage *timer = new cMessage("timer");
    scheduleAt(1.0, timer);
}

void AgentSpawner::handleMessage(cMessage *msg)
{
        cModuleType *moduleType = cModuleType::get("simulations.Agent");
        cModule *module = moduleType->create("node", getParentModule());

        // set up parameters and gate sizes before we set up its submodules
        module->par("osgModel") = "3d/glider.osgb.(20).scale.0,0,180.rot";
        module->getDisplayString().parse("p=200,100;i=misc/aircraft");
        module->finalizeParameters();

        // create internals, and schedule it
        module->buildInside();
        module->callInitialize();
        module->scheduleStart(simTime()+5.0);
}
1

1 Answers

0
votes

The OSG visualization info is maintained totally separately from the actual simulation model module object (that's because the visualization must be ALWAYS optional in the simulation, so make sure your simulation builds fine with OSG totally turned off). This means that an entirely different data structure is built during initialization time from the existing network nodes. As this is done only once during the initialization, dynamically created modules will not have their visualization counterpart data structure.

The code which created the corresponding objects is here.

The solution would be to look up the NetworkNodeOsgVisualizer module in your AgentSpawner code then create and add the corresponding data structures (NetworkNodeOsgVisualization objects). The needed methods (create and add) are there, but sadly they are protected, so you many need to modify the INET code and make them public to be able to call them.