INET Framework for OMNeT++/OMNEST
inet::visualizer::PhysicalEnvironmentOsgVisualizer Class Reference

#include <PhysicalEnvironmentOsgVisualizer.h>

Inheritance diagram for inet::visualizer::PhysicalEnvironmentOsgVisualizer:
inet::visualizer::PhysicalEnvironmentVisualizerBase inet::visualizer::VisualizerBase

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void refreshDisplay () const override
 
- Protected Member Functions inherited from inet::visualizer::PhysicalEnvironmentVisualizerBase
- Protected Member Functions inherited from inet::visualizer::VisualizerBase
virtual int numInitStages () const override
 
virtual Coord getPosition (const cModule *networkNode) const
 
virtual Coord getContactPosition (const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const
 
virtual Quaternion getOrientation (const cModule *networkNode) const
 
virtual void mapChunks (const Ptr< const Chunk > &chunk, const std::function< void(const Ptr< const Chunk > &, int)> &thunk) const
 

Protected Attributes

bool enableObjectOpacity = false
 
- Protected Attributes inherited from inet::visualizer::PhysicalEnvironmentVisualizerBase
const physicalenvironment::IPhysicalEnvironmentphysicalEnvironment = nullptr
 
bool displayObjects = false
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizationTargetModule = nullptr
 
cModule * visualizationSubjectModule = nullptr
 
const char * tags = nullptr
 

Member Function Documentation

◆ initialize()

void inet::visualizer::PhysicalEnvironmentOsgVisualizer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::PhysicalEnvironmentVisualizerBase.

33 {
35  if (!hasGUI()) return;
36  if (stage == INITSTAGE_LOCAL)
37  enableObjectOpacity = par("enableObjectOpacity");
38 }

◆ refreshDisplay()

void inet::visualizer::PhysicalEnvironmentOsgVisualizer::refreshDisplay ( ) const
overrideprotectedvirtual
41 {
42  // only update after initialize
43  if (physicalEnvironment != nullptr && getSimulation()->getEventNumber() == 0 && displayObjects) {
45  for (int i = 0; i < physicalEnvironment->getNumObjects(); i++) {
46  const IPhysicalObject *object = physicalEnvironment->getObject(i);
47  const ShapeBase *shape = object->getShape();
48  const Coord& position = object->getPosition();
49  const Quaternion& orientation = object->getOrientation();
50  const RotationMatrix rotation(orientation.toEulerAngles());
51  const double opacity = enableObjectOpacity ? object->getOpacity() : 1.0;
52  // cuboid
53  const Cuboid *cuboid = dynamic_cast<const Cuboid *>(shape);
54  if (cuboid != nullptr) {
55  auto size = cuboid->getSize();
56  auto drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3d(0, 0, 0), size.x, size.y, size.z));
57  auto stateSet = inet::osg::createStateSet(object->getFillColor(), opacity);
58  drawable->setStateSet(stateSet);
59  auto geode = new osg::Geode();
60  geode->addDrawable(drawable);
61  auto pat = inet::osg::createPositionAttitudeTransform(position, orientation);
62  pat->addChild(geode);
63  scene->addChild(pat);
64  }
65  // sphere
66  const Sphere *sphere = dynamic_cast<const Sphere *>(shape);
67  if (sphere != nullptr) {
68  double radius = sphere->getRadius();
69  auto drawable = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(position.x, position.y, position.z), radius));
70  drawable->setStateSet(inet::osg::createStateSet(object->getFillColor(), opacity));
71  auto geode = new osg::Geode();
72  geode->addDrawable(drawable);
73  scene->addChild(geode);
74  }
75  // prism
76  const Prism *prism = dynamic_cast<const Prism *>(shape);
77  if (prism != nullptr) {
78  auto geode = new osg::Geode();
79  auto stateSet = inet::osg::createStateSet(object->getFillColor(), opacity);
80  auto bottomFace = inet::osg::createPolygonGeometry(prism->getBase().getPoints());
81  bottomFace->setStateSet(stateSet);
82  auto topFace = inet::osg::createPolygonGeometry(prism->getBase().getPoints(), Coord(0, 0, prism->getHeight()));
83  topFace->setStateSet(stateSet);
84  geode->addDrawable(bottomFace);
85  geode->addDrawable(topFace);
86  for (auto face : prism->getFaces()) {
87  auto sideFace = inet::osg::createPolygonGeometry(face.getPoints());
88  sideFace->setStateSet(stateSet);
89  geode->addDrawable(sideFace);
90  }
91  auto pat = inet::osg::createPositionAttitudeTransform(position, orientation);
92  pat->addChild(geode);
93  scene->addChild(pat);
94  }
95  // polyhedron
96  const Polyhedron *polyhedron = dynamic_cast<const Polyhedron *>(shape);
97  if (polyhedron != nullptr) {
98  auto geode = new osg::Geode();
99  auto stateSet = inet::osg::createStateSet(object->getFillColor(), opacity);
100  for (auto face : polyhedron->getFaces()) {
101  auto geometry = new osg::Geometry();
102  auto vertices = new osg::Vec3Array();
103  for (auto edge : face->getEdges())
104  vertices->push_back(osg::Vec3d(edge->getP1()->x, edge->getP1()->y, edge->getP1()->z));
105  geometry->setVertexArray(vertices);
106  geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, face->getEdges().size()));
107  geometry->setStateSet(stateSet);
108  geode->addDrawable(geometry);
109  }
110  auto pat = inet::osg::createPositionAttitudeTransform(position, orientation);
111  pat->addChild(geode);
112  scene->addChild(pat);
113  }
114  }
115  }
116 }

Member Data Documentation

◆ enableObjectOpacity

bool inet::visualizer::PhysicalEnvironmentOsgVisualizer::enableObjectOpacity = false
protected

The documentation for this class was generated from the following files:
inet::physicalenvironment::IPhysicalObject::getFillColor
virtual const cFigure::Color & getFillColor() const =0
inet::visualizer::PhysicalEnvironmentVisualizerBase::initialize
virtual void initialize(int stage) override
Definition: PhysicalEnvironmentVisualizerBase.cc:18
inet::physicalenvironment::IPhysicalObject::getShape
virtual const ShapeBase * getShape() const =0
inet::physicalenvironment::IPhysicalObject
Definition: IPhysicalObject.h:19
inet::visualizer::VisualizerBase::visualizationTargetModule
cModule * visualizationTargetModule
Definition: VisualizerBase.h:25
inet::physicalenvironment::IPhysicalEnvironment::getNumObjects
virtual int getNumObjects() const =0
inet::osg::TopLevelScene::getSimulationScene
virtual SimulationScene * getSimulationScene()
Definition: OsgScene.cc:22
inet::physicalenvironment::IPhysicalEnvironment::getObject
virtual const IPhysicalObject * getObject(int index) const =0
inet::visualizer::PhysicalEnvironmentOsgVisualizer::enableObjectOpacity
bool enableObjectOpacity
Definition: PhysicalEnvironmentOsgVisualizer.h:21
inet::visualizer::PhysicalEnvironmentVisualizerBase::physicalEnvironment
const physicalenvironment::IPhysicalEnvironment * physicalEnvironment
Definition: PhysicalEnvironmentVisualizerBase.h:23
inet::visualizer::PhysicalEnvironmentVisualizerBase::displayObjects
bool displayObjects
Definition: PhysicalEnvironmentVisualizerBase.h:24
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::osg::createStateSet
StateSet * createStateSet(const cFigure::Color &color, double opacity, bool cullBackFace)
Definition: OsgUtils.cc:273
inet::osg::createPolygonGeometry
Geometry * createPolygonGeometry(const std::vector< Coord > &points, const Coord &translation)
Definition: OsgUtils.cc:148
inet::osg::createPositionAttitudeTransform
PositionAttitudeTransform * createPositionAttitudeTransform(const Coord &position, const Quaternion &orientation)
Definition: OsgUtils.cc:221