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

#include <NetworkNodeOsgVisualization.h>

Inheritance diagram for inet::visualizer::NetworkNodeOsgVisualization:
inet::visualizer::NetworkNodeVisualizerBase::NetworkNodeVisualization

Classes

class  Annotation
 

Public Member Functions

 NetworkNodeOsgVisualization (cModule *networkNode, bool displayModuleName)
 
virtual osg::Node * getMainPart ()
 
virtual int getNumAnnotations () const
 
virtual void addAnnotation (osg::Node *annotation, osg::Vec3d size, double priority)
 
virtual void removeAnnotation (osg::Node *node)
 
virtual void removeAnnotation (int index)
 
- Public Member Functions inherited from inet::visualizer::NetworkNodeVisualizerBase::NetworkNodeVisualization
 NetworkNodeVisualization (const cModule *networkNode)
 
virtual ~NetworkNodeVisualization ()
 

Protected Member Functions

virtual std::string getOsgModelPath (cModule *networkNode)
 
virtual void updateAnnotationPositions ()
 

Protected Attributes

osg::Vec3d size
 
osg::Group * annotationNode = nullptr
 
std::vector< Annotationannotations
 

Additional Inherited Members

- Public Attributes inherited from inet::visualizer::NetworkNodeVisualizerBase::NetworkNodeVisualization
const cModule * networkNode
 

Constructor & Destructor Documentation

◆ NetworkNodeOsgVisualization()

inet::visualizer::NetworkNodeOsgVisualization::NetworkNodeOsgVisualization ( cModule *  networkNode,
bool  displayModuleName 
)
33  :
34  NetworkNodeVisualizerBase::NetworkNodeVisualization(networkNode)
35 {
36  double spacing = 4;
37  osgText::Text *label = nullptr;
38  if (displayModuleName) {
39  auto font = osgText::Font::getDefaultFont();
40  label = new osgText::Text();
41  label->setCharacterSize(18);
42  label->setBoundingBoxColor(osg::Vec4(1.0, 1.0, 1.0, 1.0));
43  label->setBoundingBoxMargin(spacing);
44  label->setColor(osg::Vec4(0.0, 0.0, 0.0, 1.0));
45  label->setAlignment(osgText::Text::CENTER_BOTTOM);
46  label->setText(networkNode->getFullName());
47  label->setDrawMode(osgText::Text::FILLEDBOUNDINGBOX | osgText::Text::TEXT);
48  label->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
49  for (auto texture : font->getGlyphTextureList()) {
50  texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
51  texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
52  }
53  }
54  osg::Node *osgNode = nullptr;
55  cDisplayString& displayString = networkNode->getDisplayString();
56  if (networkNode->hasPar("osgModel") && strlen(networkNode->par("osgModel")) != 0) {
57  auto osgModelPath = getOsgModelPath(networkNode);
58  auto osgModel = osgDB::readNodeFile(osgModelPath.c_str());
59  if (osgModel == nullptr)
60  throw cRuntimeError("Visual representation osg model '%s' not found", networkNode->par("osgModel").stringValue());
61  const char *osgModelColor = networkNode->par("osgModelColor");
62  if (*osgModelColor != '\0') {
63  auto material = new osg::Material();
64  auto color = cFigure::Color(osgModelColor);
65  osg::Vec4 colorVec((double)color.red / 255.0, (double)color.green / 255.0, (double)color.blue / 255.0, 1.0);
66  material->setAmbient(osg::Material::FRONT_AND_BACK, colorVec);
67  material->setDiffuse(osg::Material::FRONT_AND_BACK, colorVec);
68  material->setAlpha(osg::Material::FRONT_AND_BACK, 1.0);
69  osgModel->getOrCreateStateSet()->setAttribute(material);
70  }
71  auto group = new osg::Group();
72  group->addChild(osgModel);
73  if (displayModuleName) {
74  label->setPosition(osg::Vec3(0.0, spacing, 0.0));
75  auto geode = new osg::Geode();
76  geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
77  geode->addDrawable(label);
78  auto boundingSphere = osgModel->getBound();
79  size = osg::Vec3d(0, 18, 0);
80  annotationNode = new osg::Group();
81  annotationNode->addChild(geode);
82  auto autoTransform = new osg::AutoTransform();
83  // TODO allow pivot point parameterization
84  autoTransform->setPivotPoint(osg::Vec3d(0.0, 0.0, 0.0));
85 // autoTransform->setPivotPoint(osg::Vec3d(image->s() / 2, image->t() / 2, 0.0));
86  autoTransform->setAutoScaleToScreen(true);
87  autoTransform->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
88  autoTransform->setPosition(osg::Vec3d(0.0, 0.0, boundingSphere.radius()));
89  autoTransform->addChild(annotationNode);
90  group->addChild(autoTransform);
91  }
92  osgNode = group;
93  }
94  else {
95  const char *icon = displayString.getTagArg("i", 0);
96  std::string path(icon);
97  path += ".png";
98  path = networkNode->resolveResourcePath(path.c_str());
99  auto image = osgDB::readImageFile(path.c_str());
100  if (image == nullptr)
101  throw cRuntimeError("Cannot find icon '%s' at '%s'", icon, path.c_str());
102  auto texture = new osg::Texture2D();
103  texture->setImage(image);
104  auto geometry = osg::createTexturedQuadGeometry(osg::Vec3(-image->s() / 2, 0.0, 0.0), osg::Vec3(image->s(), 0.0, 0.0), osg::Vec3(0.0, image->t(), 0.0), 0.0, 0.0, 1.0, 1.0);
105  geometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture);
106  geometry->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
107  geometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
108  geometry->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
109  auto geode = new osg::Geode();
110  geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
111  geode->addDrawable(geometry);
112  if (displayModuleName) {
113  label->setPosition(osg::Vec3(0.0, image->t() + spacing, 0.0));
114  geode->addDrawable(label);
115  }
116  size = osg::Vec3d(image->s(), image->t() + spacing + 18, 0);
117  annotationNode = new osg::Group();
118  annotationNode->addChild(geode);
119  auto autoTransform = new osg::AutoTransform();
120  // TODO allow pivot point parameterization
121  autoTransform->setPivotPoint(osg::Vec3d(0.0, 0.0, 0.0));
122 // autoTransform->setPivotPoint(osg::Vec3d(image->s() / 2, image->t() / 2, 0.0));
123  autoTransform->setAutoScaleToScreen(true);
124  autoTransform->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
125  autoTransform->setPosition(osg::Vec3d(0.0, 0.0, 1.0));
126  autoTransform->addChild(annotationNode);
127  osgNode = autoTransform;
128  }
129  auto objectNode = new cObjectOsgNode(networkNode);
130  objectNode->addChild(osgNode);
131  addChild(objectNode);
132  double x = atol(displayString.getTagArg("p", 0));
133  double y = atol(displayString.getTagArg("p", 1));
134  setPosition(osg::Vec3d(x, y, 0.0));
135 }

Member Function Documentation

◆ addAnnotation()

void inet::visualizer::NetworkNodeOsgVisualization::addAnnotation ( osg::Node *  annotation,
osg::Vec3d  size,
double  priority 
)
virtual
171 {
172  annotations.push_back(Annotation(node, size, priority));
173  std::stable_sort(annotations.begin(), annotations.end(), [] (Annotation a1, Annotation a2) {
174  return a1.priority < a2.priority;
175  });
176  auto positionAttitudeTransform = new osg::PositionAttitudeTransform();
177  positionAttitudeTransform->addChild(node);
178  annotationNode->addChild(positionAttitudeTransform);
180 }

Referenced by inet::visualizer::Ieee80211OsgVisualizer::addIeee80211Visualization(), inet::visualizer::InterfaceTableOsgVisualizer::addInterfaceVisualization(), and inet::visualizer::StatisticOsgVisualizer::addStatisticVisualization().

◆ getMainPart()

virtual osg::Node* inet::visualizer::NetworkNodeOsgVisualization::getMainPart ( )
inlinevirtual
46 { return getChild(0); }

◆ getNumAnnotations()

virtual int inet::visualizer::NetworkNodeOsgVisualization::getNumAnnotations ( ) const
inlinevirtual
48 { return annotations.size(); }

◆ getOsgModelPath()

std::string inet::visualizer::NetworkNodeOsgVisualization::getOsgModelPath ( cModule *  networkNode)
protectedvirtual
138 {
139  const char *osgModel = networkNode->par("osgModel");
140  auto firstDot = strchr(osgModel, '.');
141  if (firstDot == nullptr)
142  return std::string(osgModel);
143  else {
144  auto secondDot = strchr(firstDot + 1, '.');
145  if (secondDot == nullptr)
146  return networkNode->resolveResourcePath(osgModel);
147  else {
148  auto path = std::string(osgModel).substr(0, secondDot - osgModel);
149  auto resolvedPath = networkNode->resolveResourcePath(path.c_str());
150  auto pseudoLoader = std::string(osgModel).substr(secondDot - osgModel);
151  return resolvedPath + pseudoLoader;
152  }
153  }
154 }

Referenced by NetworkNodeOsgVisualization().

◆ removeAnnotation() [1/2]

void inet::visualizer::NetworkNodeOsgVisualization::removeAnnotation ( int  index)
virtual
195 {
196  auto it = annotations.begin() + index;
197  auto node = (*it).node;
198  annotations.erase(it);
199  annotationNode->removeChild(node->getParent(0));
201 }

◆ removeAnnotation() [2/2]

void inet::visualizer::NetworkNodeOsgVisualization::removeAnnotation ( osg::Node *  node)
virtual
183 {
184  for (auto it = annotations.begin(); it != annotations.end(); it++) {
185  if ((*it).node == node) {
186  annotations.erase(it);
187  break;
188  }
189  }
190  annotationNode->removeChild(node->getParent(0));
192 }

Referenced by inet::visualizer::Ieee80211OsgVisualizer::removeIeee80211Visualization(), inet::visualizer::InterfaceTableOsgVisualizer::removeInterfaceVisualization(), and inet::visualizer::StatisticOsgVisualizer::removeStatisticVisualization().

◆ updateAnnotationPositions()

void inet::visualizer::NetworkNodeOsgVisualization::updateAnnotationPositions ( )
protectedvirtual
157 {
158  double spacing = 4;
159  double totalHeight = 0;
160  for (auto annotation : annotations) {
161  // TODO what should be the default pivot point? double dx = -annotation.size.x() / 2;
162  double dx = 0;
163  double dy = size.y() + spacing + totalHeight;
164  auto positionAttitudeTransform = static_cast<osg::PositionAttitudeTransform *>(annotation.node->getParent(0));
165  positionAttitudeTransform->setPosition(osg::Vec3d(dx, dy, 0));
166  totalHeight += annotation.size.y() + spacing;
167  }
168 }

Referenced by addAnnotation(), and removeAnnotation().

Member Data Documentation

◆ annotationNode

osg::Group* inet::visualizer::NetworkNodeOsgVisualization::annotationNode = nullptr
protected

◆ annotations

std::vector<Annotation> inet::visualizer::NetworkNodeOsgVisualization::annotations
protected

◆ size

osg::Vec3d inet::visualizer::NetworkNodeOsgVisualization::size
protected

The documentation for this class was generated from the following files:
inet::visualizer::NetworkNodeOsgVisualization::getOsgModelPath
virtual std::string getOsgModelPath(cModule *networkNode)
Definition: NetworkNodeOsgVisualization.cc:137
inet::visualizer::NetworkNodeOsgVisualization::annotationNode
osg::Group * annotationNode
Definition: NetworkNodeOsgVisualization.h:36
inet::visualizer::NetworkNodeOsgVisualization::size
osg::Vec3d size
Definition: NetworkNodeOsgVisualization.h:35
inet::visualizer::NetworkNodeVisualizerBase::NetworkNodeVisualization::networkNode
const cModule * networkNode
Definition: NetworkNodeVisualizerBase.h:23
inet::visualizer::NetworkNodeOsgVisualization::annotations
std::vector< Annotation > annotations
Definition: NetworkNodeOsgVisualization.h:37
inet::DiffservUtil::Color
Color
Definition: DiffservUtil.h:17
inet::visualizer::NetworkNodeOsgVisualization::updateAnnotationPositions
virtual void updateAnnotationPositions()
Definition: NetworkNodeOsgVisualization.cc:156